const mod = await import('node:module'); const require = mod.createRequire(import.meta.url); const parser = require('../content/parser.js'); const L = String.fromCharCode(10214); const R = String.fromCharCode(10215); const LF = String.fromCharCode(10); const Q = String.fromCharCode(34); const LB = String.fromCharCode(123); const RB = String.fromCharCode(125); const BS = String.fromCharCode(92); const LT = String.fromCharCode(60); let pass = 0; let fail = 0; const ok = (name, cond) => cond ? (pass++, console.log('OK ' + name)) : (fail++, console.log('FAIL ' + name)); // Test 1: DSH JSON const json1 = LB + Q + 'tool' + Q + ':' + Q + 'dsh_read' + Q + ',' + Q + 'args' + Q + ':' + LB + Q + 'path' + Q + ':' + Q + 'README.md' + Q + RB + RB; const t1 = L + 'DSH' + R + json1 + L + '/DSH' + R; const r1 = parser.extractCalls(t1, 3); ok('DSH count', r1.calls.length === 1); ok('DSH tool', !!r1.calls[0] ? r1.calls[0].tool === 'dsh_read' : false); ok('DSH path', !!r1.calls[0] ? r1.calls[0].args.path === 'README.md' : false); // Test 2: DSH_B64 const b64 = 'eyJ0b29sIjoiZHNoX3RyZWUiLCJhcmdzIjp7InBhdGgiOiIuIn19'; const t2 = L + 'DSH_B64' + R + b64 + L + '/DSH_B64' + R; const r2 = parser.extractCalls(t2, 3); ok('B64 count', r2.calls.length === 1); ok('B64 tool', !!r2.calls[0] ? r2.calls[0].tool === 'dsh_tree' : false); // Test 3: DSH_FILE const phpBody = LT + '?php' + LF + 'namespace app' + BS + 'models;' + LF; const t3 = L + 'DSH_FILE path=' + Q + 't.php' + Q + R + LF + phpBody + L + '/DSH_FILE' + R; const r3 = parser.extractCalls(t3, 3); ok('FILE count', r3.calls.length === 1); ok('FILE path', !!r3.calls[0] ? r3.calls[0].args.path === 't.php' : false); ok('FILE tool', !!r3.calls[0] ? r3.calls[0].tool === 'dsh_write' : false); ok('FILE content', !!r3.calls[0] ? r3.calls[0].args.content.indexOf('namespace app' + BS + 'models') !== -1 : false); console.log('passed ' + pass + ', failed ' + fail); if (fail > 0) process.exit(1);