Files
probably-rendering-one-more…/apps/wiki/tests/explore.test.ts
T
codex-bot b943951bed
wiki CI and deployment / verify-and-deploy (push) Has been cancelled
studio CI and deployment / verify-and-deploy (push) Has been cancelled
Unify content under ID-based note dialogs with lightweight previews and Studio proxy
2026-10-25 22:06:05 +08:00

10 lines
1.7 KiB
TypeScript

import {test} from 'node:test';
import assert from 'node:assert/strict';
import {staticEntries,getEntry,entryText} from '../src/lib/explore';
import {pageId,previewUrl} from '../src/content/page-links';
import {guidanceDocuments} from '../src/content/skills/guidance';
import {getServerSideProps} from '../src/pages/explore/[id]';
test('every public document has a distinct persisted ID and canonical entry',async()=>{assert.equal(new Set(staticEntries.map(e=>e.id)).size,staticEntries.length);for(const e of staticEntries){assert.match(e.id,/^[a-f0-9]{24}$/);assert.equal((await getEntry(e.id))?.title,e.title);}for(const doc of guidanceDocuments)assert.ok(pageId('guidance:'+doc.path));assert.equal(await getEntry('unknown'),null);});
test('agent_mode on the canonical URL emits text with media links and no HTML',async()=>{const entry=staticEntries.find(e=>e.media.length)!;let body='';const headers:Record<string,string>={};const response={setHeader:(k:string,v:string)=>headers[k]=v,end:(value:string)=>{body=value}};await getServerSideProps({params:{id:entry.id},query:{agent_mode:'True'},res:response,req:{method:'GET'}} as never);assert.match(headers['Content-Type'],/text\/plain/);assert.ok(body.includes(entry.title));assert.ok(body.includes(entry.media[0].url));assert.ok(!body.includes('<img'));assert.ok(!body.includes('!['));assert.equal(body,entryText((await getEntry(entry.id))!));});
test('preview URLs always use bounded image endpoints',()=>{const url=new URL(previewUrl('/api/media/id?variant=poster',480),'http://test');assert.equal(url.pathname,'/api/preview');assert.equal(url.searchParams.get('source'),'/api/media/id?variant=poster');assert.equal(url.searchParams.get('width'),'480');});