mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-19 02:44:46 +00:00
117 lines
3.5 KiB
TypeScript
117 lines
3.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { DEFAULT_AGENT_MAX_CONCURRENT, DEFAULT_SUBAGENT_MAX_CONCURRENT } from "./agent-limits.js";
|
|
import {
|
|
applyAgentDefaults,
|
|
applyContextPruningDefaults,
|
|
applyMessageDefaults,
|
|
} from "./defaults.js";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
applyProviderConfigDefaultsForConfig: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("./provider-policy.js", () => ({
|
|
applyProviderConfigDefaultsForConfig: (
|
|
...args: Parameters<typeof mocks.applyProviderConfigDefaultsForConfig>
|
|
) => mocks.applyProviderConfigDefaultsForConfig(...args),
|
|
normalizeProviderConfigForConfigDefaults: (_params: { providerConfig: unknown }) =>
|
|
_params.providerConfig,
|
|
}));
|
|
|
|
describe("config defaults", () => {
|
|
beforeEach(() => {
|
|
mocks.applyProviderConfigDefaultsForConfig.mockReset();
|
|
vi.stubEnv("ANTHROPIC_API_KEY", "");
|
|
vi.stubEnv("ANTHROPIC_OAUTH_TOKEN", "");
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
it("skips provider defaults when agent defaults are absent", () => {
|
|
const cfg = {
|
|
models: {
|
|
providers: {
|
|
openai: {
|
|
api: "openai-completions",
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
expect(applyContextPruningDefaults(cfg as never)).toBe(cfg);
|
|
expect(mocks.applyProviderConfigDefaultsForConfig).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("skips provider defaults when agent defaults have no Anthropic auth signal", () => {
|
|
const cfg = {
|
|
agents: {
|
|
defaults: {},
|
|
},
|
|
};
|
|
|
|
expect(applyContextPruningDefaults(cfg as never)).toBe(cfg);
|
|
expect(mocks.applyProviderConfigDefaultsForConfig).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("uses anthropic provider defaults when agent defaults and auth signal exist", () => {
|
|
const cfg = {
|
|
auth: {
|
|
profiles: {
|
|
anthropic: { provider: "anthropic", mode: "api_key" },
|
|
},
|
|
},
|
|
agents: {
|
|
defaults: {},
|
|
},
|
|
};
|
|
const nextCfg = {
|
|
agents: {
|
|
defaults: {
|
|
contextPruning: {
|
|
mode: "cache-ttl",
|
|
},
|
|
},
|
|
},
|
|
};
|
|
mocks.applyProviderConfigDefaultsForConfig.mockReturnValue(nextCfg);
|
|
|
|
const manifestRegistry = { plugins: [] };
|
|
expect(applyContextPruningDefaults(cfg as never, { manifestRegistry })).toBe(nextCfg);
|
|
expect(mocks.applyProviderConfigDefaultsForConfig).toHaveBeenCalledTimes(1);
|
|
const [[defaultsParams]] = mocks.applyProviderConfigDefaultsForConfig.mock
|
|
.calls as unknown as Array<[{ manifestRegistry?: unknown }]>;
|
|
expect(defaultsParams.manifestRegistry).toBe(manifestRegistry);
|
|
});
|
|
|
|
it("defaults ackReactionScope without deriving other message fields", () => {
|
|
const next = applyMessageDefaults({
|
|
agents: {
|
|
list: [
|
|
{
|
|
id: "main",
|
|
identity: {
|
|
name: "Samantha",
|
|
theme: "helpful sloth",
|
|
emoji: "🦥",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
messages: {},
|
|
} as never);
|
|
|
|
expect(next.messages?.ackReactionScope).toBe("group-mentions");
|
|
expect(next.messages?.responsePrefix).toBeUndefined();
|
|
expect(next.messages?.groupChat?.mentionPatterns).toBeUndefined();
|
|
});
|
|
|
|
it("fills missing agent concurrency defaults", () => {
|
|
const next = applyAgentDefaults({ messages: {} } as never);
|
|
|
|
expect(next.agents?.defaults?.maxConcurrent).toBe(DEFAULT_AGENT_MAX_CONCURRENT);
|
|
expect(next.agents?.defaults?.subagents?.maxConcurrent).toBe(DEFAULT_SUBAGENT_MAX_CONCURRENT);
|
|
});
|
|
});
|