mirror of
https://github.com/zoo-apps/zoolabs.io.git
synced 2026-10-30 14:56:27 +00:00
Audio: twenty-eight of the twenty-nine clips carry no audio track, so a mute switch would have switched nothing. What the site can actually say out loud is the answer, through the browser's own synthesiser — no network, no key, 180 voices on this machine. The speaker is the user gesture browsers require, so reading aloud only ever starts because someone asked for it, and a new question stops the old one mid-sentence. Proposal links were broken on every card: zips.zoo.ngo serves them under /docs/<slug>/ and the generator wrote /<slug>, so all 149 pointed at a 404. Fixed, and both link shapes are now asserted — shape is the part a test can hold, and it is the part that was wrong. The reply path had no test at all, which is how the parser went unexamined while the fabricated fallback hid every failure behind it. It has six now, against a real streaming body: tokens in order, a frame split across two reads, keep-alives and non-JSON lines skipped, and a refusal arriving as its own words rather than as prose. Driven end to end against a stand-in model, the loop lands: clip swaps to Interest, the caption follows, the [feeling:] tag stays out of the visible answer, and the answer is spoken. Look: ZOO LABS reads top left at full weight — the mark left the header for the bottom right, where a launcher belongs, and puts the cursor in the question box from anywhere on the site. Zen now comes from @hanzo/font, which is where the family is authored, rather than two woff2 files copied into public/. Also fixed: <Paragraph> inside <Paragraph> put a <p> inside a <p> and broke hydration on both pages; `'' && <X/>` rendered an empty text node into a gui View, which warns on every render. Both were reported by the browser and neither had been read. Co-authored-by: Hanzo Dev <[email protected]>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { afterEach, test } from 'node:test'
|
|
import { reply } from './chat.ts'
|
|
|
|
const realFetch = globalThis.fetch
|
|
afterEach(() => {
|
|
globalThis.fetch = realFetch
|
|
})
|
|
|
|
/** Serves the given chunks as a streaming body, byte boundaries and all. */
|
|
function serve(chunks: string[], init: ResponseInit = {}) {
|
|
globalThis.fetch = (async () =>
|
|
new Response(
|
|
new ReadableStream({
|
|
start(c) {
|
|
const enc = new TextEncoder()
|
|
for (const chunk of chunks) c.enqueue(enc.encode(chunk))
|
|
c.close()
|
|
},
|
|
}),
|
|
{ status: 200, ...init }
|
|
)) as typeof fetch
|
|
}
|
|
|
|
const frame = (content: string) =>
|
|
`data: ${JSON.stringify({ choices: [{ delta: { content } }] })}\n\n`
|
|
|
|
const drain = async () => {
|
|
let out = ''
|
|
for await (const token of reply([{ role: 'user', content: 'hi' }])) out += token
|
|
return out
|
|
}
|
|
|
|
test('reads tokens in order and stops at [DONE]', async () => {
|
|
serve([frame('Calves '), frame('are '), frame('grey.'), 'data: [DONE]\n\n', frame('ignored')])
|
|
assert.equal(await drain(), 'Calves are grey.')
|
|
})
|
|
|
|
test('a frame split across two reads is not lost', async () => {
|
|
const whole = frame('Sound travels further in water.')
|
|
serve([whole.slice(0, 12), whole.slice(12), 'data: [DONE]\n\n'])
|
|
assert.equal(await drain(), 'Sound travels further in water.')
|
|
})
|
|
|
|
test('keep-alives and non-JSON lines are skipped, not thrown on', async () => {
|
|
serve([': ping\n\n', frame('Still '), 'data: not json\n\n', frame('here.'), 'data: [DONE]\n\n'])
|
|
assert.equal(await drain(), 'Still here.')
|
|
})
|
|
|
|
// The whole point of the rewrite: a refusal must reach the page as itself.
|
|
test("a refusal surfaces the endpoint's own words", async () => {
|
|
globalThis.fetch = (async () =>
|
|
new Response(JSON.stringify({ error: { message: 'a billable tenant is required' } }), {
|
|
status: 402,
|
|
statusText: 'Payment Required',
|
|
})) as typeof fetch
|
|
await assert.rejects(drain, /a billable tenant is required/)
|
|
})
|
|
|
|
test('a refusal with no message body still says something useful', async () => {
|
|
globalThis.fetch = (async () =>
|
|
new Response('nope', { status: 503, statusText: 'Service Unavailable' })) as typeof fetch
|
|
await assert.rejects(drain, /503 Service Unavailable/)
|
|
})
|