Skip to content

feat: cache registry integrity lookups - #274

Merged
andrew merged 3 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/integrity-cache-260
Jul 15, 2026
Merged

andrew merged 3 commits into
git-pkgs:mainfrom
abhinavgautam01:feature/integrity-cache-260

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #260

Summary

Cache version integrity metadata used by git pkgs integrity --registry so repeated checks do not make unnecessary registry requests.

  • Add integrity data to the existing CachedVersion model
  • Read and write the existing versions.integrity column
  • Check the version cache using the standard 24-hour enrichment TTL
  • Fetch only missing or stale package versions
  • Avoid creating an enrichment client when all requested versions are cached
  • Batch-save successful registry integrity lookups
  • Preserve existing integrity hashes when other commands update version metadata without integrity data
  • Keep dependency deduplication within each command run
  • Document the registry integrity cache behavior

The integrity column already exists in the versions table, so this change does not require a schema migration or schema-version bump.

Testing

Added regression coverage confirming that:

  • A partially populated cache fetches only missing versions
  • A repeated registry check makes zero enrichment requests
  • Cached integrity survives version updates that omit integrity data
  • Checked and skipped summary counts remain correct

Validation performed:

  • 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 caching of registry-provided integrity hashes (used by git pkgs integrity --registry) into the existing versions cache so repeated runs avoid redundant registry/enrichment requests while still honoring the standard 24-hour enrichment TTL.

Changes:

  • Extend the CachedVersion model and DB queries to read/write the existing versions.integrity column.
  • Update integrity --registry to reuse cached integrity where fresh, fetch only missing/stale versions, and batch-save successful lookups.
  • Add regression tests and document the registry integrity caching behavior.

Reviewed changes

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

Show a summary per file
File Description
README.md Documents --registry usage and the 24-hour cache behavior.
internal/database/queries.go Adds integrity to CachedVersion, includes it in cached reads, and persists it via SaveVersions.
docs/internals.md Notes that integrity --registry uses the version cache and fetches only missing/stale versions.
cmd/integrity.go Implements cached registry integrity lookups, avoids creating the enrichment client when unnecessary, and batch-saves cache updates.
cmd/analysis_test.go Adds regression coverage for cache hits/misses and preserving cached integrity across non-integrity version updates.

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

Comment thread internal/database/queries.go Resolved
Comment thread cmd/integrity.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 cache-correctness regressions:

  1. [P1] internal/database/queries.go:2355-2363 — SaveVersions preserves an existing integrity value when an update omits integrity, but it unconditionally refreshes the shared enriched_at timestamp. A later freshness, license, or deprecation update can therefore make an integrity hash older than 24 hours appear fresh indefinitely. If the registry hash changed, integrity --registry may reuse the old hash and incorrectly report no mismatch. I reproduced this by aging an integrity row by 48 hours, applying a license-only SaveVersions update, and observing GetCachedVersions return the stale integrity within a 24-hour TTL. Integrity needs its own freshness marker, or equivalent field-specific cache semantics.

  2. [P2] cmd/integrity.go:307-313 — The registry check saves only each installed exact version into versions, while freshness treats any non-empty GetCachedVersions result as a complete package-version history. After integrity --registry caches the installed version, freshness can skip GetVersions, see only that version, and report it as latest even when newer releases exist. The cache needs to distinguish exact-version metadata from a complete version-list fetch, or consumers must verify completeness before reusing it.

The existing CI is green but does not cover either cross-command interaction.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Fixed both cache-contract regressions.

Exact integrity lookups now use a dedicated integrity_checked_at timestamp and dedicated read/write helpers, so later generic version metadata updates cannot make an old integrity hash appear fresh.

I also added a version_lists completion marker that is written only after a full GetVersions response. freshness and dated outdated now reuse cached versions only when that marker is fresh, while integrity --registry stores exact-version integrity data without marking a package's release history complete.

This bumps the database schema to v14. Added regressions for an aged integrity entry followed by a generic metadata update and for integrity --registry followed by freshness to verify freshness still fetches the complete version list.

@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 rebase this branch onto current main and resolve the content conflicts introduced by #273.

In internal/database/queries.go, preserve the GetCachedVersionsIncludingStale and shared getCachedVersions path from main, which licenses --offline uses, while adding this PR's integrity and integrity_checked_at columns to the shared SELECT and Scan. In docs/internals.md, preserve the documentation for both offline licenses and integrity/version-list caching.

The two earlier cache-correctness requests look resolved at 9da2596. Once the branch is rebased and CI is green, I will re-review the combined result.

# Conflicts:
#	docs/internals.md
#	internal/database/queries.go
# Conflicts:
#	docs/internals.md
#	internal/database/queries.go
@abhinavgautam01
abhinavgautam01 force-pushed the feature/integrity-cache-260 branch from 9da2596 to 6340835 Compare July 14, 2026 03:20
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and resolved the #273 overlaps.

GetCachedVersionsIncludingStale and the shared getCachedVersions reader are preserved for licenses --offline; the shared SELECT/Scan now includes both integrity and integrity_checked_at. The internals documentation retains the offline-license behavior alongside the integrity freshness and complete version-list cache behavior.

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

Both cache-correctness regressions are resolved: integrity now has its own integrity_checked_at freshness marker independent of enriched_at, and version_lists distinguishes complete history fetches from exact-version writes so freshness/dated outdated no longer mistake an integrity-only row for a full release list. Rebase onto #273 preserves the shared getCachedVersions reader and GetCachedVersionsIncludingStale for licenses --offline. Regression tests cover both cross-command interactions.

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

Cache version integrity lookups used by integrity --registry

3 participants