Skip to content

fix(baseline): counts extension closes the duplicate-call ratchet hole#36

Merged
flaglint merged 1 commit into
mainfrom
fix/baseline-counts-and-schema-version
Jul 8, 2026
Merged

fix(baseline): counts extension closes the duplicate-call ratchet hole#36
flaglint merged 1 commit into
mainfrom
fix/baseline-counts-and-schema-version

Conversation

@flaglint

@flaglint flaglint commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #35 — the baseline "counts" extension from flaglint/spec's spec/fingerprint.md, plus bundling in the schemaVersion field on both scan-result and baseline JSON output.

The gap: the v1 fingerprint format has a known static-collision limitation — two call sites sharing (callType, flagKey, file) share one fingerprint string. Before this, a brand-new duplicate of an already-baselined call was invisible to --fail-on-new — the fingerprint was already in the baseline's known set. Copy-paste is exactly how flag debt spreads, so this was a real gap, not a theoretical one.

The fix: baseline.File gains an optional counts field (fingerprint -> occurrence count), always emitted by Write. baseline.New's signature changes to compare the current scan's own per-fingerprint counts against the baseline's: a fingerprint counts as new if it's either absent from the known set (existing behavior) or its current count exceeds its baselined one (new). A baseline without counts (older or hand-written) falls back to pure set semantics, per spec.

Also bundled: schemaVersion ("scan-result.v1" / "baseline.v1") on both JSON output shapes — small, spec-required, additive fields flaglint-go didn't emit yet.

Verification

  • Full test suite green.
  • New CLI end-to-end test (TestCLI_baselineRatchetHole_duplicateCallExceedsBaselinedCount) reproduces the exact scenario: write a baseline from a single call, add a second identically-shaped call to the same file so it shares the first's fingerprint, confirm --fail-on-new now correctly exits 1 (previously exited 0).
  • Manually confirmed the written baseline.json and scan JSON output's shape/field values via the built binary — both match flaglint/spec's baseline.v1.schema.json / scan-result.v1.schema.json.

Closes #35.

The v1 fingerprint format has a known static-collision limitation
(flaglint/spec's spec/fingerprint.md): two call sites sharing (callType,
flagKey, file) share one fingerprint string. Before this, a brand-new
*duplicate* of an already-baselined call was invisible to --fail-on-new —
the fingerprint was already in the baseline's known set, so the tool
reported "no new findings" even though a genuinely new call site had
been added. Copy-paste is exactly how flag debt spreads, so this was a
real gap.

baseline.File gains an optional "counts" field: fingerprint -> occurrence
count. Write always emits it (computed via the new CountFingerprints
helper, from the same unduplicated per-usage fingerprint list it already
received). Read parses it if present, leaving it nil if the field is
missing or explicitly null — an older or hand-written baseline without
"counts" still works, falling back to pure set semantics.

baseline.Read's return type changes from a bare map[string]bool to a new
Baseline struct (Fingerprints + Counts) to carry both pieces through to
New. baseline.New's signature changes to take the current scan's own
per-fingerprint counts (via the same CountFingerprints helper) instead of
a flat fingerprint slice: a fingerprint now counts as "new" if it's
either absent from the known set (existing behavior) or its current
count exceeds its baselined one (new). A fingerprint present in the set
but absent from Counts is treated as baselined at count 0, per spec —
only reachable for a malformed/hand-edited baseline, since Write always
emits a complete, consistent counts object.

Also bundles in "schemaVersion" (a small, spec-required, additive field):
"scan-result.v1" on the scan JSON envelope (reporter/json.go, alongside
the existing generatedAt field) and "baseline.v1" on baseline.File —
both additive, tolerated-if-absent per spec, so no version bump of our
own is needed to start emitting them now.

Verified: full test suite green, including a new CLI end-to-end test
reproducing the exact ratchet-hole scenario (write baseline from a single
call, add a second identically-shaped call to the same file so it shares
the first's fingerprint, confirm --fail-on-new now correctly exits 1
where it previously exited 0). Manually confirmed both the written
baseline.json and scan JSON output's shape/field values via the built
binary.

Signed-off-by: Krishan Kant Sharma <krishansharma0327@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@flaglint, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e87cb710-0c28-4117-a74f-6d97b496dd2b

📥 Commits

Reviewing files that changed from the base of the PR and between f9ce1f5 and c53cce6.

📒 Files selected for processing (6)
  • internal/baseline/baseline.go
  • internal/baseline/baseline_test.go
  • internal/cli/cli_test.go
  • internal/cli/validate.go
  • internal/reporter/json.go
  • internal/reporter/reporter_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/baseline-counts-and-schema-version

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@flaglint flaglint merged commit 2865f5f into main Jul 8, 2026
13 checks passed
@flaglint flaglint deleted the fix/baseline-counts-and-schema-version branch July 8, 2026 13:17
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.

baseline: --fail-on-new misses a new duplicate call sharing a fingerprint with an already-baselined one

2 participants