Repository navigation
fix(website): answer the batched path-kind probe in the file-path menu chip tests - #19337
chenmingwei23 wants to merge 1 commit into
Conversation
…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.
|
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, For the record, the diagnosis the two PRs reached separately: |
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 thepath chip menu threads the renderer handlersblock, fail with the same error:They fail on unmodified
origin/main, on older bases, and ate8d44aeb10 feat(website): add in-app open rows to the file-path menu (#19121)itself, the commit that added the file. Its parent2a3304cca2does not contain the file. The four cases have therefore never passed in CI.The cause is the file's own
fetchstub, not the component.stubKindanswers the per-path probeusePathKindused to send:usePathKindstopped sending that in762e5d22b0 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:The stub's fake
Responseis an object literal with nojson()method, soprobeBatch'sawait res.json()throws.probeBatchcatches every failure and fails closed tomissing, andMarkdownRendererwithholds a path chip until every probe for it reports a real kind. Socontainer.querySelector('code[data-path-kind="file"]')was alwaysnullandrightClickChipnever got a chip to right-click.The ten other cases in the same file render
FilePathMenudirectly, 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 Mergethen had no artifact to merge from a failed shard, andCoverage Gatefailed 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
FilePathMenu,MarkdownRenderer,usePathKindor any other component. The component side is correct.stubPathKinds;#18734already moved the ones that needed it.What changed (motivation -> approach -> change)
Symptom: four identical
expected null not to be nullfailures 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.
#18734replaced a per-pathHEAD /api/file-readprobe with a batchedPOST /api/file-kindsone, 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.#19121landed 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 thrownjson().Change:
stubKindnow delegates tostubPathKinds, keeping its own citation rule: the literalreport.md:12spelling resolves to missing, so the chip resolves to the file plus its line: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:
vitest run src/test/FilePathMenu.inApp.test.tsx, fromwebsite/: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 --noEmitexits 0.eslinton 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
usePathKindbatching path end to end in jsdom, so a browser pass adds nothing.#19215also touchesFilePathMenu, but only to add theOpen in editorrow behindcanOpenFileInEditor, which this file mocks tofalse; 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.fetchby hand when a shared stub for that endpoint already exists beside it, and a fakeResponseis an object literal rather than a realResponse, so any method the caller reaches for is missing. The fail-closedcatchis correct product behaviour and should stay; the defence is the shared stub.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
I confirm that this contribution is made under the terms of the Apache-2.0 license.