carlos / platform Public

ci: govulncheck as its own step, with an expiring exceptions file

From the Go audit (#1123). Mirrors 40-staticcheck (b064b14):
- make govulncheck runs golang.org/x/vuln/cmd/govulncheck@v1.8.0 via
  go run (pinned, no go.mod tool line) over this module and launchctx,
  in -format json; .amadan/ci.d/50-govulncheck runs that target.
- scripts/govulncheck-gate judges the JSON: a called (symbol-level)
  finding fails unless .amadan/govulncheck-exceptions.tsv lists it; an
  expired exception fails; an exception no called finding matches fails
  ("remove it"). Imported-only and required-only findings are printed,
  not fatal. A non-symbol-level or non-govulncheck stream is refused.
- One exception: GO-2026-6859 (net/http, fixed in go1.26.11) until
  2027-01-31; CI stays on go1.26.10 for the #897 deadlock and #904 found
  6859 unreachable.
- .amadan/README.md and AGENTS.md say what turns the step red and that
  it needs the module proxy and vuln.go.dev.

Today's scan: GO-2026-6859 called (excepted), GO-2026-5932 (x/crypto
openpgp) required only; make govulncheck is green.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 4b961a7b9bee11f61fdb79fdcd1835c82c665cc4 parent c4b44c3
7 files changed, +665 −2
  • .amadan/README.md +35 −1
  • .amadan/ci.d/50-govulncheck +25 −0
  • .amadan/govulncheck-exceptions.tsv +9 −0
  • AGENTS.md +7 −0
  • Makefile +22 −1
  • scripts/govulncheck-gate/main.go +375 −0
  • scripts/govulncheck-gate/main_test.go +192 −0

CI cancelled — superseded by a newer push — run details

