Repository navigation
Conversation
API and CLI reference pages often outrank the guide a reader was after, so the site search now opens on the tab for the section they are in (Docs, API, CLI, or Integrations), worked out from the same path rules that sort results into tabs. Pages outside /docs open on All. A tab the reader picks replaces that default for the rest of the page. When the wanted tab has nothing for a query the panel shows All, and returns to the wanted tab once a query reaches it again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
borland
left a comment
There was a problem hiding this comment.
🤖 Claude: I'd approve the change to docs-search.ts as it stands. I traced preferred/shown through run, the fallback, chooseTab (click and arrow keys), the setup guard for overlays without a matching tab, the demo overlay, and ?q= links, and found no correctness problems. The tests are another matter. The searchAll helper no longer makes the whole-site ranking tests check whole-site ranking, and two of the new tests can pass whether or not the feature works. Details are inline. I didn't run the Playwright suite.
|
|
||
| const all = site.locator('[data-docs-search-tabs] [data-facet="all"]'); | ||
| await all.click(); | ||
| await expect(all).toHaveAttribute('aria-selected', 'true'); |
There was a problem hiding this comment.
🤖 Claude: Major (test coverage). searchAll doesn't wait for the All results to arrive. chooseTab('all') sets aria-selected synchronously, so this assertion passes at once, while the list still holds the Docs-tab rows from the first search. The href assertions that follow retry until they match, so they can pass on those stale Docs rows before the All search lands.
That breaks the tests this helper was added for. In a guide beats a command of the same name, the Docs tab filters out CLI pages, so /docs/releases/creating-a-release/ will almost certainly be first there regardless of whole-site ranking. A regression that lets a CLI command win on All would go unnoticed. the page a query names comes first has the same problem, since namedPage promotes within the Docs filter too. a page pulled forward is not listed again can also flake: it may scroll and page the stale Docs list, then have the All response replace it mid-poll. Only a command wins when the query asks for one is safe, because its expected row can't appear on Docs.
One fix is to make the All query the only one in flight after the tab switch:
await all.click();
await expect(all).toHaveAttribute('aria-selected', 'true');
const input = site.locator('[data-docs-search-input]');
await input.fill(''); // renders empty synchronously and bumps the generation
await input.fill(query);
await expect(site.locator('[role="option"]').first()).toBeVisible({ timeout: 20_000 });There was a problem hiding this comment.
🤖 Claude: Fixed in 76ca490. After clicking All, searchAll now clears the query (which empties the list straight away) and types it again, then waits for rows. Any row it checks came from the All search, so the ranking tests are checking whole-site results and the paged-scroll test no longer races the list being replaced.
| await expect(site.locator('[role="option"]').first()).toBeVisible({ | ||
| timeout: 20_000, | ||
| }); | ||
| await expect(selectedTab(page)).toHaveAttribute('data-facet', 'docs'); |
There was a problem hiding this comment.
🤖 Claude: Minor (ineffective test). This doesn't wait for the reopened search. The rows from before the overlay closed are still in the list, so first().toBeVisible() passes at once. The tab was already docs before closing, so this assertion passes at once too, before the create release search resolves. The test only fails if something resets the tab synchronously on open. If run() started using the section instead of the picked tab, it would select cli only after its await, which is after this has passed. (The pre-PR code would pass this test too.)
Suggestion: clear the input before filling it (fill(''), then fill('create release')) so only fresh rows can show. Then also assert that no row href starts with /docs/cli/, the same way the per-section tests do.
There was a problem hiding this comment.
🤖 Claude: Fixed in 76ca490. After reopening, the test clears the query and types create release again, so it checks the tab that search settled on. It also checks that the CLI tab is visible, so going back to the section would have a tab to land on. I confirmed it now fails if open() resets the tab to the section (Expected "docs", Received "cli").
|
|
||
| // The demo overlay on the gallery page is not the reader's search, so it has | ||
| // no section to start in. | ||
| test('the demo overlay opens on All', async ({ page }) => { |
There was a problem hiding this comment.
🤖 Claude: Minor (ineffective test). This test can't fail. PAGE is /components, which is outside /docs, so sectionOf returns 'all' there anyway. All is also aria-selected="true" in the DocsSearch.astro markup before any script runs. If the name === SITE_SEARCH guard on preferred were removed, this test would still pass.
To cover the guard, the demo overlay needs to be on a page under /docs/ with a non-All section, or fixtureEngine needs exercising some other way. If neither is practical, I'd drop the test rather than keep one that suggests the guard is covered.
There was a problem hiding this comment.
🤖 Claude: Fixed in 76ca490. The test now serves the gallery page from /docs/cli/… using page.route. It checks that the demo overlay stays on All while a CLI tab is available, and that the site overlay on the same page takes up CLI. I confirmed it fails with the name === SITE_SEARCH guard removed (Expected "all", Received "cli").
Picking a tab marks it selected before its search lands, so the ranking tests and the reopen test could pass on rows left over from the previous search. Each now clears the query and types it again, so the rows it checks belong to the search under test. The demo overlay test ran from /components, outside /docs, where every overlay opens on All anyway. It now serves the gallery from inside the CLI section, and checks that the site overlay takes up CLI while the demo stays on All. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pull request environment is available at https://stoctodocspr3590.z22.web.core.windows.net/. You can view the ephemeral environment status in Octopus Deploy. This environment will be automatically deprovisioned when the pull request is closed, or after 7 days of inactivity. |
Problem
The site search lists results from every section under All, and API reference pages often outrank the guide a reader was looking for.
Change
The search overlay now opens on the tab for the section the reader is in, worked out from the same path rules that sort results into tabs:
/docs/cli/**/docs/api/**/docs/api-and-integration/**/docs/**/docsBefore
This is currently on
octopus.com/docs, searching for "aws account" which appears in all three search sections. No matter which top-nav selection you have selected, the search results are always the same.After
On a local test environment (or the staging site, when ready)
You can always switch the sections within the search results as you could before.
Switching search-result sections is "sticky" in that if you close and re-open the search box for the current page, it remembers what you selected last time. However if you navigate to another docs page, or reload, then the state clears and it defaults to the top-nav section you are working within. (this is intentional)
How to review
This was written with claude. I've skimmed the code and it looks reasonable, but I haven't looked deeply at the detail. I don't think we need to; the blast radius for the docs site is extremely limited and the code is not shared anywhere else. A claude review (which has been run already, see below), I think is all we need.
Tests
/docs.tests/docs-search.spec.ts: 36/36 passing locally against a fresh build.🤖 Generated with Claude Code