Skip to content

fix(review): make resolveInlineCommentAnchor enforce its own no-422 contract#8455

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-anchorable-8352
Jul 24, 2026
Merged

fix(review): make resolveInlineCommentAnchor enforce its own no-422 contract#8455
JSONbored merged 3 commits into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-anchorable-8352

Conversation

@RealDiligent

@RealDiligent RealDiligent commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

resolveInlineCommentAnchor (src/review/inline-comment-range.ts) documents a "fail-safe, no 422" guarantee, but its fallback branch did not enforce it:

if (!validLines || !everyLineInSet(start, end, validLines)) {
  return { start, end: start, multiLine: false };   // start itself never verified
}

Whenever the full-range check failed it returned start as a single-line anchor unconditionally, never separately checking validLines.has(start). So an un-postable line was handed back as if it were the safe anchor — the function's own existing test made this visible, returning {start: 1, end: 1, multiLine: false} for a path that was never validated at all (empty Map()).

This was safe in production only because the one caller chain (selectInlineCommentsselectAnchoredInlineFindingsanchorableInlineFindings) pre-filters findings on validLines.has(finding.line) first — an undocumented precondition that this exported, independently-tested "pure" function neither enforced nor mentioned.

Changes

  • Return type gains anchorable: boolean, set false only when start itself is not a valid RIGHT-side line (!validLines || !validLines.has(start)), true on both the single-line and multi-line success paths.
  • selectInlineComments (src/review/inline-comments.ts) now honors anchorable and skips such findings, instead of relying solely on its own pre-filter. (grep -rn resolveInlineCommentAnchor src/ confirms inline-comments.ts is the only call site; inline-comments-select.ts reaches it only through that chain.)
  • No behavior change for any finding whose start line is valid — every existing case keeps its exact anchor, now with anchorable: true.

Closes #8352

Notes on two judgment calls

1. The caller-side guard is unreachable today, so it carries a v8 ignore. parseInlineLineRange sets start = finding.line, and the pre-filter already requires validLines.has(finding.line) — so !anchor.anchorable cannot currently be hit through selectInlineComments. Left un-ignored it is a permanently-uncovered branch that would fail codecov/patch. I marked it with this repo's established convention for exactly this situation (/* v8 ignore next -- <why unreachable> */, used 45× in routes.ts alone) and documented why it exists: so a future selection change cannot silently reintroduce the 422. I did not delete the guard, which the issue explicitly requires.

2. Line endings. inline-comment-range.ts and its test are committed with CRLF while inline-comments.ts is LF (git cat-file -p origin/main:<file>). My first push matched each file's committed endings, which failed the changes job — it runs git diff --check, and that flags a CR at the end of every added line. Corrected: added lines now use LF, untouched lines keep their existing endings, so the diff stays minimal (30/15/46 lines) and git diff --check is clean. No content changed between those two pushes.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • This diff touches only src/review/** and one root test, so actionlint (no workflow change), build:mcp/test:mcp-pack (no MCP change), ui:* (no UI/OpenAPI change), test:workers (no worker change), and npm audit (no dependency change) are not exercised by it.
  • Diff coverage verified at 100%, lines and branches, via the scoped simulation CI runs (vitest run --coverage --coverage.all=false) — zero uncovered lines or branches across both changed source files. inline-comment-range.test.ts + inline-comments.test.ts pass in full (54 tests; 67 including inline-comments-select.test.ts), and root tsc --noEmit is clean.
  • I verified the new tests genuinely pin the fix: reverting the validLines.has(start) check makes both new cases fail, restoring it makes them pass.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

UI Evidence

Not applicable — backend anchor-resolution fix in src/review/; no visible UI, frontend, docs, or extension change.

@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 24, 2026 13:49
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

RealDiligent added 2 commits July 24, 2026 21:53
…ontract

The fallback branch returned a single-line anchor built from start whenever the
full-range check failed, without ever verifying start itself is a commentable
RIGHT-side line -- so an un-postable anchor was returned as if it were the
documented fail-safe. It held only because selectAnchoredInlineFindings
pre-filters on that same line, an undocumented precondition this exported,
independently-tested pure function neither enforced nor mentioned.

