Skip to content

fix(cli): close the @codespar/cli audit (project scoping, masked login, timeouts, ledger/issue, tests) - #74

Merged
fabianocruz merged 1 commit into
mainfrom
feat/cli-audit-fixes
Jun 6, 2026
Merged

fix(cli): close the @codespar/cli audit (project scoping, masked login, timeouts, ledger/issue, tests)#74
fabianocruz merged 1 commit into
mainfrom
feat/cli-audit-fixes

Conversation

@fabianocruz

Copy link
Copy Markdown
Member

Close the @codespar/cli audit

Fixes every finding from the CLI audit, with tests.

🔴 Security

  • login echoed the API key in cleartext. The interactive prompt printed the key to the terminal (scrollback + screen-share leak). Now masked — readline's echo is suppressed on a TTY; piped keys read plainly.

🟠 Correctness / reliability

  • Project scoping was entirely non-functional. config.project / CODESPAR_PROJECT was loaded but never used — the raw ApiClient never sent x-codespar-project, and SDK commands constructed new CodeSpar({apiKey, baseUrl}) with no projectId. Multi-project orgs silently hit the org default. Wired through a single resolveAuth(): ApiClient sends the header, all 7 SDK commands pass projectId, the logs SSE carries the header, and a top-level --project flag is added.
  • ApiClient had no request timeout — a hung server hung the CLI forever. Added a 30s AbortController timeout → clear CliError.
  • Missing ledger + issue commands for the SDK 0.10 meta-tools (shipped this week). Added, mirroring charge/ship, with arg validation and a shared meta-input helper.

🟡 Hygiene / UX

  • Stale User-Agent (codespar-cli/0.1.0 vs package 0.4.0) + VERSION duplicated in two spots → single version.ts source.
  • Non---json double-printcharge/ship/payment-status/verification-status printed a human summary to stderr and dumped the full JSON to stdout, making --json redundant. Dropped the redundant dump (execute/tools keep theirs — that's their actual result / schema output, not a duplicate).

✅ Tests (was: none)

19 unit tests: ApiClient (project header present/absent, timeout, error detail, 204) via a mocked fetch; ledger/issue arg validation; meta-input parsing. Added a test script; tests excluded from the published dist.

Verification

Core CI runs on GitHub-hosted runners, currently billing-blocked (see #73 — pending the self-hosted runner-group grant), so it won't auto-run here. Verified locally with the exact CI gate: turbo run build typecheck test54/54 tasks green, CLI tests 19/19.

🤖 Generated with Claude Code

…in, timeouts, ledger/issue, tests

Findings fixed:
- SECURITY — the `login` prompt echoed the API key in cleartext. Now
  masked (suppress the readline echo on a TTY; plain read off a pipe).
- Project scoping was entirely non-functional: config.project was loaded
  but never used. Wired everywhere via a single resolveAuth() — the raw
  ApiClient sends x-codespar-project, SDK commands pass projectId, the
  logs SSE carries the header, and a `--project` flag is added. Multi-
  project orgs no longer silently hit the org default.
- ApiClient had no request timeout (a hung server hung the CLI). Added a
  30s AbortController timeout surfaced as a clear CliError.
- Missing `ledger` + `issue` commands for the SDK 0.10 meta-tools. Added
  (mirror charge/ship) with validation + a shared meta-input helper.
- Stale User-Agent (0.1.0) + duplicated VERSION. Single version.ts source.
- Non-`--json` double-print (human summary to stderr + full JSON dump to
  stdout) on charge/ship/payment-status/verification-status — dropped the
  redundant dump. execute/tools keep theirs (that IS their data/schema
  output, not a duplicate).
- No tests. Added 19 unit tests (ApiClient header/timeout/error/204 via a
  mocked fetch; ledger/issue validation; meta-input parsing) + a `test`
  script; tests excluded from the published dist.

Gate: turbo build + typecheck + test 54/54 green (CLI tests 19/19).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@fabianocruz
fabianocruz merged commit 304ee0b into main Jun 6, 2026
0 of 4 checks passed
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