diff --git a/.amadan/README.md b/.amadan/README.md
index 3406166fc..0a47c06d6 100644
--- a/.amadan/README.md
+++ b/.amadan/README.md
@@ -33,7 +33,7 @@ no longer exists.
| `minio-contract` | `30-minio-contract` | MinIO on loopback, no container |
| `gofmt` | `10-gate` | repo-wide, via `make test` — see below |
-Two checks have no ancestor; the deleted workflow never ran them. They
+Three checks have no ancestor; the deleted workflow never ran them. They
were added on 2026-11-16 after a code audit found the gate could not see
them.
@@ -41,6 +41,40 @@ them.
|---|---|---|
| tagged vet | `10-gate` | `go vet -tags rootrunner,carlos_cutover_witness ./...`, via `make test`: the root-runner tests are type-checked, not run |
| `staticcheck` | `40-staticcheck` | `make staticcheck`: v0.8.2, bug checks only; `staticcheck.conf` names the families still off |
+| `govulncheck` | `50-govulncheck` | `make govulncheck`: v1.8.0 over this module and `launchctx`; fails only on vulnerabilities the code calls, less the exceptions file; see below |
+
+## `govulncheck`: what turns it red
+
+govulncheck sorts each known vulnerability by how close the code gets to
+it: **called** (a call path reaches the vulnerable function), **imported**
+(the package is imported but nothing reaches the function) or
+**required** (the module is in `go.mod` but the package is not
+imported). Only **called** findings can fail the step. The other two are
+printed, so they stay visible, but they never turn the step red.
+
+govulncheck has no way to accept a finding, so it runs with
+`-format json` and `scripts/govulncheck-gate` judges the output against
+`.amadan/govulncheck-exceptions.tsv`: one line per OSV id, with an
+expiry date and the reason. The step fails when:
+
+- a called finding is not in the file: upgrade, or add an exception;
+- an exception is past its expiry date: re-check it, then fix or renew;
+- an exception matches no called finding: remove it, so the file cannot
+ rot;
+- either scan fails to run.
+
+The one exception today is GO-2026-6859 in `net/http`, fixed in
+go1.26.11. CI stays on go1.26.10 because 1.26.11 deadlocks the edge
+(#897, `go-toolchain.sh`), and #904 found 6859 unreachable in practice.
+When the toolchain moves past the fix, the exception goes stale and the
+step says to remove it.
+
+It scans release code only (no `-test`) for the runner's own platform.
+It needs the network: the Go module proxy to fetch govulncheck (every
+step already reaches it, because amadan jobs share the worker's network
+rather than getting `--unshare-net`) and `vuln.go.dev` for the database,
+which is fetched fresh on every run. If either is unreachable the step
+fails; it does not pass on an empty answer.
## `gofmt`: ported by widening it, not by reproducing it
diff --git a/.amadan/ci.d/50-govulncheck b/.amadan/ci.d/50-govulncheck
new file mode 100755
index 000000000..0586c5ffc
--- /dev/null
+++ b/.amadan/ci.d/50-govulncheck
@@ -0,0 +1,25 @@
+#!/bin/sh
+# Known vulnerabilities (vuln.go.dev) that the code actually calls:
+# govulncheck v1.8.0, pinned, over this module and launchctx's.
+# `make govulncheck` is the one definition; this step only runs it, so a
+# developer gets the same answer with the same command.
+#
+# Its own step, not part of `make test`, for staticcheck's reasons: a red
+# here is a finding, not a failed test, and `make test` stays no slower.
+#
+# Red means one of: a called vulnerability that
+# .amadan/govulncheck-exceptions.tsv does not list (upgrade, or add an
+# exception with an expiry and a reason); an exception past its expiry; an
+# exception nothing calls any more (remove it); or a scan that could not
+# run. Imported-only and required-only findings are printed, never fatal.
+#
+# The stdlib's findings follow the toolchain sourced below. Moving it to a
+# Go that fixes an excepted vulnerability makes that exception stale, and
+# the step then says to remove it.
+#
+# Network: the Go module proxy, as every step already uses, and
+# vuln.go.dev, fetched fresh on every run.
+set -eu
+. .amadan/go-toolchain.sh
+
+make govulncheck
diff --git a/.amadan/govulncheck-exceptions.tsv b/.amadan/govulncheck-exceptions.tsv
new file mode 100644
index 000000000..8d50ebab4
--- /dev/null
+++ b/.amadan/govulncheck-exceptions.tsv
@@ -0,0 +1,9 @@
+# Vulnerabilities `make govulncheck` (.amadan/ci.d/50-govulncheck) lets
+# through although the code calls them. One per line, tab-separated:
+#
+# OSV id <TAB> expires (YYYY-MM-DD, valid through that day) <TAB> reason
+#
+# The step fails once an exception expires, and fails when one no longer
+# matches a called finding (remove it then). Lines starting with # are
+# comments. scripts/govulncheck-gate reads this file.
+GO-2026-6859 2027-01-31 net/http MaxBytesReader header race, fixed in go1.26.11. CI and releases stay on go1.26.10 because 1.26.11 deadlocks the edge's Expect: 100-continue path (#897, .amadan/go-toolchain.sh); #904 checked every production MaxBytesReader site and found it unreachable.
diff --git a/AGENTS.md b/AGENTS.md
index 3ed0091e9..022fca76c 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -288,6 +288,13 @@ anything.
`make test` also vets with `-tags rootrunner,carlos_cutover_witness`,
so the root-runner tests must compile even though only the root runner
runs them.
+- `50-govulncheck` runs `make govulncheck` (v1.8.0, pinned) over this
+ module and `launchctx`. It fails on a vulnerability the code calls
+ unless `.amadan/govulncheck-exceptions.tsv` lists it (id, expiry,
+ reason), and on an exception that has expired or no longer matches
+ anything. Imported-only and required-only findings are printed, not
+ fatal. It needs `vuln.go.dev` and the module proxy; `.amadan/README.md`
+ has the details.
- `20-cross@5` adds `GOOS=darwin`/`windows`/`linux-arm64` compiles, one
per shard. **The gate is not Linux-only**: `internal/host` is linked
into the CLI, which people run on Macs, so a Linux-only type assumption
diff --git a/Makefile b/Makefile
index cd6258f01..5b58fa1eb 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ LDFLAGS := -s -w -X github.com/carlosframework/platform/internal/version.Build=$
GOOS ?=
GOARCH ?=
-.PHONY: test build build-console fmt staticcheck census-card census-propose console-mockup-kit parity-doc
+.PHONY: test build build-console fmt staticcheck govulncheck census-card census-propose console-mockup-kit parity-doc
# The build gate: vet, format, tests. `.amadan/ci.d/10-gate` runs this same
# target, so what CI checks and what you check are one definition.
@@ -72,6 +72,27 @@ staticcheck:
if [ $$rc -ne 0 ] || [ -n "$$out" ]; then echo "staticcheck: findings above (staticcheck.conf says which checks run)" >&2; exit 1; fi; \
echo "staticcheck: clean"
+# Known vulnerabilities the code calls, as CI checks them
+# (.amadan/ci.d/50-govulncheck). Not part of `make test`, like staticcheck,
+# and pinned and fetched with `go run pkg@version` for the same reason (no
+# tool line in go.mod).
+#
+# Both modules the gate tests: this one and launchctx, which has its own
+# go.mod. Release code only (no -test), for the platform make runs on.
+# govulncheck cannot accept a finding, so it writes JSON and
+# scripts/govulncheck-gate judges it: a called finding fails unless
+# .amadan/govulncheck-exceptions.tsv lists it, and an expired or unused
+# exception fails too. Imported-only and required-only findings are
+# printed, not fatal. In JSON mode govulncheck exits 0 whatever it finds,
+# so a non-zero exit is a scan that failed (no vuln.go.dev, no module
+# proxy) and fails the target.
+GOVULNCHECK := golang.org/x/vuln/cmd/govulncheck@v1.8.0
+govulncheck:
+ @dir=$$(mktemp -d) || exit 1; trap 'rm -rf "$$dir"' EXIT; \
+ go run $(GOVULNCHECK) -format json ./... >"$$dir/platform.json" && \
+ (cd launchctx && go run $(GOVULNCHECK) -format json ./...) >"$$dir/launchctx.json" && \
+ go run ./scripts/govulncheck-gate -exceptions .amadan/govulncheck-exceptions.tsv "$$dir/platform.json" "$$dir/launchctx.json"
+
# Regenerates docs/console-mockup-kit/shell.html: a signed-in console page
# from the real templates with every stylesheet inlined and an empty
# <main> to draw a mockup in (docs/console-mockup-kit/README.md).
diff --git a/scripts/govulncheck-gate/main.go b/scripts/govulncheck-gate/main.go
new file mode 100644
index 000000000..ebb0495cc
--- /dev/null
+++ b/scripts/govulncheck-gate/main.go
@@ -0,0 +1,375 @@
+// Command govulncheck-gate reads govulncheck's -format json output and
+// decides whether CI's 50-govulncheck step passes. govulncheck itself has
+// no way to accept a finding, so the exceptions live in a file here
+// (.amadan/govulncheck-exceptions.tsv) and this program applies them.
+//
+// The rules, in order of how often they matter:
+//
+// - A finding the code actually calls (govulncheck's symbol level) fails
+// the step unless its OSV id is in the exceptions file.
+// - Findings the code only imports, or only requires through go.mod, are
+// printed and do not fail: govulncheck found no call path to them.
+// - An exception past its expiry date fails, so a "for now" cannot
+// quietly become forever.
+// - An exception that matches no called finding fails too: it is stale
+// and should be removed, so the file cannot rot.
+//
+// Usage:
+//
+// govulncheck-gate -exceptions FILE SCAN.json [SCAN.json ...]
+//
+// Each SCAN.json is one `govulncheck -format json` run (one per module).
+// The findings of all of them are judged together, so an exception is
+// stale only when no scan reaches it.
+package main
+
+import (
+ "bufio"
+ "encoding/json"
+ "errors"
+ "flag"
+ "fmt"
+ "io"
+ "os"
+ "regexp"
+ "sort"
+ "strings"
+ "time"
+)
+
+// level is how close govulncheck says the code gets to a vulnerability.
+type level int
+
+const (
+ levelModule level = iota + 1 // a required module has it; no import
+ levelPackage // a vulnerable package is imported; no call
+ levelSymbol // a vulnerable function is called
+)
+
+func (l level) String() string {
+ switch l {
+ case levelSymbol:
+ return "called"
+ case levelPackage:
+ return "imported"
+ default:
+ return "required"
+ }
+}
+
+// exception is one line of the exceptions file.
+type exception struct {
+ id string
+ expires time.Time // the last day it is valid, inclusive
+ reason string
+ line int
+}
+
+var osvID = regexp.MustCompile(`^GO-[0-9]{4}-[0-9]{4,}$`)
+
+// parseExceptions reads the exceptions file: one tab-separated
+// "ID<TAB>EXPIRES<TAB>REASON" line per exception, EXPIRES as YYYY-MM-DD.
+// Blank lines and lines starting with # are skipped.
+func parseExceptions(r io.Reader) ([]exception, error) {
+ var out []exception
+ seen := map[string]int{}
+ sc := bufio.NewScanner(r)
+ n := 0
+ for sc.Scan() {
+ n++
+ text := strings.TrimRight(sc.Text(), "\r")
+ if strings.TrimSpace(text) == "" || strings.HasPrefix(text, "#") {
+ continue
+ }
+ fields := strings.Split(text, "\t")
+ if len(fields) != 3 {
+ return nil, fmt.Errorf("line %d: want ID<TAB>EXPIRES<TAB>REASON, got %d field(s)", n, len(fields))
+ }
+ id, date, reason := strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1]), strings.TrimSpace(fields[2])
+ if !osvID.MatchString(id) {
+ return nil, fmt.Errorf("line %d: %q is not a Go vulnerability id (GO-YYYY-NNNN)", n, id)
+ }
+ expires, err := time.Parse(time.DateOnly, date)
+ if err != nil {
+ return nil, fmt.Errorf("line %d: expiry %q is not YYYY-MM-DD", n, date)
+ }
+ if reason == "" {
+ return nil, fmt.Errorf("line %d: %s has no reason", n, id)
+ }
+ if prev, ok := seen[id]; ok {
+ return nil, fmt.Errorf("line %d: %s is already listed on line %d", n, id, prev)
+ }
+ seen[id] = n
+ out = append(out, exception{id: id, expires: expires, reason: reason, line: n})
+ }
+ return out, sc.Err()
+}
+
+// The parts of govulncheck's JSON protocol (v1.0.0) this program reads.
+type message struct {
+ Config *struct {
+ ProtocolVersion string `json:"protocol_version"`
+ ScannerVersion string `json:"scanner_version"`
+ GoVersion string `json:"go_version"`
+ ScanLevel string `json:"scan_level"`
+ } `json:"config"`
+ SBOM *struct {
+ Modules []struct {
+ Path string `json:"path"`
+ } `json:"modules"`
+ } `json:"SBOM"`
+ OSV *struct {
+ ID string `json:"id"`
+ Summary string `json:"summary"`
+ } `json:"osv"`
+ Finding *struct {
+ OSV string `json:"osv"`
+ FixedVersion string `json:"fixed_version"`
+ Trace []frame `json:"trace"`
+ } `json:"finding"`
+}
+
+type frame struct {
+ Module string `json:"module"`
+ Version string `json:"version"`
+ Package string `json:"package"`
+ Function string `json:"function"`
+ Receiver string `json:"receiver"`
+ Position *struct {
+ Filename string `json:"filename"`
+ Line int `json:"line"`
+ } `json:"position"`
+}
+
+// symbol renders a frame as pkg.Func or pkg.(*T).Func.
+func (f frame) symbol() string {
+ if f.Receiver != "" {
+ return fmt.Sprintf("%s.(%s).%s", f.Package, f.Receiver, f.Function)
+ }
+ return f.Package + "." + f.Function
+}
+
+// vuln is everything the scans said about one OSV id.
+type vuln struct {
+ id string
+ summary string
+ level level
+ module string // the vulnerable module, with its version
+ fixed string
+ sites map[string]bool // for called findings: where our code calls in
+}
+
+// readScan adds one govulncheck JSON stream's findings to vulns and
+// returns the scanned module's path. It refuses a stream that is not a
+// symbol-level scan: a package- or module-level scan reports no calls,
+// so judged by these rules it would pass whatever it found.
+func readScan(r io.Reader, vulns map[string]*vuln) (string, error) {
+ dec := json.NewDecoder(r)
+ var mod string
+ sawConfig := false
+ summaries := map[string]string{}
+ for {
+ var m message
+ err := dec.Decode(&m)
+ if errors.Is(err, io.EOF) {
+ break
+ }
+ if err != nil {
+ return "", fmt.Errorf("decoding govulncheck output: %w", err)
+ }
+ switch {
+ case m.Config != nil:
+ sawConfig = true
+ if m.Config.ScanLevel != "symbol" {
+ return "", fmt.Errorf("scan level is %q, want \"symbol\" (do not pass -scan to govulncheck)", m.Config.ScanLevel)
+ }
+ case m.SBOM != nil && len(m.SBOM.Modules) > 0:
+ mod = m.SBOM.Modules[0].Path
+ case m.OSV != nil:
+ summaries[m.OSV.ID] = m.OSV.Summary
+ case m.Finding != nil:
+ f := m.Finding
+ if len(f.Trace) == 0 {
+ return "", fmt.Errorf("finding %s has no trace", f.OSV)
+ }
+ v := vulns[f.OSV]
+ if v == nil {
+ top := f.Trace[0]
+ v = &vuln{id: f.OSV, module: top.Module, fixed: f.FixedVersion, sites: map[string]bool{}}
+ if top.Version != "" {
+ v.module += "@" + top.Version
+ }
+ vulns[f.OSV] = v
+ }
+ lv := levelModule
+ switch top := f.Trace[0]; {
+ case top.Function != "":
+ lv = levelSymbol
+ case top.Package != "":
+ lv = levelPackage
+ }
+ if lv > v.level {
+ v.level = lv
+ }
+ if lv == levelSymbol {
+ v.sites[callSite(f.Trace)] = true
+ }
+ }
+ }
+ if !sawConfig {
+ return "", errors.New("no config message: this is not govulncheck -format json output")
+ }
+ for id, s := range summaries {
+ if v := vulns[id]; v != nil && v.summary == "" {
+ v.summary = s
+ }
+ }
+ return mod, nil
+}
+
+// callSite describes where a called finding enters from our code: the
+// last frame of the trace is ours, the first is the vulnerable symbol.
+func callSite(trace []frame) string {
+ entry, vuln := trace[len(trace)-1], trace[0]
+ where := entry.symbol()
+ if entry.Position != nil {
+ where = fmt.Sprintf("%s:%d: %s", entry.Position.Filename, entry.Position.Line, where)
+ }
+ return where + " reaches " + vuln.symbol()
+}
+
+// maxSites is how many call sites to print for a finding that fails.
+const maxSites = 10
+
+// judge prints a report of vulns against the exceptions to w and returns
+// the problems that fail the step (none means green). today is a date in
+// UTC; an exception is valid through its expiry date.
+func judge(w io.Writer, vulns map[string]*vuln, excs []exception, today time.Time, excFile string) []string {
+ byID := map[string]exception{}
+ for _, e := range excs {
+ byID[e.id] = e
+ }
+ ids := make([]string, 0, len(vulns))
+ for id := range vulns {
+ ids = append(ids, id)
+ }
+ // Called first, then imported, then required; by id within a level.
+ sort.Slice(ids, func(i, j int) bool {
+ a, b := vulns[ids[i]], vulns[ids[j]]
+ if a.level != b.level {
+ return a.level > b.level
+ }
+ return a.id < b.id
+ })
+
+ var problems []string
+ for _, id := range ids {
+ v := vulns[id]
+ fmt.Fprintf(w, "%s %s %s, fixed in %s\n", v.id, v.level, v.module, orNone(v.fixed))
+ if v.summary != "" {
+ fmt.Fprintf(w, " %s\n", v.summary)
+ }
+ if v.level != levelSymbol {
+ fmt.Fprintf(w, " not fatal: no call path to the vulnerable code\n")
+ continue
+ }
+ e, ok := byID[id]
+ if ok {
+ fmt.Fprintf(w, " excepted until %s (%s:%d): %s\n", e.expires.Format(time.DateOnly), excFile, e.line, e.reason)
+ continue
+ }
+ sites := make([]string, 0, len(v.sites))
+ for s := range v.sites {
+ sites = append(sites, s)
+ }
+ sort.Strings(sites)
+ for i, s := range sites {
+ if i == maxSites {
+ fmt.Fprintf(w, " ... and %d more call path(s)\n", len(sites)-maxSites)
+ break
+ }
+ fmt.Fprintf(w, " %s\n", s)
+ }
+ problems = append(problems, fmt.Sprintf("%s is called and not in %s: upgrade %s, or add an exception with an expiry and a reason", id, excFile, v.module))
+ }
+
+ for _, e := range excs {
+ if v := vulns[e.id]; v == nil || v.level != levelSymbol {
+ problems = append(problems, fmt.Sprintf("%s:%d: %s is excepted but no scan calls it any more: remove the exception", excFile, e.line, e.id))
+ }
+ if today.After(e.expires) {
+ problems = append(problems, fmt.Sprintf("%s:%d: the exception for %s expired on %s: re-check it, then fix the finding or renew the exception with a new date and reason", excFile, e.line, e.id, e.expires.Format(time.DateOnly)))
+ }
+ }
+ return problems
+}
+
+func orNone(s string) string {
+ if s == "" {
+ return "no release yet"
+ }
+ return s
+}
+
+func main() {
+ excFile := flag.String("exceptions", ".amadan/govulncheck-exceptions.tsv", "the exceptions file")
+ flag.Usage = func() {
+ fmt.Fprintln(os.Stderr, "usage: govulncheck-gate [-exceptions FILE] SCAN.json [SCAN.json ...]")
+ flag.PrintDefaults()
+ }
+ flag.Parse()
+ if flag.NArg() == 0 {
+ flag.Usage()
+ os.Exit(2)
+ }
+ if err := run(os.Stdout, *excFile, flag.Args(), time.Now().UTC()); err != nil {
+ fmt.Fprintln(os.Stderr, "govulncheck:", err)
+ os.Exit(1)
+ }
+}
+
+// errFindings is returned when the report itself has listed the problems.
+var errFindings = errors.New("failed; see above")
+
+func run(w io.Writer, excFile string, scans []string, now time.Time) error {
+ f, err := os.Open(excFile)
+ if err != nil {
+ return err
+ }
+ excs, err := parseExceptions(f)
+ f.Close()
+ if err != nil {
+ return fmt.Errorf("%s: %w", excFile, err)
+ }
+
+ vulns := map[string]*vuln{}
+ var mods []string
+ for _, path := range scans {
+ f, err := os.Open(path)
+ if err != nil {
+ return err
+ }
+ mod, err := readScan(f, vulns)
+ f.Close()
+ if err != nil {
+ return fmt.Errorf("%s: %w", path, err)
+ }
+ if mod == "" {
+ mod = path
+ }
+ mods = append(mods, mod)
+ }
+ fmt.Fprintf(w, "govulncheck: scanned %s\n", strings.Join(mods, ", "))
+
+ today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
+ problems := judge(w, vulns, excs, today, excFile)
+ if len(problems) > 0 {
+ fmt.Fprintln(w)
+ for _, p := range problems {
+ fmt.Fprintln(w, "FAIL:", p)
+ }
+ return errFindings
+ }
+ fmt.Fprintf(w, "govulncheck: clean (%d finding(s), none called outside %s)\n", len(vulns), excFile)
+ return nil
+}
diff --git a/scripts/govulncheck-gate/main_test.go b/scripts/govulncheck-gate/main_test.go
new file mode 100644
index 000000000..477855d34
--- /dev/null
+++ b/scripts/govulncheck-gate/main_test.go
@@ -0,0 +1,192 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+// The scan below is shaped like real govulncheck v1.8.0 -format json
+// output: a config, an SBOM, OSV records, then findings whose first frame
+// is the vulnerable symbol (module level: no package; package level: no
+// function) and whose last frame is the caller in our code.
+const scanHead = `{"config":{"protocol_version":"v1.0.0","scanner_name":"govulncheck","scanner_version":"v1.8.0","go_version":"go1.26.10","scan_level":"symbol","scan_mode":"source"}}
+{"SBOM":{"go_version":"go1.26.10","modules":[{"path":"example.com/shop"}]}}
+{"progress":{"message":"Checking the code against the vulnerabilities..."}}
+`
+
+func osvMsg(id string) string {
+ return fmt.Sprintf(`{"osv":{"id":%q,"summary":"summary of %s"}}`+"\n", id, id)
+}
+
+func calledMsg(id string) string {
+ return fmt.Sprintf(`{"finding":{"osv":%q,"fixed_version":"v1.26.11","trace":[
+{"module":"stdlib","version":"v1.26.10","package":"net/http","function":"Read","receiver":"*body","position":{"filename":"src/net/http/transfer.go","line":838}},
+{"module":"example.com/shop","package":"example.com/shop/web","function":"Serve","position":{"filename":"web/serve.go","line":12}}]}}`+"\n", id)
+}
+
+func requiredMsg(id string) string {
+ return fmt.Sprintf(`{"finding":{"osv":%q,"fixed_version":"v0.58.1","trace":[{"module":"golang.org/x/crypto","version":"v0.58.0"}]}}`+"\n", id)
+}
+
+func importedMsg(id string) string {
+ return fmt.Sprintf(`{"finding":{"osv":%q,"fixed_version":"v0.58.1","trace":[{"module":"golang.org/x/crypto","version":"v0.58.0","package":"golang.org/x/crypto/openpgp"}]}}`+"\n", id)
+}
+
+var today = time.Date(2026, 11, 16, 0, 0, 0, 0, time.UTC)
+
+// gate writes the exceptions and scans to files and runs the gate on them.
+func gate(t *testing.T, exceptions string, scans ...string) (string, error) {
+ t.Helper()
+ dir := t.TempDir()
+ exc := filepath.Join(dir, "exceptions.tsv")
+ if err := os.WriteFile(exc, []byte(exceptions), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ var paths []string
+ for i, s := range scans {
+ p := filepath.Join(dir, fmt.Sprintf("scan%d.json", i))
+ if err := os.WriteFile(p, []byte(s), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ paths = append(paths, p)
+ }
+ var out strings.Builder
+ err := run(&out, exc, paths, today)
+ return out.String(), err
+}
+
+const exc6859 = "# id\texpires\treason\nGO-2026-6859\t2027-01-31\tpinned to go1.26.10 by #897; #904 found it unreachable\n"
+
+func TestUnknownCalledFindingFails(t *testing.T) {
+ out, err := gate(t, exc6859, scanHead+osvMsg("GO-2026-6859")+calledMsg("GO-2026-6859")+osvMsg("GO-2026-7000")+calledMsg("GO-2026-7000"))
+ if err == nil {
+ t.Fatalf("an unlisted called finding passed:\n%s", out)
+ }
+ if !strings.Contains(out, "FAIL: GO-2026-7000 is called and not in") {
+ t.Errorf("no failure line for GO-2026-7000:\n%s", out)
+ }
+ if !strings.Contains(out, "web/serve.go:12: example.com/shop/web.Serve reaches net/http.(*body).Read") {
+ t.Errorf("the call site is not shown:\n%s", out)
+ }
+ if strings.Contains(out, "FAIL: GO-2026-6859") {
+ t.Errorf("the listed finding failed too:\n%s", out)
+ }
+}
+
+func TestListedCalledFindingPasses(t *testing.T) {
+ out, err := gate(t, exc6859, scanHead+osvMsg("GO-2026-6859")+requiredMsg("GO-2026-6859")+calledMsg("GO-2026-6859"))
+ if err != nil {
+ t.Fatalf("a listed finding failed: %v\n%s", err, out)
+ }
+ if !strings.Contains(out, "excepted until 2027-01-31") {
+ t.Errorf("the exception is not reported:\n%s", out)
+ }
+}
+
+func TestExceptionValidThroughItsExpiryDay(t *testing.T) {
+ exc := "GO-2026-6859\t2026-11-16\treason\n"
+ if out, err := gate(t, exc, scanHead+calledMsg("GO-2026-6859")); err != nil {
+ t.Fatalf("an exception failed on its own expiry day: %v\n%s", err, out)
+ }
+}
+
+func TestExpiredExceptionFails(t *testing.T) {
+ exc := "GO-2026-6859\t2026-11-15\tpinned for now\n"
+ out, err := gate(t, exc, scanHead+calledMsg("GO-2026-6859"))
+ if err == nil {
+ t.Fatalf("an expired exception passed:\n%s", out)
+ }
+ if !strings.Contains(out, "the exception for GO-2026-6859 expired on 2026-11-15") {
+ t.Errorf("no expiry failure:\n%s", out)
+ }
+}
+
+func TestStaleExceptionFails(t *testing.T) {
+ for name, scan := range map[string]string{
+ "absent": scanHead,
+ "required": scanHead + requiredMsg("GO-2026-6859"),
+ "imported": scanHead + importedMsg("GO-2026-6859"),
+ } {
+ t.Run(name, func(t *testing.T) {
+ out, err := gate(t, exc6859, scan)
+ if err == nil {
+ t.Fatalf("a stale exception passed:\n%s", out)
+ }
+ if !strings.Contains(out, "GO-2026-6859 is excepted but no scan calls it any more: remove the exception") {
+ t.Errorf("no stale failure:\n%s", out)
+ }
+ })
+ }
+}
+
+// An exception is judged against every scan together: it is not stale
+// because one module's scan does not call it, if another's does.
+func TestExceptionCalledInAnyScanIsNotStale(t *testing.T) {
+ out, err := gate(t, exc6859, scanHead+requiredMsg("GO-2026-6859"), scanHead+calledMsg("GO-2026-6859"))
+ if err != nil {
+ t.Fatalf("%v\n%s", err, out)
+ }
+}
+
+func TestUncalledFindingsArePrintedNotFatal(t *testing.T) {
+ out, err := gate(t, "", scanHead+osvMsg("GO-2026-5932")+requiredMsg("GO-2026-5932")+osvMsg("GO-2026-5933")+importedMsg("GO-2026-5933"))
+ if err != nil {
+ t.Fatalf("uncalled findings failed: %v\n%s", err, out)
+ }
+ for _, want := range []string{
+ "GO-2026-5932 required golang.org/x/crypto@v0.58.0, fixed in v0.58.1",
+ "GO-2026-5933 imported golang.org/x/crypto@v0.58.0",
+ "summary of GO-2026-5932",
+ "not fatal",
+ } {
+ if !strings.Contains(out, want) {
+ t.Errorf("output lacks %q:\n%s", want, out)
+ }
+ }
+}
+
+func TestNotGovulncheckOutputFails(t *testing.T) {
+ for name, scan := range map[string]string{
+ "empty": "",
+ "garbage": "not json",
+ "package level": strings.Replace(scanHead, `"scan_level":"symbol"`, `"scan_level":"package"`, 1),
+ } {
+ t.Run(name, func(t *testing.T) {
+ if out, err := gate(t, "", scan); err == nil || err == errFindings {
+ t.Fatalf("accepted (err %v):\n%s", err, out)
+ }
+ })
+ }
+}
+
+func TestBadExceptionsFileFails(t *testing.T) {
+ for name, exc := range map[string]string{
+ "two fields": "GO-2026-6859\t2027-01-31\n",
+ "bad id": "CVE-2026-1\t2027-01-31\treason\n",
+ "bad date": "GO-2026-6859\t31/01/2027\treason\n",
+ "no reason": "GO-2026-6859\t2027-01-31\t \n",
+ "duplicate": exc6859 + "GO-2026-6859\t2027-02-28\tagain\n",
+ } {
+ t.Run(name, func(t *testing.T) {
+ if out, err := gate(t, exc, scanHead+calledMsg("GO-2026-6859")); err == nil || err == errFindings {
+ t.Fatalf("accepted (err %v):\n%s", err, out)
+ }
+ })
+ }
+}
+
+// The checked-in exceptions file must always parse.
+func TestRepoExceptionsFileParses(t *testing.T) {
+ f, err := os.Open("../../.amadan/govulncheck-exceptions.tsv")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ if _, err := parseExceptions(f); err != nil {
+ t.Fatal(err)
+ }
+}