CLI compat (phase C): default PNG + always persist reg.json#585
Merged
Conversation
1babac7 to
9fda0c7
Compare
Follow-up to #583 and #584. Closes the last first-class compat gap with classic reg-cli: the JSON/HTML report now references PNG diff images by default and `reg.json` is always written to disk. ## What changes for users ### Default `diffFormat` = `png` Before: Wasm defaulted to WebP, so `failedItems` / `diffItems` in the JSON contained `*.webp` entries and the HTML report loaded WebP images. That's a real behaviour break for downstream consumers of reg-cli's JSON (reg-suit, reg-notify-*, custom bots). After: both `cli.ts` and `compare()` default `--diffFormat` to `png` when the caller hasn't specified it. Users who want WebP can still opt in with `--diffFormat webp` or `{ diffFormat: 'webp' }`. ### `reg.json` is always persisted Before: the Wasm side returned the JSON report as a string through the Worker `complete` message, but nobody wrote it. CIs that read `./reg.json` after running reg-cli saw nothing. After: both `cli.ts` and `compare()` write the report to the `--json` path (defaulting to `./reg.json`) immediately before emitting the external `complete` event. If the write fails, the library emits `'error'` instead of `'complete'`. ## Implementation - `js/cli.ts`: reads `--json` / `-J` (default `./reg.json`), reads `--diffFormat` (default `png`). Pushes the effective values to the Wasm argv and writes `reg.json` itself after complete. - `js/index.ts`: same defaults applied inside `compare()` before building the Wasm argv; `writeRegJson()` extracted and exported so `cli.ts` reuses the exact same persistence code path. - The previous fast-path in `compare()` that returned the inner emitter unchanged when no side effects were needed is gone, since writing `reg.json` is now an unconditional side effect. Cheap — one `writeFile` of ~KB JSON. ## Test plan - [x] CLI: diff images in diff dir are `*.png`, `reg.json` exists, `reg.json` contains `*.png` entries in `diffItems`. - [x] CLI explicit `--diffFormat webp`: diff images are `*.webp`, JSON references `*.webp`. - [x] Library `compare({ ... })` with no `json`: `./reg.json` written, diffItems end in `.png`. - [x] Library `compare({ json: '/path/out.json' })`: written to /path/out.json, parent dir created if missing. - [x] Writing to an unwritable path fires `error`, not `complete`. ## Still not in scope - `-F / --from` (JSON → HTML without running diff) - `-X / --additionalDetection` Both have limited blast radius (few users rely on them) and can land in a follow-up without blocking migration. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4950db4 to
378a755
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacks on #584 (phase B). Closes the last first-class compat gap with classic reg-cli.
What changes for users
1. Default
diffFormatis nowpngdiffItemsin the JSON contained*.webpentries and the HTML report loaded WebP images. Downstream consumers of reg-cli's JSON (reg-suit, reg-notify-*, custom bots) broke when swapping classic → Wasm.cli.tsandcompare()default--diffFormattopngwhen the caller hasn't specified it. Opt-in WebP is still available via--diffFormat webpor{ diffFormat: 'webp' }.2.
reg.jsonis always writtencompletemessage, but nobody wrote it to disk. CIs that read./reg.jsonafter running reg-cli saw nothing.cli.tsandcompare()bothwriteFile(jsonPath, ...)immediately before emitting the externalcomplete. Default path is./reg.json(classic default). Write failures fire'error'instead of'complete'.Implementation notes
writeRegJson()injs/index.ts, exported socli.tsreuses the exact same persistence path.compare()— writingreg.jsonis now unconditional. Cheap (~KB JSON).Test plan
*.png,reg.jsonexists,diffItemsin JSON references*.png.--diffFormat webp: diff dir contains*.webp, JSON references*.webp.compare({ ... })with nojson:./reg.jsonwritten under cwd.compare({ json: 'bench/foo/out.json' }): written tobench/foo/out.json, parent dir created if missing.'error', not'complete'.Still not in scope
-F / --from(JSON → HTML without running diff) — limited blast radius-X / --additionalDetection— report-UI-only settingEither can land in a follow-up without blocking migration.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com