test-vl-compile-warnings.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import fs from 'fs';
  2. import os from 'os';
  3. import path from 'path';
  4. import { createVLCompileTool } from './src/tools/vl-compile.js';
  5. function assert(condition, message) {
  6. if (!condition) throw new Error(message);
  7. }
  8. console.log('\n── VLCompile Warning Handling ──');
  9. const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vlcode-compile-tool-'));
  10. const originalFetch = global.fetch;
  11. global.fetch = async () => ({
  12. async text() {
  13. return [
  14. 'event: status',
  15. 'data: {"status":"success"}',
  16. '',
  17. 'event: result',
  18. 'data: {"data":{"gid":1653,"errList":[{"level":"warning","message":"deprecated"}],"apps":{"frontends":{"Apps/TeacherApp.vx":{"previewUrl":"https://example.test/app"}}}}}',
  19. '',
  20. ].join('\n');
  21. },
  22. });
  23. try {
  24. const tool = createVLCompileTool({ workDir, port: 4002 });
  25. const result = JSON.parse(await tool.execute({}));
  26. assert(result.success === true, 'warning-only compile should be treated as success');
  27. assert(result.errCount === 0, 'warning-only compile should have zero hard errors');
  28. assert(result.warningCount === 1, 'warning count should be preserved');
  29. assert(result.previewUrls['Apps/TeacherApp.vx'] === 'https://example.test/app', 'preview URL should be preserved on warning-only compile');
  30. console.log('PASS test-vl-compile-warnings.js');
  31. } finally {
  32. global.fetch = originalFetch;
  33. }