mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 10:10:43 +00:00
test: tighten models config serialization assertions
This commit is contained in:
@@ -66,6 +66,16 @@ function createPluginMetadataSnapshot(workspaceDir: string): PluginMetadataSnaps
|
||||
};
|
||||
}
|
||||
|
||||
async function expectMissingPath(operation: Promise<unknown>) {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user