remoteNodeFiles.test.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect, it } from 'vitest'
  2. import { rewriteRemoteNodeFiles } from '@/components/workspace/viewModels'
  3. describe('remote node file links', () => {
  4. it('routes remote images and files through the source node', () => {
  5. const node = '11111111-1111-4111-8111-111111111111'
  6. const content = [
  7. '![图](</Users/remote/Agents/result one.png>)',
  8. '[报告](/Users/remote/Agents/report.pdf)',
  9. '[日志](file:///Users/remote/Agents/run.log)',
  10. ].join('\n')
  11. const rewritten = rewriteRemoteNodeFiles(content, node)
  12. expect(rewritten).toContain(`/api/plugins/yaoyao/v1/nodes/${node}/files?path=%2FUsers%2Fremote%2FAgents%2Fresult%20one.png`)
  13. expect(rewritten).toContain('path=%2FUsers%2Fremote%2FAgents%2Freport.pdf')
  14. expect(rewritten).toContain('path=%2FUsers%2Fremote%2FAgents%2Frun.log')
  15. expect(rewritten).not.toContain('](</Users/remote')
  16. })
  17. it('normalizes real Hermes MEDIA directives before routing them', () => {
  18. const node = '11111111-1111-4111-8111-111111111111'
  19. const content = [
  20. 'MEDIA:/Users/samien/Agents/smoke_zimage_turbo_00001_.png',
  21. 'MEDIA:`/Users/samien/Agents/远程 报告.pdf`',
  22. ].join('\n')
  23. const rewritten = rewriteRemoteNodeFiles(content, node)
  24. expect(rewritten).toContain(`![smoke_zimage_turbo_00001_.png](/api/plugins/yaoyao/v1/nodes/${node}/files?path=%2FUsers%2Fsamien%2FAgents%2Fsmoke_zimage_turbo_00001_.png)`)
  25. expect(rewritten).toContain(`[远程 报告.pdf](/api/plugins/yaoyao/v1/nodes/${node}/files?path=%2FUsers%2Fsamien%2FAgents%2F%E8%BF%9C%E7%A8%8B%20%E6%8A%A5%E5%91%8A.pdf)`)
  26. expect(rewritten).not.toContain('MEDIA:')
  27. })
  28. it('keeps an incomplete streaming MEDIA directive untouched', () => {
  29. const node = '11111111-1111-4111-8111-111111111111'
  30. expect(rewriteRemoteNodeFiles('MEDIA:/Users/samien/Agents/partial.png', node, true))
  31. .toBe('MEDIA:/Users/samien/Agents/partial.png')
  32. })
  33. it('does not rewrite web URLs or local-agent content', () => {
  34. expect(rewriteRemoteNodeFiles('[官网](https://example.com/a.png)', 'local'))
  35. .toBe('[官网](https://example.com/a.png)')
  36. })
  37. })