Skip to content

test(pr): guard head-sha FileContent fetch; align ADR 0004/0005 with the fetch scope - #306

Merged
nownabe merged 1 commit into
mainfrom
issue-267-headsha-fetch
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
issue-267-headsha-fetch

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

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 (fetchRemoteState now adds (headSha, path) for every anchored path). Two things were left behind:

  1. Nothing pinned the derived behaviour. The fetcher test added in fix(pr): post drafts in the current head's coordinates #303 asserts which URLs are requested; no test asserts that a comment anchored at an older sha ends up mapped after bootstrap.
  2. ADR 0004 §1/§2/§6 and ADR 0005 §2 still described head FileContent as 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:

  • The Repository fetches (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.currentFiles has no consumer today, and that would cost one GET contents per changed .md on every refresh.
  • useSelectedFileContent keeps fetching the viewed path itself. Where the two overlap, the hook's request is a conditional GET answered from ghRequest'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 at oldsha on a file that is byte-identical at headsha, then deriveAppState. Asserts both that contentsRefs is ["headsha", "oldsha"] and that displayPosition is { 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)×M calls.
  • 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/pr code.

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, the for (const t of Array.from(targetSet.values())) block that adds (headSha, path) targets) was temporarily deleted and the file then restored with git checkout --.

With that loop removed, the head-sha content is never fetched:

expect(received).toEqual(expected)

@@ -1,3 +1,3 @@
  [
-   "headsha",
    "oldsha",

- Expected  - 1
+ Received  + 0

(fail) bootstrap — head-sha content for re-anchoring (issue #267) > a comment anchored at an older sha re-anchors as mapped when the file is unchanged at head

and the derived status is exactly the bug the issue reports (captured by running the displayPosition assertion first):

expect(received).toEqual(expected)

  {
-   "range": {
-     "ec": 6,
-     "el": 2,
-     "sc": 1,
-     "sl": 2,
-   },
-   "status": "mapped",
+   "status": "outdated",
  }

- Expected  - 7
+ Received  + 1

(fail) bootstrap — head-sha content for re-anchoring (issue #267) > a comment anchored at an older sha re-anchors as mapped when the file is unchanged at head

With lib/pr/remote-fetcher.ts restored: 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.currentFiles has no consumer — a candidate for the refactor sweep, not this issue. This is why the issue's "and for every changed Markdown file, so currentFiles is populated" criterion is deliberately not implemented.
  • ADR 0005 §2's "already-fetched (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

…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).
@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe merged commit 42256d4 into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the issue-267-headsha-fetch branch September 20, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[High] Head-sha file content is never loaded into RemoteState, so re-anchoring runs against an empty document

1 participant