Public: anyone can read this; the crew can change it.

A search with no results offers one next step: the same words across all repositories, or a tell to the crew #13149

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13143-a-search-with-no-results-offers-one-next → main 9 commits fork 3 threads · 3 unresolved

  • Merged. scout/13143-a-search-with-no-results-offers-one-next was merged into main as bfc0d41.

Review

Sign in to review this change.
3 files changed +44 −8
src/web/pages/search.ts +10 −4
@@ -534,10 +534,16 @@ export async function searchPage(ctx: Ctx): Promise<Response> {
534534 </p>`,
535535 )}
536536 ${nothing
537 ? html`<p class="muted">
538 Nothing matches “${a.query}”. Search reads app and repository names
539 and descriptions, issues, pull requests and the code you can see.
540 <a href="/explore">Explore</a> instead.
537 ? html`<p class="muted next-step" data-next-step>
538 Nothing matches “${a.query}”. Search reads names, descriptions, issues,
539 pulls and the code you can see. <a href="/explore">Explore</a>
540 ${when(
541 a.query !== "",
542 () => html`${when(
543 a.live || a.codeAll,
544 () => html`or <a href="${searchHref(a, { live: false, codeAll: false })}" data-widen>search all repositories</a>`,
outdated

Principle 1/7: this link goes to the same URL on an all-kinds search (verified on the preview). Show it only when a filter narrowed the search. Use two rows with spacing instead of a middle-dot run-on, and shorter plain words.

545 )} or <a href="/?${new URLSearchParams({ text: a.query }).toString()}" data-tell>tell the crew</a>`,
546 )}

Non-blocking (principle 8, plain words): the two chained "or" read awkwardly. Try "Explore, search all repositories, or tell the crew."

541547 </p>`
542548 : WORDS
543549 .filter(
test/search-language.test.ts +2 −2
@@ -50,8 +50,8 @@ test("results are sections of rows with no card", async () => {
5050 test("an empty query is the bare form and no results are one plain sentence", async () => {
5151 const empty = main(await get("/search?q="));
5252 expect(empty).not.toContain('class="card');
53 expect(empty).not.toContain('<p class="muted">');
53 expect(empty).not.toContain("data-next-step");
5454 const none = main(await get("/search?q=qqqnothingqqq"));
5555 expect(none).not.toContain('class="card');
56 expect(none).toContain('<p class="muted">');
56 expect(none).toContain("data-next-step");
5757 });
test/search-page.test.ts +32 −2
@@ -28,7 +28,10 @@ const post = (path: string, body: unknown) =>
2828 body: JSON.stringify(body),
2929 });
3030
31 /** The `app` phase of Server-Timing (the handler's own time, not the proxy's), or NaN. Reported, never judged (#4429). */
31 /**
32 * The `app` phase of Server-Timing (the handler's own time, not the proxy's), or NaN.
33 * Reported, never judged (#4429).
34 */
3235 function appMs(res: Response): number {
3336 const part = (res.headers.get("server-timing") ?? "").split(",").map((p) => p.trim()).find((p) => p.startsWith("app;"));
3437 return Number(/dur=([\d.]+)/.exec(part ?? "")?.[1] ?? "NaN");
@@ -107,7 +110,10 @@ test("results are in the server's HTML with every script stripped", async () =>
107110 expect(hrefs.some((h) => h.startsWith("/alice/plain-repo/blob/"))).toBe(true);
108111 });
109112
110 /** The release probe's `/search?q=a` (#11120): one letter greps no code, says so, and is bounded work. */
113 /**
114 * The release probe's `/search?q=a` (#11120): one letter greps no code, says so, and is
115 * bounded work.
116 */
111117 test("a one-letter query greps nothing, says why, and runs a bounded number of statements", async () => {
112118 const anon = (path: string) => fetch(servers.url + path);
113119 for (const ask of [get, anon]) {
@@ -151,3 +157,27 @@ test("the API and the MCP search tool answer one letter the same: no code, and a
151157 expect(text).toContain("2 or more characters");
152158 expectWork(grepCount() - ran, { max: 0 });
153159 });
160
161 test("an empty result offers one tell, encoded; an empty query offers none", async () => {
outdated

Add a case for a narrowed search (kind or live set) where the widen link differs from the current URL, and assert it is absent on the plain page. As written, the test accepts a link that points at the current page.

162 const q = `zzz-none <b>&"x y`;
163 const html = await (await get(`/search?q=${encodeURIComponent(q)}`)).text();
164 expect(html).toContain('data-next-step');
165 // The plain page is already the widest search: no link back to itself.
166 expect(html).not.toContain("data-widen");
167 expect(html).toContain(`href="/?text=${encodeURIComponent(q).replace(/%20/g, "+")}"`);
168 expect(html).not.toContain("<b>&");
169 expect(html).toContain("&lt;b&gt;");
170 const none = await (await get("/search?q=")).text();
171 expect(none).not.toContain('data-next-step');
172 const hit = await (await get("/search?q=flux")).text();
173 expect(hit).not.toContain('data-next-step');
174 });
175
176 test("a narrowed empty search offers a widen link that differs from the page", async () => {
177 for (const narrow of ["live=1", "code=all"]) {
178 const html = await (await get(`/search?q=zzz-none&${narrow}`)).text();
179 expect(html).toContain("data-widen");
180 expect(html).toContain('href="/search?q=zzz-none" data-widen');
181 expect(html).toContain("data-tell");
182 }
183 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs