import { parseSource } from '../src/shared/utils/bash-parser.ts';
import { isSafeShellCommand } from '../src/domain/agent/services/approval.ts';
import { getToolRiskLevel, ToolRiskLevel } from '../src/domain/agent/services/approval.ts';

const commands = [
  'cd /c/Users/zhuoz/Desktop/gui && ls -la build* 2>/dev/null || echo "No build directory found"',
  'cd C:/Users/zhuoz/Desktop/gui && find build -name "libAutoJdv*" -o -name "AutoJdv.dll" 2>/dev/null | head -5',
  'ls -la',
  'echo hello',
];

for (const cmd of commands) {
  console.log(`\n=== Testing: ${cmd.slice(0, 80)}... ===`);

  const t0 = Date.now();
  let astResult;
  try {
    astResult = parseSource(cmd);
  } catch (e) {
    console.log('parseSource THREW:', e);
    continue;
  }
  const parseTime = Date.now() - t0;
  console.log(`parseSource: type=${astResult?.type} children=${astResult?.children?.length} time=${parseTime}ms`);

  const t1 = Date.now();
  const safe = isSafeShellCommand(cmd);
  const safeTime = Date.now() - t1;
  console.log(`isSafeShellCommand: ${safe} time=${safeTime}ms`);

  const t2 = Date.now();
  const risk = getToolRiskLevel('Shell', { command: cmd });
  const riskTime = Date.now() - t2;
  console.log(`getToolRiskLevel: ${risk} time=${riskTime}ms`);
}

console.log('\nAll tests completed.');
