diff --git a/src/agents/models-config.write-serialization.test.ts b/src/agents/models-config.write-serialization.test.ts index a20e1db4cd8..770c6fd974f 100644 --- a/src/agents/models-config.write-serialization.test.ts +++ b/src/agents/models-config.write-serialization.test.ts @@ -1,16 +1,36 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { CUSTOM_PROXY_MODELS_CONFIG, installModelsConfigTestHooks, withModelsTempHome, } from "./models-config.e2e-harness.js"; -import { ensureOpenClawModelsJson } from "./models-config.js"; import { readGeneratedModelsJson } from "./models-config.test-utils.js"; +const { planOpenClawModelsJsonMock } = vi.hoisted(() => ({ + planOpenClawModelsJsonMock: vi.fn(), +})); + +vi.mock("./models-config.plan.js", () => ({ + planOpenClawModelsJson: (...args: unknown[]) => planOpenClawModelsJsonMock(...args), +})); + installModelsConfigTestHooks(); +let ensureOpenClawModelsJson: typeof import("./models-config.js").ensureOpenClawModelsJson; + +beforeEach(async () => { + vi.resetModules(); + planOpenClawModelsJsonMock.mockImplementation( + async (params: { cfg?: typeof CUSTOM_PROXY_MODELS_CONFIG }) => ({ + action: "write", + contents: `${JSON.stringify({ providers: params.cfg?.models?.providers ?? {} }, null, 2)}\n`, + }), + ); + ({ ensureOpenClawModelsJson } = await import("./models-config.js")); +}); + describe("models-config write serialization", () => { it("serializes concurrent models.json writes to avoid overlap", async () => { await withModelsTempHome(async () => {