Skip to content

feat(cli): one exit code precedence for audit, outcome in the JSON and LLM reports - #1669

Merged
nc9 merged 6 commits into
mainfrom
feat/exit-code-precedence-1657
Nov 10, 2026
Merged

nc9 merged 6 commits into
mainfrom
feat/exit-code-precedence-1657

Conversation

@nc9

@nc9 nc9 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1657

What

squirrel audit set process.exitCode in 34 places, each overwriting the last. The explicit-publish failure paths returned early, which skipped the failed/blocked code and the --fail-on gate. Now computeExitCode (apps/cli/src/audit/exit-code.ts) is a pure precedence table, process.exitCode is assigned in one place (applyExitCode, reached through exitWith and settle), and the audit command has no assignment left.

The JSON and LLM reports carry the answer: outcome: { exit_code, status, publish: { status, reason? } } in JSON, <outcome exit-code status publish publish-reason/> in LLM. Both are written after publishing, so they can include its result; the other formats are written where they were.

The two changed cases, and the decision for each

  • Explicit --publish fails on a blocked site: exit 3, was 1. The audit's own outcome outranks the publish; a CI job that already treats 3 as "perimeter refused us" keeps that signal. An explicit publish that fails on an otherwise ok audit still exits 1 and still does not evaluate --fail-on, as before.
  • Auto-publish fails: exit 0, unchanged, now visible. Auto-publish is a side effect of a successful audit, and the code already said it must not fail the run. The mismatch (terminal success, dashboard error) is addressed by making it readable: outcome.publish is failed with the error code, and the docs state the choice. If you would rather it exit non-zero, it is one row in the table (computeExitCode) plus its test row. Flagging this as the decision to confirm.

Acceptance criteria

  • Table-driven coverage of every exit path. End to end with the real CLI (apps/cli/tests/cli/audit-exit-codes-1657-e2e.test.ts, 11 rows: ok, failed, blocked, redirected, unreachable, fail-on tripped and not, blocked beats the gate, three validation errors): green on the old code in its own first commit, and green after the refactor (the rows now also assert outcome). partial exiting 0 is pinned by the existing max-duration e2e. The publish rows cannot run end to end, because a publish needs a public host and these fixtures are loopback (a non-public host never publishes), so they are in the unit table apps/cli/tests/audit/exit-code.test.ts (30 tests), with the two changed rows marked.
  • process.exitCode is assigned in one place in the audit command (0 occurrences in commands/audit.ts).
  • JSON and LLM output include the final exit code, audit status and publish status, with a reason when failed or skipped (packages/report/tests/outcome-1657.test.ts).
  • A failed auto-publish is visible in JSON (outcome.publish.status: "failed"); the exit code chosen (0) is documented.
  • An explicit publish failure on a blocked site exits 3, documented.
  • docs/cli/audit.mdx lists the precedence ("Which code wins"); docs/configuration/output.mdx and docs/reports.mdx describe the new fields; make validate passes.

Not covered: the unreachable and redirected start-URL reports (their own status shapes) do not carry outcome; they exit 5 and 4 as before.

Gates: the three new test files plus audit-stdout, waf-followups, offline-truthfulness, start-redirect, include-pages and max-duration e2e by explicit path; tsgo in apps/cli, packages/report, packages/core-contracts; root lint; bun run format:check in apps/cli; make validate.

The squirrelscan agent skill needs no change. This overlaps in CHANGELOG and docs/configuration/output.mdx with the --resume change; whichever lands second needs a one-line merge.

Update: rebased on main after the resume PR, with the review fixes

  • Rebased on main (the resume change is in). The report's schema version is now 1.8 (a separate last commit: meta.resume took 1.7).
  • The report is written and the exit code set exactly once even when a step of the publish phase throws or the run is interrupted (createSettler, in exit-code.ts): a throw settles with a failed explicit publish carrying exception, a signal with interrupted, so a held-back JSON or LLM report is not lost. Unit-tested (the order, no double write, a blocked audit keeps 3, the gate is skipped only for an explicit failure); the signal path itself is not tested.
  • The first-audit funnel's failed check reads through auditStatusToLifecycle instead of a second open-coded copy.

@nc9
nc9 force-pushed the feat/exit-code-precedence-1657 branch from 44d0dc1 to a3ac776 Compare November 10, 2026 05:07
@nc9
nc9 force-pushed the feat/exit-code-precedence-1657 branch from a3ac776 to 0016edc Compare November 10, 2026 09:02
@nc9
nc9 marked this pull request as ready for review November 10, 2026 09:45
@nc9
nc9 merged commit 25f4d00 into main Nov 10, 2026
16 checks passed
@nc9
nc9 deleted the feat/exit-code-precedence-1657 branch November 10, 2026 09: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.

squirrel audit: exit code and outcome come from 34 scattered assignments; one precedence function, outcome in JSON

1 participant