Skip to content

test: add CLI test coverage (39 tests)#28

Merged
robotlearning123 merged 4 commits intomainfrom
feat/cli-test-coverage
Mar 2, 2026
Merged

test: add CLI test coverage (39 tests)#28
robotlearning123 merged 4 commits intomainfrom
feat/cli-test-coverage

Conversation

@robotlearning123
Copy link
Member

Summary

  • Refactored cli.ts to export program and guard parseAsync() with isMain check (+3 lines) for testability
  • Added src/__tests__/cli.test.ts with 39 BDD-style tests covering all 11 CLI commands
  • Total test suite: 216 → 255 tests, all passing

Coverage

  • All 11 commands: submit, batch, list, status, cancel, retry, diff, logs, stats, workers, search
  • Global flags: --json (parameterized across 6 commands), --url
  • Error handling: HTTP 404/500, network errors (ECONNREFUSED)
  • API behavior: Content-Type headers, request body construction, URL query params, output formatting

Approach

Mock globalThis.fetch to verify HTTP method + URL + body for each command. Capture console.log to verify output formatting (table vs JSON). No subprocess spawning needed.

Test plan

  • npx tsc --noEmit — zero errors
  • node --import tsx --test src/__tests__/cli.test.ts — 39/39 pass
  • Full suite src/__tests__/*.test.ts — 255/255 pass
  • Pre-commit hooks pass on both commits

🤖 Generated with Claude Code

Test and others added 2 commits March 1, 2026 22:59
Add isMain check so importing cli.ts for testing doesn't trigger
automatic argument parsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Mock globalThis.fetch to verify HTTP method, URL, request body,
query params, output formatting, --json flag, --url flag, and
error handling for every CLI command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@robotlearning123
Copy link
Member Author

Code review

Found 1 issue:

  1. CLAUDE.md not updated to reflect the new test suite. The "Build, Test & Run" section says "217 tests across 5 suites" and the "Test Files" section lists exactly 5 files. This PR adds a 6th suite (cli.test.ts) with 39 tests (255 total across 6 suites) but does not update either section. Per CLAUDE.md: "CLAUDE.md is the agent's single source of truth, enforced mechanically."

cc-manager/CLAUDE.md

Lines 30 to 35 in 7e9222c

```bash
# Run tests (217 tests across 5 suites)
node --import tsx --test src/__tests__/*.test.ts
```

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

255 tests across 6 suites.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@robotlearning123
Copy link
Member Author

Code review

No issues found. Previous issue (CLAUDE.md test count/file listing) has been fixed in ab8e9e5. Re-checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

process.argv[1] won't match import.meta.url when CLI is invoked
through an npm symlink (npm link / npm install -g). Normalize
both paths with realpathSync to fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@robotlearning123 robotlearning123 merged commit 6017a24 into main Mar 2, 2026
2 checks passed
@robotlearning123 robotlearning123 deleted the feat/cli-test-coverage branch March 2, 2026 04:22
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