test-autotest-state-hydration.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env node
  2. import assert from 'assert';
  3. import fs from 'fs';
  4. import os from 'os';
  5. import path from 'path';
  6. import { createAutoTestPipelineTool } from './src/tools/autotest-pipeline.js';
  7. const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vlcode-autotest-state-'));
  8. const vlDir = path.join(workDir, '.vl-code');
  9. fs.mkdirSync(vlDir, { recursive: true });
  10. fs.writeFileSync(path.join(vlDir, 'autotest-cases.json'), JSON.stringify({
  11. testPlan: { pages: [{ path: '/TaskList' }] },
  12. testCases: [
  13. {
  14. id: 'WF_001',
  15. name: 'Smoke',
  16. priority: 'P0',
  17. page: '/TaskList',
  18. steps: [{ action: 'navigate', selector: 'https://example.test/app' }],
  19. },
  20. ],
  21. }, null, 2));
  22. fs.writeFileSync(path.join(vlDir, 'autotest-results.json'), JSON.stringify({
  23. runResults: [
  24. {
  25. caseId: 'WF_001',
  26. pass: false,
  27. status: 'soft_pass',
  28. steps: [{ index: 0, action: 'navigate', selector: 'https://example.test/app', status: 'soft_pass' }],
  29. },
  30. ],
  31. evaluations: [
  32. {
  33. caseId: 'WF_001',
  34. name: 'Smoke',
  35. evaluation: {
  36. pass: false,
  37. softPass: true,
  38. reason: 'Soft pass: 1 steps skipped (selectors not found in DOM)',
  39. evidence: '⚠️ Step 1 navigate "https://example.test/app": soft-pass (not found)',
  40. },
  41. },
  42. ],
  43. timestamp: '2026-03-14T15:40:00.000Z',
  44. }, null, 2));
  45. const tool = createAutoTestPipelineTool(
  46. {
  47. workDir,
  48. llmProvider: 'cli',
  49. cliAvailable: true,
  50. model: 'claude-opus-4-6',
  51. },
  52. {
  53. getAllFiles() { return []; },
  54. }
  55. );
  56. const status = await tool.execute({ action: 'status' });
  57. assert.equal(status.testCases, 1, 'status should hydrate persisted test cases');
  58. assert.equal(status.runResults, 1, 'status should hydrate persisted run results');
  59. assert.equal(status.passed, 0);
  60. assert.equal(status.softPassed, 1);
  61. assert.equal(status.failed, 0);
  62. assert.match(status.result, /1 test cases, 1 results/);
  63. const report = await tool.execute({ action: 'report' });
  64. assert.match(report.result, /Soft-Passed/);
  65. assert.match(report.result, /WF_001/);
  66. fs.rmSync(workDir, { recursive: true, force: true });
  67. console.log('\n── AutoTest State Hydration ──');
  68. console.log('PASS test-autotest-state-hydration.js');