test-orchestrator-fix-skill.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import fs from 'fs';
  2. import os from 'os';
  3. import path from 'path';
  4. import { AgentOrchestrator } from './src/core/orchestrator.js';
  5. function assert(condition, message) {
  6. if (!condition) throw new Error(message);
  7. }
  8. console.log('\n── Orchestrator Fix Skill ──');
  9. const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vlcode-fix-skill-'));
  10. fs.mkdirSync(path.join(workDir, '.vl-code'), { recursive: true });
  11. let compileCalls = 0;
  12. const toolRegistry = {
  13. _skillFilter: null,
  14. async execute(name) {
  15. if (name !== 'VLCompile') throw new Error(`Unexpected tool call: ${name}`);
  16. compileCalls++;
  17. return {
  18. result: JSON.stringify({ success: true, errCount: 0, warningCount: 0 }),
  19. error: null,
  20. };
  21. },
  22. getToolSchemas() { return []; },
  23. };
  24. const contextManager = {
  25. messages: [],
  26. turnCount: 0,
  27. addUserMessage(blocks) { this.messages.push({ role: 'user', content: blocks }); },
  28. getMessages() { return this.messages; },
  29. };
  30. const promptAssembler = {
  31. buildInitialReminders() { return []; },
  32. buildSystemPrompt() { return ''; },
  33. };
  34. const projectContext = {
  35. isVLProject() { return true; },
  36. getAllFiles() { return []; },
  37. getSummary() { return { projectName: path.basename(workDir) }; },
  38. };
  39. try {
  40. const orchestrator = new AgentOrchestrator({
  41. config: { workDir, model: 'test-model' },
  42. toolRegistry,
  43. contextManager,
  44. promptAssembler,
  45. cli: {},
  46. projectContext,
  47. });
  48. const skillNames = orchestrator.getSkills().map(skill => skill.name);
  49. assert(skillNames.includes('fix'), '/fix alias should be registered as a skill');
  50. assert(skillNames.includes('compile-fix'), '/compile-fix should remain available');
  51. let done = false;
  52. const result = await orchestrator.executeSkill('fix', undefined, {
  53. onText() {},
  54. onToolResult() {},
  55. onPlanMode() {},
  56. onDone() { done = true; },
  57. });
  58. assert(result?.success === true, '/fix alias should use the compile-fix loop');
  59. assert(compileCalls === 1, '/fix alias should compile the project once when there are no errors');
  60. assert(done === true, '/fix alias should invoke onDone');
  61. const intent = orchestrator.detectWorkflowIntent('请修复这个编译错误');
  62. assert(intent?.type === 'repair', 'compile-error phrasing should route to repair intent, not VLAdjust');
  63. console.log('PASS test-orchestrator-fix-skill.js');
  64. } finally {
  65. fs.rmSync(workDir, { recursive: true, force: true });
  66. }