fix(e2e): stream Parallels fresh logs

This commit is contained in:
Vincent Koc
2026-06-01 08:49:03 +02:00
parent 68bfacae03
commit 8fdb1d0f55
2 changed files with 18 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S pnpm tsx
import { spawn } from "node:child_process";
import { appendFileSync, readFileSync, writeFileSync } from "node:fs";
import { readFile, rm, writeFile } from "node:fs/promises";
import { readFile, rm } from "node:fs/promises";
import path from "node:path";
import { pathToFileURL } from "node:url";
import {
@@ -638,28 +638,25 @@ class NpmUpdateSmoke {
onOutput: (text: string) => void = () => undefined,
): Promise<number> {
return new Promise((resolve, reject) => {
writeFileSync(logPath, "", "utf8");
const child = spawn(command, args, {
cwd: repoRoot,
env: { ...process.env, ...env },
stdio: ["ignore", "pipe", "pipe"],
});
let log = "";
child.stdout.on("data", (chunk: Buffer) => {
const text = chunk.toString("utf8");
log += text;
appendFileSync(logPath, text, "utf8");
onOutput(text);
});
child.stderr.on("data", (chunk: Buffer) => {
const text = chunk.toString("utf8");
log += text;
appendFileSync(logPath, text, "utf8");
onOutput(text);
});
child.on("error", reject);
child.on("close", (code) => {
void (async () => {
await writeFile(logPath, log, "utf8");
resolve(code ?? 1);
})();
resolve(code ?? 1);
});
});
}

View File

@@ -77,6 +77,19 @@ describe("parallels npm update smoke", () => {
expect(updateBlock).not.toContain("log += text");
});
it("streams fresh lane logs instead of retaining them in memory", () => {
const script = readFileSync(SCRIPT_PATH, "utf8");
const spawnLoggedBlock = script.slice(
script.indexOf(" private spawnLogged"),
script.indexOf(" private async monitorJobs"),
);
expect(spawnLoggedBlock).toContain('writeFileSync(logPath, "", "utf8")');
expect(spawnLoggedBlock).toContain("appendFileSync(logPath, text");
expect(spawnLoggedBlock).not.toContain("let log");
expect(spawnLoggedBlock).not.toContain("log += text");
});
it("runs Windows updates through a detached done-file runner", () => {
const script = readFileSync(SCRIPT_PATH, "utf8");
const transports = readFileSync(GUEST_TRANSPORTS_PATH, "utf8");