|
1 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | +import { readFileSync } from "node:fs"; |
2 | 3 | import { DIRECTOR_REGISTRY } from "../agent/directors/registry.js"; |
3 | 4 | import { createAdvertisedToolset } from "../session/assemble-runtime.js"; |
4 | 5 | import { |
@@ -114,6 +115,97 @@ describe("exec director allowlist", () => { |
114 | 115 | ); |
115 | 116 | }); |
116 | 117 |
|
| 118 | + test("the promoter does not commit a name outside the overlay allow list", () => { |
| 119 | + const overlay = resolveExecDirectorOverlay("explorer"); |
| 120 | + const { activated, computeAdvertised, flushPromotions } = |
| 121 | + createAdvertisedToolset({ |
| 122 | + sessionMode: "orchestrator", |
| 123 | + toolAvailability: { languageServerAvailable: true }, |
| 124 | + getProvider: () => ({ providerName: "test", model: "test-model" }), |
| 125 | + builtInPrefix: overlay.advertisedAllow, |
| 126 | + }); |
| 127 | + let committed = 0; |
| 128 | + const promote = createExecToolPromoter({ |
| 129 | + activate: (names) => activated.activate(names), |
| 130 | + isAllowed: (name) => isExecOverlayToolAllowed(overlay, name), |
| 131 | + commitWire: () => { |
| 132 | + if (flushPromotions()) committed += 1; |
| 133 | + }, |
| 134 | + }); |
| 135 | + const registry = [ |
| 136 | + { |
| 137 | + name: OUTSIDE_ALLOW, |
| 138 | + description: "create an issue", |
| 139 | + inputSchema: { type: "object", properties: {} }, |
| 140 | + }, |
| 141 | + { |
| 142 | + name: "lsp", |
| 143 | + description: "language server", |
| 144 | + inputSchema: { type: "object", properties: {} }, |
| 145 | + }, |
| 146 | + ]; |
| 147 | + promote([OUTSIDE_ALLOW]); |
| 148 | + expect(activated.has(OUTSIDE_ALLOW)).toBe(false); |
| 149 | + expect(committed).toBe(0); |
| 150 | + expect(computeAdvertised(registry).map((d) => d.name)).not.toContain( |
| 151 | + OUTSIDE_ALLOW, |
| 152 | + ); |
| 153 | + }); |
| 154 | + |
| 155 | + test("the promoter still commits lsp when the overlay allows it", () => { |
| 156 | + const overlay = resolveExecDirectorOverlay("explorer"); |
| 157 | + expect(isExecOverlayToolAllowed(overlay, "lsp")).toBe(true); |
| 158 | + const { activated, computeAdvertised, flushPromotions } = |
| 159 | + createAdvertisedToolset({ |
| 160 | + sessionMode: "orchestrator", |
| 161 | + toolAvailability: { languageServerAvailable: true }, |
| 162 | + getProvider: () => ({ providerName: "test", model: "test-model" }), |
| 163 | + builtInPrefix: overlay.advertisedAllow, |
| 164 | + }); |
| 165 | + let committed = 0; |
| 166 | + const promote = createExecToolPromoter({ |
| 167 | + activate: (names) => activated.activate(names), |
| 168 | + isAllowed: (name) => isExecOverlayToolAllowed(overlay, name), |
| 169 | + commitWire: () => { |
| 170 | + if (flushPromotions()) committed += 1; |
| 171 | + }, |
| 172 | + }); |
| 173 | + const registry = [ |
| 174 | + { |
| 175 | + name: "lsp", |
| 176 | + description: "language server", |
| 177 | + inputSchema: { type: "object", properties: {} }, |
| 178 | + }, |
| 179 | + { |
| 180 | + name: OUTSIDE_ALLOW, |
| 181 | + description: "create an issue", |
| 182 | + inputSchema: { type: "object", properties: {} }, |
| 183 | + }, |
| 184 | + ]; |
| 185 | + promote([OUTSIDE_ALLOW, "lsp"]); |
| 186 | + expect(activated.has(OUTSIDE_ALLOW)).toBe(false); |
| 187 | + expect(activated.has("lsp")).toBe(true); |
| 188 | + expect(committed).toBe(1); |
| 189 | + const names = computeAdvertised(registry).map((d) => d.name); |
| 190 | + expect(names).toContain("lsp"); |
| 191 | + expect(names).not.toContain(OUTSIDE_ALLOW); |
| 192 | + }); |
| 193 | + |
| 194 | + test("exec wires commitWire on the overlay-filtered promoter and onToolsActivate uses it", () => { |
| 195 | + const source = readFileSync( |
| 196 | + new URL("./runner.ts", import.meta.url), |
| 197 | + "utf8", |
| 198 | + ); |
| 199 | + expect(source).toContain("commitWire: commitPromotedWire"); |
| 200 | + expect(source).toMatch( |
| 201 | + /createExecToolPromoter\(\{[\s\S]*?isAllowed:\s*\(name\)\s*=>\s*isExecOverlayToolAllowed\(overlay,\s*name\)[\s\S]*?commitWire:\s*commitPromotedWire/, |
| 202 | + ); |
| 203 | + expect(source).toMatch( |
| 204 | + /onToolsActivate:\s*\(names\)\s*=>\s*promoteAndCommitWire\(names\)/, |
| 205 | + ); |
| 206 | + expect(source).toContain("setToolPromoter(promoteAndCommitWire"); |
| 207 | + }); |
| 208 | + |
117 | 209 | test("skywalker overlay leaves every tool allowed", () => { |
118 | 210 | const overlay = resolveExecDirectorOverlay("skywalker"); |
119 | 211 | expect(isExecOverlayToolAllowed(overlay, OUTSIDE_ALLOW)).toBe(true); |
|
0 commit comments