Skip to content

test: cover check-result.mjs - #15

Merged
ZhenghuaBao merged 1 commit into
mainfrom
test/check-result-coverage
Aug 19, 2026
Merged

test: cover check-result.mjs#15
ZhenghuaBao merged 1 commit into
mainfrom
test/check-result-coverage

Conversation

@ZhenghuaBao

Copy link
Copy Markdown
Contributor

scripts/check-result.mjs is the availability gate — action.yml calls it as node "$CHECK" "$1" "$rc" — and it had no tests. A wrong answer here is silent and expensive: converting a bad key, a gateway outage, or a CLI crash into a clean "no issues found" would clear a PR that was never actually reviewed.

19 tests over the four fail-closed paths and the one case that must not be swept up with them.

Fail closed

Engine exit code - checked before the file is read; nonzero, signal-shaped (137, the OOM/timeout kill), and non-numeric codes all fail closed rather than coercing to 0.

Result shape - missing file, unparseable JSON, absent comments key, and non-array comments are all reported as unavailable, never as empty.

Partial review - any warnings entry fails closed and outranks findings: partial coverage means the clean files were never checked, so a result with real findings and warnings is still not trustworthy. An empty or non-array warnings value is correctly ignored.

Must pass

comments: [] with no warnings is a real, complete result and has to exit 0. Otherwise every clean PR would read as broken. This is the case most at risk of being "fixed" into a failure by someone tightening the gate.

Also pinned

stdout stays empty on every path, since the caller captures it. All diagnostics go to stderr.

Note

The rcRaw || "0" default means an empty-string exit code is treated as success. That is not reachable from the current call site (action.yml initializes rc=0 and only overwrites it via || rc=$?, so it is always numeric), so it is left as-is and not pinned by a test.

🤖 Generated with Claude Code

check-result.mjs is the availability gate — action.yml calls it as
`node "$CHECK" "$1" "$rc"` and a wrong answer here is silent and expensive:
converting a bad key, a gateway outage, or a CLI crash into a clean
"no issues found" would clear a PR that was never reviewed. It had no tests.

19 tests over the four fail-closed paths and the one that must NOT fail:

- engine exit code: checked before the file is read; nonzero, signal-shaped
  (137), and non-numeric codes all fail closed rather than coercing to 0.
- result shape: missing file, unparseable JSON, absent `comments` key, and
  non-array `comments` are all "unavailable", never "empty".
- partial review: any `warnings` entry fails closed and outranks findings,
  because partial coverage means the clean files were never checked. An
  empty or non-array `warnings` value is correctly ignored.
- the success path: `comments: []` with no warnings is a REAL complete
  result and must exit 0, or every clean PR reads as broken.

Also pins that stdout stays empty on every path, since the caller captures it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ZhenghuaBao
ZhenghuaBao merged commit e73ffe5 into main Aug 19, 2026
2 checks passed
@ZhenghuaBao
ZhenghuaBao deleted the test/check-result-coverage branch August 19, 2026 03:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 344fc50027

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +144 to +145

test("a non-array warnings value is ignored rather than treated as partial", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject malformed warnings instead of pinning fail-open behavior

When the engine emits a truthy but non-array warnings value—for example after schema drift or malformed output—this assertion requires the availability gate to exit 0, even though it cannot determine whether the review was partial. That contradicts this test suite's fail-closed contract and protects the existing unsafe fallback from correction; the test should require malformed warnings to make the result unavailable.

Useful? React with 👍 / 👎.

Comment on lines +84 to +86
test("an omitted exit code is treated as 0", () => {
const r = run(writeResult(OK));
assert.equal(r.status, 0, r.stderr);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail closed when the required engine exit code is omitted

If a caller is accidentally rewired to omit the second argument, this test requires the gate to treat the missing engine status as success and accept any parseable result file. That masks exactly the kind of caller/engine failure this availability gate is intended to catch, and it contradicts the documented check-result.mjs <result.json> <exit-code> interface; the contract test should make a missing exit code fail rather than pinning the current default-to-zero behavior.

Useful? React with 👍 / 👎.

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