Skip to content

fix(website): answer the batched path-kind probe in the file-path menu chip tests - #19337

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/19121-filepathmenu-inapp-red
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/19121-filepathmenu-inapp-red

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop the frontend test shard, the coverage merge and the coverage gate from going red on every pull request because of one test file.

Four cases in website/src/test/FilePathMenu.inApp.test.tsx, all in the path chip menu threads the renderer handlers block, fail with the same error:

AssertionError: expected null not to be null
 at src/test/FilePathMenu.inApp.test.tsx:249:19

They fail on unmodified origin/main, on older bases, and at e8d44aeb10 feat(website): add in-app open rows to the file-path menu (#19121) itself, the commit that added the file. Its parent 2a3304cca2 does not contain the file. The four cases have therefore never passed in CI.

The cause is the file's own fetch stub, not the component. stubKind answers the per-path probe usePathKind used to send:

HEAD /api/file-read?path=<p>   ->  headers: { 'X-Path-Kind': 'file' | 'dir' }

usePathKind stopped sending that in 762e5d22b0 perf(dashboard): resolve transcript path kinds in one batched request (#18734). It now sends one batched request per React commit and parses a JSON body:

POST /api/file-kinds  { paths: [...] }   ->  { kinds: { "<p>": "file" | "dir" | "missing" } }

The stub's fake Response is an object literal with no json() method, so probeBatch's await res.json() throws. probeBatch catches every failure and fails closed to missing, and MarkdownRenderer withholds a path chip until every probe for it reports a real kind. So container.querySelector('code[data-path-kind="file"]') was always null and rightClickChip never got a chip to right-click.

The ten other cases in the same file render FilePathMenu directly, send no probe, and have always passed. They are the control that shows the menu itself is correct.

Why it matters

One file turned three lanes red on every pull request that ran the shard, and had done so since it landed. Frontend Tests (4) failed on the shard holding it (712 of that shard's 713 files passed). Frontend Coverage Merge then had no artifact to merge from a failed shard, and Coverage Gate failed closed behind it. Every author on the repo paid for it, and a standing red teaches everyone to stop reading the board.

There is no user-facing bug here. The in-app open rows do render. Anyone reading the four reds as a product defect would have gone looking for one that does not exist.

Not a goal

  • No change to FilePathMenu, MarkdownRenderer, usePathKind or any other component. The component side is correct.
  • No change to what the four cases assert. Each one passes unchanged.
  • No wider migration of other tests onto stubPathKinds; #18734 already moved the ones that needed it.
  • No change to the shard layout or the coverage gate's fail-closed behaviour. Both acted correctly on a genuinely failing shard.

What changed (motivation -> approach -> change)

Symptom: four identical expected null not to be null failures at one line, rightClickChip's wait for the path chip.

Root cause: the test's fixture promises a transport the code under test no longer uses. #18734 replaced a per-path HEAD /api/file-read probe with a batched POST /api/file-kinds one, and shipped a shared stub, website/src/test/pathKindStub.ts, so tests could answer the new shape. It migrated the other probe-dependent tests (ArtifactsPage.test.tsx, SessionDocPath.test.tsx) onto it. #19121 landed later and hand-rolled the retired protocol instead of using the helper, so its stub answered a request that is never sent while the real request got a thrown json().

Change: stubKind now delegates to stubPathKinds, keeping its own citation rule: the literal report.md:12 spelling resolves to missing, so the chip resolves to the file plus its line:

function stubKind(kind: 'file' | 'dir') {
  stubPathKinds(path => {
    if (/:\d+$/.test(path)) return null
    return kind
  })
}

That plus the import { stubPathKinds } from './pathKindStub' line is the whole diff: one test file, 7 insertions, 6 deletions.

Backwards compatibility

Compatible: the diff touches one test file's fetch stub, so nothing main accepts today is rejected, renamed or removed.

Removes nothing: the deleted lines are the body of a test-local helper, replaced by a call into an existing helper; no key, field, validator, public function or stored record changes.

Tests

No test is added. The four cases this fixes are the test, and they now lock in what they were written to lock in:

  • a remote file chip opens itself in the side panel, keeping its cited line
  • a remote file chip opens its containing folder in the side panel
  • a remote directory chip opens that directory in the side panel
  • a chip in a renderer with no handlers keeps the native-only menu

vitest run src/test/FilePathMenu.inApp.test.tsx, from website/:

Test Files Tests
before 1 failed 4 failed, 10 passed (14)
after 1 passed 14 passed (14)

Neighbours of the touched file, run together: FilePathMenu.inApp, FilePathMenu, usePathKind, SessionDocPath, ArtifactsPage, MarkdownRenderer.folderChip, MarkdownRenderer.contextmenu, MarkdownRenderer.inlineCodeCue. Test Files 8 passed (8), Tests 156 passed (156).

tsc --noEmit exits 0. eslint on the touched file exits 0.

Manual verification

N/A: the defect is a test fixture answering a retired request shape, and the fixed cases exercise the real usePathKind batching path end to end in jsdom, so a browser pass adds nothing. #19215 also touches FilePathMenu, but only to add the Open in editor row behind canOpenFileInEditor, which this file mocks to false; it neither caused this red nor changes the fix.

Related Issues

N/A: found while clearing a review board, not filed first.

Pattern harvest

Rule candidate: review-prompt

Pattern: a test hand-rolls a transport stub for a request shape the code under test no longer sends, and the component's fail-closed error path turns the mismatch into a plausible-looking assertion failure instead of a loud one. Two signals make the class findable in review: a new test stubs globalThis.fetch by hand when a shared stub for that endpoint already exists beside it, and a fake Response is an object literal rather than a real Response, so any method the caller reaches for is missing. The fail-closed catch is correct product behaviour and should stay; the defence is the shared stub.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

I confirm that this contribution is made under the terms of the Apache-2.0 license.

…u chip tests

The four path-chip cases stubbed the per-path HEAD /api/file-read probe, which usePathKind no longer sends, so every path read missing and the chip never rendered. Delegate to the shared stubPathKinds helper.
@chenmingwei23
chenmingwei23 requested review from a team and KiroCrewCaptain as code owners October 12, 2026 07:51
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Oct 12, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate. #19288 merged to main with the same root cause and the same fix while this PR was being opened, so the only delta left here is import order and comment wording.

Independent confirmation that #19288's fix is correct: on main at 0a47021, vitest run src/test/FilePathMenu.inApp.test.tsx from website/ gives 14 passed (14), against 4 failed / 10 passed before it.

For the record, the diagnosis the two PRs reached separately: stubKind answered the per-path HEAD /api/file-read + X-Path-Kind probe that usePathKind stopped sending in #18734. The replacement sends POST /api/file-kinds and parses a JSON body, and the stub's fake Response object literal has no json(), so probeBatch threw, failed closed to missing for every path, and MarkdownRenderer withheld the chip. All four cases died on the chip wait in rightClickChip, not on anything they assert about the menu. The component was never wrong, and the ten cases in the same file that render FilePathMenu directly are the control that shows it.

@chenmingwei23
chenmingwei23 deleted the fix/19121-filepathmenu-inapp-red branch October 12, 2026 07:52
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant