Documentation
¶
Overview ¶
Package baseline implements signal control SC1 (ADR-0027): a user-private, per-developer record of already-accepted findings so that repeat runs surface only NEW issues instead of re-dumping the whole brownfield backlog every time.
The record lives at <repoRoot>/.commitbrief/baseline.json. That directory is already gitignored by `setup --local`, so the file never enters a diff, never reaches CI, and never weakens the senior/CI gate — those still see every finding. The baseline only quiets the local developer's own runs.
A finding is identified by the ADR-0045 fingerprint stamped on it (render.Finding.Fingerprint = sha256(path, rule_id, symbol)): line-drift resilient, and independent of the LLM-volatile Title, Description and Snippet prose. A version 2 file stores those fingerprints.
Known coarseness (accepted in ADR-0045 §Negative): the identity ignores the Title, so baselining one finding also hides any later finding with the same file, rule and symbol, and a finding with no symbol (typically general.other) hides every same-rule finding in that file.
A version 1 file (written before ADR-0045) stores the legacy formula
sha256(File + "\0" + Severity + "\0" + normalize(Title))
and is still read with that formula so an existing baseline keeps working until the developer migrates it. The v1 hash is one-way (neither rule_id nor symbol can be recovered from it), so migration is lossy by construction: it is a fresh `--update-baseline` over the same range that created the file. The caller surfaces that as a one-time warning (Set.Legacy).
Index ¶
Constants ¶
const FileVersion = 2
FileVersion is the schema version stamped into baseline.json. It is the file's own format version and is unrelated to the locked --json schema (render.SchemaVersion); bumping it lets a future format change reject or migrate an older file rather than silently mis-reading it. Version 2 keys on render.Finding.Fingerprint (ADR-0045); version 1 keyed on legacyFingerprint and is still readable.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
Filter splits findings into the ones to KEEP (not in the baseline) and a count of how many were dropped because their fingerprint is baselined. This is a TRUE removal (ADR-0027): the kept slice is what fail-on, JSON findings[], and display all see — distinct from the display-only --min-severity filter. An empty/nil Set keeps everything (count 0), so the no-baseline-file path is a transparent pass-through. The kept slice is always non-nil (callers downstream distinguish nil = graceful degrade from empty = clean), preserving that invariant.
func Write ¶
Write replaces baseline.json with the fingerprints of the given findings, always as a version 2 file (rewriting a version 1 file is the migration). It is the `--update-baseline` action: the whole current set becomes the new accepted baseline (an absorb, not a merge), so removing a finding from the code and re-baselining drops its fingerprint too. The parent .commitbrief/ directory is created if absent; the write is atomic (temp + rename) so an interrupted run never leaves a half-written file. Returns the number of distinct fingerprints written.
Types ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is the in-memory form of a loaded baseline: the accepted fingerprints plus the file format version that decides which formula a finding is matched with. The zero value is a valid empty set — Matches returns false and Len is 0 — so a missing file degrades to "baseline off" without special-casing at the call site.
func Load ¶
Load reads the baseline for repoRoot. A missing file is NOT an error — it yields an empty Set and a nil error, so a first-ever run (or a developer who never opted in) simply has nothing baselined. A present-but-malformed file IS an error so a corrupted baseline surfaces loudly instead of silently unhiding findings the developer thought were accepted.
Versions 1 and 2 are read (see the package comment); any other version is a hard error so a file from a newer binary is never half-understood.
func (Set) Contains ¶
Contains reports whether fp is an accepted fingerprint, as stored. It does not apply any formula; use Matches for a finding. Safe on a zero Set.
func (Set) Legacy ¶ added in v1.19.0
Legacy reports whether the set was loaded from a non-empty version 1 file, i.e. it is matched with the pre-ADR-0045 formula and should be migrated.
func (Set) Matches ¶ added in v1.19.0
Matches reports whether finding f is accepted by the baseline. A version 2 set compares the finding's stamped Fingerprint; a version 1 set compares the legacy formula, which still reads Severity and Title off the finding. A finding with no stamped fingerprint never matches a version 2 set.