/** * Unit tests for Windows cmd.exe argument escaping (ccw/dist/utils/shell-escape.js) */ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; const shellEscapeUrl = new URL('../dist/utils/shell-escape.js', import.meta.url).href; // eslint-disable-next-line @typescript-eslint/no-explicit-any let mod: any; describe('escapeWindowsArg', async () => { mod = await import(shellEscapeUrl); it('escapes cmd.exe metacharacters with caret', () => { const cases: Array<{ input: string; expected: string }> = [ { input: 'arg|command', expected: 'arg^|command' }, { input: 'arg&command', expected: 'arg^&command' }, { input: 'arg&&command', expected: 'arg^&^&command' }, { input: 'arg||command', expected: 'arg^|^|command' }, { input: 'arg>out.txt', expected: 'arg^>out.txt' }, { input: 'arg>>out.txt', expected: 'arg^>^>out.txt' }, { input: 'arg { assert.equal(mod.escapeWindowsArg('hello world'), '"hello world"'); assert.equal(mod.escapeWindowsArg('test & echo'), '"test ^& echo"'); assert.equal(mod.escapeWindowsArg('a|b c'), '"a^|b c"'); }); it('handles empty arguments', () => { assert.equal(mod.escapeWindowsArg(''), '""'); }); });