Skip to content

CLI compat (phase C): default PNG + always persist reg.json#585

Merged
bokuweb merged 1 commit intootelfrom
cli-compat-phase-c
Apr 18, 2026
Merged

CLI compat (phase C): default PNG + always persist reg.json#585
bokuweb merged 1 commit intootelfrom
cli-compat-phase-c

Conversation

@bokuweb
Copy link
Copy Markdown
Member

@bokuweb bokuweb commented Apr 18, 2026

Stacks on #584 (phase B). Closes the last first-class compat gap with classic reg-cli.

What changes for users

1. Default diffFormat is now png

  • Before: Wasm defaulted to WebP. diffItems in the JSON contained *.webp entries 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.
  • After: cli.ts and compare() default --diffFormat to png when the caller hasn't specified it. Opt-in WebP is still available via --diffFormat webp or { diffFormat: 'webp' }.

2. reg.json is always written

  • Before: the Wasm side returned the JSON report as a string through the Worker complete message, but nobody wrote it to disk. CIs that read ./reg.json after running reg-cli saw nothing.
  • After: cli.ts and compare() both writeFile(jsonPath, ...) immediately before emitting the external complete. Default path is ./reg.json (classic default). Write failures fire 'error' instead of 'complete'.

Implementation notes

  • Extracted writeRegJson() in js/index.ts, exported so cli.ts reuses the exact same persistence path.
  • Removed the "return inner emitter unchanged" fast-path in compare() — writing reg.json is now unconditional. Cheap (~KB JSON).

Test plan

  • CLI default: diff dir contains *.png, reg.json exists, diffItems in JSON references *.png.
  • CLI explicit --diffFormat webp: diff dir contains *.webp, JSON references *.webp.
  • Library compare({ ... }) with no json: ./reg.json written under cwd.
  • Library compare({ json: 'bench/foo/out.json' }): written to bench/foo/out.json, parent dir created if missing.
  • Writing to an unwritable path fires 'error', not 'complete'.

Still not in scope

  • -F / --from (JSON → HTML without running diff) — limited blast radius
  • -X / --additionalDetection — report-UI-only setting

Either can land in a follow-up without blocking migration.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

@bokuweb bokuweb force-pushed the cli-compat-phase-b branch from 1babac7 to 9fda0c7 Compare April 18, 2026 12:44
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>
@bokuweb bokuweb force-pushed the cli-compat-phase-c branch from 4950db4 to 378a755 Compare April 18, 2026 12:44
Base automatically changed from cli-compat-phase-b to otel April 18, 2026 12:45
@bokuweb bokuweb merged commit d0682b6 into otel Apr 18, 2026
2 checks passed
@bokuweb bokuweb deleted the cli-compat-phase-c branch April 18, 2026 12:45
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