Skip to content

Feat: Exit Codes - #18

Merged
JosephMaynard merged 9 commits into
masterfrom
feat/exit-codes
Mar 1, 2026
Merged

JosephMaynard merged 9 commits into
masterfrom
feat/exit-codes

Conversation

@JosephMaynard

@JosephMaynard JosephMaynard commented Mar 1, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added a --fail-on policy option (selectable rules) to fail scans on policy violations and a --no-report flag to suppress reports; CLI now exits non-zero when configured violations occur.
  • Documentation

    • README updated with new CLI flags, supported policy rules, example usage, CI failure semantics, and exit-code behavior.
  • Tests

    • Added tests for CLI output/exit behavior and policy rule parsing/evaluation.
  • Style

    • Expanded editor/workspace color customizations for title bar and status bar.

@coderabbitai

coderabbitai Bot commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a CLI policy enforcement feature (--fail-on) with parsing, evaluation, reporting, and exit-on-violation behavior; new failOn module and tests; README updates documenting new flags; new CLI tests; and VS Code workbench color customizations in .vscode/settings.json.

Changes

Cohort / File(s) Summary
Editor config
\.vscode/settings.json
Added VS Code workbench color customizations: inactive title bar colors and expanded status bar color variants.
Documentation
README.md
Documented new CLI flags --no-report and --fail-on, CI failure policy rules and semantics, example usage, and updated "Show options" guidance.
CLI core & tests
src/cli.ts, src/cli.test.ts
Added failOn: Set<FailOnRule> to CliOptions; support for --fail-on parsing/validation and help text; integrated policy evaluation and reporting into run flow; printPolicyViolations and exit(1) on violations; tests for summary output and fail-on behavior.
Policy module & tests
src/failOn.ts, src/failOn.test.ts
New policy module with FailOnRule, PolicyViolation, SUPPORTED_FAIL_ON_RULES, parseFailOnRules(), and evaluatePolicyViolations(); tests for parsing edge cases and evaluation across vulnerability/license scenarios.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as RGBA(52,105,153,0.5)
    participant Eval as RGBA(16,124,75,0.5)
    participant Out as RGBA(153,102,51,0.5)

    User->>CLI: run scan --fail-on <rules>
    CLI->>CLI: parseFailOnRules(<rules>)
    alt invalid or empty rules
        CLI->>Out: print error & help
        Out->>User: exit non-zero
    else valid rules
        CLI->>Eval: evaluatePolicyViolations(aggregatedData, rules)
        Eval->>Eval: compute violation counts
        Eval->>CLI: return PolicyViolation[]
        CLI->>Out: printPolicyViolations(violations)
        alt violations present
            Out->>User: print banner & violations
            Out->>User: exit 1
        else no violations
            Out->>User: continue / exit 0
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through flags and parsed each rule,
I counted licences, vulnerabilities, and tool.
When policies frown and violations show,
I thump a banner and let you know.
Hop on — the CLI now makes it so!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feat: Exit Codes' accurately summarizes the main feature addition—implementing exit code behavior and policy violation handling—which is central to the changes across CLI parsing, failOn module, and documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/exit-codes

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/cli.test.ts (1)

9-65: Good integration test for CLI summary output.

The test validates the summary format and CTA placement using deterministic conditions (--offline, --no-report, NO_COLOR=1). The 30-second timeout is appropriate for spawning a full CLI process.

Consider adding a test case that exercises --fail-on to verify the exit code behavior when policy violations are detected.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cli.test.ts` around lines 9 - 65, Add a new integration test in
src/cli.test.ts that exercises the CLI's --fail-on behavior: use the same
spawnSync pattern (process.execPath, tsNodeBin, cliPath) with arguments
['scan','--project', repoRoot,'--offline','--no-report','--fail-on','<policy>']
(or a policy that will definitely trigger in the repo) and NO_COLOR=1; assert
the process exit code (result.status) is non-zero when a policy violation is
detected and that stdout/stderr contains the policy violation message; keep
setup consistent with the existing test (repoRoot, tsNodeBin, cliPath, env) so
the new test integrates cleanly.
.vscode/settings.json (1)

5-13: Editor theme customizations noted.

These VSCode color settings are unrelated to the exit codes feature. Consider whether personal editor preferences should be committed to the repo, or if they belong in a user-local settings file instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.vscode/settings.json around lines 5 - 13, This commit adds user-specific
VSCode color keys (e.g., "titleBar.activeForeground", "statusBar.background",
"statusBar.noFolderForeground") that are unrelated to the feature; remove these
personal editor settings from the committed JSON and either (a) move them to a
local-only settings file (user settings) or (b) add the workspace .vscode
settings file to your local .gitignore so it isn’t committed, ensuring only
project-relevant editor settings remain in the repo.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.vscode/settings.json:
- Around line 5-13: This commit adds user-specific VSCode color keys (e.g.,
"titleBar.activeForeground", "statusBar.background",
"statusBar.noFolderForeground") that are unrelated to the feature; remove these
personal editor settings from the committed JSON and either (a) move them to a
local-only settings file (user settings) or (b) add the workspace .vscode
settings file to your local .gitignore so it isn’t committed, ensuring only
project-relevant editor settings remain in the repo.

In `@src/cli.test.ts`:
- Around line 9-65: Add a new integration test in src/cli.test.ts that exercises
the CLI's --fail-on behavior: use the same spawnSync pattern (process.execPath,
tsNodeBin, cliPath) with arguments ['scan','--project',
repoRoot,'--offline','--no-report','--fail-on','<policy>'] (or a policy that
will definitely trigger in the repo) and NO_COLOR=1; assert the process exit
code (result.status) is non-zero when a policy violation is detected and that
stdout/stderr contains the policy violation message; keep setup consistent with
the existing test (repoRoot, tsNodeBin, cliPath, env) so the new test integrates
cleanly.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c2f192 and 16bcda3.

📒 Files selected for processing (6)
  • .vscode/settings.json
  • README.md
  • src/cli.test.ts
  • src/cli.ts
  • src/failOn.test.ts
  • src/failOn.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cli.test.ts`:
