perf(test): tighten codex model and fs bridge tests

This commit is contained in:
Peter Steinberger
2026-04-20 15:47:43 +01:00
parent a72f102259
commit d2a271d5c8
2 changed files with 17 additions and 23 deletions

View File

@@ -4,10 +4,25 @@ import { listCodexAppServerModels } from "./models.js";
import { resetSharedCodexAppServerClientForTests } from "./shared-client.js";
import { createClientHarness } from "./test-support.js";
const mocks = vi.hoisted(() => ({
bridgeCodexAppServerStartOptions: vi.fn(async ({ startOptions }) => startOptions),
resolveOpenClawAgentDir: vi.fn(() => "/tmp/openclaw-agent"),
}));
vi.mock("./auth-bridge.js", () => ({
bridgeCodexAppServerStartOptions: mocks.bridgeCodexAppServerStartOptions,
}));
vi.mock("openclaw/plugin-sdk/provider-auth", () => ({
resolveOpenClawAgentDir: mocks.resolveOpenClawAgentDir,
}));
describe("listCodexAppServerModels", () => {
afterEach(() => {
resetSharedCodexAppServerClientForTests();
vi.restoreAllMocks();
mocks.bridgeCodexAppServerStartOptions.mockClear();
mocks.resolveOpenClawAgentDir.mockClear();
});
it("lists app-server models through the typed helper", async () => {
@@ -15,6 +30,7 @@ describe("listCodexAppServerModels", () => {
const startSpy = vi.spyOn(CodexAppServerClient, "start").mockReturnValue(harness.client);
const listPromise = listCodexAppServerModels({ limit: 12, timeoutMs: 1000 });
await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(1));
const initialize = JSON.parse(harness.writes[0] ?? "{}") as { id?: number };
harness.send({
id: initialize.id,

View File

@@ -126,29 +126,7 @@ describe("sandbox pinned mutation helper", () => {
const result = runWritePlan(
["write", workspace, "nested/deeper", "note.txt", "1"],
"hello",
);
expect(result.status).toBe(0);
await expect(
fs.readFile(path.join(workspace, "nested", "deeper", "note.txt"), "utf8"),
).resolves.toBe("hello");
});
},
);
it.runIf(process.platform !== "win32" && hasAbsolutePythonCandidate)(
"finds an absolute python when the write plan runs with an empty PATH",
async () => {
await withTempDir({ prefix: "openclaw-mutation-helper-" }, async (root) => {
const workspace = path.join(root, "workspace");
await fs.mkdir(workspace, { recursive: true });
const result = runWritePlan(
["write", workspace, "nested/deeper", "note.txt", "1"],
"hello",
{
PATH: "",
},
hasAbsolutePythonCandidate ? { PATH: "" } : undefined,
);
expect(result.status).toBe(0);