Skip to content

Commit e688c05

Browse files
committed
fix(server): keep provider update progress on the latest frame
1 parent 9e09926 commit e688c05

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,20 @@ describe("providerMaintenanceRunner", () => {
395395
4_096,
396396
);
397397
assert.strictEqual(ProviderMaintenanceRunner.toProgressLine("x".repeat(300))?.length, 200);
398+
399+
for (const redraw of ["\r", "\u001b[G", "\u001b[0G", "\u001b[1G", "\u001b[01G"]) {
400+
const output = `first${redraw}second${redraw}last`;
401+
for (let boundary = 0; boundary <= output.length; boundary++) {
402+
let partialLine = "";
403+
for (const chunk of [output.slice(0, boundary), output.slice(boundary)]) {
404+
partialLine = ProviderMaintenanceRunner.splitOutputLines(partialLine, chunk).partialLine;
405+
}
406+
assert.strictEqual(ProviderMaintenanceRunner.toProgressLine(partialLine), "last");
407+
}
408+
}
409+
for (const incomplete of ["\u001b", "\u001b[", "\u001b[0", "\u001b[01"]) {
410+
assert.strictEqual(ProviderMaintenanceRunner.toProgressLine(`progress${incomplete}`), null);
411+
}
398412
});
399413

400414
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
@@ -203,11 +203,14 @@ export function splitOutputLines(
203203
partialLine: string,
204204
text: string,
205205
): { readonly lines: ReadonlyArray<string>; readonly partialLine: string } {
206-
const parts = (partialLine + text).split(/\r\n|\r|\n/);
206+
const parts = (partialLine + text).replace(/\x1b\[0*1?G/g, "\r").split(/\r\n|\r|\n/);
207207
return { partialLine: (parts.pop() ?? "").slice(-UPDATE_PARTIAL_LINE_MAX_LENGTH), lines: parts };
208208
}
209209

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

0 commit comments

Comments
 (0)