Skip to content

Commit e532c4e

Browse files
committed
fix(test-suite): fail clean on teardown errors
1 parent d3aa5a6 commit e532c4e

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

test-suite/fhevm/src/artifacts.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,17 @@ export const composeUp = async (
556556

557557
export const composeDown = async (component: string, deps: Pick<ArtifactDeps, "liveRunner">) => {
558558
if (!(await exists(composePath(component)))) {
559-
return;
559+
return true;
560560
}
561561
const code = await deps.liveRunner([...dockerArgs(component), "down", "-v"], {
562562
allowFailure: true,
563563
env: await composeEnv(),
564564
});
565565
if (code !== 0) {
566566
console.warn(`[warn] compose down failed for ${component} (${code})`);
567+
return false;
567568
}
569+
return true;
568570
};
569571

570572
export const regen = async (state: State, deps: Pick<ArtifactDeps, "runner">) => {

test-suite/fhevm/src/cli.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,28 @@ describe("runtime invariants", () => {
555555
}
556556
});
557557

558+
test("clean keeps runtime state when teardown fails", async () => {
559+
process.chdir(REPO_ROOT);
560+
const before = await maybeRead(STATE_FILE);
561+
await fs.rm(STATE_DIR, { recursive: true, force: true });
562+
await fs.mkdir(STATE_DIR, { recursive: true });
563+
const state = stubState({ discovery: readyDiscovery(), completedSteps: ["bootstrap"] });
564+
await fs.writeFile(STATE_FILE, JSON.stringify(state));
565+
const { logs, restore } = captureConsole("error");
566+
try {
567+
await main(["bun", "src/cli.ts", "clean"], { ...noopDeps, liveRunner: async () => 1 });
568+
} finally {
569+
restore();
570+
}
571+
expect(await maybeRead(STATE_FILE)).toBeDefined();
572+
expect(logs.some((l) => l.includes("Failed to stop components"))).toBe(true);
573+
await fs.rm(STATE_DIR, { recursive: true, force: true });
574+
if (before !== undefined) {
575+
await fs.mkdir(STATE_DIR, { recursive: true });
576+
await fs.writeFile(STATE_FILE, before);
577+
}
578+
});
579+
558580
test("up --dry-run reports a helpful message when gh is missing", async () => {
559581
const { logs, restore } = captureConsole("error");
560582
try {

test-suite/fhevm/src/runtime.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,17 @@ const waitForRelayer = async (deps: RuntimeDeps) => {
575575

576576
const resetAfterStep = async (step: StepName, deps: RuntimeDeps) => {
577577
const start = stateStepIndex(step);
578+
const failed: string[] = [];
578579
for (let index = STEP_NAMES.length - 1; index >= start; index -= 1) {
579580
for (const component of COMPONENT_BY_STEP[STEP_NAMES[index]]) {
580-
await composeDown(component, deps);
581+
if (!(await composeDown(component, deps))) {
582+
failed.push(component);
583+
}
581584
}
582585
}
586+
if (failed.length) {
587+
throw new Error(`Failed to stop components while resetting from ${step}: ${failed.join(", ")}`);
588+
}
583589
};
584590

585591
const ensureRuntimeArtifacts = async (state: State, deps: Pick<RuntimeDeps, "runner">, reason: string) => {
@@ -1072,17 +1078,23 @@ const runDown = async (deps: RuntimeDeps) => {
10721078
await ensureRuntimeArtifacts(state, deps, "teardown");
10731079
}
10741080
let stopped = false;
1081+
const failed: string[] = [];
10751082
for (const component of [...COMPONENTS].reverse()) {
10761083
if (!(await exists(composePath(component)))) {
10771084
continue;
10781085
}
10791086
stopped = true;
10801087
log(`[down] ${component}`);
1081-
await composeDown(component, deps);
1088+
if (!(await composeDown(component, deps))) {
1089+
failed.push(component);
1090+
}
10821091
}
10831092
if (!stopped) {
10841093
log("[down] nothing to stop");
10851094
}
1095+
if (failed.length) {
1096+
throw new Error(`Failed to stop components: ${failed.join(", ")}`);
1097+
}
10861098
};
10871099

10881100
const runStatus = async (deps: RuntimeDeps) => {

0 commit comments

Comments
 (0)