Skip to content

feat(cli): oa check --fetch warms the proxies; show what pulls a dependency in - #483

Merged
M0Rf30 merged 2 commits into
openartifact:mainfrom
orcamedia:feat/oa-check-fetch-required-by
Nov 13, 2026
Merged

M0Rf30 merged 2 commits into
openartifact:mainfrom
orcamedia:feat/oa-check-fetch-required-by

Conversation

@orcamedia

Copy link
Copy Markdown
Contributor

Two things I ran into using oa check on a real Laravel project (132 locked packages, a fresh Packagist proxy behind a group).

--fetch

On a fresh proxy every answer is unknown until each package has been fetched once. --fetch first requests each distinct package's metadata through the repository, the way the package manager would:

  • What it requests: composer's p2/<name>.json, or npm's packument (a scoped name as @scope%2fname).
  • Effect: the proxies behind the repository, also through a group, fetch and cache the documents.
  • Load: at most 8 requests at a time. Metadata only, never packages.
  • Failures: a request that doesn't answer 200 is counted and reported, not fatal. A package whose every version a curation rule hides answers 404 for its p2 document, so it's counted there and then reported held by the check.

This doesn't change the server's rule that the availability check never asks the upstream: the warming goes through the normal serving path, on request.

"Required by"

A held indirect dependency didn't say where it came from. The parsers now record which locked packages require each dependency:

  • composer: each package's require; platform requirements never match a locked name.
  • npm v2/v3: dependencies, optionalDependencies and peerDependencies of the installed packages. An alias is looked up both by its folder (the key the requirer uses) and by the package it installs.
  • npm v1: requires, with npm: aliases resolved.

The table gets a REQUIRED BY column: (direct), or up to three names and "+N more". --format json adds required_by. The availability request now carries only package and version; before, it also sent dev.

Real run

getaways-agents, a fresh server built from this branch, a Packagist proxy (72 h minimum age, a block rule on doctrine/cache) behind a group:

$ oa check php --lockfile composer.lock
132 dependencies: 0 available, 1 held, 0 not found, 131 unknown.

$ oa check php --lockfile composer.lock --fetch
Fetched the metadata of 132 packages through php (1 did not answer 200).

STATUS  PACKAGE         VERSION  FROM       REQUIRED BY    REASON
held    doctrine/cache  2.2.0    packagist  doctrine/dbal  blocked by repository curation: abandoned on Packagist, no replacement

132 dependencies: 131 available, 1 held, 0 not found, 0 unknown.

The run took 2.8 s; exit status 1. The one non-200 was doctrine/cache (404, every version curated).

Also: upgrade notes

The note from #480 had landed under 0.24.0, but #480 merged after the release and isn't in it (the released upgrading.md doesn't contain it). This PR adds an Unreleased section and moves that note there, next to this PR's note.

Tests

  • pkg/lockfile:

    • the fixtures now carry dependency maps, and the expected RequiredBy covers a shared dependency, a dev dependency, an npm peer, an npm alias (folder vs. package name) and v1 aliases;
    • the fuzz invariant adds: requirers sorted, unique and never the package itself.

    Each fuzzer ran 15 s.

  • oa check against a fake server:

    • TestCheckRequiredBy: the column, (direct), the JSON field, and a request body without required_by or dev;
    • TestCheckFetch: a GET per distinct package before the check, the failure count, no GET without --fetch, and npm scoped paths.

Checks

  • golangci-lint run ./... passes.
  • go test -short -race passes for internal/oacli, pkg/lockfile and tests/.
  • make docs-check (CLI reference regenerated) and make deadcode pass.

🤖 Generated with Claude Code

…ndency in

On a fresh proxy every answer is unknown until the package manager has
fetched each package once. --fetch requests each distinct package's
metadata through the repository first (composer p2 documents, npm
packuments), at most 8 at a time, so the proxies behind it, also
through a group, fetch and cache it; a request that does not answer 200
is counted and reported, not fatal.

The lockfile parsers record which locked packages require each
dependency (composer "require", npm dependencies/optional/peer of the
packages map with aliases resolved, lockfileVersion 1 "requires"). The
table gets a REQUIRED BY column ((direct) when only the project requires
it) and --format json a required_by list. The availability request now
carries only package and version.

The upgrade notes get a new Unreleased section: the openartifact#480 note had landed
under 0.24.0, which it is not part of.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@M0Rf30 M0Rf30 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the full diff; CI is green and it merges cleanly. Nothing blocking, a few things worth fixing:

  1. (direct) claims more than it knows. It means "no locked package requires it": neither composer.json nor the root package.json dependencies are read. A package the project requires directly that another locked package also requires never shows (direct) (the fixture has this: acme/console → RequiredBy: [acme/test-runner]). Either reword the docs/help ("(direct) when the project requires it") or note the column can be incomplete.
  2. Orphaned doc comment in pkg/lockfile/npm.go: the old // npmV1 walks the dependency tree… lines now sit above npmV1Requirers, merged into its comment, and npmV1 has no doc comment.
  3. Composer dev-* versions: --fetch only requests p2/<name>.json, never p2/<name>~dev.json, so a locked dev-main package stays unknown after warming.
  4. Test nits (cmd_check_test.go):
    • TestCheckRequiredBy: strings.Contains(body, "dev") fails on any package name containing "dev"; decode the body and check its keys instead.
    • TestCheckFetch: the srv2 := newCheckServer(...) block got split one argument per line by the formatter; plain statements would read better.

…v documents

- REQUIRED BY shows "-" when no locked package requires a dependency. A
  lockfile does not record the project's own requirements, so "(direct)"
  claimed more than it knows; the help and docs say a dependency listed
  with requirers may be direct as well.
- --fetch requests p2/<name>~dev.json for a locked Composer branch
  (dev-main, 1.x-dev), the document that lists it, so it no longer stays
  unknown after warming.
- npmV1 has its doc comment back; it had merged into npmV1Requirers'.
- Tests: the request body is decoded and its keys checked instead of a
  substring match, the REQUIRED BY cell is read by column, and
  metadataPath has its own table test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@M0Rf30
M0Rf30 merged commit a9bd052 into openartifact:main Nov 13, 2026
23 checks passed
@orcamedia

Copy link
Copy Markdown
Contributor Author

Thanks for the review, all addressed in feac33c:

  • (direct) is now - ("no locked package requires it"); the help, ci.md and upgrading note say a dependency listed with requirers may also be required directly, since the lockfile doesn't record the project's own requirements.
  • --fetch requests p2/<name>~dev.json for a locked branch (dev-main, 1.x-dev), using pkg/composer.IsDev like the proxy.
  • npmV1 has its own doc comment again.
  • Tests: the request body is decoded and its keys checked; the REQUIRED BY cell is read by column; the split srv2 block is plain statements, and the path cases moved to a table test TestMetadataPath.

@orcamedia
orcamedia deleted the feat/oa-check-fetch-required-by branch November 13, 2026 22:24
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.

2 participants