test: guard agent runtime config mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 04:25:30 +01:00
parent 366b5cf738
commit bf2b40866d

View File

@@ -63,6 +63,15 @@ async function withTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
return withTempHomeBase(fn, { prefix: "openclaw-agent-" });
}
function requireResolveCommandConfigParams(callIndex = 0): ResolveCommandConfigParams {
const call = resolveCommandConfigWithSecretsMock.mock.calls.at(callIndex);
if (!call) {
throw new Error(`expected command config resolution call ${callIndex}`);
}
const [params] = call;
return params;
}
function mockConfig(home: string, storePath: string): OpenClawConfig {
const cfg = {
agents: {
@@ -153,7 +162,7 @@ describe("agentCommand runtime config", () => {
targetIds: new Set(["models.providers.*.apiKey"]),
runtime,
});
const targetIds = resolveCommandConfigWithSecretsMock.mock.calls[0]?.[0].targetIds;
const targetIds = requireResolveCommandConfigParams().targetIds;
expect(targetIds.has("models.providers.*.apiKey")).toBe(true);
expect(targetIds.has("channels.telegram.botToken")).toBe(false);
expect(setRuntimeConfigSnapshotMock).toHaveBeenCalledWith(resolvedConfig, sourceConfig);
@@ -180,7 +189,7 @@ describe("agentCommand runtime config", () => {
runtimeTargetsChannelSecrets: true,
});
const targetIds = resolveCommandConfigWithSecretsMock.mock.calls[0]?.[0].targetIds;
const targetIds = requireResolveCommandConfigParams().targetIds;
expect(targetIds.has("channels.telegram.botToken")).toBe(true);
});
});