Skip to content

Populate Version#integrity for maven via .jar.sha1 sidecar - #1670

Merged
andrew merged 3 commits into
ecosyste-ms:mainfrom
Marc-cn:maven-version-integrity
Jun 9, 2026
Merged

Populate Version#integrity for maven via .jar.sha1 sidecar#1670
andrew merged 3 commits into
ecosyste-ms:mainfrom
Marc-cn:maven-version-integrity

Conversation

@Marc-cn

@Marc-cn Marc-cn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Maven Central publishes a .sha1 sidecar next to each artifact; fetch
-.jar.sha1 and map it to integrity as sha1-.
Returns nil for pom-only artifacts (no jar). Refs #1630.

Verified: stored integrity for dev.zio:zio-aws-autoscaling_3 5.17.225.2
matches an independent sha1 of the downloaded .jar (16d2a89f...); a full
sync populated 507/507 versions of that package.

Maven Central publishes a .sha1 sidecar next to each artifact; fetch
<artifact>-<version>.jar.sha1 and map it to integrity as sha1-<hex>.
Returns nil for pom-only artifacts (no jar). Refs ecosyste-ms#1630.

Verified: stored integrity for dev.zio:zio-aws-autoscaling_3 5.17.225.2
matches an independent sha1 of the downloaded .jar (16d2a89f...); a full
sync populated 507/507 versions of that package.
@andrew

andrew commented Jun 8, 2026

Copy link
Copy Markdown
Member

A couple of issues to flag before this can go in:

1. Tests are broken. Five existing maven tests now error with WebMock::NetConnectNotAllowedError because version_integrity makes an unstubbed .jar.sha1 request. Running bundle exec rails test test/models/ecosystem/maven_test.rb locally produces 5 errors. Each affected test needs a stub for its .jar.sha1 URL, e.g.:

stub_request(:get, "https://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.11.0/maven-compiler-plugin-3.11.0.jar.sha1")
  .to_return(status: 200, body: "abc123...")

CI didn't run on this PR (fork from first-time contributor needs approval), which is why this wasn't caught.

2. No positive test for the new code. version_integrity adds real parsing logic (regex match, downcase, prefix) and there's no test exercising it. Worth adding one test that stubs a .jar.sha1 with a known SHA1 and asserts integrity == "sha1-<hex>", plus one for the pom-only / 404 case returning nil.

3. Same rescue concern as #1669 — broad rescue StandardError should narrow to Faraday::Error. See the comment on that PR.

Marc-cn added 2 commits June 8, 2026 14:24
Per review on ecosyste-ms#1669:  The .jar.sha1
fetch only does a network request (no JSON parse), so catch Faraday::Error, matching maven.rb:165 / :559.
Per review (ecosyste-ms#1670):
- setup stubs .jar.sha1 with a 404 default so the existing versions_metadata
  tests no longer error on the new request
- add a positive test (known sha1 -> sha1-<hex>) and a negative test
  (pom-only / 404 -> nil)
@Marc-cn

Marc-cn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks:

  1. Added a .jar.sha1 stub in setup so the existing tests no longer error on the new request (the 5 NetConnectNotAllowedErrors are gone)
  2. Added two version_integrity tests: a positive case asserting sha1-<hex> from a stubbed sidecar, and a pom-only/404 case asserting nil.
  3. pushed before

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

Thanks for the follow-ups. Setup stub catches the previously-failing requests (43 runs, 0 errors locally), and the two new version_integrity tests exercise both the happy path and the 404 case. LGTM.

@andrew
andrew merged commit 16fffde into ecosyste-ms:main Jun 9, 2026
2 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