Skip to content

Conversation

wangxiaoxuan273
Copy link
Contributor

@wangxiaoxuan273 wangxiaoxuan273 commented Mar 10, 2025

What this PR does / why we need it:

This Pull Request:

  1. adds the information for the subject manifest to the output of oras discover when using the --format json option.
  2. changes the output field name of manifests to referrers.

Current display:

$ oras discover mcr.microsoft.com/oss/kubernetes/kubectl:v1.29.1 --format json
{
  "reference": "mcr.microsoft.com/oss/kubernetes/kubectl@sha256:bece4f4746a39cb39e38451c70fa5a1e5ea4fa20d4cca40136b51d9557918b01",
  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
  "digest": "sha256:bece4f4746a39cb39e38451c70fa5a1e5ea4fa20d4cca40136b51d9557918b01",
  "size": 1788,
  "referrers": [
    {
      "reference": "mcr.microsoft.com/oss/kubernetes/kubectl@sha256:325129be79f416fe11a9ec44233cfa57f5d89434e6d37170f97e48f7904983e3",
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "digest": "sha256:325129be79f416fe11a9ec44233cfa57f5d89434e6d37170f97e48f7904983e3",
      "size": 788,
      "annotations": {
        "org.opencontainers.image.created": "2024-03-15T22:49:10Z",
        "vnd.microsoft.artifact.lifecycle.end-of-life.date": "2024-03-15"
      },
      "artifactType": "application/vnd.microsoft.artifact.lifecycle"
    },
.....

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #1403

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Xiaoxuan Wang added 6 commits March 10, 2025 11:17
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.53%. Comparing base (a3f3230) to head (1f10d83).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1649   +/-   ##
=======================================
  Coverage   84.52%   84.53%           
=======================================
  Files         126      126           
  Lines        5681     5682    +1     
=======================================
+ Hits         4802     4803    +1     
  Misses        625      625           
  Partials      254      254           

☔ View full report in Codecov by Sentry.
📢 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.

Xiaoxuan Wang added 3 commits March 10, 2025 15:50
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
@Wwwsylvia Wwwsylvia requested a review from Copilot March 10, 2025 08:44
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR updates the output of the oras discover command when using JSON and go-template formats by including a dedicated subject field and renaming the existing manifests field to referrers. The changes affect tests, command help text, metadata models, and related helper functions to support the new structure.

  • Updated test expectations to unmarshal into a new structure with Subject and Referrers.
  • Modified CLI examples and internal model functions to align with the new JSON format.
  • Adjusted multiple e2e tests to validate the updated discover output across different outputs (json, tree, table, etc).

Reviewed Changes

File Description
test/e2e/suite/command/discover.go Replaced references to "manifests" with a new "discover" struct containing Subject and Referrers.
test/e2e/internal/testdata/foobar/const.go Added new descriptor constants (FooBar, FooBarOCI) for subject manifest support.
cmd/oras/root/discover.go Updated CLI help examples to use the new referrers field in go-template output.
cmd/oras/internal/display/metadata/model/discover.go Changed model structure and NewDiscover signature to include subject and referrers instead of manifests.
test/e2e/suite/command/resolve_host.go, cp.go, attach.go, oci_artifact.go Adjusted tests to reference the new referrers field consistently across JSON and go-template outputs.
cmd/oras/internal/display/metadata/template/discover.go and json/discover.go Updated construction of discover models to pass subject information appropriately.

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

test/e2e/suite/command/discover.go:110

  • [nitpick] The struct name 'discover' is very generic and is repeatedly defined across multiple test files. Consider renaming it or extracting it into a common helper to improve maintainability.
type discover struct {

test/e2e/suite/command/discover.go:131

  • [nitpick] While JSON output tests validate the subject field, consider adding tests for non-JSON outputs (e.g., tree and table) to ensure that the subject information is consistently conveyed.
It("should include information of subject and referrers manifests", func() {

@shizhMSFT shizhMSFT changed the title feat: oras discover json format should include the subject manifest feat!: oras discover json format should include the subject manifest Mar 10, 2025
@shizhMSFT shizhMSFT requested a review from FeynmanZhou March 10, 2025 14:16
Xiaoxuan Wang added 2 commits March 12, 2025 11:00
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
@wangxiaoxuan273 wangxiaoxuan273 force-pushed the discover-json-show-image branch from aad8926 to 2c6676b Compare March 12, 2025 05:35
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Copy link
Contributor

@Copilot Copilot AI left a comment

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 updates the output of the oras discover command to include the subject manifest and renames the output field from "manifests" to "referrers" when using the JSON format. Key changes include:

  • Updating tests and examples to expect a subject descriptor and referrers field.
  • Changing the underlying model and template implementations to replace "manifests" with "referrers".
  • Adjusting go-template examples and related E2E tests to reflect the renamed field.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/e2e/suite/command/discover.go Updated JSON parsing in tests to check "referrers" instead of "manifests" and include subject validation.
test/e2e/internal/testdata/foobar/const.go Added new descriptor constants for subject manifests.
cmd/oras/root/discover.go Updated go-template example to output "referrers".
cmd/oras/internal/display/metadata/model/discover.go Updated model to accept a subject and referrers, and renamed JSON key.
test/e2e/suite/command/cp.go Updated tests to verify output based on "referrers" field.
test/e2e/suite/command/resolve_host.go Updated tests to check the new JSON field "referrers".
test/e2e/suite/command/attach.go Adjusted attachment tests to output and verify using "referrers".
test/e2e/suite/scenario/oci_artifact.go Updated artifact tests to use "referrers" in go-template output.
cmd/oras/internal/display/metadata/json/discover.go Updated JSON discover handler to pass the subject manifest.
cmd/oras/internal/display/metadata/template/discover.go Updated template discover handler accordingly.
Comments suppressed due to low confidence (1)

test/e2e/suite/command/discover.go:110

  • [nitpick] Consider extracting the repeated inline 'discover' struct definition into a shared test helper to improve maintainability and consistency across tests.
type discover struct {

Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@TerryHowe TerryHowe left a comment

Choose a reason for hiding this comment

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

/lgtm

@wangxiaoxuan273
Copy link
Contributor Author

Spec related: #1625

@shizhMSFT shizhMSFT changed the title feat!: oras discover json format should include the subject manifest feat!: refine oras discover JSON format Mar 14, 2025
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM but this PR depends on #1625

@FeynmanZhou
Copy link
Member

FeynmanZhou commented Mar 14, 2025

@shizhMSFT @wangxiaoxuan273 @oras-project/oras-cli You can review this PR now #1625

Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@Wwwsylvia Wwwsylvia merged commit eccaaa9 into oras-project:main Mar 25, 2025
8 checks passed
@wangxiaoxuan273 wangxiaoxuan273 deleted the discover-json-show-image branch August 25, 2025 02:58
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.

5 participants