test-workflow-read-files.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import fs from 'fs';
  2. import os from 'os';
  3. import path from 'path';
  4. import { WorkflowExecutor } from './src/vl/workflow-executor.js';
  5. function assert(condition, message) {
  6. if (!condition) throw new Error(message);
  7. }
  8. console.log('\n── Workflow readFiles Context ──');
  9. const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vlcode-workflow-readfiles-'));
  10. fs.mkdirSync(path.join(workDir, 'Apps'), { recursive: true });
  11. fs.writeFileSync(
  12. path.join(workDir, 'Apps', 'Demo.vx'),
  13. '// VL_VERSION:3.5\n<App-Demo>\n <Page-Demo />\n</App-Demo>\n',
  14. 'utf-8'
  15. );
  16. let captured = null;
  17. try {
  18. const executor = new WorkflowExecutor({ workDir, model: 'test-model' });
  19. executor.client = {
  20. messages: {
  21. async create(params) {
  22. captured = params;
  23. return {
  24. content: [{ type: 'text', text: '{"ok":true}' }],
  25. usage: {},
  26. stop_reason: 'end_turn',
  27. model: 'test-model',
  28. };
  29. },
  30. },
  31. };
  32. const adapter = executor._buildLLMAdapter();
  33. await adapter.call({
  34. readFiles: ['Apps/Demo.vx'],
  35. messages: [{ role: 'user', content: 'Regenerate this app entry.' }],
  36. output_config: { format: { type: 'json_object' } },
  37. });
  38. assert(Array.isArray(captured?.messages) && captured.messages.length >= 2, 'readFiles should prepend file context to the LLM messages');
  39. assert(captured.messages[0].content.includes('<file-context path="Apps/Demo.vx">'), 'prepended file context should include the requested path');
  40. assert(captured.messages[0].content.includes('// VL_VERSION:3.5'), 'prepended file context should include current file content');
  41. assert(captured.messages[1].content === 'Regenerate this app entry.', 'original user message should remain after the file context');
  42. console.log('PASS test-workflow-read-files.js');
  43. } finally {
  44. fs.rmSync(workDir, { recursive: true, force: true });
  45. }