- Around line 108-109: The test currently asserts a non-zero exit with
expect(result.status).not.toBe(0); which is too lax—change the assertion to
require the specific failure code 1 by replacing that call with
expect(result.status).toBe(1); so the test (in the same test block where result
is produced) validates the exact intended fail-on exit code rather than any
non-zero value.
- Around line 5-6: The inline regex in stripAnsi contains a literal control
character and trips Biome lint; extract the pattern into a top-level RegExp
constant (e.g. ANSI_ESCAPE_REGEX = new RegExp('\\\\x1b\\[[0-9;]*[A-Za-z]', 'g'))
and replace the inline pattern in function stripAnsi to use that constant
(return value.replace(ANSI_ESCAPE_REGEX, '')). This moves the escaped control
sequence into a string literal for the RegExp constructor and fixes the lint
rule while keeping stripAnsi behavior unchanged.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16bcda3 and a889704.

📒 Files selected for processing (1)
  • src/cli.test.ts

Comment thread src/cli.test.ts Outdated
Comment thread src/cli.test.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cli.test.ts`:
- Around line 41-64: The merged output used for assertions includes stderr
noise; keep the combined stripAnsi(`${result.stdout}\n${result.stderr}`) for the
general expectations but for the final-line CTA assertion use only the cleaned
stdout (e.g. stripAnsi(result.stdout).replace(/\r/g, '')) so the
.trim().endsWith(...) check is not affected by stderr; update the assertion that
currently calls expect(output.trim().endsWith(...)).toBe(true) to operate on the
cleaned stdout string instead while leaving all other checks against the
existing combined `output`.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a889704 and c495232.

📒 Files selected for processing (1)
  • src/cli.test.ts

Comment thread src/cli.test.ts
@coderabbitai

coderabbitai Bot commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Note

Docstrings generation - SUCCESS
Generated docstrings and committed to branch feat/exit-codes (commit: e161d24f0964aeeccf531e2d3ab1cd14ac0d9f7f)

Docstrings generation was requested by @JosephMaynard.

The following files were modified:

* `src/cli.ts`
* `src/failOn.ts`

These files were ignored:
* `src/cli.test.ts`
* `src/failOn.test.ts`

These file types are not supported:
* `.vscode/settings.json`
* `README.md`

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/failOn.ts`:
- Line 88: Update the JSDoc for the parameter "value" in src/failOn.ts so the
example uses the correct rule names; replace the incorrect
"production-vulnerabilities,high-severity" with
"production-vuln,high-severity-vuln" in the docstring so it matches the actual
rules (refer to the "value" param in the failOn function/JSDoc).

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a03fd6 and e161d24.

📒 Files selected for processing (2)
  • src/cli.ts
  • src/failOn.ts

Comment thread src/failOn.ts Outdated
/**
* Parse a comma-separated list of fail-on rule names into a validated set.
*
* @param value - Comma-separated rule names (e.g., "production-vulnerabilities,high-severity")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Docstring example uses incorrect rule name.

The example shows "production-vulnerabilities,high-severity" but the actual rule names are production-vuln and high-severity-vuln. This could confuse developers reading the documentation.

📝 Proposed fix
- * `@param` value - Comma-separated rule names (e.g., "production-vulnerabilities,high-severity")
+ * `@param` value - Comma-separated rule names (e.g., "production-vuln,high-severity-vuln")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* @param value - Comma-separated rule names (e.g., "production-vulnerabilities,high-severity")
* `@param` value - Comma-separated rule names (e.g., "production-vuln,high-severity-vuln")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/failOn.ts` at line 88, Update the JSDoc for the parameter "value" in
src/failOn.ts so the example uses the correct rule names; replace the incorrect
"production-vulnerabilities,high-severity" with
"production-vuln,high-severity-vuln" in the docstring so it matches the actual
rules (refer to the "value" param in the failOn function/JSDoc).

@JosephMaynard
JosephMaynard merged commit 71be37b into master Mar 1, 2026
1 check passed
@JosephMaynard
JosephMaynard deleted the feat/exit-codes branch March 1, 2026 22:21
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