|
|
@@ -1,7 +1,7 @@
|
|
|
// @vitest-environment jsdom
|
|
|
import { cleanup, render } from '@testing-library/react'
|
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
|
-import { AssistantMarkdown } from '../src/client/chat/AssistantMarkdown.tsx'
|
|
|
+import { AssistantMarkdown, localPathMediaUrl } from '../src/client/chat/AssistantMarkdown.tsx'
|
|
|
import type { ChatNodeOwnerProps, ChatViewSlotProps } from '../src/client/contract/slots.ts'
|
|
|
import type { AssistantBlock } from '../src/client/contract/snapshot.ts'
|
|
|
|
|
|
@@ -14,6 +14,34 @@ function textBlock(text: string): AssistantBlock {
|
|
|
return { kind: 'text', text }
|
|
|
}
|
|
|
|
|
|
+const ORIGIN = 'http://127.0.0.1:3080'
|
|
|
+
|
|
|
+describe('localPathMediaUrl', () => {
|
|
|
+ it('maps an absolute POSIX path on an HTTP page to the file API', () => {
|
|
|
+ expect(localPathMediaUrl('http:', ORIGIN, '/tmp/graph.png'))
|
|
|
+ .toBe(`${ORIGIN}/api/file?path=${encodeURIComponent('/tmp/graph.png')}`)
|
|
|
+ expect(localPathMediaUrl('https:', 'https://127.0.0.1:3080', '/tmp/graph.png'))
|
|
|
+ .toBe(`https://127.0.0.1:3080/api/file?path=${encodeURIComponent('/tmp/graph.png')}`)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('keeps non-HTTP transports inert', () => {
|
|
|
+ expect(localPathMediaUrl('file:', 'file:///app', '/tmp/graph.png')).toBeUndefined()
|
|
|
+ expect(localPathMediaUrl('ws:', ORIGIN, '/tmp/graph.png')).toBeUndefined()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('keeps destinations that cannot be Host-served local files inert', () => {
|
|
|
+ expect(localPathMediaUrl('http:', ORIGIN, '')).toBeUndefined()
|
|
|
+ expect(localPathMediaUrl('http:', ORIGIN, '//cdn.example.com/x.png')).toBeUndefined()
|
|
|
+ expect(localPathMediaUrl('http:', ORIGIN, 'relative.png')).toBeUndefined()
|
|
|
+ expect(localPathMediaUrl('http:', ORIGIN, 'C:\\tmp\\x.png')).toBeUndefined()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('encodes the full path including spaces', () => {
|
|
|
+ expect(localPathMediaUrl('http:', ORIGIN, '/tmp/my graph.png'))
|
|
|
+ .toBe(`${ORIGIN}/api/file?path=${encodeURIComponent('/tmp/my graph.png')}`)
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
describe('AssistantMarkdown local-path images', () => {
|
|
|
it('renders a local image path in closing prose through the same-origin API', () => {
|
|
|
const { container } = render(
|