/** * plugins/workflow-runner/test/listResources.test.ts * —— 守 `skills/workflow-creator/scripts/list-resources.mjs` 的准确性 * * 这个脚本的**全部价值就是准确**:agent 照着它写 `allowedTools`,写错的名字会被 * 引擎静默过滤掉。一份不准的清单比没有清单更糟 —— 它会让人理直气壮地写错。 * * 第一版就栽在这里:从**变量名**推断工具名(`lspTool` → `Lsp`、 * `webFetchTool` → `Webfetch`、`genImageTool` → `GenImage`),三个全错, * 真名是 `LSP` / `WebFetch` / `GenerateImage`。现在改成直接问内核要 `name` 字段。 * * 另有两个 Windows 专属的坑(spawn 到 shell 时命令被截断),见脚本里的注释。 */ import { describe, expect, test } from 'bun:test'; import { spawnSync } from 'node:child_process'; import { join } from 'node:path'; import { ALL_TOOLS } from '../../../src/tools/index.js'; const ROOT = join(import.meta.dir, '..', '..', '..'); const SCRIPT = join( ROOT, 'skills', 'workflow-creator', 'scripts', 'list-resources.mjs', ); function runScript(args: string[] = []) { const r = spawnSync('node', [SCRIPT, ...args], { cwd: ROOT, encoding: 'utf8', shell: process.platform === 'win32', }); return { status: r.status, stdout: r.stdout ?? '', stderr: r.stderr ?? '' }; } describe('list-resources.mjs', () => { test('跑得起来(node 直接 spawn,不需要 bun 在 PATH 里也不该崩)', () => { const r = runScript(['--plugins']); expect(r.status).toBe(0); }); test('★ 工具名与 ALL_TOOLS 的真实 name 字段**完全一致**', () => { // 一个字母都不能差 —— 差了就会被 allowedTools 静默过滤。 const r = runScript(['--json']); expect(r.status).toBe(0); const data = JSON.parse(r.stdout) as { tools: string[]; toolsExact: boolean; }; if (!data.toolsExact) { // 拿不到真值时脚本必须**明说降级**而不是给一份猜的清单 expect(data.tools).toEqual([]); return; } expect([...data.tools].sort()).toEqual(ALL_TOOLS.map((t) => t.name).sort()); }); test('★ 那三个曾被推断错的名字必须正确', () => { // LSP / WebFetch / GenerateImage —— 变量名分别是 lspTool / webFetchTool / genImageTool, // 按变量名推断会得到 Lsp / Webfetch / GenImage,全错。 const r = runScript(['--json']); const data = JSON.parse(r.stdout) as { tools: string[]; toolsExact: boolean; }; if (!data.toolsExact) return; for (const name of ['LSP', 'WebFetch', 'GenerateImage', 'WebBrowser']) { expect(data.tools).toContain(name); } }); test('skills 清单非空且带描述(否则 agent 判断不了该用哪个)', () => { const r = runScript(['--json']); const data = JSON.parse(r.stdout) as { skills: { name: string; description: string }[]; }; expect(data.skills.length).toBeGreaterThan(10); // 至少多数条目要有描述 —— 全空说明 frontmatter 解析坏了 const withDesc = data.skills.filter((s) => s.description.length > 0); expect(withDesc.length).toBeGreaterThan(data.skills.length / 2); }); test('★ 一定要列出 workflow-runner 与 computer_use(最容易被忽略的两个入口)', () => { const r = runScript(['--json']); const data = JSON.parse(r.stdout) as { plugins: { name: string; commands: string[] }[]; }; const names = data.plugins.map((p) => p.name); expect(names).toContain('workflow-runner'); // computer_use 的 plugin.json 里 name 写的是 computer-use(连字符) expect(names.some((n) => n.replace('_', '-') === 'computer-use')).toBe( true, ); }); test('人类可读输出里工具按用途归组,不是一坨字母序', () => { const r = runScript(['--tools']); if (!r.stdout.includes('═══ 工具')) return; // bun 不可用时的降级路径 expect(r.stdout).toContain('读写文件'); expect(r.stdout).toContain('桌面操控'); expect(r.stdout).toContain('ComputerUse'); }); });