Skip to content

Store manifest-declared license history - #325

Merged
andrew merged 4 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/manifest-license-storage-305
Aug 29, 2026
Merged

andrew merged 4 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/manifest-license-storage-305

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #305

Summary

  • add commit-scoped database storage for licenses declared by project manifests
  • persist both ParseResult.Licenses and ParseResult.LicenseFile
  • track license-only manifest changes without counting them as dependency changes
  • record manifest removal events so historical queries do not return deleted manifests
  • add GetManifestLicensesAtRef for retrieving manifest license state at a specific commit
  • bump the database schema version and document the new table

Implementation

The new manifest_licenses table stores license state against a commit and manifest. This preserves historical license information while supporting manifests that declare multiple licenses.

The analyzer emits manifest-license events for additions, modifications, and removals. The batch writer persists these events independently of dependency changes, allowing a commit that only changes a project's declared license to be indexed correctly.

Testing

Added regression coverage for:

  • manifests declaring multiple licenses
  • license-file declarations
  • license-only manifest modifications
  • manifest deletion
  • historical license lookups at different commits
  • incremental indexing with existing manifest paths
  • ensuring license-only commits are not marked as dependency-change commits

Verification

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds commit-scoped persistence and historical querying for licenses declared directly in project manifests, enabling point-in-time license lookups per manifest path without re-parsing past commits.

Changes:

  • Introduces a new manifest_licenses table and bumps the DB schema version to store manifest-declared licenses/license-file paths as commit-scoped events (including removals).
  • Extends the analyzer and indexer pipeline to emit and persist manifest license events independently of dependency changes.
  • Adds GetManifestLicensesAtRef plus regression tests and documentation updates for the new storage/query behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/indexer/indexer.go Persists manifest-license events per analyzed commit via the batch writer.
internal/indexer/indexer_test.go Adds integration test ensuring license-only commits are indexed without dependency-change flags and are queryable by commit.
internal/database/schema.go Adds the manifest_licenses table and supporting indexes.
internal/database/queries.go Adds ManifestLicense model + GetManifestLicensesAtRef query and includes the new table in database info output.
internal/database/database.go Bumps schema version to v16.
internal/database/database_test.go Updates schema creation test to include manifest_licenses.
internal/database/batch_writer.go Adds batch writer support for buffering and inserting manifest-license events transactionally.
internal/database/batch_writer_test.go Adds regression test for manifest license state retrieval across commits (including removal).
internal/analyzer/analyzer.go Emits manifest license events for add/modify/delete operations on manifests.
internal/analyzer/analyzer_test.go Adds analyzer-level tests for multi-license manifests, license-file, modifications, and deletions.
docs/schema.md Documents the new manifest_licenses table and indexes.
docs/internals.md Updates internals documentation to describe manifest-license event tracking and selection logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@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.

This PR bumps the schema from v15 to v16 and adds writes to manifest_licenses, but an existing v15 database is still opened without a version check. When reindex reaches a manifest change, insertManifestLicenses writes to a table that does not exist and the reindex fails.

Please detect the existing v15 schema before entering this PR’s new write path, return a clear error instructing the user to run git pkgs upgrade, and add a regression test covering reindex with a v15 database.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Thanks, Fixed. reindex now reads the existing database schema version immediately after opening the database and rejects an outdated schema before branch lookup or indexing begins. The error identifies the existing and current schema versions and instructs the user to run git pkgs upgrade.

I also added a regression test that creates a realistic v15 database by removing the v16-only manifest_licenses table and setting schema_info to version 15. After adding a license-only manifest commit, the test verifies that reindex returns the upgrade instruction instead of reaching the missing-table write.

@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.

Please address both schema compatibility paths:

  • Move the schema guard into the shared indexing path. branch add and bisect invoke the indexer directly and bypass the check in cmd/reindex.go. Against schema v15, git pkgs branch add feature reaches insertManifestLicenses and fails with no such table: manifest_licenses. Add command-level coverage for these entrypoints.

  • Handle newer schemas separately. A v16 binary labels schema v17 as outdated and advises git pkgs upgrade, whose current path rebuilds the database at v16. During rollback, report that the binary is older than the database and require a compatible binary.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/manifest-license-storage-305 branch from 8dd3376 to 94d6336 Compare August 28, 2026 10:59
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Addressed both compatibility paths. Schema validation now runs in the shared indexer, covering reindex, branch add and bisect before any writes. Newer schemas now require a compatible binary and upgrade refuses to rebuild or downgrade them. Added command-level regressions and rebased onto current main.

@andrew
andrew merged commit 6590987 into git-pkgs:main Aug 29, 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.

analyzer: store manifest-declared license per manifest

3 participants