Skip to content

fix(cli): download the original screenshot files - #418

Closed
gregberge wants to merge 1 commit into
mainfrom
fix/cli-download-original-files
Closed

gregberge wants to merge 1 commit into
mainfrom
fix/cli-download-original-files

Conversation

@gregberge

Copy link
Copy Markdown
Member

Description

argos build download and argos baseline download could write a JPEG under a .png name.

Argos serves screenshots under 100 megapixels through ImageKit at files.argos-ci.com/<key>. ImageKit picks the format of each response itself (vary: Accept), and for some small PNGs it returns a JPEG, even when the request sends Accept: image/png. The commands wrote those bytes under the snapshot's name, so the file's type no longer matched its extension, and the pixels were lossy instead of the uploaded PNG. That breaks exporting a build or comparing its files with other screenshots.

Reproduce

On main, after argos login:

node packages/cli/dist/index.mjs build download 45160 --project argos-ci/argos-javascript --json -o out
file out/chromium/locator-handler.png
# JPEG image data, baseline, precision 8, 100x100, components 3

The API reports contentType: image/png for that snapshot. Its URL serves a JPEG, and tr=orig-true gets the original back:

curl -sI https://files.argos-ci.com/30ae3497c7825b91b86abf33d213a46b2767f16af868d8f11c131114a7fa0f0c | grep -i -e content-type -e x-server
# content-type: image/jpeg
# x-server: ImageKit.io
curl -sI "https://files.argos-ci.com/30ae3497c7825b91b86abf33d213a46b2767f16af868d8f11c131114a7fa0f0c?tr=orig-true" | grep -i content-type
# content-type: image/png

In that build, 3 of the 38 PNGs came down as JPEGs. With this change, all 38 are PNGs, and every one of the 43 files hashes (SHA-256) to its upload key, so the bytes on disk are exactly what was uploaded.

Fix

Before fetching a file, getOriginalFileUrl adds tr=orig-true to files.argos-ci.com URLs with URL.searchParams, which keeps any other query parameters. The backend's own scripts/import-build.ts uses the same parameter to fetch originals. Other URLs are fetched as they are: larger images and text snapshots (ARIA YAML) come as presigned S3 URLs, which already serve the original. Adding a parameter to them fails with 403 SignatureDoesNotMatch (checked). The JSON output still lists each snapshot's url as the API gave it. Errors show the URL that was actually fetched.

I didn't add a check that the response's content type matches the snapshot's contentType. That field is whatever the uploader declared: argos upload declares a .jpg as image/jpeg but uploads PNG bytes (core converts every image to PNG), and S3 serves text snapshots as text/plain. So the check couldn't prove the bytes are original, and it could reject valid files.

Should the API return original URLs?

Yes, I think so. Snapshot.url in the REST API is the ImageKit URL that the web app uses, where format conversion saves bandwidth. API clients don't benefit from conversion, and they expect the bytes behind url to match contentType. Building it in serializeSnapshot (apps/backend/src/api/schema/primitives/snapshot-diff.ts in argos-ci/argos) with tr=orig-true would fix this for every client, not only the CLI. This change is still worth keeping after that: searchParams.set leaves such a URL unchanged, and older API deployments stay covered.

Type of changes

bug

Checklist

Optional checks:

  • My changes requires a change to the documentation
  • I have updated the documentation accordingly

🤖 Generated with Claude Code

Argos serves most screenshots through ImageKit (files.argos-ci.com), which
picks the format of each response itself: a small PNG can come back as a
JPEG. `argos build download` and `argos baseline download` wrote those bytes
under the snapshot's `.png` name, so the file's type did not match its
extension and its pixels were lossy.

Ask ImageKit for the original with `tr=orig-true`. Presigned S3 URLs (large
images, text snapshots) already serve the original, and an added parameter
would break their signature, so they are fetched as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gregberge

Copy link
Copy Markdown
Member Author

Closing in favor of argos-ci/argos#2774: the API now returns the original file URLs (tr=orig-true), so the CLI doesn't need to rewrite them.

@gregberge gregberge closed this Nov 12, 2026
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.

1 participant