diff --git a/web/PARITY.md b/web/PARITY.md index ac226e1e..2b9ede22 100644 --- a/web/PARITY.md +++ b/web/PARITY.md @@ -111,6 +111,22 @@ unit-tested in `test/repository.test.mjs` and the model in `test/actions.test.mj rename's exact server reason and, under `--decide`, the full live decision flow. ## Search + +Type-prefix follow-up (2026-10-20, **partial — isolated browser fixture, not a +live-server acceptance run**): unquoted, case-insensitive `t:` / `type:` tokens +accept the existing singular kinds (`pipeline`, `run`, `step`, `field`, +`artifact`, `version`). The last recognized token overrides the selector and is +reflected in Kind and the summary. Selecting Kind or Clear filter removes all +recognized tokens; unsupported and quoted tokens remain literal text. Only the +remaining text and the effective `kind` reach the unchanged `search` request. +Type-only queries show explicit help, not results: `Store.Search` deliberately +returns no results for blank text. Parser tests plus `node test/ui-search-types.mjs` +exercise the real view/repository with recorded fixture requests and no service +connection. Captures: `captures/search-types/01-type-filter.png` through +`06-cleared-filter.png` (including precedence, selector replacement, literal +tokens and type-only help). This browser-only shorthand is not yet on Android; +the earlier live-search acceptance evidence below is unchanged. + | # | Feature | Protocol | Status | | --- | --- | --- | --- | | S1 | Omni-search across pipelines, versions, runs, steps, fields, artifacts | `search` | done — the shell's `Search` control (rail on wide, dock on narrow) opens a full-width panel in the workspace flow (field autofocused, placeholder `Search pipelines, runs and artifacts`, a `Close search` control; opening and closing leave the current view, selection and loaded data untouched, Escape closes the field and returns focus to the Search control). One flat result list with no kind grouping, over a controls row: the kind select (`All kinds`/`Pipelines`/`Runs`/`Steps`/`Fields`/`Artifacts`/`Versions`), the sort select (`Relevance`/`Newest first`/`Name`), the one-line `{Kind} · {Sort}` summary and a `Clear filter` reset. The request is exactly `{type:"search",search:{query,kind,limit:0}}` — the server's own default cap, never above `SearchMaxLimit` 200 — debounced 250 ms after the last keystroke with Enter sending at once; a blank query clears locally with no request; the previous results stay visible (a thin progress bar above them) while a newer query loads and a stale reply is dropped by token; the first load shows the spinner and `Searching…`; an error takes precedence over the results. Failure copy is `AppViewModel`'s: a rejection naming an unknown command, or an older server's reply without `search_results`, reads `This server does not support search. Update the Pipelines server, then try again.` and any other failure carries the server's own text. Row text and blank fallbacks mirror `OmniSearchResults.searchRow` (a field hit's snippet emphasises the first case-insensitive query occurrence, never via `innerHTML`) and the empty state keeps Android's `No matches for "{query}".` / `No {kind} match "{query}".`. Captured 2026-10-19: `captures/01-search-results.png` (flat mixed list for the query `plan`, the controls row and summary `All kinds · Relevance`), `captures/02-search-kind-filter.png` (the `Pipelines` filter narrowing the list and the summary to `Pipelines · Relevance`) | diff --git a/web/src/search.js b/web/src/search.js index cee6198b..1495c913 100644 --- a/web/src/search.js +++ b/web/src/search.js @@ -42,6 +42,27 @@ export const SEARCH_KINDS = [ /** The default, no-narrowing kind. */ export const DEFAULT_SEARCH_KIND = ""; +/** Unquoted, whitespace-delimited t:/type: tokens; last supported token wins. + * Unknown tokens and quoted text stay literal, including their whitespace. + * The selector is a fallback; explicitly changing it removes tokens in the view. + */ +export function parseSearchQuery(value, selectedKind = DEFAULT_SEARCH_KIND) { + const source = String(value ?? ""); + let kind = selectedKind; + let hasType = false; + const query = source.replace(/(?:[^\s"'\\]|\\[\s\S]|"(?:[^"\\]|\\[\s\S])*(?:"|$)|'(?:[^'\\]|\\[\s\S])*(?:'|$))+/g, (token) => { + const match = /^(?:t|type):([a-z]+)$/i.exec(token); + const candidate = match?.[1].toLowerCase(); + if (!candidate || !SEARCH_KINDS.some((option) => option.value === candidate)) return token; + kind = candidate; + hasType = true; + return ""; + }); + return { query, kind, hasType }; +} + +export const SEARCH_TYPE_HELP = "Add search text after the type filter (for example, t:pipeline plan). This server does not list results by type alone."; + /** * The orders the search sort control offers. "Relevance" keeps the server's own * ranking (score, then recency, then a stable kind/target tie-break); "Newest diff --git a/web/src/views/search.js b/web/src/views/search.js index 30cf6779..dfa9c254 100644 --- a/web/src/views/search.js +++ b/web/src/views/search.js @@ -12,6 +12,8 @@ import { SEARCH_DEBOUNCE_MS, SEARCH_KINDS, SEARCH_SORTS, + SEARCH_TYPE_HELP, + parseSearchQuery, SearchSequencer, filterSearchResults, resolveRunTarget, @@ -28,6 +30,7 @@ import { export function createSearchView(rt) { const { state, repo, searchHost } = rt; + const parsedSearch = () => parseSearchQuery(state.searchQuery, state.searchKind); let searchTimer = null; let searchEdit = null; // The last search is resumed on the next open (the field, kind, sort and the @@ -181,9 +184,11 @@ function sendSearchNow() { * request is sent with the new kind. A sort change never sends a request. */ function setSearchKind(kind) { + state.searchQuery = parsedSearch().query; + const input = document.getElementById("searchInput"); + if (input) input.value = state.searchQuery; state.searchKind = kind; - refreshSearch(); - if (searchQuerySendable(state.searchQuery)) sendSearchNow(); + sendSearchNow(); } function setSearchSort(sort) { @@ -198,8 +203,16 @@ function setSearchSort(sort) { * failure carries the server's own text. A stale reply is dropped entirely. */ async function runSearch(sent) { + const parsed = parseSearchQuery(sent.query, state.searchKind); + if (!parsed.query.trim()) { + state.searchResults = []; + state.searchLoading = false; + state.searchLoaded = false; + refreshSearch(); + return; + } try { - const reply = await repo.search(sent.query, state.searchKind); + const reply = await repo.search(parsed.query, parsed.kind); if (!state.searchSequencer.accepts(sent.token)) return; if (reply == null) { state.searchLoading = false; @@ -230,11 +243,11 @@ async function runSearch(sent) { */ function refreshSearch() { const kindSelect = document.getElementById("searchKind"); - if (kindSelect) kindSelect.value = state.searchKind; + if (kindSelect) kindSelect.value = parsedSearch().kind; const sortSelect = document.getElementById("searchSort"); if (sortSelect) sortSelect.value = state.searchSort; const summary = document.getElementById("searchSummary"); - if (summary) summary.textContent = searchControlsSummary(state.searchKind, state.searchSort); + if (summary) summary.textContent = searchControlsSummary(parsedSearch().kind, state.searchSort); const area = document.getElementById("searchResults"); if (area) fillSearchResults(area); } @@ -260,7 +273,7 @@ function renderSearch() { }, ...SEARCH_KINDS.map((option) => h("option", { value: option.value, text: option.label })), ); - kindSelect.value = state.searchKind; + kindSelect.value = parsedSearch().kind; const sortSelect = h( "select", { @@ -288,7 +301,7 @@ function renderSearch() { oninput: (event) => onSearchInput(event.target.value), onkeydown: (event) => { const shown = sortSearchResults( - filterSearchResults(state.searchResults, state.searchKind), + filterSearchResults(state.searchResults, parsedSearch().kind), state.searchSort, ); if (event.key === "ArrowDown" || event.key === "ArrowUp") { @@ -302,8 +315,9 @@ function renderSearch() { } if (event.key === "Enter") { event.preventDefault(); - if (shown.length) routeSearchResult(shown[state.searchActiveIndex] ?? shown[0]); - else sendSearchNow(); + if (shown.length && !state.searchLoading && !state.searchError && parsedSearch().query.trim()) { + routeSearchResult(shown[state.searchActiveIndex] ?? shown[0]); + } else sendSearchNow(); } }, }), @@ -324,7 +338,7 @@ function renderSearch() { h("span", { id: "searchSummary", class: "search-summary muted", - text: searchControlsSummary(state.searchKind, state.searchSort), + text: searchControlsSummary(parsedSearch().kind, state.searchSort), }), h("button", { id: "searchClearFilter", @@ -340,7 +354,8 @@ function renderSearch() { const panel = h( "div", { id: "searchPanel", class: "search-panel", role: "dialog", "aria-modal": "true", "aria-label": "Search" }, - h("div", { class: "search-modal", role: "search" }, fieldRow, controls, area), + h("div", { class: "search-modal", role: "search" }, fieldRow, controls, + h("p", { class: "muted", text: "Filter with t:pipeline or type:artifact (pipeline, run, step, field, artifact, version). Last type wins; choosing Kind replaces it. Quote tokens to search literally." }), area), ); // A spotlight: clicking the dimmed backdrop closes it (the modal itself stops). panel.addEventListener("click", (event) => { @@ -361,15 +376,20 @@ function renderSearch() { * the filtered and sorted rows, or the empty-state line. */ function fillSearchResults(area) { + const parsed = parsedSearch(); + if (parsed.hasType && !parsed.query.trim()) { + area.replaceChildren(h("div", { class: "search-empty muted", text: SEARCH_TYPE_HELP })); + return; + } const shown = sortSearchResults( - filterSearchResults(state.searchResults, state.searchKind), + filterSearchResults(state.searchResults, parsed.kind), state.searchSort, ); const nodes = []; if (searchPanelProgress(state)) { nodes.push(h("div", { class: "search-progress", role: "progressbar", "aria-label": "Searching" })); } - const body = searchPanelBody(state, shown, state.searchKind); + const body = searchPanelBody(state, shown, parsed.kind); if (body.kind === "error") { nodes.push(h("div", { class: "search-error", text: body.message })); } else if (body.kind === "results") { @@ -504,7 +524,7 @@ async function openRunFromSearch(runId) { * read-only and is never clickable. Every server string is set as text. */ function renderSearchResultRow(hit) { - const row = searchRow(hit, state.searchQuery); + const row = searchRow(hit, parsedSearch().query); const target = searchTarget(hit); const artifactHit = hit?.kind === "artifact" && hit.artifact ? hit.artifact : null; const element = h("div", { diff --git a/web/test/search-query.test.mjs b/web/test/search-query.test.mjs new file mode 100644 index 00000000..50d344ba --- /dev/null +++ b/web/test/search-query.test.mjs @@ -0,0 +1,38 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { parseSearchQuery, SEARCH_KINDS } from "../src/search.js"; + +test("both type aliases and kinds are case insensitive", () => { + for (const { value } of SEARCH_KINDS.filter((kind) => kind.value)) { + for (const prefix of ["t", "type", "T", "TyPe"]) { + assert.deepEqual(parseSearchQuery(`${prefix}:${value.toUpperCase()} plan`), { + query: " plan", kind: value, hasType: true, + }); + } + } +}); + +test("normal, quoted and unsupported text is preserved byte for byte", () => { + for (const query of [ + ' ordinary text\twith\nspacing ', + '"t:pipeline" "hello world"', "'type:artifact'", + '"escaped \\" t:run"', '"unclosed t:run', + "t:prompt type:unknown t: t:PIPELINES", "not:t:run t:run,", + "prefix\"t:run\"", "\\t:run", + ]) { + assert.deepEqual(parseSearchQuery(query, "field"), { query, kind: "field", hasType: false }); + } + assert.equal(parseSearchQuery('t:artifact "t:pipeline" report').query, ' "t:pipeline" report'); +}); + +test("last supported token wins over selector; unknown tokens do not override it", () => { + assert.deepEqual(parseSearchQuery("t:run plan TYPE:artifact t:unknown", "pipeline"), { + query: " plan t:unknown", kind: "artifact", hasType: true, + }); + assert.equal(parseSearchQuery("plan", "step").kind, "step"); +}); + +test("type-only query is distinguishable from literal text and blank input", () => { + assert.deepEqual(parseSearchQuery("t:pipeline"), { query: "", kind: "pipeline", hasType: true }); + assert.deepEqual(parseSearchQuery(""), { query: "", kind: "", hasType: false }); +}); diff --git a/web/test/ui-search-types.mjs b/web/test/ui-search-types.mjs new file mode 100644 index 00000000..145a6044 --- /dev/null +++ b/web/test/ui-search-types.mjs @@ -0,0 +1,86 @@ +// 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"); +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); + return { search_results: { results: [] } }; + }}); + 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`); + + const before = await page.evaluate("framesSent.length"); + await page.fill("#searchInput", "t:pipeline"); + await eventually(() => page.evaluate("document.querySelector('#searchResults').textContent.includes('Add search text')")); + await new Promise((done) => setTimeout(done, 400)); + assert.equal(await page.evaluate("framesSent.length"), before); + await page.screenshot(`${out}/05-type-only-help.png`); + await page.click("#searchClearFilter"); + assert.equal(await page.evaluate("document.querySelector('#searchInput').value"), ""); + assert.equal(await page.evaluate("document.querySelector('#searchKind').value"), ""); + await page.screenshot(`${out}/06-cleared-filter.png`); + console.log(`PASS: type tokens, wire kind/query, precedence, selector replacement, literals, type-only help and clear. Captures: ${out}`); +} finally { + await browser?.close(); + await new Promise((done) => server.close(done)); +}