Skip to content

Use indexed manifest licenses for SBOM root metadata - #369

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/sbom-manifest-license-query-342
Oct 24, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/sbom-manifest-license-query-342

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #342

Summary

Connect SBOM generation to the existing manifest_licenses table, giving GetManifestLicensesAtRef a production consumer.

  • Read indexed license declarations for root-level package manifests at the requested revision.
  • Verify that each indexed declaration's source manifest matches the requested revision before reusing it.
  • Fall back to tree parsing for missing or stale metadata, including partially indexed and on-demand-only databases.
  • Continue reading declared license-file text from the requested revision.
  • Preserve existing license normalization, warnings, and root-manifest selection.

The query now returns the source commit SHA for each license event. No schema migration or dependency update is required.

Scope

This implements the issue's SBOM-consumer option. It does not change on-demand indexing or add project-license entries to the licenses command.

Regression Coverage

  • Production SBOM output uses indexed license data.
  • Historical license changes and removed declarations.
  • Default and explicit database branch selection.
  • Root-manifest filtering and partially populated indexes.
  • Stale license events after on-demand manifest changes.
  • Historical license-file contents and missing/empty-file warnings.
  • Query errors are surfaced rather than silently ignored.

Verification

  • Formatting checked with gofmt
  • go build ./...
  • go mod tidy -diff
  • go test ./... -count=1
  • go test -race ./... -count=1
  • go tool golangci-lint run ./...
  • git diff --check

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/sbom_root_license.go:110–112 aborts when an existing database lacks manifest_licenses. I reproduced this with a populated schema-15 database: sbom --skip-enrichment on main outputs the MIT license, while this PR exits with loading project licenses: querying indexed project licenses: SQL logic error: no such table: manifest_licenses (1).

Please fall back to tree parsing when the table is absent and add a CLI regression test using the previous schema. The test that deletes rows from the current table does not cover databases created before the table was introduced.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. indexedProjectLicenses now checks whether manifest_licenses exists and falls back to tree parsing when it doesn't, so schema-15 databases produce the same root license as main. I added TestSBOMFallsBackToTreeWithoutManifestLicensesTable, which drops the table, sets the schema to the previous version, then runs sbom --skip-enrichment through the CLI. It fails with the no such table error before the fix and passes after. I also corrected the misleading comment on the row-deletion test.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing-table fallback addresses my earlier review. Verified SBOM output with a schema-15 database, an on-demand-only index, stale manifest license events, and updated license-file text; the schema-15 database retains its schema and has no license table created.

@andrew
andrew merged commit 0bf2bf3 into git-pkgs:main Oct 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

manifest_licenses table is write-only in production

2 participants