mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 02:20:44 +00:00
91 lines
2.6 KiB
TypeScript
91 lines
2.6 KiB
TypeScript
import { 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();
|
|
});
|
|
|
|
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("uses anthropic provider defaults when agent defaults exist", () => {
|
|
const cfg = {
|
|
agents: {
|
|
defaults: {},
|
|
},
|
|
};
|
|
const nextCfg = {
|
|
agents: {
|
|
defaults: {
|
|
contextPruning: {
|
|
mode: "cache-ttl",
|
|
},
|
|
},
|
|
},
|
|
};
|
|
mocks.applyProviderConfigDefaultsForConfig.mockReturnValue(nextCfg);
|
|
|
|
expect(applyContextPruningDefaults(cfg as never)).toBe(nextCfg);
|
|
expect(mocks.applyProviderConfigDefaultsForConfig).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|