basant307/AI_Governance_Project
048
1import { describe, it, expect, vi } from 'vitest';2import { registerComputerUseTools } from './index.js';3import { COMPUTER_USE_TOOL_NAMES } from './schemas.js';4 5describe('registerComputerUseTools', () => {6 it('calls registerLazy once per upstream tool with the computer_use__ prefix', async () => {7 // Contract: registration goes through the caller-supplied registerLazy8 // (the helper from Config.createToolRegistry that runs9 // PermissionManager.isToolEnabled). Direct registry.registerFactory10 // would bypass the coreTools allowlist and whole-tool deny rules —11 // see PR #4590 review (DragonnZhang).12 const registered: string[] = [];13 const registerLazy = vi.fn(async (name: string) => {14 registered.push(name);15 });16 17 await registerComputerUseTools(registerLazy as never);18 19 expect(registerLazy).toHaveBeenCalledTimes(COMPUTER_USE_TOOL_NAMES.length);20 expect(registered).toHaveLength(COMPUTER_USE_TOOL_NAMES.length);21 for (const name of COMPUTER_USE_TOOL_NAMES) {22 expect(registered).toContain(`computer_use__${name}`);23 }24 });25 26 it('skips tools that registerLazy chooses not to register (PermissionManager deny)', async () => {27 // Verifies the permission gate is honored: if registerLazy is a no-op28 // for a given tool name (e.g. PermissionManager.isToolEnabled returns29 // false), no factory is invoked for it.30 const denyList = new Set(['computer_use__click', 'computer_use__drag']);31 const registered: string[] = [];32 const registerLazy = vi.fn(33 async (name: string, _factory: () => Promise<unknown>) => {34 if (!denyList.has(name)) registered.push(name);35 },36 );37 38 await registerComputerUseTools(registerLazy as never);39 40 // registerLazy IS called for every curated tool (the gate runs inside41 // it), but click + drag are denied so they don't land in `registered`.42 expect(registerLazy).toHaveBeenCalledTimes(COMPUTER_USE_TOOL_NAMES.length);43 expect(registered).toHaveLength(COMPUTER_USE_TOOL_NAMES.length - 2);44 expect(registered).not.toContain('computer_use__click');45 expect(registered).not.toContain('computer_use__drag');46 });47});48 