Adds an anchorable flag, false only when start is not a valid RIGHT-side line,
and has selectInlineComments drop such findings instead of trusting the
pre-filter alone. No behavior change for any finding whose start line is valid.

Closes JSONbored#8352
The 'changes' job runs git diff --check, which flags a CR at the end of any
added line. inline-comment-range.ts and its test are committed with CRLF, so
matching their existing endings made every line this PR adds fail that check.
Added lines now use LF (untouched lines keep their existing endings, so the
diff stays minimal); no content change.
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.60%. Comparing base (8dffb03) to head (c64a89e).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8455      +/-   ##
==========================================
- Coverage   92.47%   89.60%   -2.87%     
==========================================
  Files         791       99     -692     
  Lines       79321    22761   -56560     
  Branches    23954     3891   -20063     
==========================================
- Hits        73355    20396   -52959     
+ Misses       4839     2187    -2652     
+ Partials     1127      178     -949     
Flag Coverage Δ
shard-1 69.09% <58.33%> (+11.06%) ⬆️
shard-2 40.00% <66.66%> (-10.09%) ⬇️
shard-3 96.36% <83.33%> (+41.97%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/review/inline-comment-range.ts 100.00% <100.00%> (ø)
src/review/inline-comments.ts 100.00% <100.00%> (ø)

... and 692 files with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 24, 2026
@loopover-orb

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-24 15:48:39 UTC

3 files · 1 AI reviewer · no blockers · CI green · clean

⏸️ Suggested Action - Manual Review

Review summary
This correctly closes a real gap: resolveInlineCommentAnchor's fallback previously returned an unverified start line as a safe anchor, and the fix now separately checks validLines.has(start) before falling back, threading the new anchorable flag through selectInlineComments to drop un-postable findings. The change is well-scoped, includes targeted tests for both new falsy paths (missing path map and unmapped start line), and preserves byte-identical output for every previously-valid case. The v8-ignore'd caller-side guard is honestly documented as defense-in-depth against a currently-unreachable path, which is reasonable given the undocumented precondition this PR is explicitly fixing.

Nits — 5 non-blocking
  • src/review/inline-comment-range.ts:36 and inline-comments.ts:146 — '422' is a bare magic number in prose comments; a named constant or explicit link to the GitHub API error would make the intent clearer at a glance.
  • The v8-ignore'd guard in inline-comments.ts's selectInlineComments loop is currently unreachable by the PR's own admission — worth confirming reviewers are comfortable with untestable defense-in-depth code shipping without a way to exercise it, even though the reasoning for keeping it is sound.
  • No explicit PR-description confirmation that fix(review): resolveInlineCommentAnchor's single-line fallback doesn't verify the start line is itself commentable #8352 issue linkage was verified beyond the Closes line — worth double-checking the issue actually matches this exact defect before merge, though the description's technical narration is credible.
  • Consider a named constant (e.g. `const GITHUB_INLINE_COMMENT_422_NOTE`) or a short referenced comment linking to GitHub's REST docs for the 422 behavior, purely for future readers who hit this comment without the PR context.
  • If there's an easy way to synthesize a caller path where anchor.anchorable is false post-selection (e.g. a mocked selectAnchoredInlineFindings), it would let the v8-ignore be dropped in favor of a real test — otherwise the ignore + comment combo is the right call.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8352
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 361 registered-repo PR(s), 142 merged, 36 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 361 PR(s), 36 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The diff fixes resolveInlineCommentAnchor to check validLines.has(start) before returning a fallback anchor, adds the anchorable field set false only in that case, updates the sole caller (inline-comments.ts) to skip unanchorable findings, and adds tests covering both the missing-path and invalid-start-line cases with anchorable:false plus updated assertions for existing passing cases.

Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, Ruby, JavaScript, Svelte, TypeScript, Cuda, Markdown, MDX
  • Official Gittensor activity: 361 PR(s), 36 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 24, 2026
@JSONbored
JSONbored merged commit 3ca5337 into JSONbored:main Jul 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(review): resolveInlineCommentAnchor's single-line fallback doesn't verify the start line is itself commentable

2 participants