Skip to content

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

Closed

Description

@nc9

process.exitCode is assigned 34 times in apps/cli/src/cli/commands/audit.ts (validation ~1375-1573, redirected 2120, error/unreachable 2972-2989, publish 3358/3389, failed/blocked/fail-on 3587-3624). Each handler overwrites the last, and the explicit-publish failure paths return early, which skips the failed/blocked code and the --fail-on gate.

Reachable today:

  • auto-publish fails: exit 0, while the tracked run is finalized with completionReason: "error" (~3086-3099). Terminal says success, dashboard says error.
  • explicit --publish fails on a WAF-blocked site: exit 1, not 3.

Why: CI gates and coding agents read the exit code and JSON. Today the code depends on code-path order.

Approach: one pure computeExitCode({ auditStatus, publishOutcome, gate, validation }) with a precedence table, called once at the end. A typed PublishOutcome = skipped(reason) | published(id) | failed(code) returned by one publish phase instead of the autoPublishError / publishedReportId locals. --format json and llm output carry outcome: { exit_code, status, publish: { status, reason? } }.

A partial report exiting 0 is documented and intended (docs/cli/audit.mdx); keep it.

Pin the current exit code for every scenario in a table test before refactoring; change only the two cases above, and document the decision for each.

Acceptance Criteria

  • A table-driven test covers every exit path (ok, failed, blocked, redirected, unreachable, fail-on tripped, partial, explicit publish failure, auto-publish failure, validation errors) and was green on the old code before the refactor, except the rows this issue changes
  • process.exitCode is assigned in one place in the audit command
  • JSON and LLM output include the final exit code, audit status and publish status (with reason when failed or skipped)
  • A failed auto-publish is visible in JSON output; the exit code chosen for it is documented
  • An explicit publish failure on a blocked site exits with the documented code for that case
  • docs/cli/audit.mdx "Exit codes" lists the precedence

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1clisize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions