search: browse bounded recent items with kind-only queries

This commit is contained in:
2026-10-20 17:54:00 +01:00
parent cce7ea903a
commit 9cdfd9d9ab
12 changed files with 477 additions and 94 deletions
+14 -7
View File
@@ -158,19 +158,26 @@ 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
Type-prefix follow-up (2026-10-20, **partial — isolated browser fixture and
scratch server-command tests, not a deployed-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`
Type-only queries now send a real empty `query` plus a valid nonempty `kind` to
list bounded recent canonical items. The server uses recency indexes on existing
tables, then numeric entity/visit IDs and target as deterministic tie-breaks;
existing result caps and field-scan budgets still apply. Blank text with no kind
remains a no-op, and an invalid kind still errors. No wildcard text is invented.
The UI labels recent items and result/scan caps, and distinguishes an empty kind
from a scan-limited empty result. 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;
connection. Captures: `captures/search-types-recent/01-type-filter.png` through
`09-cleared-filter.png` (including precedence, selector replacement, literal
tokens, type-only pipeline/artifact results and both empty states). Server tests
exercise empty-query searches for all six kinds over an actual `/connect`
WebSocket against a throwaway database. This browser-only shorthand is not yet on Android;
the earlier live-search acceptance evidence below is unchanged.
| # | Feature | Protocol | Status |
+9 -8
View File
@@ -61,7 +61,6 @@ export function parseSearchQuery(value, selectedKind = DEFAULT_SEARCH_KIND) {
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
@@ -337,19 +336,21 @@ export function searchPanelEmptyMessage(state, shown, kind) {
if ((shown ?? []).length > 0) return null;
if (state?.loading) return null;
const query = String(state?.query ?? "");
if (query.trim() === "") return null;
if (query.trim() === "") {
if (!state?.loaded || !kind) return null;
const label = searchKindLabel(kind).toLowerCase();
return state?.truncated ? `No ${label} found within the server's scan limit.` : `No ${label} yet.`;
}
if (kind === "" || kind == null) return `No matches for "${query}".`;
return `No ${searchKindLabel(kind).toLowerCase()} match "${query}".`;
}
/**
* Whether a keystroke's text is worth asking the server about. A blank or
* whitespace-only query is cleared locally and never sent, so the server is not
* asked to scan for nothing. The one predicate the field's input handler and its
* immediate-send path share.
* Text searches and valid kind-only browsing are sendable. Empty text with no
* supported kind still clears locally, without an all-kind scan.
*/
export function searchQuerySendable(query) {
return String(query ?? "").trim() !== "";
export function searchQuerySendable(query, kind = "") {
return String(query ?? "").trim() !== "" || SEARCH_KINDS.some((option) => option.value !== "" && option.value === kind);
}
/**
+27 -27
View File
@@ -12,7 +12,6 @@ import {
SEARCH_DEBOUNCE_MS,
SEARCH_KINDS,
SEARCH_SORTS,
SEARCH_TYPE_HELP,
parseSearchQuery,
SearchSequencer,
filterSearchResults,
@@ -87,9 +86,9 @@ function openSearch() {
state.searchFocusPending = true;
renderHeader();
renderSearch();
// Resume: the previous results show immediately, and a non-blank query is
// refreshed so the list is not stale.
if (searchQuerySendable(state.searchQuery)) {
// Resume: show previous results immediately, then refresh text or kind-only
// searches so the list is not stale.
if (searchQuerySendable(state.searchQuery, parsedSearch().kind)) {
state.searchLoading = true;
const sent = state.searchSequencer.begin(state.searchSequencer.edit(state.searchQuery));
if (sent) runSearch(sent);
@@ -134,16 +133,16 @@ function cancelSearchDebounce() {
}
/**
* A keystroke. A blank/whitespace query clears the results locally and sends
* nothing; otherwise the previous results stay visible, the request is marked in
* flight and the send is debounced `SEARCH_DEBOUNCE_MS` from the last keystroke.
* A keystroke. Blank text without a kind clears locally and sends nothing;
* kind-only searches browse recent items. Previous results stay visible while
* loading; sending is debounced `SEARCH_DEBOUNCE_MS` from the last keystroke.
* Recording the edit is itself enough to drop any older reply still in flight.
*/
function onSearchInput(value) {
state.searchQuery = value;
state.searchError = "";
cancelSearchDebounce();
if (!searchQuerySendable(value)) {
if (!searchQuerySendable(value, parsedSearch().kind)) {
state.searchSequencer.edit("");
state.searchResults = [];
state.searchLoading = false;
@@ -165,7 +164,7 @@ function onSearchInput(value) {
function sendSearchNow() {
const query = state.searchQuery;
cancelSearchDebounce();
if (!searchQuerySendable(query)) {
if (!searchQuerySendable(query, parsedSearch().kind)) {
state.searchSequencer.edit("");
state.searchResults = [];
state.searchLoading = false;
@@ -180,8 +179,8 @@ function sendSearchNow() {
/**
* A kind-filter change: the in-hand filter is re-applied immediately so the list
* always matches the control, and — when the query is non-blank — a fresh server
* request is sent with the new kind. A sort change never sends a request.
* always matches the control. Text or a valid kind sends a fresh server request;
* clearing both stays local. A sort change never sends a request.
*/
function setSearchKind(kind) {
state.searchQuery = parsedSearch().query;
@@ -204,15 +203,8 @@ function setSearchSort(sort) {
*/
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(parsed.query, parsed.kind);
const reply = await repo.search(parsed.query.trim() ? parsed.query : "", parsed.kind);
if (!state.searchSequencer.accepts(sent.token)) return;
if (reply == null) {
state.searchLoading = false;
@@ -222,6 +214,7 @@ async function runSearch(sent) {
return;
}
state.searchResults = Array.isArray(reply.results) ? reply.results : [];
state.searchTruncated = Boolean(reply.truncated);
state.searchActiveIndex = 0;
state.searchLoading = false;
state.searchError = "";
@@ -315,7 +308,7 @@ function renderSearch() {
}
if (event.key === "Enter") {
event.preventDefault();
if (shown.length && !state.searchLoading && !state.searchError && parsedSearch().query.trim()) {
if (shown.length && !state.searchLoading && !state.searchError) {
routeSearchResult(shown[state.searchActiveIndex] ?? shown[0]);
} else sendSearchNow();
}
@@ -355,7 +348,7 @@ function renderSearch() {
"div",
{ id: "searchPanel", class: "search-panel", role: "dialog", "aria-modal": "true", "aria-label": "Search" },
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),
h("p", { class: "muted", text: "Filter with t:pipeline or type:artifact (pipeline, run, step, field, artifact, version). Type alone lists recent items. 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) => {
@@ -377,19 +370,20 @@ function renderSearch() {
*/
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, parsed.kind),
state.searchSort,
);
const nodes = [];
if (searchPanelProgress(state)) {
const panelState = {
query: parsed.query, loading: state.searchLoading, loaded: state.searchLoaded,
error: state.searchError, results: state.searchResults,
truncated: state.searchTruncated,
};
if (searchPanelProgress(panelState)) {
nodes.push(h("div", { class: "search-progress", role: "progressbar", "aria-label": "Searching" }));
}
const body = searchPanelBody(state, shown, parsed.kind);
const body = searchPanelBody(panelState, shown, parsed.kind);
if (body.kind === "error") {
nodes.push(h("div", { class: "search-error", text: body.message }));
} else if (body.kind === "results") {
@@ -414,6 +408,12 @@ function fillSearchResults(area) {
} else if (body.kind === "empty") {
nodes.push(h("div", { class: "search-empty muted", text: body.message }));
}
if (body.kind === "results" && !state.searchLoading && parsed.kind && !parsed.query.trim()) {
nodes.push(h("div", {
class: "search-summary muted",
text: state.searchTruncated ? "Recent items · limited by the server's result or scan cap." : "Recent items",
}));
}
area.replaceChildren(...nodes);
}
+20 -1
View File
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { parseSearchQuery, SEARCH_KINDS } from "../src/search.js";
import { parseSearchQuery, searchQuerySendable, searchPanelBody, 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)) {
@@ -36,3 +36,22 @@ 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 });
});
test("blank text is sendable only with a supported nonempty kind", () => {
for (const { value } of SEARCH_KINDS) {
assert.equal(searchQuerySendable(" \n\t ", value), value !== "");
}
assert.equal(searchQuerySendable("", "unknown"), false);
assert.equal(searchQuerySendable("plan"), true);
});
test("kind-only responses distinguish loading, honest empty state and cleared filters", () => {
assert.equal(searchPanelBody({ loading: true, query: "" }, [], "pipeline").kind, "searching");
assert.deepEqual(searchPanelBody({ loaded: true, query: "" }, [], "pipeline"), {
kind: "empty", message: "No pipelines yet.",
});
assert.equal(searchPanelBody({ loaded: false, query: "" }, [], "pipeline").kind, "idle");
assert.equal(searchPanelBody({ loaded: true, query: "" }, [], "").kind, "idle");
assert.equal(searchPanelBody({ loaded: true, query: "", truncated: true }, [], "field").message,
"No fields found within the server's scan limit.");
});
+30 -10
View File
@@ -8,7 +8,7 @@ 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");
const out = resolve(process.argv[2] || "captures/search-types-recent");
await mkdir(out, { recursive: true });
const server = createServer(async (req, res) => {
try {
@@ -39,7 +39,14 @@ try {
window.framesSent = [];
const repo = new PipelinesRepository({ call: async (frame) => {
framesSent.push(frame);
return { search_results: { results: [] } };
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 };
@@ -69,17 +76,30 @@ try {
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 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"), "");
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}`);
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));