fix(baseline): counts extension closes the duplicate-call ratchet hole#36
Conversation
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>
|
Warning Review limit reached
Next review available in: 17 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Closes #35 — the baseline "counts" extension from flaglint/spec's
spec/fingerprint.md, plus bundling in theschemaVersionfield 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.Filegains an optionalcountsfield (fingerprint -> occurrence count), always emitted byWrite.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 withoutcounts(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
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-newnow correctly exits 1 (previously exited 0).baseline.jsonand scan JSON output's shape/field values via the built binary — both match flaglint/spec'sbaseline.v1.schema.json/scan-result.v1.schema.json.