Skip to content

feat(check): support checking a whole OCI layout - #2372

Merged
TerryHowe merged 3 commits into
oras-project:mainfrom
lyn1dev:feat/check-whole-layout
Nov 28, 2026
Merged

TerryHowe merged 3 commits into
oras-project:mainfrom
lyn1dev:feat/check-whole-layout

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Adds whole OCI image layout checking to oras check when invoked on a layout directory or tar archive without a tag or digest reference:

  • oras check --oci-layout <path>
  • oras check --oci-layout-path <path>

This is the first of two separate PRs for #2360 (whole OCI layout checking; --include-referrers is left for a follow-up PR).

Summary of changes

  • CLI dispatch (cmd/oras/root/check.go, cmd/oras/internal/argument/checker.go):
    • Added argument.AtMost(1) so --oci-layout-path <path> accepts zero positional arguments while still rejecting extra arguments.
    • Dispatched bare layout paths without a tag or digest (--oci-layout <path> or --oci-layout-path <path>) to whole-layout checking, while keeping trailing empty references (--oci-layout <path>:) and tagless registry references returning "no tag or digest specified".
    • Rejected --platform when checking a whole layout.
  • Directory layout verification:
    • Runs oci.Verify on the layout directory to validate oci-layout, index.json, every blob in blobs/, interrupted-write leftovers, stray files / unsupported algorithms, and reachability.
    • Seeds an oras.VerifiedSet with each verified blob's digest and actual on-disk size, then runs oras.VerifyGraph over all manifests listed in index.json so manifest shapes, descriptor sizes, and cross-manifest references are validated without re-reading intact leaf blobs.
    • Reports missing blobs from the graph walk (keeping absent foreign layers as Not checked and absent subjects not listed in index.json as Warning, while failing when a missing manifest is listed in index.json), deduplicates findings across oci.Verify and graph walks, and reports leftovers and unreferenced blobs as informational Note: lines.
  • Tar archive verification:
    • Opens tar layouts via oci.NewStorageFromTar, walks all manifests in index.json with a shared oras.VerifiedSet, and prints Not checked: unreferenced blobs and stray files are not checked in a tar archive.
  • Tests:
    • Added unit tests in cmd/oras/root/check_test.go and cmd/oras/internal/argument/checker_test.go covering directory and tar layouts, wrong descriptor sizes, mistyped manifests, corrupt/missing index.json and oci-layout, ingest/ leftovers, absent foreign layers, corrupt/missing referrers vs. absent subjects, unreferenced blobs, stray/unsupported blob files, VerifiedSet read-skipping, cancellation, and CLI flags.
    • Updated test/e2e/suite/command/check.go for tagless registry checks and added whole-layout and oras backup directory/tar E2E cases.

Verification

  • go test -race ./cmd/oras/internal/argument ./cmd/oras/root passed.
  • go test -c ./suite/command and go vet ./... in test/e2e succeeded.
  • golangci-lint run --new-from-rev=HEAD reported 0 issues on the modified packages.

Which issue(s) this PR fixes:

Part of #2360

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test? Yes
  • Does this need to be documented in ORAS website? Yes (once oras check leaves experimental or alongside command reference updates)
  • Does this change require a release note? Yes

Allow oras check to verify an entire OCI image layout directory or tar archive when invoked without a tag or digest reference via --oci-layout or --oci-layout-path.

Signed-off-by: lyn1dev <[email protected]>
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Apply review suggestions: unreferenced blobs no longer inflate the
"Checked N nodes" count, so directory and tar layouts report the same
number, and a single layout problem is reported as "1 layout problem".

Signed-off-by: Terry Howe <[email protected]>
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.46965% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.53%. Comparing base (6370c7e) to head (44c7c46).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/root/check.go 81.29% 36 Missing and 22 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2372      +/-   ##
==========================================
- Coverage   90.71%   90.53%   -0.18%     
==========================================
  Files         157      158       +1     
  Lines        6967     7473     +506     
==========================================
+ Hits         6320     6766     +446     
- Misses        376      416      +40     
- Partials      271      291      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe
TerryHowe merged commit ecd186b into oras-project:main Nov 28, 2026
10 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.

2 participants