Add cve-validate CLI#14
Open
jgamblin wants to merge 3 commits into
Open
Conversation
Adds a `cve-validate` bin for validating CVE Records and CNA Containers from the shell or a CI pipeline, wrapping the existing Validate API. - src/cli.ts: parse args, read one or more JSON files (or stdin via `-` / a pipe), validate as record (default) or published-cna / rejected-cna via --type, and print human-readable or --json output. Exit 0 (all valid), 1 (any invalid or unreadable), 2 (usage error). Supports --help/--version. - package.json: add the `bin`, build src/cli.ts alongside src/index.ts, add a `test:cli` script. - scripts/test-cli.mjs: spawn the built CLI and assert output + exit codes across valid/invalid/mixed inputs, --json, stdin, --quiet, --type, --help, --version, unknown option, bad type, missing file, and malformed JSON. - README: document the CLI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Surface registered warnings in default human output (previously only in --json): print each warning under its result and include a count in the summary; document it in the README. - ASCII fallback for the status glyphs on non-UTF-8 (legacy Windows) consoles. - Guard the entrypoint with a top-level catch so any unexpected failure (e.g. an unreadable manifest in --version) exits with a code instead of an unhandled rejection. - Tests: lock stdout/stderr separation (empty stderr on success/--json, empty stdout on usage errors), assert warnings are populated (length + messageId) in both JSON and human output, make --version non-vacuous, and cover short flags, --type= form, rejected-cna, the '--' separator, detail lines, and a packaging guard that src/ and dist/ stay in the published files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Round-2 review found a high-severity defect: the entrypoint called process.exit(code) as soon as run() resolved, terminating before async stdout writes to a pipe had drained. Large output (e.g. --json over many files) was truncated at the ~64KB OS pipe buffer, making piped JSON unparseable and silently dropping validation results. - Set process.exitCode instead of calling process.exit(), so the event loop drains stdout before exiting (both the .then and .catch branches). - Add a slow-pipe regression test that produces >64KB of output, consumes it with backpressure, and asserts the full payload parses (proven to fail on the old process.exit path). - Count only warnings that are actually printed toward the summary, so the --quiet count matches visible output. - Make the quiet assertion match the per-file marker directly instead of a fragile /valid$/m that also matches "invalid". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Adds a
cve-validatecommand so CVE Records and CNA Containers can be validated from the shell or a CI pipeline, without writing a script against the library API. This is one of the more commonly requested additions. It wraps the existingValidateAPI — no validation logic changes.Usage
--type record|published-cna|rejected-cna(defaultrecord)--json,-q/--quiet,-h/--help,-v/--version, and--end-of-options✓/✗/⚠on UTF-8 terminals and falls back toPASS/FAIL/WARNotherwise--json … | jqis cleanChanges
src/cli.ts— the CLI (arg parsing, file/stdin input, dispatch to the threeValidatemethods, human/JSON output).package.json—bin: cve-validate → dist/cli.js, buildsrc/cli.tsalongsidesrc/index.ts, add atest:cliscript.scripts/test-cli.mjs— spawn-based tests covering valid/invalid/mixed inputs,--json, stdin (-and piped),--quiet, all three--typevalues and the--type=form,--help/--version(asserting the real package version), short flags,--, unknown option, bad--type, missing file, malformed JSON, a packaging guard (assertssrc//dist/stay infilesand thebinpath), and a slow-pipe truncation regression test.README.md— CLI section.Notes
process.exitCoderather than callingprocess.exit(), so buffered stdout drains before exit — otherwise large--jsonoutput is truncated at the OS pipe buffer when piped to another process. The regression test reproduces this with a backpressured slow reader.binresolves its schema/registry JSON assets fromsrc/at runtime, sosrc/must remain in the packagefilesallowlist (it is today; a test guards this).package.json/README edits in distinct regions, so all three merge in any order.nullrecord input currently surfaces a rawTypeErrorstring rather than a cleanFAILED_JSON_SCHEMA_VALIDATION; the root cause is the input guard insrc/core/validate.ts, best fixed there separately.🤖 Generated with Claude Code