Skip to content

Add comprehensive unit test suite (181 tests)#8

Open
slacki-ai wants to merge 2 commits intomainfrom
test/unit-test-suite
Open

Add comprehensive unit test suite (181 tests)#8
slacki-ai wants to merge 2 commits intomainfrom
test/unit-test-suite

Conversation

@slacki-ai
Copy link
Copy Markdown
Collaborator

Summary

  • Adds a vitest-based unit test suite with 181 tests across 12 test files, covering all major ClaudeX subsystems
  • All tests are fully mocked (Slack API, Claude SDK, filesystem, fetch) — no real jobs, no databases, no side effects
  • Includes 38 crash-prevention tests specifically targeting error paths that cause "process exited with code 1"
  • One test is marked as it.fails() to document a known bug: missing try/catch in resolveUserName (events.ts line 354-368)

Test Coverage

Area Files Tests
Slack integration messages, tools, events, client, files 97
Crash prevention events-crashes, response-crashes 38
Claude SDK response, session 31
Utilities paths, file-detect 22
Data store sessions 10

Run with

npm test          # single run
npm run test:watch  # watch mode

Test plan

  • npm test passes: 180 passing, 1 expected fail
  • Review test coverage for completeness
  • Verify no flaky tests in CI

🤖 Generated with Claude Code

slacki-ai and others added 2 commits March 17, 2026 08:21
…ary-continuation

Root cause: query() had no maxTurns, letting sessions run until the model's
context window was exhausted — killing the session before a Slack reply was sent.

Changes:

session.ts
- DEFAULT_MAX_TURNS = 200 (configurable via CLAUDE_MAX_TURNS env var)
- maxTurns: DEFAULT_MAX_TURNS in sharedOptions — applies to every session
- summarizeSession(): resumes a timed-out session with maxTurns: 5 and a prompt
  asking Claude for a concise summary of what was done and what remains

response.ts
- ClaudeResponse.subtype — SDK result subtype ('error_max_turns', etc.)
- ClaudeResponse.didAutoCompact — set to true when a compact_boundary message
  is seen; this is the SDK's token-based trigger (fires when context fills up),
  so this is more accurate than a turn-count check
- consumeResponse() tracks compact_boundary events in the stream

files.ts
- uploadContentAsFile(): writes a string to a temp file and uploads it to Slack

events.ts
- handleMessage(): if didAutoCompact, posts an informational notice so the user
  knows the session auto-compacted during their request
- callClaudeWithRetry(): on error_max_turns:
    1. Resumes the session (still has full recent context) to generate a summary.
       Claude writes this from the full history including the recent "second half"
       that auto-compaction hadn't touched.
    2. Uploads the summary as session-summary.txt (file, not inline text, since
       it can be long).
    3. Starts a fresh continuation session with the summary as context so the
       task can resume without the bloated history that caused the limit.
  If any step fails, falls back to the raw error. The continuation deliberately
  does not re-enter the recovery path to avoid infinite loops.

tools.ts
- slackSendMessage: disable link/media unfurling

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add vitest-based unit test suite covering all major ClaudeX subsystems:
- Slack integration: messages, tools, events, client, files (6 files, 103 tests)
- Claude SDK: response parsing, session management, crash scenarios (3 files, 38 tests)
- Data store: session persistence, atomic writes, corruption handling (1 file, 10 tests)
- Utilities: path resolution, file detection (2 files, 22 tests)
- Crash prevention: 38 dedicated tests for error paths that cause "process exited with code 1"

All tests are fully mocked (no real Slack API calls, no Claude sessions, no filesystem
side effects). One test is marked as expected-fail to document a known bug in
resolveUserName (missing try/catch in events.ts).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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