import { describe, expect, it } from 'vitest'; import type { GameCreatorDirectToolCall } from '../src/app/types'; import { toolCallInputText, toolCallRowText, } from '../src/features/project-workspace/toolCallGroupPresentation'; function commandCall(command: string): GameCreatorDirectToolCall { return { schemaVersion: 'agc-tool-call.v1', id: 'command', turnId: 'turn', kind: 'command', title: '执行命令', summary: command.slice(0, 120), status: 'completed', startedAt: 1, updatedAt: 2, detail: { command, output: 'pwsh -Command output must stay unchanged' }, }; } describe('Windows 命令卡片展示', () => { it('从 WindowsApps 路径后的完整输入提取脚本,并解开 shlex 引号拼接', () => { const script = `foreach ($f in @('game/package.json','game/vite.config.js','game/index.html','game/game.js')) { Write-Output "===== $f ====="; Get-Content -Raw $f }`; const argument = "'" + script.replaceAll("'", "'\"'\"'") + "'"; const command = String.raw`" Files\WindowsApps\Microsoft.PowerShell_7.6.6.0_x64__8wekyb3d8bbwe\pwsh.exe" -Command ${argument}`; const call = commandCall(command); expect(toolCallInputText(call)).toBe(script); expect(toolCallRowText(call)).toBe(`${script.slice(0, 120)}…`); expect(call.detail.command).toBe(command); expect(call.detail.output).toBe('pwsh -Command output must stay unchanged'); }); it.each([ ['pwsh -Command Get-Date', 'Get-Date'], [ 'pwsh.exe -NoLogo -NoProfile -NonInteractive -Command "Get-Date"', 'Get-Date', ], [ String.raw`"C:\Program Files\PowerShell\7\pwsh.exe" -c 'Get-Date'`, 'Get-Date', ], ["POWERSHELL.EXE -ExecutionPolicy Bypass -Command 'Get-Date'", 'Get-Date'], [ String.raw`pwsh -Command "Write-Output \"hello\"; Get-Content C:\game\a.txt"`, String.raw`Write-Output "hello"; Get-Content C:\game\a.txt`, ], ["pwsh -Command 'Get-Date\nGet-Location'", 'Get-Date\nGet-Location'], ["pwsh -Command 'Get-Date…", "'Get-Date…"], ])('隐藏启动器:%s', (command, script) => { expect(toolCallInputText(commandCall(command))).toBe(script); }); it.each([ 'npm run build', 'pwsh -File game/build.ps1', 'pwsh -EncodedCommand ZgBvAG8A', 'not-pwsh.exe -Command Get-Date', 'echo pwsh -Command Get-Date', "bash -c 'echo hello'", ])('保留非目标调用:%s', (command) => { expect(toolCallInputText(commandCall(command))).toBe(command); }); it('不改写 MCP 工具参数', () => { const call = { ...commandCall('pwsh -Command Get-Date'), kind: 'mcp_tool' as const, }; expect(toolCallInputText(call)).toBe('pwsh -Command Get-Date'); }); });