From 072be9863ed7dee8f21e50a2d89fd0f4166d3213 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 24 Sep 2026 10:53:53 -0400 Subject: [PATCH] fix(e2e-harness): let the final result write replace the outro write The host writes result.json when the outro appears, and a guard then made every later write return early. So the final write after keep-skills never ran, and for every program whose outro screen id is `outro`, `screenPath` stopped at `outro` and `skillsComplete` stayed false, even when mcp, slack-connect and keep-skills ran. This ports `createE2eResultWriter` from the refactor stack (#1308): the first outcome is written once, and only the final write may replace it. Part of #1333 Generated-By: PostHog Desktop Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589 --- e2e-harness/__tests__/e2e-result.test.ts | 24 ++++++++++++ e2e-harness/e2e-result.ts | 13 +++++++ scripts/tui-host.no-jest.ts | 47 +++++++++++------------- 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/e2e-harness/__tests__/e2e-result.test.ts b/e2e-harness/__tests__/e2e-result.test.ts index 961c1dda5..f1932026d 100644 --- a/e2e-harness/__tests__/e2e-result.test.ts +++ b/e2e-harness/__tests__/e2e-result.test.ts @@ -20,6 +20,7 @@ import { E2eRunRecorder, abortReasonFrom, buildE2eResult, + createE2eResultWriter, detectedSourcesFrom, readReportFile, taskOutcomesFrom, @@ -463,6 +464,29 @@ describe('buildE2eResult', () => { expect(build()).toMatchObject(base); }); + it('replaces an outro result only when the final skills decision is written', () => { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'wizard-result-')); + const file = path.join(directory, 'result.json'); + let skillsComplete = false; + const write = createE2eResultWriter(file, () => ({ + ...build(), + skillsComplete, + })); + const written = () => JSON.parse(fs.readFileSync(file, 'utf8')); + + try { + write(); + expect(written()).toMatchObject({ skillsComplete: false }); + skillsComplete = true; + write(); + expect(written()).toMatchObject({ skillsComplete: false }); + write(true); + expect(written()).toMatchObject({ skillsComplete: true }); + } finally { + fs.rmSync(directory, { recursive: true, force: true }); + } + }); + it('projects tasks down to label and status', () => { expect(build().tasks).toEqual([ { label: 'Connect your data sources', status: 'completed' }, diff --git a/e2e-harness/e2e-result.ts b/e2e-harness/e2e-result.ts index 1ba4b9d88..810b4a8c2 100644 --- a/e2e-harness/e2e-result.ts +++ b/e2e-harness/e2e-result.ts @@ -247,6 +247,19 @@ export interface E2eResultBase { skillsComplete: boolean; } +/** Write the first outcome once, then allow the final skills decision to replace it. */ +export function createE2eResultWriter( + file: string | undefined, + getResult: () => Record, +): (final?: boolean) => void { + let written = false; + return (final = false) => { + if (!file || (written && !final)) return; + fs.writeFileSync(file, JSON.stringify(getResult(), null, 2)); + written = true; + }; +} + /** * Build the `E2E_RESULT_JSON` payload. Additive over {@link E2eResultBase} — * the pre-existing keys are copied through byte-identical. diff --git a/scripts/tui-host.no-jest.ts b/scripts/tui-host.no-jest.ts index 75b246b8e..c21ac7a75 100644 --- a/scripts/tui-host.no-jest.ts +++ b/scripts/tui-host.no-jest.ts @@ -54,6 +54,7 @@ import { profileFor, resolveE2eProfile } from '@e2e-harness/profiles'; import { E2eRunRecorder, buildE2eResult, + createE2eResultWriter, readReportFile, } from '@e2e-harness/e2e-result'; @@ -443,7 +444,6 @@ async function main() { }; const recorder = new E2eRunRecorder(); const screenPath: string[] = []; - let resultWritten = false; // An abort exits from inside the runner, so hook `exit` too — see writeResult. process.on('exit', () => writeResult()); // Snapshot on key moments — a screen change, a task-list update, or a @@ -627,9 +627,7 @@ async function main() { // integration re-writes it after keep-skills (skillsComplete). Registered // on `exit` too: `wizardAbort` renders the error outro and exits, and an // aborted run would otherwise write nothing at all. - const writeResult = (): void => { - if (!process.env.E2E_RESULT_JSON || resultWritten) return; - resultWritten = true; + const buildResult = () => { const appDir = process.env.APP_DIR!; // One dependency-name pattern per ecosystem manifest. A run only needs // the names, so a line-level scan beats per-format parsers. @@ -678,28 +676,25 @@ async function main() { } catch { /* none */ } - fs.writeFileSync( - process.env.E2E_RESULT_JSON, - JSON.stringify( - buildE2eResult({ - base: { - runPhase: store.session.runPhase, - hasPosthogDep: posthogDeps.length > 0, - newDeps: posthogDeps, - envFile, - screenPath, - skillsComplete: store.session.skillsComplete, - }, - recorder, - session: store.session, - tasks: store.tasks, - reportFile: readReportFile(appDir, programConfig.reportFile), - }), - null, - 2, - ), - ); + return buildE2eResult({ + base: { + runPhase: store.session.runPhase, + hasPosthogDep: posthogDeps.length > 0, + newDeps: posthogDeps, + envFile, + screenPath, + skillsComplete: store.session.skillsComplete, + }, + recorder, + session: store.session, + tasks: store.tasks, + reportFile: readReportFile(appDir, programConfig.reportFile), + }); }; + const writeResult = createE2eResultWriter( + process.env.E2E_RESULT_JSON, + buildResult, + ); const unsubResult = store.subscribe(() => { if (store.currentScreen === 'outro') writeResult(); }); @@ -717,7 +712,7 @@ async function main() { unsubResult(); await snap(); // the final screen await chain; // flush any pending snapshots - writeResult(); // final write (integration: after keep-skills) + writeResult(true); // final write (integration: after keep-skills) process.exit(0); } }