From 5664978a1833ca8bca2f5213a6b0bb283fb0ca7f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 17:03:50 +0100 Subject: [PATCH] test: tighten models config serialization assertions --- .../models-config.write-serialization.test.ts | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/agents/models-config.write-serialization.test.ts b/src/agents/models-config.write-serialization.test.ts index 76dd49c935c..0d444e15854 100644 --- a/src/agents/models-config.write-serialization.test.ts +++ b/src/agents/models-config.write-serialization.test.ts @@ -66,6 +66,16 @@ function createPluginMetadataSnapshot(workspaceDir: string): PluginMetadataSnaps }; } +async function expectMissingPath(operation: Promise) { + let error: NodeJS.ErrnoException | undefined; + try { + await operation; + } catch (caught) { + error = caught as NodeJS.ErrnoException; + } + expect(error?.code).toBe("ENOENT"); +} + beforeAll(async () => { vi.doMock("./models-config.plan.js", () => ({ planOpenClawModelsJson: (...args: unknown[]) => planOpenClawModelsJsonMock(...args), @@ -128,9 +138,10 @@ describe("models-config write serialization", () => { await ensureOpenClawModelsJson({}, agentDir); - expect(planOpenClawModelsJsonMock).toHaveBeenCalledWith( - expect.not.objectContaining({ pluginMetadataSnapshot: snapshot }), - ); + const params = planOpenClawModelsJsonMock.mock.calls[0]?.[0] as + | { pluginMetadataSnapshot?: PluginMetadataSnapshot } + | undefined; + expect(params?.pluginMetadataSnapshot).not.toBe(snapshot); }); }); @@ -143,12 +154,11 @@ describe("models-config write serialization", () => { await ensureOpenClawModelsJson({}, agentDir, { workspaceDir }); - expect(planOpenClawModelsJsonMock).toHaveBeenCalledWith( - expect.objectContaining({ - workspaceDir, - pluginMetadataSnapshot: snapshot, - }), - ); + const params = planOpenClawModelsJsonMock.mock.calls[0]?.[0] as + | { workspaceDir?: string; pluginMetadataSnapshot?: PluginMetadataSnapshot } + | undefined; + expect(params?.workspaceDir).toBe(workspaceDir); + expect(params?.pluginMetadataSnapshot).toBe(snapshot); }); }); @@ -164,9 +174,9 @@ describe("models-config write serialization", () => { expect(result.agentDir).toBe(path.join(home, ".openclaw", "agents", "ops", "agent")); await expect(fs.access(path.join(result.agentDir, "models.json"))).resolves.toBeUndefined(); - await expect( + await expectMissingPath( fs.access(path.join(home, ".openclaw", "agents", "main", "agent", "models.json")), - ).rejects.toMatchObject({ code: "ENOENT" }); + ); }); }); @@ -184,12 +194,14 @@ describe("models-config write serialization", () => { }); expect(planOpenClawModelsJsonMock).toHaveBeenCalledTimes(2); - expect(planOpenClawModelsJsonMock).toHaveBeenLastCalledWith( - expect.objectContaining({ - providerDiscoveryProviderIds: ["anthropic"], - providerDiscoveryTimeoutMs: 5000, - }), - ); + const params = planOpenClawModelsJsonMock.mock.calls[1]?.[0] as + | { + providerDiscoveryProviderIds?: string[]; + providerDiscoveryTimeoutMs?: number; + } + | undefined; + expect(params?.providerDiscoveryProviderIds).toEqual(["anthropic"]); + expect(params?.providerDiscoveryTimeoutMs).toBe(5000); }); });