mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
perf(test): reduce test startup overhead
This commit is contained in:
@@ -30,6 +30,9 @@ export const DEFAULT_BOOTSTRAP_FILENAME = "BOOTSTRAP.md";
|
|||||||
export const DEFAULT_MEMORY_FILENAME = "MEMORY.md";
|
export const DEFAULT_MEMORY_FILENAME = "MEMORY.md";
|
||||||
export const DEFAULT_MEMORY_ALT_FILENAME = "memory.md";
|
export const DEFAULT_MEMORY_ALT_FILENAME = "memory.md";
|
||||||
|
|
||||||
|
const workspaceTemplateCache = new Map<string, Promise<string>>();
|
||||||
|
let gitAvailabilityPromise: Promise<boolean> | null = null;
|
||||||
|
|
||||||
function stripFrontMatter(content: string): string {
|
function stripFrontMatter(content: string): string {
|
||||||
if (!content.startsWith("---")) {
|
if (!content.startsWith("---")) {
|
||||||
return content;
|
return content;
|
||||||
@@ -45,6 +48,12 @@ function stripFrontMatter(content: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadTemplate(name: string): Promise<string> {
|
async function loadTemplate(name: string): Promise<string> {
|
||||||
|
const cached = workspaceTemplateCache.get(name);
|
||||||
|
if (cached) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pending = (async () => {
|
||||||
const templateDir = await resolveWorkspaceTemplateDir();
|
const templateDir = await resolveWorkspaceTemplateDir();
|
||||||
const templatePath = path.join(templateDir, name);
|
const templatePath = path.join(templateDir, name);
|
||||||
try {
|
try {
|
||||||
@@ -55,6 +64,15 @@ async function loadTemplate(name: string): Promise<string> {
|
|||||||
`Missing workspace template: ${name} (${templatePath}). Ensure docs/reference/templates are packaged.`,
|
`Missing workspace template: ${name} (${templatePath}). Ensure docs/reference/templates are packaged.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
workspaceTemplateCache.set(name, pending);
|
||||||
|
try {
|
||||||
|
return await pending;
|
||||||
|
} catch (error) {
|
||||||
|
workspaceTemplateCache.delete(name);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WorkspaceBootstrapFileName =
|
export type WorkspaceBootstrapFileName =
|
||||||
@@ -99,12 +117,20 @@ async function hasGitRepo(dir: string): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function isGitAvailable(): Promise<boolean> {
|
async function isGitAvailable(): Promise<boolean> {
|
||||||
|
if (gitAvailabilityPromise) {
|
||||||
|
return gitAvailabilityPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
gitAvailabilityPromise = (async () => {
|
||||||
try {
|
try {
|
||||||
const result = await runCommandWithTimeout(["git", "--version"], { timeoutMs: 2_000 });
|
const result = await runCommandWithTimeout(["git", "--version"], { timeoutMs: 2_000 });
|
||||||
return result.code === 0;
|
return result.code === 0;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
return gitAvailabilityPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureGitRepo(dir: string, isBrandNewWorkspace: boolean) {
|
async function ensureGitRepo(dir: string, isBrandNewWorkspace: boolean) {
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
|
||||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
|
||||||
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
|
||||||
|
|
||||||
function makePrompter(): WizardPrompter {
|
|
||||||
return {
|
|
||||||
intro: async () => {},
|
|
||||||
outro: async () => {},
|
|
||||||
note: async () => {},
|
|
||||||
select: async () => "",
|
|
||||||
multiselect: async () => [],
|
|
||||||
text: async () => "",
|
|
||||||
confirm: async () => false,
|
|
||||||
progress: () => ({ update: () => {}, stop: () => {} }),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("applyDefaultModelChoice", () => {
|
|
||||||
it("ensures allowlist entry exists when returning an agent override", async () => {
|
|
||||||
const defaultModel = "vercel-ai-gateway/anthropic/claude-opus-4.6";
|
|
||||||
const noteAgentModel = vi.fn(async () => {});
|
|
||||||
const applied = await applyDefaultModelChoice({
|
|
||||||
config: {},
|
|
||||||
setDefaultModel: false,
|
|
||||||
defaultModel,
|
|
||||||
// Simulate a provider function that does not explicitly add the entry.
|
|
||||||
applyProviderConfig: (config: OpenClawConfig) => config,
|
|
||||||
applyDefaultConfig: (config: OpenClawConfig) => config,
|
|
||||||
noteAgentModel,
|
|
||||||
prompter: makePrompter(),
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(noteAgentModel).toHaveBeenCalledWith(defaultModel);
|
|
||||||
expect(applied.agentModelOverride).toBe(defaultModel);
|
|
||||||
expect(applied.config.agents?.defaults?.models?.[defaultModel]).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("adds canonical allowlist key for anthropic aliases", async () => {
|
|
||||||
const defaultModel = "anthropic/opus-4.6";
|
|
||||||
const applied = await applyDefaultModelChoice({
|
|
||||||
config: {},
|
|
||||||
setDefaultModel: false,
|
|
||||||
defaultModel,
|
|
||||||
applyProviderConfig: (config: OpenClawConfig) => config,
|
|
||||||
applyDefaultConfig: (config: OpenClawConfig) => config,
|
|
||||||
noteAgentModel: async () => {},
|
|
||||||
prompter: makePrompter(),
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(applied.config.agents?.defaults?.models?.[defaultModel]).toEqual({});
|
|
||||||
expect(applied.config.agents?.defaults?.models?.["anthropic/claude-opus-4-6"]).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("uses applyDefaultConfig path when setDefaultModel is true", async () => {
|
|
||||||
const defaultModel = "openai/gpt-5.1-codex";
|
|
||||||
const applied = await applyDefaultModelChoice({
|
|
||||||
config: {},
|
|
||||||
setDefaultModel: true,
|
|
||||||
defaultModel,
|
|
||||||
applyProviderConfig: (config: OpenClawConfig) => config,
|
|
||||||
applyDefaultConfig: () => ({
|
|
||||||
agents: {
|
|
||||||
defaults: {
|
|
||||||
model: { primary: defaultModel },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
noteDefault: defaultModel,
|
|
||||||
noteAgentModel: async () => {},
|
|
||||||
prompter: makePrompter(),
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(applied.agentModelOverride).toBeUndefined();
|
|
||||||
expect(applied.config.agents?.defaults?.model).toEqual({ primary: defaultModel });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
|
||||||
import {
|
|
||||||
applyGoogleGeminiModelDefault,
|
|
||||||
GOOGLE_GEMINI_DEFAULT_MODEL,
|
|
||||||
} from "./google-gemini-model-default.js";
|
|
||||||
|
|
||||||
describe("applyGoogleGeminiModelDefault", () => {
|
|
||||||
it("sets gemini default when model is unset", () => {
|
|
||||||
const cfg: OpenClawConfig = { agents: { defaults: {} } };
|
|
||||||
const applied = applyGoogleGeminiModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(true);
|
|
||||||
expect(applied.next.agents?.defaults?.model).toEqual({
|
|
||||||
primary: GOOGLE_GEMINI_DEFAULT_MODEL,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("overrides existing model", () => {
|
|
||||||
const cfg: OpenClawConfig = {
|
|
||||||
agents: { defaults: { model: "anthropic/claude-opus-4-5" } },
|
|
||||||
};
|
|
||||||
const applied = applyGoogleGeminiModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(true);
|
|
||||||
expect(applied.next.agents?.defaults?.model).toEqual({
|
|
||||||
primary: GOOGLE_GEMINI_DEFAULT_MODEL,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("no-ops when already gemini default", () => {
|
|
||||||
const cfg: OpenClawConfig = {
|
|
||||||
agents: { defaults: { model: GOOGLE_GEMINI_DEFAULT_MODEL } },
|
|
||||||
};
|
|
||||||
const applied = applyGoogleGeminiModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(false);
|
|
||||||
expect(applied.next).toEqual(cfg);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
|
||||||
import {
|
|
||||||
applyOpenAICodexModelDefault,
|
|
||||||
OPENAI_CODEX_DEFAULT_MODEL,
|
|
||||||
} from "./openai-codex-model-default.js";
|
|
||||||
import { OPENAI_DEFAULT_MODEL } from "./openai-model-default.js";
|
|
||||||
|
|
||||||
describe("applyOpenAICodexModelDefault", () => {
|
|
||||||
it("sets openai-codex default when model is unset", () => {
|
|
||||||
const cfg: OpenClawConfig = { agents: { defaults: {} } };
|
|
||||||
const applied = applyOpenAICodexModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(true);
|
|
||||||
expect(applied.next.agents?.defaults?.model).toEqual({
|
|
||||||
primary: OPENAI_CODEX_DEFAULT_MODEL,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("sets openai-codex default when model is openai/*", () => {
|
|
||||||
const cfg: OpenClawConfig = {
|
|
||||||
agents: { defaults: { model: OPENAI_DEFAULT_MODEL } },
|
|
||||||
};
|
|
||||||
const applied = applyOpenAICodexModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(true);
|
|
||||||
expect(applied.next.agents?.defaults?.model).toEqual({
|
|
||||||
primary: OPENAI_CODEX_DEFAULT_MODEL,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not override openai-codex/*", () => {
|
|
||||||
const cfg: OpenClawConfig = {
|
|
||||||
agents: { defaults: { model: OPENAI_CODEX_DEFAULT_MODEL } },
|
|
||||||
};
|
|
||||||
const applied = applyOpenAICodexModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(false);
|
|
||||||
expect(applied.next).toEqual(cfg);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not override non-openai models", () => {
|
|
||||||
const cfg: OpenClawConfig = {
|
|
||||||
agents: { defaults: { model: "anthropic/claude-opus-4-5" } },
|
|
||||||
};
|
|
||||||
const applied = applyOpenAICodexModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(false);
|
|
||||||
expect(applied.next).toEqual(cfg);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,9 +1,128 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
|
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||||
|
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
||||||
|
import {
|
||||||
|
applyGoogleGeminiModelDefault,
|
||||||
|
GOOGLE_GEMINI_DEFAULT_MODEL,
|
||||||
|
} from "./google-gemini-model-default.js";
|
||||||
|
import {
|
||||||
|
applyOpenAICodexModelDefault,
|
||||||
|
OPENAI_CODEX_DEFAULT_MODEL,
|
||||||
|
} from "./openai-codex-model-default.js";
|
||||||
import {
|
import {
|
||||||
applyOpenAIConfig,
|
applyOpenAIConfig,
|
||||||
applyOpenAIProviderConfig,
|
applyOpenAIProviderConfig,
|
||||||
OPENAI_DEFAULT_MODEL,
|
OPENAI_DEFAULT_MODEL,
|
||||||
} from "./openai-model-default.js";
|
} from "./openai-model-default.js";
|
||||||
|
import {
|
||||||
|
applyOpencodeZenModelDefault,
|
||||||
|
OPENCODE_ZEN_DEFAULT_MODEL,
|
||||||
|
} from "./opencode-zen-model-default.js";
|
||||||
|
|
||||||
|
function makePrompter(): WizardPrompter {
|
||||||
|
return {
|
||||||
|
intro: async () => {},
|
||||||
|
outro: async () => {},
|
||||||
|
note: async () => {},
|
||||||
|
select: async () => "",
|
||||||
|
multiselect: async () => [],
|
||||||
|
text: async () => "",
|
||||||
|
confirm: async () => false,
|
||||||
|
progress: () => ({ update: () => {}, stop: () => {} }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("applyDefaultModelChoice", () => {
|
||||||
|
it("ensures allowlist entry exists when returning an agent override", async () => {
|
||||||
|
const defaultModel = "vercel-ai-gateway/anthropic/claude-opus-4.6";
|
||||||
|
const noteAgentModel = vi.fn(async () => {});
|
||||||
|
const applied = await applyDefaultModelChoice({
|
||||||
|
config: {},
|
||||||
|
setDefaultModel: false,
|
||||||
|
defaultModel,
|
||||||
|
// Simulate a provider function that does not explicitly add the entry.
|
||||||
|
applyProviderConfig: (config: OpenClawConfig) => config,
|
||||||
|
applyDefaultConfig: (config: OpenClawConfig) => config,
|
||||||
|
noteAgentModel,
|
||||||
|
prompter: makePrompter(),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(noteAgentModel).toHaveBeenCalledWith(defaultModel);
|
||||||
|
expect(applied.agentModelOverride).toBe(defaultModel);
|
||||||
|
expect(applied.config.agents?.defaults?.models?.[defaultModel]).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds canonical allowlist key for anthropic aliases", async () => {
|
||||||
|
const defaultModel = "anthropic/opus-4.6";
|
||||||
|
const applied = await applyDefaultModelChoice({
|
||||||
|
config: {},
|
||||||
|
setDefaultModel: false,
|
||||||
|
defaultModel,
|
||||||
|
applyProviderConfig: (config: OpenClawConfig) => config,
|
||||||
|
applyDefaultConfig: (config: OpenClawConfig) => config,
|
||||||
|
noteAgentModel: async () => {},
|
||||||
|
prompter: makePrompter(),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(applied.config.agents?.defaults?.models?.[defaultModel]).toEqual({});
|
||||||
|
expect(applied.config.agents?.defaults?.models?.["anthropic/claude-opus-4-6"]).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses applyDefaultConfig path when setDefaultModel is true", async () => {
|
||||||
|
const defaultModel = "openai/gpt-5.1-codex";
|
||||||
|
const applied = await applyDefaultModelChoice({
|
||||||
|
config: {},
|
||||||
|
setDefaultModel: true,
|
||||||
|
defaultModel,
|
||||||
|
applyProviderConfig: (config: OpenClawConfig) => config,
|
||||||
|
applyDefaultConfig: () => ({
|
||||||
|
agents: {
|
||||||
|
defaults: {
|
||||||
|
model: { primary: defaultModel },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
noteDefault: defaultModel,
|
||||||
|
noteAgentModel: async () => {},
|
||||||
|
prompter: makePrompter(),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(applied.agentModelOverride).toBeUndefined();
|
||||||
|
expect(applied.config.agents?.defaults?.model).toEqual({ primary: defaultModel });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("applyGoogleGeminiModelDefault", () => {
|
||||||
|
it("sets gemini default when model is unset", () => {
|
||||||
|
const cfg: OpenClawConfig = { agents: { defaults: {} } };
|
||||||
|
const applied = applyGoogleGeminiModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(true);
|
||||||
|
expect(applied.next.agents?.defaults?.model).toEqual({
|
||||||
|
primary: GOOGLE_GEMINI_DEFAULT_MODEL,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("overrides existing model", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: { defaults: { model: "anthropic/claude-opus-4-5" } },
|
||||||
|
};
|
||||||
|
const applied = applyGoogleGeminiModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(true);
|
||||||
|
expect(applied.next.agents?.defaults?.model).toEqual({
|
||||||
|
primary: GOOGLE_GEMINI_DEFAULT_MODEL,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("no-ops when already gemini default", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: { defaults: { model: GOOGLE_GEMINI_DEFAULT_MODEL } },
|
||||||
|
};
|
||||||
|
const applied = applyGoogleGeminiModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(false);
|
||||||
|
expect(applied.next).toEqual(cfg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("applyOpenAIProviderConfig", () => {
|
describe("applyOpenAIProviderConfig", () => {
|
||||||
it("adds allowlist entry for default model", () => {
|
it("adds allowlist entry for default model", () => {
|
||||||
@@ -38,3 +157,102 @@ describe("applyOpenAIConfig", () => {
|
|||||||
expect(next.agents?.defaults?.model).toEqual({ primary: OPENAI_DEFAULT_MODEL, fallback: [] });
|
expect(next.agents?.defaults?.model).toEqual({ primary: OPENAI_DEFAULT_MODEL, fallback: [] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("applyOpenAICodexModelDefault", () => {
|
||||||
|
it("sets openai-codex default when model is unset", () => {
|
||||||
|
const cfg: OpenClawConfig = { agents: { defaults: {} } };
|
||||||
|
const applied = applyOpenAICodexModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(true);
|
||||||
|
expect(applied.next.agents?.defaults?.model).toEqual({
|
||||||
|
primary: OPENAI_CODEX_DEFAULT_MODEL,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets openai-codex default when model is openai/*", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: { defaults: { model: OPENAI_DEFAULT_MODEL } },
|
||||||
|
};
|
||||||
|
const applied = applyOpenAICodexModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(true);
|
||||||
|
expect(applied.next.agents?.defaults?.model).toEqual({
|
||||||
|
primary: OPENAI_CODEX_DEFAULT_MODEL,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not override openai-codex/*", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: { defaults: { model: OPENAI_CODEX_DEFAULT_MODEL } },
|
||||||
|
};
|
||||||
|
const applied = applyOpenAICodexModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(false);
|
||||||
|
expect(applied.next).toEqual(cfg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not override non-openai models", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: { defaults: { model: "anthropic/claude-opus-4-5" } },
|
||||||
|
};
|
||||||
|
const applied = applyOpenAICodexModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(false);
|
||||||
|
expect(applied.next).toEqual(cfg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("applyOpencodeZenModelDefault", () => {
|
||||||
|
it("sets opencode default when model is unset", () => {
|
||||||
|
const cfg: OpenClawConfig = { agents: { defaults: {} } };
|
||||||
|
const applied = applyOpencodeZenModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(true);
|
||||||
|
expect(applied.next.agents?.defaults?.model).toEqual({
|
||||||
|
primary: OPENCODE_ZEN_DEFAULT_MODEL,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("overrides existing model", () => {
|
||||||
|
const cfg = {
|
||||||
|
agents: { defaults: { model: "anthropic/claude-opus-4-5" } },
|
||||||
|
} as OpenClawConfig;
|
||||||
|
const applied = applyOpencodeZenModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(true);
|
||||||
|
expect(applied.next.agents?.defaults?.model).toEqual({
|
||||||
|
primary: OPENCODE_ZEN_DEFAULT_MODEL,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("no-ops when already opencode-zen default", () => {
|
||||||
|
const cfg = {
|
||||||
|
agents: { defaults: { model: OPENCODE_ZEN_DEFAULT_MODEL } },
|
||||||
|
} as OpenClawConfig;
|
||||||
|
const applied = applyOpencodeZenModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(false);
|
||||||
|
expect(applied.next).toEqual(cfg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("no-ops when already legacy opencode-zen default", () => {
|
||||||
|
const cfg = {
|
||||||
|
agents: { defaults: { model: "opencode-zen/claude-opus-4-5" } },
|
||||||
|
} as OpenClawConfig;
|
||||||
|
const applied = applyOpencodeZenModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(false);
|
||||||
|
expect(applied.next).toEqual(cfg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves fallbacks when setting primary", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: {
|
||||||
|
defaults: {
|
||||||
|
model: {
|
||||||
|
primary: "anthropic/claude-opus-4-5",
|
||||||
|
fallbacks: ["google/gemini-3-pro"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const applied = applyOpencodeZenModelDefault(cfg);
|
||||||
|
expect(applied.changed).toBe(true);
|
||||||
|
expect(applied.next.agents?.defaults?.model).toEqual({
|
||||||
|
primary: OPENCODE_ZEN_DEFAULT_MODEL,
|
||||||
|
fallbacks: ["google/gemini-3-pro"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
|
||||||
import {
|
|
||||||
applyOpencodeZenModelDefault,
|
|
||||||
OPENCODE_ZEN_DEFAULT_MODEL,
|
|
||||||
} from "./opencode-zen-model-default.js";
|
|
||||||
|
|
||||||
describe("applyOpencodeZenModelDefault", () => {
|
|
||||||
it("sets opencode default when model is unset", () => {
|
|
||||||
const cfg: OpenClawConfig = { agents: { defaults: {} } };
|
|
||||||
const applied = applyOpencodeZenModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(true);
|
|
||||||
expect(applied.next.agents?.defaults?.model).toEqual({
|
|
||||||
primary: OPENCODE_ZEN_DEFAULT_MODEL,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("overrides existing model", () => {
|
|
||||||
const cfg = {
|
|
||||||
agents: { defaults: { model: "anthropic/claude-opus-4-5" } },
|
|
||||||
} as OpenClawConfig;
|
|
||||||
const applied = applyOpencodeZenModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(true);
|
|
||||||
expect(applied.next.agents?.defaults?.model).toEqual({
|
|
||||||
primary: OPENCODE_ZEN_DEFAULT_MODEL,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("no-ops when already opencode-zen default", () => {
|
|
||||||
const cfg = {
|
|
||||||
agents: { defaults: { model: OPENCODE_ZEN_DEFAULT_MODEL } },
|
|
||||||
} as OpenClawConfig;
|
|
||||||
const applied = applyOpencodeZenModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(false);
|
|
||||||
expect(applied.next).toEqual(cfg);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("no-ops when already legacy opencode-zen default", () => {
|
|
||||||
const cfg = {
|
|
||||||
agents: { defaults: { model: "opencode-zen/claude-opus-4-5" } },
|
|
||||||
} as OpenClawConfig;
|
|
||||||
const applied = applyOpencodeZenModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(false);
|
|
||||||
expect(applied.next).toEqual(cfg);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("preserves fallbacks when setting primary", () => {
|
|
||||||
const cfg: OpenClawConfig = {
|
|
||||||
agents: {
|
|
||||||
defaults: {
|
|
||||||
model: {
|
|
||||||
primary: "anthropic/claude-opus-4-5",
|
|
||||||
fallbacks: ["google/gemini-3-pro"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const applied = applyOpencodeZenModelDefault(cfg);
|
|
||||||
expect(applied.changed).toBe(true);
|
|
||||||
expect(applied.next.agents?.defaults?.model).toEqual({
|
|
||||||
primary: OPENCODE_ZEN_DEFAULT_MODEL,
|
|
||||||
fallbacks: ["google/gemini-3-pro"],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { validateConfigObject } from "./config.js";
|
||||||
|
|
||||||
describe("broadcast", () => {
|
describe("broadcast", () => {
|
||||||
it("accepts a broadcast peer map with strategy", async () => {
|
it("accepts a broadcast peer map with strategy", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
agents: {
|
agents: {
|
||||||
list: [{ id: "alfred" }, { id: "baerbel" }],
|
list: [{ id: "alfred" }, { id: "baerbel" }],
|
||||||
@@ -16,18 +15,14 @@ describe("broadcast", () => {
|
|||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects invalid broadcast strategy", async () => {
|
it("rejects invalid broadcast strategy", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
broadcast: { strategy: "nope" },
|
broadcast: { strategy: "nope" },
|
||||||
});
|
});
|
||||||
expect(res.ok).toBe(false);
|
expect(res.ok).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects non-array broadcast entries", async () => {
|
it("rejects non-array broadcast entries", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
broadcast: { "120363403215116621@g.us": 123 },
|
broadcast: { "120363403215116621@g.us": 123 },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { validateConfigObject } from "./config.js";
|
||||||
|
|
||||||
describe("gateway.remote.transport", () => {
|
describe("gateway.remote.transport", () => {
|
||||||
it("accepts direct transport", async () => {
|
it("accepts direct transport", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
gateway: {
|
gateway: {
|
||||||
remote: {
|
remote: {
|
||||||
@@ -15,9 +14,7 @@ describe("gateway.remote.transport", () => {
|
|||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects unknown transport", async () => {
|
it("rejects unknown transport", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
gateway: {
|
gateway: {
|
||||||
remote: {
|
remote: {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { validateConfigObject } from "./config.js";
|
||||||
|
|
||||||
describe("gateway.tools config", () => {
|
describe("gateway.tools config", () => {
|
||||||
it("accepts gateway.tools allow and deny lists", async () => {
|
it("accepts gateway.tools allow and deny lists", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
gateway: {
|
gateway: {
|
||||||
tools: {
|
tools: {
|
||||||
@@ -15,9 +14,7 @@ describe("gateway.tools config", () => {
|
|||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects invalid gateway.tools values", async () => {
|
it("rejects invalid gateway.tools values", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
gateway: {
|
gateway: {
|
||||||
tools: {
|
tools: {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { validateConfigObject } from "./config.js";
|
||||||
|
|
||||||
describe("config msteams", () => {
|
describe("config msteams", () => {
|
||||||
it("accepts replyStyle at global/team/channel levels", async () => {
|
it("accepts replyStyle at global/team/channel levels", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
channels: {
|
channels: {
|
||||||
msteams: {
|
msteams: {
|
||||||
@@ -29,9 +28,7 @@ describe("config msteams", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects invalid replyStyle", async () => {
|
it("rejects invalid replyStyle", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
channels: { msteams: { replyStyle: "nope" } },
|
channels: { msteams: { replyStyle: "nope" } },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { validateConfigObject } from "./config.js";
|
||||||
|
|
||||||
describe("sandbox docker config", () => {
|
describe("sandbox docker config", () => {
|
||||||
it("accepts binds array in sandbox.docker config", async () => {
|
it("accepts binds array in sandbox.docker config", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
agents: {
|
agents: {
|
||||||
defaults: {
|
defaults: {
|
||||||
@@ -38,9 +37,7 @@ describe("sandbox docker config", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects non-string values in binds array", async () => {
|
it("rejects non-string values in binds array", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
agents: {
|
agents: {
|
||||||
defaults: {
|
defaults: {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { validateConfigObject } from "./config.js";
|
||||||
|
|
||||||
describe("talk.voiceAliases", () => {
|
describe("talk.voiceAliases", () => {
|
||||||
it("accepts a string map of voice aliases", async () => {
|
it("accepts a string map of voice aliases", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
talk: {
|
talk: {
|
||||||
voiceAliases: {
|
voiceAliases: {
|
||||||
@@ -15,9 +14,7 @@ describe("talk.voiceAliases", () => {
|
|||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects non-string voice alias values", async () => {
|
it("rejects non-string voice alias values", () => {
|
||||||
vi.resetModules();
|
|
||||||
const { validateConfigObject } = await import("./config.js");
|
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
talk: {
|
talk: {
|
||||||
voiceAliases: {
|
voiceAliases: {
|
||||||
|
|||||||
@@ -162,7 +162,6 @@ beforeEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
setActivePluginRegistry(createDefaultRegistry());
|
|
||||||
// Guard against leaked fake timers across test files/workers.
|
// Guard against leaked fake timers across test files/workers.
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user