ReviewOS

also looking at this

stacks/bunpress

fix: serve modern image assets in native docs development

#90
Merged chris wants to merge codex/docs-modern-image-assets into main
2 files +39 -1
test/markdown-source-links.test.tsmodified+38-0
Changes to test/markdown-source-links.test.ts
@@ -452,3 +452,41 @@ test('include reference validation refuses excessive candidates without publishi
452452 try { expect((await fetch(`${url}/docs/guides/start`)).status).toBe(500) }
453453 finally { stop() }
454454}, 30000)
455
456test('native dev serves WebP and AVIF bytes from public and docs roots under the docs mount', async () => {
457 const f = await fixture()
458 await mkdir(join(f.docs, 'public/assets'), { recursive: true })
459 await mkdir(join(f.docs, 'assets'), { recursive: true })
460 const assets = [
461 { name: 'public.webp', type: 'image/webp', directory: 'public/assets' },
462 { name: 'public.avif', type: 'image/avif', directory: 'public/assets' },
463 { name: 'root.webp', type: 'image/webp', directory: 'assets' },
464 { name: 'root.avif', type: 'image/avif', directory: 'assets' },
465 ]
466 // The HTTP server transports opaque original bytes; decoding belongs to the browser.
467 const bytes = new Uint8Array([0, 1, 255, 128, 82, 73, 70, 70, 0])
468 for (const asset of assets)
469 await writeFile(join(f.docs, asset.directory, asset.name), bytes)
470 await writeFile(join(f.docs, 'assets/public.webp'), 'shadowed root bytes')
471 const { url, stop } = await startServer({ port: 0, root: f.docs, watch: false, quiet: true, config })
472 try {
473 for (const asset of assets) {
474 for (const prefix of ['', '/docs']) {
475 const response = await fetch(`${url}${prefix}/assets/${asset.name}`)
476 const actual = new Uint8Array(await response.arrayBuffer())
477 expect({ name: asset.name, prefix, status: response.status }).toEqual({ name: asset.name, prefix, status: 200 })
478 expect(response.headers.get('content-type')).toBe(asset.type)
479 expect(actual).toEqual(bytes)
480 }
481 }
482 const missing = await fetch(`${url}/docs/assets/missing.webp`)
483 expect(missing.status).toBe(404)
484 const page = await fetch(`${url}/docs/guides/start`)
485 expect(page.status).toBe(200)
486 await assertLinks(await page.text())
487 }
488 finally { stop() }
489 expect(await buildDocs({ dir: f.docs, outdir: f.out, config: f.configFile, searchIndex: false })).toBe(true)
490 for (const asset of assets.filter(asset => asset.directory === 'public/assets'))
491 expect(new Uint8Array(await Bun.file(join(f.out, '.bunpress/assets', asset.name)).arrayBuffer())).toEqual(bytes)
492}, 30000)