Skip to content

test: vitest scaffold + pure helpers (28 tests) - #12

Open
chronostrophe wants to merge 1 commit into
hanzili:mainfrom
chronostrophe:pr/test-scaffold
Open

test: vitest scaffold + pure helpers (28 tests)#12
chronostrophe wants to merge 1 commit into
hanzili:mainfrom
chronostrophe:pr/test-scaffold

Conversation

@chronostrophe

Copy link
Copy Markdown

Summary

Adds a vitest test scaffold and extracts pure helpers from src/index.ts so the trickiest logic is unit-testable without a live browser.

  • src/util/format.ts: formatCaughtError (redaction-safe error formatting, DEBUG-gated) + isDebugEnabled.
  • src/util/steps.ts: agent step-list pure helpers.
  • tests/util/*.test.ts: 28 tests covering redaction rules, error formatting edge cases, and step helpers.
  • vitest.config.ts + npm test / npm run typecheck scripts.
  • Also includes a small SIGINT/SIGTERM handler that closes the CDP WebSocket cleanly on exit (cometClient.disconnect() is idempotent) — without it, a killed process can leave Comet with a dangling debugger attach that stalls the next comet_connect.

Test plan

  • npm test — 28/28 pass
  • npx tsc --noEmit — clean
  • Built on pristine upstream/main (6f10c86) — no other commits required

No behavior change to the happy path; error text now goes through the redaction helper.

- src/util/format.ts: redactUrls, isDebugEnabled, formatCaughtError
  (extracted from the inline catch handler so the DEBUG+redaction logic
  is unit-testable)
- src/util/steps.ts: extractSteps with position-ordered regex (preserves
  body-position ordering; dedupes via Set)
- src/index.ts: route the MCP catch handler through formatCaughtError +
  isDebugEnabled; skip the redundant 'Error: <msg>' first line of V8
  stacks so the message isn't repeated in the output
- tests/util/format.test.ts (19 tests): URL redaction across http/https/ws,
  parens handling, multi-URL, non-URL preservation, DEBUG truthy/falsy
  literals, formatCaughtError with debug on/off and stack-line cap,
  non-Error throws
- tests/util/steps.test.ts (9 tests): empty/no-match, short-UI filter,
  trailing-context kept, insertion order, dedup, 100-char truncation,
  all 7 verbs, real-world Comet body with mixed signal+noise
- package.json: vitest devDep + scripts (test, test:watch)
- vitest.config.ts: node env, tests/**/*.test.ts

Verified: npx tsc --noEmit clean; npm test → 28/28 passing in 1.7s.

L2 re-investigated with grep references: state.currentUrl IS assigned in
connect() (line 810) and navigate() (line 834); the L2 alarm was a false
positive from initial analysis.
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