mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-19 04:04:45 +00:00
test: dedupe secret resolution mock reads
This commit is contained in:
@@ -22,6 +22,23 @@ const { resolveQueuedReplyExecutionConfig, resolveQueuedReplyRuntimeConfig } =
|
||||
const { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } =
|
||||
await import("../../config/config.js");
|
||||
|
||||
type ResolveCommandSecretRefsCall = {
|
||||
config: OpenClawConfig;
|
||||
commandName: string;
|
||||
targetIds?: Set<string>;
|
||||
allowedPaths?: Set<string>;
|
||||
};
|
||||
|
||||
function resolveCommandSecretRefsCall(callIndex = 0): ResolveCommandSecretRefsCall {
|
||||
const call = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls[callIndex]?.[0] as
|
||||
| ResolveCommandSecretRefsCall
|
||||
| undefined;
|
||||
if (!call) {
|
||||
throw new Error(`expected command secret resolution call ${callIndex}`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
describe("resolveQueuedReplyExecutionConfig channel scope", () => {
|
||||
beforeEach(() => {
|
||||
clearRuntimeConfigSnapshot();
|
||||
@@ -70,11 +87,7 @@ describe("resolveQueuedReplyExecutionConfig channel scope", () => {
|
||||
|
||||
expect(resolved).toBe(scopedResolved);
|
||||
expect(hoisted.resolveCommandSecretRefsViaGatewayMock).toHaveBeenCalledTimes(2);
|
||||
const baseCall = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls.at(0)?.[0] as {
|
||||
config: OpenClawConfig;
|
||||
commandName: string;
|
||||
targetIds: Set<string>;
|
||||
};
|
||||
const baseCall = resolveCommandSecretRefsCall();
|
||||
expect(baseCall.config).toBe(sourceConfig);
|
||||
expect(baseCall.commandName).toBe("reply");
|
||||
expect(baseCall.targetIds).toEqual(new Set(["skills.entries.*.apiKey"]));
|
||||
@@ -83,12 +96,7 @@ describe("resolveQueuedReplyExecutionConfig channel scope", () => {
|
||||
channel: "discord",
|
||||
accountId: "work",
|
||||
});
|
||||
const scopedCall = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls.at(1)?.[0] as {
|
||||
config: OpenClawConfig;
|
||||
commandName: string;
|
||||
targetIds: Set<string>;
|
||||
allowedPaths?: Set<string>;
|
||||
};
|
||||
const scopedCall = resolveCommandSecretRefsCall(1);
|
||||
expect(scopedCall.config).toBe(baseResolved);
|
||||
expect(scopedCall.commandName).toBe("reply");
|
||||
expect(scopedCall.targetIds).toEqual(new Set(["channels.discord.token"]));
|
||||
@@ -134,10 +142,7 @@ describe("resolveQueuedReplyExecutionConfig channel scope", () => {
|
||||
messageProvider: "discord",
|
||||
});
|
||||
|
||||
const baseCall = hoisted.resolveCommandSecretRefsViaGatewayMock.mock.calls.at(0)?.[0] as {
|
||||
config: OpenClawConfig;
|
||||
commandName: string;
|
||||
};
|
||||
const baseCall = resolveCommandSecretRefsCall();
|
||||
expect(baseCall.config).toBe(runtimeConfig);
|
||||
expect(baseCall.commandName).toBe("reply");
|
||||
expect(hoisted.getScopedChannelsCommandSecretTargetsMock).toHaveBeenCalledWith({
|
||||
|
||||
Reference in New Issue
Block a user