baseline

package
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

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 a line-drift-resilient fingerprint:

sha256(File + "\0" + Severity + "\0" + normalize(Title))

Line is deliberately excluded (code shifts as the file grows, and a brownfield baseline must survive that); Description and Snippet are excluded because they are LLM-volatile prose that would churn the fingerprint on every re-run. normalize trims, collapses internal whitespace, and lowercases the Title. The documented limit is that the same Title twice in one file at the same severity collides into a single fingerprint; the escape hatch is `--update-baseline`.

Index

Constants

View Source
const FileVersion = 1

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.

Variables

This section is empty.

Functions

func Filter

func Filter(findings []render.Finding, set Set) (kept []render.Finding, baselined int)

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 Fingerprint

func Fingerprint(f render.Finding) string

Fingerprint derives the stable identity of a finding per ADR-0027: sha256(File + "\0" + Severity + "\0" + normalize(Title)), hex-encoded. The NUL separators keep the three fields unambiguous (no field can contain a NUL), so "ab" + "c" and "a" + "bc" never collide.

func Path

func Path(repoRoot string) string

Path returns the absolute baseline.json path for the given repo root.

func Write

func Write(repoRoot string, findings []render.Finding) (int, error)

Write replaces baseline.json with the fingerprints of the given findings. 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 map[string]struct{}

Set is the in-memory form of a loaded baseline: the set of accepted fingerprints. The zero value (nil map) is a valid empty set — every Contains call returns false — so a missing file degrades to "baseline off" without special-casing at the call site.

func Load

func Load(repoRoot string) (Set, error)

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.

func (Set) Contains

func (s Set) Contains(fp string) bool

Contains reports whether fp is an accepted fingerprint. Safe on a nil Set.

func (Set) Len

func (s Set) Len() int

Len returns the number of accepted fingerprints. Safe on a nil Set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL