resolve: stop guessing SPDX ids for ambiguous license aliases (#31) #38

Merged
KofTwentyTwo merged 1 commits from feature/GH-31-spdxnorm-no-guess into develop 2026-06-09 15:17:56 +00:00
KofTwentyTwo commented 2026-06-09 12:59:45 +00:00 (Migrated from github.com)

Summary

internal/resolve/spdxnorm.go had an alias table that fabricated SPDX ids, breaking the package's core "never guess" invariant. This fix makes ambiguous and non-curated aliases resolve to unresolved with a reason instead of inventing an id.

[HIGH] Fabricated ids removed

  • "bsd" / "bsd license" -> previously BSD-2-Clause, inventing a clause count (could be 2/3/4-clause). Now unresolved.
  • "gnu lesser general public license" -> previously LGPL-3.0-or-later, inventing BOTH a version (2.1 vs 3.0) and the grant (only vs or-later). Now unresolved.

These guesses flowed into deny/allow verdicts and the incompatibility table, where -only vs -or-later and clause counts are decisive.

[MED] Resolved-but-unclassifiable contradiction fixed

Alias re-validation now uses spdx.Lookup (curated rendering set) instead of spdx.Validate (full index). The Eclipse Public License aliases (EPL-2.0 / EPL-1.0) passed Validate but are outside the curated set, so policy.Classify returned Unknown while the dependency was still marked resolved. They are now left unresolved, and any future alias whose target is valid-but-uncurated is structurally rejected by the Lookup gate.

Aliases kept (unambiguous + curated)

Apache-2.0 spellings, MIT spellings, explicit 3-clause BSD spellings, isc license, the unlicense, mozilla public license 2.0, and the explicit gnu affero general public license v3.0 or later.

Behavior change

Dependencies whose declared license was a bare BSD/BSD License, a bare LGPL name, or an EPL spelling now flip from resolved to unresolved with a reason (e.g. "declared license not recognized as SPDX: BSD"). This is the correct, honest behavior: those names cannot be pinned to a single SPDX id without guessing.

Tests (TDD, red-green)

  • normalizeSPDX now yields unresolved for "BSD", "BSD License", "GNU Lesser General Public License", "Eclipse Public License 2.0", "Eclipse Public License 1.0".
  • New TestSPDXAliasesAreCuratedAndClassifiable asserts every remaining alias maps to a curated id with policy.Classify != Unknown.

Gate

  • gofmt -l . clean
  • go vet ./... clean
  • go test ./... -race pass
  • coverage 100% (2087/2087)
  • golangci-lint run 0 issues

Closes #31

## Summary `internal/resolve/spdxnorm.go` had an alias table that fabricated SPDX ids, breaking the package's core "never guess" invariant. This fix makes ambiguous and non-curated aliases resolve to **unresolved with a reason** instead of inventing an id. ### [HIGH] Fabricated ids removed - `"bsd"` / `"bsd license"` -> previously `BSD-2-Clause`, inventing a clause count (could be 2/3/4-clause). Now unresolved. - `"gnu lesser general public license"` -> previously `LGPL-3.0-or-later`, inventing BOTH a version (2.1 vs 3.0) and the grant (`only` vs `or-later`). Now unresolved. These guesses flowed into deny/allow verdicts and the incompatibility table, where `-only` vs `-or-later` and clause counts are decisive. ### [MED] Resolved-but-unclassifiable contradiction fixed Alias re-validation now uses `spdx.Lookup` (curated rendering set) instead of `spdx.Validate` (full index). The Eclipse Public License aliases (`EPL-2.0` / `EPL-1.0`) passed `Validate` but are outside the curated set, so `policy.Classify` returned `Unknown` while the dependency was still marked resolved. They are now left unresolved, and any future alias whose target is valid-but-uncurated is structurally rejected by the `Lookup` gate. ### Aliases kept (unambiguous + curated) Apache-2.0 spellings, MIT spellings, explicit 3-clause BSD spellings, `isc license`, `the unlicense`, `mozilla public license 2.0`, and the explicit `gnu affero general public license v3.0 or later`. ## Behavior change Dependencies whose declared license was a bare `BSD`/`BSD License`, a bare LGPL name, or an EPL spelling now flip from resolved to **unresolved with a reason** (e.g. "declared license not recognized as SPDX: BSD"). This is the correct, honest behavior: those names cannot be pinned to a single SPDX id without guessing. ## Tests (TDD, red-green) - `normalizeSPDX` now yields unresolved for `"BSD"`, `"BSD License"`, `"GNU Lesser General Public License"`, `"Eclipse Public License 2.0"`, `"Eclipse Public License 1.0"`. - New `TestSPDXAliasesAreCuratedAndClassifiable` asserts every remaining alias maps to a curated id with `policy.Classify != Unknown`. ## Gate - `gofmt -l .` clean - `go vet ./...` clean - `go test ./... -race` pass - coverage 100% (2087/2087) - `golangci-lint run` 0 issues Closes #31
Sign in to join this conversation.