-
-
Notifications
You must be signed in to change notification settings - Fork 80.9k
Expand file tree
/
Copy pathsubagent-target-policy.test.ts
More file actions
122 lines (113 loc) · 3.65 KB
/
Copy pathsubagent-target-policy.test.ts
File metadata and controls
122 lines (113 loc) · 3.65 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { describe, expect, it } from "vitest";
import {
resolveSubagentAllowedTargetIds,
resolveSubagentTargetPolicy,
} from "./subagent-target-policy.js";
describe("subagent target policy", () => {
it("defaults to requester-only when no allowlist is configured", () => {
expect(
resolveSubagentTargetPolicy({
requesterAgentId: "main",
targetAgentId: "main",
requestedAgentId: "main",
}),
).toEqual({ ok: true });
const result = resolveSubagentTargetPolicy({
requesterAgentId: "main",
targetAgentId: "other",
requestedAgentId: "other",
});
expect(result.ok).toBe(false);
if (result.ok) {
throw new Error("Expected target policy to reject other agent");
}
expect(result.allowedText).toBe("main");
});
it("keeps omitted agentId self-spawns allowed even when an allowlist is configured", () => {
expect(
resolveSubagentTargetPolicy({
requesterAgentId: "task-manager",
targetAgentId: "task-manager",
allowAgents: ["planner"],
}),
).toEqual({ ok: true });
});
it("rejects explicit self-targets when the configured allowlist excludes the requester", () => {
const result = resolveSubagentTargetPolicy({
requesterAgentId: "task-manager",
targetAgentId: "task-manager",
requestedAgentId: "task-manager",
allowAgents: ["planner", "checker"],
});
expect(result.ok).toBe(false);
if (result.ok) {
throw new Error("Expected target policy to reject explicit self-target");
}
expect(result.allowedText).toBe("checker, planner");
expect(result.error).toBe(
"agentId is not allowed for sessions_spawn (allowed: checker, planner)",
);
});
it("resolves allowed target ids without auto-adding requester for explicit allowlists", () => {
expect(
resolveSubagentAllowedTargetIds({
requesterAgentId: "main",
allowAgents: ["planner"],
configuredAgentIds: ["main", "planner"],
}),
).toEqual({
allowAny: false,
allowedIds: ["planner"],
});
});
it("limits wildcard allowlists to configured agents plus the requester", () => {
expect(
resolveSubagentAllowedTargetIds({
requesterAgentId: "main",
allowAgents: ["*"],
configuredAgentIds: ["planner", "checker"],
}),
).toEqual({
allowAny: true,
allowedIds: ["checker", "main", "planner"],
});
});
it("rejects wildcard targets outside the configured registry", () => {
const result = resolveSubagentTargetPolicy({
requesterAgentId: "main",
targetAgentId: "bogus",
requestedAgentId: "bogus",
allowAgents: ["*"],
configuredAgentIds: ["main", "planner"],
});
expect(result.ok).toBe(false);
if (result.ok) {
throw new Error("Expected target policy to reject unconfigured wildcard target");
}
expect(result.allowedText).toBe("main, planner");
expect(result.error).toBe(
'agentId "bogus" is not in the configured agent registry (allowed: main, planner)',
);
});
it("preserves explicit targets when wildcard allowlists are mixed", () => {
expect(
resolveSubagentAllowedTargetIds({
requesterAgentId: "main",
allowAgents: ["*", "beta"],
configuredAgentIds: ["main", "planner"],
}),
).toEqual({
allowAny: true,
allowedIds: ["beta", "main", "planner"],
});
expect(
resolveSubagentTargetPolicy({
requesterAgentId: "main",
targetAgentId: "beta",
requestedAgentId: "beta",
allowAgents: ["*", "beta"],
configuredAgentIds: ["main", "planner"],
}),
).toEqual({ ok: true });
});
});