-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathagent-selection.test.ts
More file actions
73 lines (64 loc) · 3.25 KB
/
agent-selection.test.ts
File metadata and controls
73 lines (64 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { mergeAgentsForScope } from "./agent-selection.ts";
type TestAgent = {
name: string;
source: "builtin" | "user" | "project";
systemPrompt: string;
};
function makeAgent(name: string, source: "builtin" | "user" | "project", systemPrompt: string): TestAgent {
return { name, source, systemPrompt };
}
describe("mergeAgentsForScope", () => {
it("returns project agents when scope is project", () => {
const userAgents = [makeAgent("shared", "user", "user prompt")];
const projectAgents = [makeAgent("shared", "project", "project prompt")];
const result = mergeAgentsForScope("project", userAgents as any, projectAgents as any);
assert.equal(result.length, 1);
assert.equal(result[0]?.source, "project");
});
it("returns user agents when scope is user", () => {
const userAgents = [makeAgent("shared", "user", "user prompt")];
const projectAgents = [makeAgent("shared", "project", "project prompt")];
const result = mergeAgentsForScope("user", userAgents as any, projectAgents as any);
assert.equal(result.length, 1);
assert.equal(result[0]?.source, "user");
});
it("prefers project agents on name collisions when scope is both", () => {
const userAgents = [makeAgent("shared", "user", "user prompt")];
const projectAgents = [makeAgent("shared", "project", "project prompt")];
const result = mergeAgentsForScope("both", userAgents as any, projectAgents as any);
assert.equal(result.length, 1);
assert.equal(result[0]?.source, "project");
assert.equal(result[0]?.systemPrompt, "project prompt");
});
it("keeps agents from both scopes when names are distinct", () => {
const userAgents = [makeAgent("user-only", "user", "user prompt")];
const projectAgents = [makeAgent("project-only", "project", "project prompt")];
const result = mergeAgentsForScope("both", userAgents as any, projectAgents as any);
assert.equal(result.length, 2);
assert.ok(result.find((a) => a.name === "user-only" && a.source === "user"));
assert.ok(result.find((a) => a.name === "project-only" && a.source === "project"));
});
it("includes builtin agents when no user or project override exists", () => {
const builtinAgents = [makeAgent("scout", "builtin", "builtin prompt")];
const result = mergeAgentsForScope("both", [] as any, [] as any, builtinAgents as any);
assert.equal(result.length, 1);
assert.equal(result[0]?.source, "builtin");
});
it("user agents override builtins with the same name", () => {
const builtinAgents = [makeAgent("scout", "builtin", "builtin prompt")];
const userAgents = [makeAgent("scout", "user", "custom prompt")];
const result = mergeAgentsForScope("both", userAgents as any, [] as any, builtinAgents as any);
assert.equal(result.length, 1);
assert.equal(result[0]?.source, "user");
assert.equal(result[0]?.systemPrompt, "custom prompt");
});
it("project agents override builtins with the same name", () => {
const builtinAgents = [makeAgent("scout", "builtin", "builtin prompt")];
const projectAgents = [makeAgent("scout", "project", "project prompt")];
const result = mergeAgentsForScope("both", [] as any, projectAgents as any, builtinAgents as any);
assert.equal(result.length, 1);
assert.equal(result[0]?.source, "project");
});
});