|
2 | 2 | // warning dedupe, and plugin-aware policy application. |
3 | 3 | import { beforeEach, describe, expect, test, vi } from "vitest"; |
4 | 4 | import { markFrozenClawToolAllowPolicy } from "../claws/tool-policy-runtime.js"; |
| 5 | +import { |
| 6 | + createPluginMetadataSnapshot, |
| 7 | + makeRegistry, |
| 8 | +} from "../config/plugin-auto-enable.test-helpers.js"; |
| 9 | +import { setCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata.test-support.js"; |
5 | 10 | import { buildDeclaredToolAllowlistContext } from "./tool-policy-declared-context.js"; |
6 | 11 | import { |
7 | 12 | applyToolPolicyPipeline, |
@@ -301,23 +306,44 @@ describe("tool-policy-pipeline", () => { |
301 | 306 | ]); |
302 | 307 | }); |
303 | 308 |
|
304 | | - test("declared context excludes disabled plugin tools", () => { |
305 | | - const declared = buildDeclaredToolAllowlistContext({ |
306 | | - config: { plugins: { entries: { browser: { enabled: false } } } }, |
307 | | - workspaceDir: process.cwd(), |
308 | | - }); |
309 | | - |
310 | | - expect(Array.from(declared?.pluginToolNames ?? [])).not.toContain("browser"); |
311 | | - }); |
312 | | - |
313 | | - test("declared context excludes denied plugin tools", () => { |
314 | | - const declared = buildDeclaredToolAllowlistContext({ |
315 | | - config: { plugins: { entries: { browser: { enabled: true } } } }, |
316 | | - workspaceDir: process.cwd(), |
317 | | - toolDenylist: ["browser"], |
318 | | - }); |
319 | | - |
320 | | - expect(Array.from(declared?.pluginToolNames ?? [])).not.toContain("browser"); |
| 309 | + test.each([ |
| 310 | + { |
| 311 | + name: "disabled owner", |
| 312 | + plugins: { entries: { "blocked-owner": { enabled: false } } }, |
| 313 | + toolDenylist: undefined, |
| 314 | + }, |
| 315 | + { name: "denied owner", plugins: { deny: ["blocked-owner"] }, toolDenylist: undefined }, |
| 316 | + { name: "tool-denied owner", plugins: {}, toolDenylist: ["blocked-owner"] }, |
| 317 | + { name: "denied tool", plugins: {}, toolDenylist: ["blocked_tool"] }, |
| 318 | + ])("declared context excludes a $name and keeps eligible tools", ({ plugins, toolDenylist }) => { |
| 319 | + const config = { plugins }; |
| 320 | + const workspaceDir = process.cwd(); |
| 321 | + const manifestRegistry = makeRegistry([ |
| 322 | + { |
| 323 | + id: "Allowed-Owner", |
| 324 | + origin: "bundled", |
| 325 | + channels: [], |
| 326 | + contracts: { tools: ["allowed_tool"] }, |
| 327 | + }, |
| 328 | + { |
| 329 | + id: "Blocked-Owner", |
| 330 | + origin: "bundled", |
| 331 | + channels: [], |
| 332 | + contracts: { tools: ["blocked_tool"] }, |
| 333 | + }, |
| 334 | + ]); |
| 335 | + setCurrentPluginMetadataSnapshot( |
| 336 | + createPluginMetadataSnapshot({ config, manifestRegistry, workspaceDir }), |
| 337 | + { config, workspaceDir }, |
| 338 | + ); |
| 339 | + try { |
| 340 | + expect(buildDeclaredToolAllowlistContext({ config, workspaceDir, toolDenylist })).toEqual({ |
| 341 | + pluginIds: ["Allowed-Owner"], |
| 342 | + pluginToolNames: ["allowed_tool"], |
| 343 | + }); |
| 344 | + } finally { |
| 345 | + setCurrentPluginMetadataSnapshot(undefined); |
| 346 | + } |
321 | 347 | }); |
322 | 348 |
|
323 | 349 | test("declared context excludes disabled MCP servers", () => { |
|
0 commit comments