This commit is contained in:
omp-port
2026-10-21 03:30:57 +00:00
parent 83514f01c6
commit 42c921da1c
5 changed files with 149 additions and 34 deletions

View File

@@ -39,6 +39,9 @@ import {
loadRunState,
markCheckStatus,
applyPhaseStatus,
initRunState,
markRunStatus,
saveRunState,
PHASE_RECON,
PHASE_ANALYSIS,
PHASE_FIX,
@@ -229,41 +232,100 @@ describe("/pygienium-all orchestrator (task 12)", () => {
expect(summary).not.toContain("## beta");
});
it("skips terminal checks on re-run; --fresh re-runs them", async () => {
it("a completed run is not resumed: the next invocation runs every check again", async () => {
registerCheck(fakeCheck("alpha"));
registerCheck(fakeCheck("beta"));
// First run: both complete.
await captureStdout(() => handleAllCommand("--fix", stubCtx(cwd)));
expect(track.dispatched.length).toBe(4); // 2 checks × 2 phases
const firstAlphaFix = await readFile(
join(cwd, ".pygienium", "checks", "alpha", "changes.md"),
"utf8",
);
expect(track.dispatched).toEqual(["alpha", "alpha", "beta", "beta"]);
// Second run without --fresh: both already terminal → skipped.
// Second run, no flags: the stored run completed, so this is a new scan.
// Every check dispatches again — the regression this pins dispatched
// nothing but whichever check an interrupted run happened to leave open.
track.dispatched.length = 0;
const out = await captureStdout(() =>
handleAllCommand("--fix", stubCtx(cwd)),
);
expect(track.dispatched).toHaveLength(0);
expect(out.join("\n")).toContain("skipping");
const state2 = await loadRunState(cwd);
expect(state2?.status).toBe("complete");
expect(track.dispatched).toEqual(["alpha", "alpha", "beta", "beta"]);
expect(out.join("\n")).not.toContain("skipping");
const state = await loadRunState(cwd);
expect(state?.status).toBe("complete");
expect(state?.checks.alpha?.status).toBe("complete");
expect(state?.checks.beta?.status).toBe("complete");
// Third run with --fresh: both re-dispatched from scratch.
// --fresh remains the explicit reset and dispatches the same way.
track.dispatched.length = 0;
await captureStdout(() => handleAllCommand("--fix --fresh", stubCtx(cwd)));
expect(track.dispatched).toEqual(["alpha", "alpha", "beta", "beta"]);
const state3 = await loadRunState(cwd);
expect(state3?.status).toBe("complete");
// The fresh re-run overwrote alpha's changes.md (still valid content).
const alphaFix2 = await readFile(
join(cwd, ".pygienium", "checks", "alpha", "changes.md"),
"utf8",
});
it("resumes an unfinished run: terminal checks skip, the rest re-dispatch", async () => {
registerCheck(fakeCheck("alpha"));
registerCheck(fakeCheck("beta"));
// A run that stopped with alpha done and beta failed is unfinished work,
// so it continues instead of starting over.
const state = initRunState(cwd, [
{ name: "alpha", label: "alpha", fix: true },
{ name: "beta", label: "beta", fix: true },
]);
state.recon = {
complete: true,
path: join(cwd, ".pygienium", "recon.json"),
finishedAt: Date.now(),
};
markComplete(state, "alpha");
markCheckStatus(state, "beta", "failed", "provider reset mid-scan");
markRunStatus(state, "partial");
await saveRunState(state);
const out = await captureStdout(() =>
handleAllCommand("--fix", stubCtx(cwd)),
);
expect(alphaFix2).toContain("alpha changes");
void firstAlphaFix;
expect(track.dispatched).toEqual(["beta", "beta"]);
expect(out.join("\n")).toContain("skipping");
});
it("settles a phase an interrupted run left in_progress on a skipped check", async () => {
registerCheck(fakeCheck("alpha"));
registerCheck(fakeCheck("beta"));
// alpha finished, but a later interrupted run left its analysis phase open.
const state = initRunState(cwd, [
{ name: "alpha", label: "alpha", fix: false },
{ name: "beta", label: "beta", fix: false },
]);
state.recon = {
complete: true,
path: join(cwd, ".pygienium", "recon.json"),
finishedAt: Date.now(),
};
markComplete(state, "alpha");
// Directly, because applyPhaseStatus would also move the check itself back
// to in_progress — the corruption here is a phase left open behind a
// check that still reads complete.
const staleAnalysis = state.checks.alpha?.phases.find(
(p) => p.id === PHASE_ANALYSIS,
);
if (!staleAnalysis) throw new Error("alpha has no analysis phase");
staleAnalysis.status = "in_progress";
applyPhaseStatus(state, "beta", PHASE_ANALYSIS, "in_progress");
await saveRunState(state);
await captureStdout(() => handleAllCommand("", stubCtx(cwd)));
const after = await loadRunState(cwd);
// alpha was skipped as already complete: its stale phase settles to
// complete rather than leaving the check finished-but-running.
const alphaPhases = after?.checks.alpha?.phases ?? [];
expect(alphaPhases.every((p) => p.status !== "in_progress")).toBe(true);
expect(
alphaPhases.find((p) => p.id === PHASE_ANALYSIS)?.status,
).toBe("complete");
// beta never finished, so the run resumes it and its scan runs again
// (scan-only: this run passes no --fix).
expect(track.dispatched).toEqual(["beta"]);
});
it("resumes an interrupted run (re-dispatches non-terminal checks only)", async () => {