Skip to content

Add offline license metadata caching support - #273

Merged
andrew merged 3 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/offline-cache-272
Jul 13, 2026
Merged

andrew merged 3 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/offline-cache-272

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #272

Summary

Improve offline and reduced-request support for license checks by building on the existing SQLite enrichment cache.

  • Add git pkgs licenses --offline
  • Use cached package and version metadata regardless of age in offline mode
  • Ensure offline mode never makes enrichment API requests
  • Return a clear error when required metadata has not been cached
  • Support offline operation with licenses --drift
  • Increase the license lookup timeout from 60 seconds to 5 minutes
  • Honor the documented GIT_PKGS_DB environment variable
  • Document persisting the metadata database with GitHub Actions cache
  • Add regression coverage for stale caches, missing metadata, offline drift, and database path overrides

Offline mode intentionally fails when required metadata is missing so license-policy checks cannot silently pass with incomplete data.

Testing

  • go test ./...
  • 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 true offline support for git pkgs licenses by reusing the existing SQLite enrichment cache, including allowing stale cache entries in --offline mode while guaranteeing no enrichment API requests are made. It also implements the documented GIT_PKGS_DB override so the metadata DB can be persisted outside .git (e.g., across CI runs), updates docs, and adds regression tests around stale/missing cache behavior and offline drift.

Changes:

  • Add git pkgs licenses --offline (including support for --drift) that uses cached metadata regardless of TTL and errors when required cache entries are missing.
  • Extend enrichment license lookup timeout from 60s to 5m, and add DB query helpers to fetch cached packages/versions including stale entries.
  • Honor GIT_PKGS_DB for DB location and document CI caching of the SQLite metadata database.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
README.md Document licenses --offline behavior and mention GIT_PKGS_DB for persistence.
internal/git/repository.go Implement GIT_PKGS_DB override (absolute and repo-relative paths).
internal/git/repository_test.go Add coverage for GIT_PKGS_DB override behavior.
internal/database/queries.go Refactor cached package/version queries and add “including stale” variants.
docs/internals.md Document offline license behavior and cache semantics.
docs/ci-cd.md Document caching the SQLite metadata DB via GitHub Actions cache.
cmd/licenses.go Add --offline flag, enforce no network in offline mode, and extend lookup timeouts.
cmd/licenses_test.go Add regression tests for stale cache usage, missing metadata failures, and offline drift behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/licenses_test.go Resolved
Comment thread cmd/licenses_test.go Resolved

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

Requesting changes for two reproduced regressions:

  1. internal/database/queries.go:1840-1853 — GetCachedPackagesIncludingStale selects funding-, maintainer-, and health-only package rows whose enriched_at is NULL. Scanning that value into a string fails with “converting NULL to string is unsupported”, so licenses --offline returns a raw SQL error instead of the promised cache-miss message. Please exclude rows without enrichment metadata, for example with enriched_at IS NOT NULL, and add coverage for a funding-only row.

  2. internal/git/repository.go:81-86 — Custom database paths do not work when their parent directory does not already exist. For example, GIT_PKGS_DB=.cache/pkgs.sqlite3 resolves correctly, but database.Create/OpenOrCreate fails with SQLite error 14 on a clean checkout. Please create the parent directory before opening a new custom database and test actual database creation, not only path calculation.

Both cases were reproduced against this PR revision. The existing CI is green but does not cover them.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Updated

  • GetCachedPackagesIncludingStale now requires enriched_at IS NOT NULL, so rows containing only funding, maintainer or health metadata are treated as cache misses. Added a regression test that stores a funding-only row and verifies licenses --offline returns the intended missing-metadata error without making a network request.
  • New database creation now ensures the parent directory exists in both database.Create and database.OpenOrCreate. Added coverage that creates databases through both paths using GIT_PKGS_DB values under previously absent relative directories.

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

Re-reviewed at d49f27d. The two previously requested fixes are complete, the focused regressions are covered, and the full test suite and CI pass.

@andrew
andrew merged commit eba05e3 into git-pkgs:main Jul 13, 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.

Better offline/reduced API call support

3 participants