Skip to content

fix(h5p-verify): exit once the report is written (#117) - #119

Merged
alekswebnet merged 1 commit into
mainfrom
fix/verify-json-pipe
Nov 3, 2026
Merged

alekswebnet merged 1 commit into
mainfrom
fix/verify-json-pipe

Conversation

@alekswebnet

@alekswebnet alekswebnet commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #117.

What

bin/h5p-verify.mjs printed the report with console.log and called process.exit straight after. On macOS Node writes to a pipe asynchronously, and process.exit drops whatever is still waiting. So a program reading --json through a pipe got the first 8,192 bytes, and the JSON did not parse. The command now writes the report, or the summary, and exits from the write's callback, with the same exit code as before. It also exits if the reader has gone away, as head does.

Checked

  • New test in verify.test.ts: it runs the command through execFile, as a program would, on a quiz with 300 fields the semantics do not name. Played untrusted, each removed field is reported, so the report runs to tens of kilobytes. The test checks that stdout is over 16 kB and parses to the same report as report.json. Without the fix it fails on macOS with "expected 8192 to be greater than 16384". CI's Linux runners may not catch a regression, since a Linux pipe takes 64 kB at once.
  • A reader that stops early: a 23 kB report piped into head -c 100 exits 0 with nothing on stderr.
  • The verifier's typecheck and suite pass: 27 tests.
  • The other commands:
    • h5p-author sets process.exitCode and does not call process.exit after printing, so it is not affected.
    • h5p-embed prints a few short lines.
    • h5p-normalize has the same pattern: process.exit after its summary. But it writes each entry's line while it works, so only the short summary comes just before the exit. A dry run of boardgame.h5p, 16,167 bytes of output, arrived whole through execFile in 3 runs of 3. It is left as it is.

🤖 Generated with Claude Code

The command printed the report and called process.exit straight after.
Node writes to a pipe asynchronously on macOS, and process.exit drops
what is still waiting, so a program reading --json through a pipe got
the first 8,192 bytes and JSON that did not parse. It now exits from the
write's callback, or when the reader has gone away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alekswebnet
alekswebnet merged commit 07b96d6 into main Nov 3, 2026
8 checks passed
@alekswebnet
alekswebnet deleted the fix/verify-json-pipe branch November 3, 2026 11:11
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.

h5p-verify --json is cut off at 8 kB when a program reads it through a pipe

1 participant