Skip to content

Commit e13c0a9

Browse files
bitmvkmaria-rcks
andauthored
fix(server): keep provider update progress on the latest frame (#26823)
Co-authored-by: maria-rcks <[email protected]>
1 parent 32ce9db commit e13c0a9

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎apps/server/src/provider/providerMaintenanceRunner.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,28 @@ describe("providerMaintenanceRunner", () => {
609609
4_096,
610610
);
611611
assert.strictEqual(ProviderMaintenanceRunner.toProgressLine("x".repeat(300))?.length, 200);
612+
613+
for (const redraw of [
614+
"\r",
615+
"\u001b[G",
616+
"\u001b[0G",
617+
"\u001b[1G",
618+
"\u001b[01G",
619+
"\u001b[999D",
620+
"\u001b[999D\u001b[J",
621+
]) {
622+
const output = `first${redraw}second${redraw}last`;
623+
for (let boundary = 0; boundary <= output.length; boundary++) {
624+
let partialLine = "";
625+
for (const chunk of [output.slice(0, boundary), output.slice(boundary)]) {
626+
partialLine = ProviderMaintenanceRunner.splitOutputLines(partialLine, chunk).partialLine;
627+
}
628+
assert.strictEqual(ProviderMaintenanceRunner.toProgressLine(partialLine), "last");
629+
}
630+
}
631+
for (const incomplete of ["\u001b", "\u001b[", "\u001b[0", "\u001b[01"]) {
632+
assert.strictEqual(ProviderMaintenanceRunner.toProgressLine(`progress${incomplete}`), null);
633+
}
612634
});
613635

614636
it.effect("aborts without running when the installation changed since the advisory", () => {

‎apps/server/src/provider/providerMaintenanceRunner.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,14 @@ export function splitOutputLines(
204204
partialLine: string,
205205
text: string,
206206
): { readonly lines: ReadonlyArray<string>; readonly partialLine: string } {
207-
const parts = (partialLine + text).split(/\r\n|\r|\n/);
207+
const parts = (partialLine + text).replace(/\x1b\[(?:0*1?G|999D)/g, "\r").split(/\r\n|\r|\n/);
208208
return { partialLine: (parts.pop() ?? "").slice(-UPDATE_PARTIAL_LINE_MAX_LENGTH), lines: parts };
209209
}
210210

211211
export function toProgressLine(line: string): string | null {
212+
if (/\x1b(?:\[[0-9]*)?$/.test(line)) {
213+
return null;
214+
}
212215
const text = NodeUtil.stripVTControlCharacters(line).replace(/\s+/g, " ").trim();
213216
if (text.length === 0) {
214217
return null;

0 commit comments

Comments
 (0)