openclaw/src/config/config.multi-agent-agentdir-validation.test.ts

55 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-01-14 01:08:15 +00:00
import fs from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import { loadConfig, validateConfigObject } from "./config.js";
2026-01-14 01:08:15 +00:00
import { withTempHome } from "./test-helpers.js";
describe("multi-agent agentDir validation", () => {
it("rejects shared agents.list agentDir", async () => {
2026-01-30 03:15:10 +01:00
const shared = path.join(tmpdir(), "openclaw-shared-agentdir");
2026-01-14 01:08:15 +00:00
const res = validateConfigObject({
agents: {
list: [
{ id: "a", agentDir: shared },
{ id: "b", agentDir: shared },
],
},
});
expect(res.ok).toBe(false);
if (!res.ok) {
expect(res.issues.some((i) => i.path === "agents.list")).toBe(true);
expect(res.issues[0]?.message).toContain("Duplicate agentDir");
}
});
it("throws on shared agentDir during loadConfig()", async () => {
await withTempHome(async (home) => {
2026-01-30 03:15:10 +01:00
const configDir = path.join(home, ".openclaw");
2026-01-14 01:08:15 +00:00
await fs.mkdir(configDir, { recursive: true });
await fs.writeFile(
2026-01-30 03:15:10 +01:00
path.join(configDir, "openclaw.json"),
2026-01-14 01:08:15 +00:00
JSON.stringify(
{
agents: {
list: [
2026-01-30 03:15:10 +01:00
{ id: "a", agentDir: "~/.openclaw/agents/shared/agent" },
{ id: "b", agentDir: "~/.openclaw/agents/shared/agent" },
2026-01-14 01:08:15 +00:00
],
},
2026-01-19 03:38:51 +00:00
bindings: [{ agentId: "a", match: { channel: "telegram" } }],
2026-01-14 01:08:15 +00:00
},
null,
2,
),
"utf-8",
);
const spy = vi.spyOn(console, "error").mockImplementation(() => {});
expect(() => loadConfig()).toThrow(/duplicate agentDir/i);
expect(spy.mock.calls.flat().join(" ")).toMatch(/Duplicate agentDir/i);
spy.mockRestore();
});
});
});