// Isolated browser fixture: real view + repository, recorded wire frames; no // connection to any Pipelines service and no production data or mutations. import assert from "node:assert/strict"; import { createServer } from "node:http"; import { readFile, mkdir } from "node:fs/promises"; import { resolve, extname } from "node:path"; import { fileURLToPath } from "node:url"; import { launchChrome, eventually } from "./browser.mjs"; const root = fileURLToPath(new URL("../", import.meta.url)); const out = resolve(process.argv[2] || "captures/search-types-recent"); await mkdir(out, { recursive: true }); const server = createServer(async (req, res) => { try { if (req.url === "/") { res.setHeader("Content-Type", "text/html; charset=utf-8"); const index = await readFile(resolve(root, "index.html"), "utf8"); const styles = index.match(/]+>/g).join("\n"); res.end(`${styles}
Isolated search fixture — recorded requests, no live service
`); return; } const path = resolve(root, `.${req.url}`); if (!path.startsWith(root)) throw new Error("invalid path"); res.setHeader("Content-Type", extname(path) === ".js" ? "text/javascript" : "text/css"); res.end(await readFile(path)); } catch { res.writeHead(404).end(); } }); await new Promise((done) => server.listen(0, "127.0.0.1", done)); let browser; try { browser = await launchChrome(); const page = await browser.openPage(`http://127.0.0.1:${server.address().port}`); await page.evaluate(`(async () => { const { createSearchView } = await import('/src/views/search.js'); const { SearchSequencer } = await import('/src/search.js'); const { PipelinesRepository } = await import('/src/repository.js'); window.framesSent = []; const repo = new PipelinesRepository({ call: async (frame) => { framesSent.push(frame); const fixtures = { pipeline: [{ kind: 'pipeline', target: 'pipeline:12', pipeline: { id: 12, name: 'Recent fixture pipeline', version: 1, stages: 2 } }], artifact: [{ kind: 'artifact', target: '/artifacts/12/1/report.txt', artifact: { run_id: 12, sequence: 1, name: 'Recent fixture report.txt', url: '/artifacts/12/1/report.txt', content_type: 'text/plain', size_bytes: 20 } }], }; return { search_results: { results: frame.search.query === '' ? fixtures[frame.search.kind] || [] : [], truncated: frame.search.query === '' && ['field', 'pipeline'].includes(frame.search.kind), } }; }}); const state = { searchQuery: '', searchKind: '', searchSort: 'relevance', searchResults: [], searchSequencer: new SearchSequencer(), searchActiveIndex: 0 }; const view = createSearchView({ state, repo, searchHost: document.querySelector('#host'), renderHeader() {} }); view.openSearch(); })()`); const last = () => page.evaluate("framesSent.at(-1)"); const search = async (text) => { const before = await page.evaluate("framesSent.length"); await page.fill("#searchInput", text); await eventually(async () => (await page.evaluate("framesSent.length")) > before); }; await search("T:pipeline plan"); assert.deepEqual((await last()).search, { query: " plan", kind: "pipeline", limit: 0 }); assert.equal(await page.evaluate("document.querySelector('#searchKind').value"), "pipeline"); await page.screenshot(`${out}/01-type-filter.png`); await search("t:run plan TYPE:artifact"); assert.equal((await last()).search.kind, "artifact"); await page.screenshot(`${out}/02-last-type-wins.png`); await page.evaluate("document.querySelector('#searchKind').value = 'step'; document.querySelector('#searchKind').dispatchEvent(new Event('change'))"); await eventually(async () => (await last()).search.kind === "step"); assert.equal(await page.evaluate("document.querySelector('#searchInput').value"), " plan "); await page.screenshot(`${out}/03-selector-replaces-token.png`); await search('"t:run" t:unknown'); assert.equal((await last()).search.query, '"t:run" t:unknown'); await page.screenshot(`${out}/04-literal-tokens.png`); await search("t:pipeline"); assert.deepEqual((await last()), { type: "search", search: { query: "", kind: "pipeline", limit: 0 } }); await eventually(() => page.evaluate("document.querySelector('#searchResults').textContent.includes('Recent fixture pipeline')")); await page.screenshot(`${out}/05-type-only-pipelines.png`); await search("type:ARTIFACT"); assert.deepEqual((await last()).search, { query: "", kind: "artifact", limit: 0 }); await eventually(() => page.evaluate("document.querySelector('#searchResults').textContent.includes('Recent fixture report.txt')")); await page.screenshot(`${out}/06-type-only-artifacts.png`); await page.evaluate("document.querySelector('#searchKind').value = 'step'; document.querySelector('#searchKind').dispatchEvent(new Event('change'))"); await eventually(() => page.evaluate("document.querySelector('#searchResults').textContent === 'No steps yet.'")); assert.deepEqual((await last()).search, { query: "", kind: "step", limit: 0 }); await page.screenshot(`${out}/07-empty-kind.png`); await page.evaluate("document.querySelector('#searchKind').value = 'field'; document.querySelector('#searchKind').dispatchEvent(new Event('change'))"); await eventually(() => page.evaluate("document.querySelector('#searchResults').textContent.includes(\"No fields found within the server's scan limit.\")")); await page.screenshot(`${out}/08-scan-bound-empty.png`); const beforeClear = await page.evaluate("framesSent.length"); await page.click("#searchClearFilter"); assert.equal(await page.evaluate("document.querySelector('#searchInput').value"), ""); assert.equal(await page.evaluate("document.querySelector('#searchKind').value"), ""); assert.equal(await page.evaluate("document.querySelector('#searchResults').textContent"), ""); assert.equal(await page.evaluate("framesSent.length"), beforeClear); await page.screenshot(`${out}/09-cleared-filter.png`); console.log(`PASS: type tokens, wire kind/query, precedence, selector replacement, literals, kind-only results/empty state and clear. Captures: ${out}`); } finally { await browser?.close(); await new Promise((done) => server.close(done)); }