Skip to content

Add license drift detection - #220

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feature/license-drift-23
Jun 6, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feature/license-drift-23

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #23

Summary

  • Add git pkgs licenses --drift to detect resolved dependencies whose installed-version license differs from latest package metadata
  • Support text, JSON, and CSV output for license drift results
  • Reuse cached package/version metadata and fetch uncached version license data through enrichment
  • Document the new --drift option in the README

Tests

  • go test ./cmd -run 'TestLicensesCommand|TestSpdxPermissiveCheck'
  • go test ./...
  • 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.

Some real concerns before this can land.

Sequential GetVersions loop on cache misses. loadLicenseDriftVersionLicenses iterates missingPackagePURLs and calls client.GetVersions(ctx, packagePURL) one at a time, with a fresh 5-minute timeout per call. On a cold-cache lockfile with hundreds of resolved deps that's hundreds of sequential round-trips. The funding/maintainers PRs (#214, #215) ran into the same shape and resolved it by moving to BulkLookup. There's no bulk-versions API in enrichment so the resolution can't be identical, but at minimum the loop should run through a worker pool with a single shared timeout. Worth checking whether GetVersion (singular, returning just the installed version) is enough — you only need one version's license per package, not the full version list, so smaller responses plus parallel fetch may be the right shape.

--drift silently ignores other flags. runLicenses short-circuits into runLicenseDrift as soon as --drift is set, dropping --permissive, --copyleft, --unknown, --group, --allow, and --deny on the floor. Either reject those combinations explicitly with an error, or restructure so they compose. Silently ignoring is the worst option.

docs/internals.md not updated. The Package Enrichment section enumerates which commands fetch what; licenses --drift adds a new per-version fetch pattern that the section doesn't currently describe (the existing entry assumes package-level only). One sentence near the cache paragraph noting that --drift reads per-version license data from the versions cache and falls back to enrichment.GetVersions on misses would close the gap.

Minor: the drift text output repeats the package name three times — express (npm): express@4.18.2 MIT -> express@5.0.0 GPL-3.0-only. express (npm): 4.18.2 MIT -> 5.0.0 GPL-3.0-only is plenty.

@andrew

andrew commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #225 just landed and centralizes the user agent string into a package-level userAgent var in cmd/root.go. When you rebase, please change enrichment.WithUserAgent("git-pkgs/" + version) to enrichment.WithUserAgent(userAgent) so we keep the format in one place.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/license-drift-23 branch from 1318e2c to 791dce2 Compare June 3, 2026 14:19
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Some real concerns before this can land.

Sequential GetVersions loop on cache misses. loadLicenseDriftVersionLicenses iterates missingPackagePURLs and calls client.GetVersions(ctx, packagePURL) one at a time, with a fresh 5-minute timeout per call. On a cold-cache lockfile with hundreds of resolved deps that's hundreds of sequential round-trips. The funding/maintainers PRs (#214, #215) ran into the same shape and resolved it by moving to BulkLookup. There's no bulk-versions API in enrichment so the resolution can't be identical, but at minimum the loop should run through a worker pool with a single shared timeout. Worth checking whether GetVersion (singular, returning just the installed version) is enough — you only need one version's license per package, not the full version list, so smaller responses plus parallel fetch may be the right shape.

--drift silently ignores other flags. runLicenses short-circuits into runLicenseDrift as soon as --drift is set, dropping --permissive, --copyleft, --unknown, --group, --allow, and --deny on the floor. Either reject those combinations explicitly with an error, or restructure so they compose. Silently ignoring is the worst option.

docs/internals.md not updated. The Package Enrichment section enumerates which commands fetch what; licenses --drift adds a new per-version fetch pattern that the section doesn't currently describe (the existing entry assumes package-level only). One sentence near the cache paragraph noting that --drift reads per-version license data from the versions cache and falls back to enrichment.GetVersions on misses would close the gap.

Minor: the drift text output repeats the package name three times — express (npm): express@4.18.2 MIT -> express@5.0.0 GPL-3.0-only. express (npm): 4.18.2 MIT -> 5.0.0 GPL-3.0-only is plenty.

fixed.. licenses --drift now fetches only the installed version metadata via GetVersion and does it through an 8-worker pool under one shared 5-minute timeout, instead of sequential GetVersions calls per package. i also made --drift reject incompatible license filtering/grouping flags explicitly, documented the per-version cache/fetch behavior in docs/internals.md and shortened the text output to avoid repeating package names...

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Heads-up: #225 just landed and centralizes the user agent string into a package-level userAgent var in cmd/root.go. When you rebase, please change enrichment.WithUserAgent("git-pkgs/" + version) to enrichment.WithUserAgent(userAgent) so we keep the format in one place.

fixed after rebasing onto current main. The drift fetch path now uses enrichment.WithUserAgent(userAgent) instead of rebuilding the user-agent string locally....

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

All prior asks resolved: loadLicenseDriftVersionLicenses now runs through an 8-worker pool sharing a single 5-minute timeout and uses client.GetVersion instead of the heavier GetVersions; validateLicenseDriftFlags rejects --drift combined with --allow/--deny/--permissive/--copyleft/--unknown/--group with an explicit error; docs/internals.md describes the new per-version cache+fetch behavior; the text output drops the duplicated package name; and the enrichment client uses the centralized userAgent var.

@andrew

andrew commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Approved — but #215 just landed and touches the same docs/internals.md sentence, so this needs a rebase on top of main. After the rebase, append your licenses --drift sentence after the now-expanded funding/maintainers/deprecated line. I'll merge once it's clean.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/license-drift-23 branch from 791dce2 to 92cefc1 Compare June 5, 2026 15:58
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Approved — but #215 just landed and touches the same docs/internals.md sentence, so this needs a rebase on top of main. After the rebase, append your licenses --drift sentence after the now-expanded funding/maintainers/deprecated line. I'll merge once it's clean.

rebased on current main and resolved the docs/internals.md overlap. The existing funding/maintainers/deprecated cache sentence is kept intact and the licenses --drift per-version cache/fetch sentence now follows it as a separate sentence..

@abhinavgautam01
abhinavgautam01 requested a review from andrew June 5, 2026 16:21
@andrew
andrew merged commit 76bb7b1 into git-pkgs:main Jun 6, 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.

License drift detection

2 participants