/**
* /design-html's Pretext embedding recipe, run as written. "### Pretext Source
* Embedding" in the generated design-html/SKILL.md tells the agent to copy
* design-html/vendor/pretext-embed.html into the page, splice the vendored
* bundle in at its PRETEXT_BUNDLE line with a documented awk command, and put
* page code at its "// page code" line. The scaffold keeps the bundle in an
* inert ');
expect(SCAFFOLD).toContain("new Blob([document.getElementById('pretext-src').text], { type: 'text/javascript' })");
expect(SCAFFOLD).toContain('URL.revokeObjectURL(pretextURL)');
expect(SCAFFOLD.indexOf(PAGE_CODE_LINE)).toBeGreaterThan(SCAFFOLD.indexOf('await import(pretextURL)'));
expect(SCAFFOLD.lastIndexOf('')).toBeGreaterThan(SCAFFOLD.indexOf(PAGE_CODE_LINE));
for (const name of NAMES) {
expect(BUNDLE, name).toMatch(new RegExp(`\\w+ as ${name}\\b`));
expect(SCAFFOLD, name).toMatch(new RegExp(`[{,] ${name}[ ,]`));
}
});
test('the vendored bundle can sit in a raw-text `);
expect(built).not.toContain('PRETEXT_BUNDLE');
const pages: Record = {
'/finalized.html': built,
'/old.html': htmlDocument(``),
};
server = Bun.serve({
hostname: '127.0.0.1', port: 0,
fetch: (req) => {
const html = pages[new URL(req.url).pathname];
return html ? new Response(html, { headers: { 'content-type': 'text/html; charset=utf-8' } }) : new Response('not found', { status: 404 });
},
});
browser = await chromium.launch({ headless: true, executablePath: CHROMIUM, timeout: 90_000 });
for (const url of [`file://${finalized}`, `http://127.0.0.1:${server.port}/finalized.html`]) {
const { errors, raw } = await load(browser, url);
expect(errors, url).toEqual([]);
expect(raw, `${url}: the page code never finished`).not.toBe('');
const result = JSON.parse(raw);
expect(result.lineCount, url).toBeGreaterThan(1);
expect(result.height, url).toBe(result.lineCount * LINE_HEIGHT);
expect(result.walked, url).toBe(result.lineCount);
expect(result.lines, url).toBe(result.lineCount);
expect(typeof result.firstLine === 'string' && result.firstLine.length > 0, url).toBe(true);
}
const old = await load(browser, `http://127.0.0.1:${server.port}/old.html`);
expect(old.raw).toBe('');
expect(old.errors).toContain('ReferenceError: prepareWithSegments is not defined');
} finally {
await browser?.close();
server?.stop(true);
fs.rmSync(dir, { recursive: true, force: true });
}
}, 120_000);
});