Skip to content

Codebase quality sweep: error handling, drift detection, test hygiene#176

Merged
jpr5 merged 5 commits into
mainfrom
blitz/aimock-quality-sweep/integration
May 11, 2026
Merged

Codebase quality sweep: error handling, drift detection, test hygiene#176
jpr5 merged 5 commits into
mainfrom
blitz/aimock-quality-sweep/integration

Conversation

@jpr5
Copy link
Copy Markdown
Contributor

@jpr5 jpr5 commented May 11, 2026

Summary

Codebase-wide quality sweep addressing 6 categories of issues across 53 files:

  • Error handling hardening — wrap unguarded stream writes in try/catch (recorder.ts, agui-recorder.ts), add response termination for headers-already-sent paths (server.ts, a2a-mock.ts, mcp-mock.ts), fix vector-mock double body consumption
  • Parse error detail surfacing — capture and include the actual JSON.parse error message in all 25+ bare catch blocks across every provider handler, WebSocket handler, and stream-collapse function
  • Drift detection gapscompareSSESequences now compares ALL events per type (not just the first), catching shape variations like Anthropic thinking deltas; Ollama drift tests use synchronous env-var gate instead of broken async describe.skipIf
  • Test hygiene — fix 12 unrestored spy/mock leaks across 6 test files, correct misleading "toolCalls should win" comments/assertions, move prototype-level spy to afterEach, update 17 test assertion strings for new error format

Test plan

  • 2867 tests pass (79 files, 37 skipped)
  • TypeScript typecheck clean
  • Prettier + ESLint clean (pre-commit hooks pass)
  • 7-agent CR Round 1: 0 new bucket (a) findings from changes; 2 minor items fixed (comment + confirmed non-issue)
  • 10-slot blitz execution with zero merge conflicts

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@176

commit: a3d9f95

@jpr5 jpr5 self-assigned this May 11, 2026
jpr5 added 5 commits May 11, 2026 10:57
- recorder.ts: capture error context in 3 bare catch blocks (URL
  parse, JSON parse, fixture merge), wrap clientRes.write/end in
  try/catch to prevent unhandled exceptions on client disconnect
- agui-recorder.ts: wrap 4 unguarded stream write/end calls in
  try/catch, add response termination when headers already sent,
  capture URL parse error context
- server.ts: add response termination to top-level catch when
  headers already sent, capture JSON parse detail in 400 response,
  move res.end inside try/catch in 7 error recovery paths
- a2a-mock.ts, mcp-mock.ts: add response termination when headers
  already sent in standalone server catch blocks
- vector-mock.ts: guard readBody with method check to prevent
  double body consumption on passthrough
Capture and surface the actual JSON.parse error message in every
request-body parse catch block across all provider handlers,
WebSocket handlers, and stream-collapse functions. Previously these
returned generic "Malformed JSON" without the parse position or
reason.

Also add firstDroppedSample field to CollapseResult for stream
chunk parse failures, preserving forensic data for debugging.

25 files across all LLM providers, multimedia endpoints, WebSocket
handlers, and stream collapse.
skipIf timing

- schema.ts compareSSESequences: replace .find() with .filter() +
  mergeShapes to compare ALL events per type, catching shape
  variations in subsequent events (e.g., Anthropic thinking deltas)
- ollama.drift.ts: replace async OLLAMA_REACHABLE with synchronous
  process.env.OLLAMA_HOST gate, matching every other drift file
- recorder.test.ts: fix misleading "toolCalls should win" comments
  and assertions to reflect actual content+toolCalls coexistence;
  move prototype-level setTimeout spy to afterEach for leak safety
- fixture-loader.test.ts, sse-writer.test.ts, mcp-mock.test.ts,
  metrics.test.ts, chaos.test.ts: add vi.restoreAllMocks() to
  afterEach for unrestored spy cleanup
- ws-framing.test.ts: add closeAllConnections before server.close
- 17 test files: update "Malformed JSON" assertions to match new
  error detail format
@jpr5 jpr5 force-pushed the blitz/aimock-quality-sweep/integration branch from fa745bd to a3d9f95 Compare May 11, 2026 17:58
@jpr5 jpr5 merged commit 449382f into main May 11, 2026
22 checks passed
@jpr5 jpr5 deleted the blitz/aimock-quality-sweep/integration branch May 11, 2026 18:02
jpr5 added a commit that referenced this pull request May 11, 2026
## Summary

Follow-up quality sweep addressing 30 issues surfaced by 7-agent CR on
PR #175, complementing the broader sweep in #176.

**Recorder proxy relay** — forward HTTP method instead of hardcoding
POST, clear response timeout after completion, fix client-disconnect
handler to check `writableFinished` before destroying upstream, wrap
hook callbacks in try/catch, override audio content-type on error relay,
atomic fixture writes, toolCall sanitization, tighter video detection

**Server error handling** — deferred splice for one-shot error fixtures,
SyntaxError guard on Azure injection catch, fixture-level chaos
evaluation for non-completions endpoints, fal body double-consumption
fix, fal PUT body support

**Test hygiene** — tmpDir leak fix, global fetch replaced with node:http
helpers, try/finally fixture cleanup, deduplicated helpers, explicit
mock properties, resource guard on setup helper

## Test plan

- [x] 2872 tests pass (79 files, 37 skipped)
- [x] TypeScript typecheck clean
- [x] Prettier + ESLint clean
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