Repository navigation
test(pr): guard head-sha FileContent fetch; align ADR 0004/0005 with the fetch scope - #306
Merged
Merged
Conversation
…the fetch scope The runtime fix landed in #303, but nothing pinned the end-to-end behaviour and the ADRs still described a rule the Repository cannot execute: head content at the *viewed* path, which is UI state above the Repository. Pin the derived status with a bootstrap-level regression test and restate the scope as head content for every *anchored* path, with the viewed path loaded by the editor hook (a free 304 when they overlap).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The runtime defect in #267 — head-sha file content never reaching
RemoteState, so re-anchoring ran against an empty document — was already fixed by #303 (fetchRemoteStatenow adds(headSha, path)for every anchored path). Two things were left behind:mappedafter bootstrap.FileContentas living at(newHeadSha, currentPath)— a rule the Repository cannot execute, because the viewed path is ephemeral UI state above it (ADR 0002 §1/§4).The design settles the scope question the issue's acceptance criteria left open:
(headSha, path)for every anchored path (it needs both ends of the line map, and nothing else knows the anchored paths). It does not fetch every changed Markdown file —AppState.currentFileshas no consumer today, and that would cost oneGET contentsper changed.mdon every refresh.useSelectedFileContentkeeps fetching the viewed path itself. Where the two overlap, the hook's request is a conditional GET answered fromghRequest's ETag cache — a 304 costs no rate-limit budget, so the duplication is one free round trip, not a second download. The issue's third acceptance criterion is satisfied by the "or the duplication is explicitly justified" branch, and the justification is now written down in the hook header and ADR 0005 §2.What
tests/pr/bootstrap.test.ts: new end-to-end regression test — bootstrap with one comment anchored atoldshaon a file that is byte-identical atheadsha, thenderiveAppState. Asserts both thatcontentsRefsis["headsha", "oldsha"]and thatdisplayPositionis{ status: "mapped", range: … }.docs/adr/0005-refresh-policy.md§2: refresh scope restated as every(anchor.sha, path)plus(headSha, path)for each anchored path, with an explicit note that the viewed path is not in scope and is loaded by the editor hook.docs/adr/0004-reanchoring.md§1/§2/§6 and Consequences → Negative: current source is(headSha, comment.path)guaranteed by the prefetch; §2 includes the head-sha copy; cost restated as up to(N+1)×Mcalls.entrypoints/review/hooks/useSelectedFileContent.ts: header comment rewritten (stale "Pack B / R8d" / "legacy Effect 2" wording dropped) to state that fetching above the Repository is deliberate and why.No changes to
lib/prcode.Regression test verified against the pre-#303 behaviour
The new test is green on first run — as expected, since #303 already fixed the behaviour. To prove it has teeth, the #303 loop in
fetchRemoteState(lib/pr/remote-fetcher.ts, thefor (const t of Array.from(targetSet.values()))block that adds(headSha, path)targets) was temporarily deleted and the file then restored withgit checkout --.With that loop removed, the head-sha content is never fetched:
and the derived status is exactly the bug the issue reports (captured by running the
displayPositionassertion first):With
lib/pr/remote-fetcher.tsrestored: 654 pass, 0 fail across 61 files.Checks
bun run test(654 pass / 0 fail),bun run check:lint,bun run check:format,bun run typecheck,bun run build— all pass.Manual verification (optional, needs a real PR)
Open a PR with a Bark comment from an earlier push on a file the later push did not touch: the comment should be highlighted inline (no "position not found" badge) and Accept enabled for a suggestion. In DevTools → Network filtered on
contents/, the viewed commented file should show one 200 (bootstrap) and one 304 (hook); a changed file with no comments should show exactly one request.Noted, out of scope
AppState.currentFileshas no consumer — a candidate for the refactor sweep, not this issue. This is why the issue's "and for every changed Markdown file, socurrentFilesis populated" criterion is deliberately not implemented.(sha, path)pairs are retained" is not implemented today (every refresh refetches, cheaply via ETag). That gap is item 8 of the docs-drift issue [Low] Docs drift: design doc, ADR and spec statements that no longer hold #294 and the sentence is left as is.Closes #267