mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 06:16:37 +00:00
* fix(cliproxy): guard against empty upstream SSE responses in agy profile When CLIProxyAPIPlus drops unsigned thinking blocks during sub-agent execution, the response stream can contain no content_block_start or message_delta events. This causes Claude Code CLI to crash with "No assistant message found". Add empty response detection in the tool sanitization proxy's streaming handler. Both the pipe-through and SSE-processing paths now track whether meaningful content was received. If upstream sent data but no content blocks on a 200 OK, a synthetic minimal valid SSE response is injected to prevent the client crash and surface a clear error message. Closes #350 * fix(cliproxy): improve empty response detection and add tests Address code review findings: - Remove message_delta from content detection (lifecycle event, not content); only content_block_start indicates actual content - Add try-catch in end handlers to handle client disconnects gracefully - Add 3 integration tests: empty stream injection, normal stream passthrough, 4xx/5xx non-injection * fix(cliproxy): avoid duplicate message_start in synthetic response Track whether upstream already sent a message_start event. When injecting the synthetic error response, omit message_start if upstream already sent one, preventing duplicate events in the SSE stream. Addresses PR review feedback from ccs-reviewer[bot]. * test(cliproxy): add SSE processing path and real failure mode tests Address code review observations: - Add test exercising SSE processing path (sanitized tool names) for empty response detection, ensuring both code paths are covered - Add test mirroring real failure mode where upstream sends only message_start then ends abruptly (no message_delta/message_stop) - Document duplicate message_start assumption with inline comment
CCS Test Suite
Organization
tests/
├── unit/ # Module unit tests (Mocha)
│ ├── glmt/ # GLMT transformer tests
│ └── delegation/ # Delegation module tests
├── npm/ # npm package tests (Mocha)
├── native/ # Native installation tests (bash/PowerShell)
│ ├── unix/ # Unix/Linux/macOS tests
│ └── windows/ # Windows PowerShell tests
├── integration/ # Integration tests (manual execution)
└── shared/ # Shared utilities
├── fixtures/ # Test configuration and environment
├── unit/ # Helper function tests
├── helpers.sh # Bash test utilities
└── test-data.js # Test data for npm tests
Running Tests
bun run test # All automated tests (unit + npm)
bun run test:unit # Unit tests only (Mocha)
bun run test:npm # npm package tests (Mocha)
bun run test:native # Native Unix tests (bash)
Test Categories
Unit Tests (unit/)
Module-level tests using Mocha framework:
unit/glmt/- GLMT transformer, SSE parser, delta accumulatorunit/delegation/- Permission mode, session manager, result formatter
npm Tests (npm/)
npm package functionality tests using Mocha:
postinstall.test.js- Postinstall behaviorcli.test.js- CLI argument parsingcross-platform.test.js- Cross-platform compatibilityspecial-commands.test.js- Integration tests
Native Tests (native/)
Installation tests for curl|bash (Unix) and irm|iex (Windows):
native/unix/edge-cases.sh- Unix edge case testsnative/windows/edge-cases.ps1- Windows edge case tests
Integration Tests (integration/)
Manual execution tests for specific scenarios:
token-counting-test.js- Token counting validationz-ai-streaming-test.js- Z.AI streamingglmt-integration-test.sh- GLMT integrationsymlink-chain-test.sh- Symlink chain handlingux-integration-test.sh- CLI UX integration
Adding New Tests
- Unit tests: Add to
unit/<module>/using Mocha + Node.js assert - npm tests: Add to
npm/using Mocha - Native tests: Add to
native/unix/ornative/windows/ - Integration tests: Add to
integration/