fix(scripts): clean Z.AI fallback repro temp state

This commit is contained in:
Vincent Koc
2026-06-01 16:25:05 +02:00
parent 645c7dc40b
commit 110f7d55e3
2 changed files with 161 additions and 79 deletions

View File

@@ -1,6 +1,10 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
appendBoundedReproOutput,
runZaiFallbackRepro,
resolveZaiFallbackPnpmCommand,
} from "../../scripts/zai-fallback-repro.ts";
@@ -32,4 +36,47 @@ describe("zai fallback repro command resolution", () => {
expect(first).toEqual({ text: "bcdef", truncatedChars: 1 });
expect(second).toEqual({ text: "fghij", truncatedChars: 5 });
});
it("cleans temporary repro state after fallback proof", async () => {
const tempRoots: string[] = [];
const calls: string[] = [];
const exitCode = await runZaiFallbackRepro({
env: {
ANTHROPIC_API_KEY: "anthropic-test-key",
OPENCLAW_ZAI_FALLBACK_SESSION_ID: "session-test",
PATH: process.env.PATH,
ZAI_API_KEY: "zai-test-key",
},
error: () => {},
log: () => {},
mkdtemp: async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-zai-fallback-test-"));
tempRoots.push(root);
return root;
},
randomUUID: () => "uuid-test",
runCommand: async (label, _args, env) => {
calls.push(label);
if (label === "run1") {
const sessionFile = path.join(
String(env.OPENCLAW_STATE_DIR),
"agents",
"main",
"sessions",
"session-test.jsonl",
);
await fs.mkdir(path.dirname(sessionFile), { recursive: true });
await fs.writeFile(sessionFile, '{"toolResult":true}\n', "utf8");
}
return { code: 0, signal: null, stderr: "", stdout: "" };
},
warn: () => {},
});
expect(exitCode).toBe(0);
expect(calls).toEqual(["run1", "run2"]);
expect(tempRoots).toHaveLength(1);
await expect(fs.stat(tempRoots[0])).rejects.toMatchObject({ code: "ENOENT" });
});
});