Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions e2e-harness/__tests__/e2e-result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
E2eRunRecorder,
abortReasonFrom,
buildE2eResult,
createE2eResultWriter,
detectedSourcesFrom,
readReportFile,
taskOutcomesFrom,
Expand Down Expand Up @@ -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' },
Expand Down
13 changes: 13 additions & 0 deletions e2e-harness/e2e-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>,
): (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.
Expand Down
47 changes: 21 additions & 26 deletions scripts/tui-host.no-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { profileFor, resolveE2eProfile } from '@e2e-harness/profiles';
import {
E2eRunRecorder,
buildE2eResult,
createE2eResultWriter,
readReportFile,
} from '@e2e-harness/e2e-result';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
});
Expand All @@ -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);
}
}
Expand Down
Loading