Repository navigation
Adds a vitest test suite covering the SDK and an end-to-end run against a real aiosendspin server. - #93
Merged
Conversation
Introduces Vitest test infrastructure to validate the PR #82 refactor. Includes a mock Sendspin server (TypeScript/ws) for E2E protocol testing and unit tests for the core components (TimeFilter, StateManager, Decoder). - E2E: Full session lifecycle (handshake, time sync, streaming, commands, disconnect) - E2E: External WebSocket adoption, volume/mute, sync delay, format updates - Unit: Kalman filter time synchronization (offset, drift, reset, adaptive forgetting) - Unit: State management (volume clamping, callbacks, server/group state merging) - Unit: PCM decoder (16/24/32-bit, mono/stereo, generation filtering, edge cases) https://claude.ai/code/session_011MZZ4bayCXYhwnrd9rY5dc
Swap the TypeScript mock server for a real aiosendspin (Python) server subprocess, testing the SDK against the reference protocol implementation. The Python server is controlled via a stdin/stdout line protocol from the Node.js test runner. - Add tests/helpers/sendspin-server.py: aiosendspin server with CLI control - Add tests/helpers/aiosendspin-server.ts: Node.js subprocess wrapper - Rewrite E2E tests to use the real server (handshake, time sync, streaming, server commands, disconnect, full lifecycle) - Remove the old mock-server.ts - Add .venv/ to .gitignore Requires Python 3.12+ with aiosendspin[server] installed in .venv/. https://claude.ai/code/session_011MZZ4bayCXYhwnrd9rY5dc
Runs the Vitest suite (unit + aiosendspin E2E) on every push and PR. Sets up Python 3.12 and installs aiosendspin[server] into .venv/ so the E2E tests can spawn a real Sendspin server subprocess. https://claude.ai/code/session_011MZZ4bayCXYhwnrd9rY5dc
# Conflicts: # yarn.lock
Drop the private _tcp_site reach by reserving a free port explicitly, collapse newlines in error replies, and discard late responses after a read timeout so they aren't mismatched to the next command. Give each test a fresh server to stop client-queue and stream state from bleeding across tests.
The clearState and interval-management tests asserted nothing and passed for a no-op. Decode a frame after clearState, and spy on clearTimeout/ clearInterval to confirm the tracked timers are actually cleared.
The 24/32-bit decode tests checked only sample range, which an all-zeros decoder passes; assert the decoded peak approaches the source amplitude. Remove the volume-change callback test subsumed by the full-state test.
Cover the NTP offset arithmetic, robust median candidate selection, out-of-order response rejection, and probe-timeout abort with a stubbed performance.now and a fake WebSocketManager.
Cover auto-reconnect and adopt error paths, message routing plus the static-delay guard and stream/clear roles filter, and the core supported-command guard, audio-before-format drop, and teardown paths.
Add nested server-state merge and null-clear cases, and a drift compensation case asserting the transform applies drift once significant.
The helper's stream_clear stopped and restarted the stream (end+start) instead of clearing it; use push_stream.clear() so the seek path emits stream/clear, and assert the client clears without ending playback.
…tests Don't assert the exact t4 when all burst samples are equivalent (selection is covered separately), and disconnect the manager in afterEach.
Cover scheduler timestamp math/correction bands/generation handling, output-latency EMA, clock-source promotion/estimation, and recorrection deadband/sustain/cooldown.
Cover opus/WebCodecs de-interleaving, FLAC header prepend, and codec-support browser detection / format expansion.
Adds coverage to the existing core/protocol-handler/websocket-manager/ time-sync-manager/time-filter test files: trackProgress/URL/forwarding, client/state shape + commands + stream end, websocket send/adopt, time-sync cadence/shape, and time-filter edge cases.
Remove low-value defaults/setters and near-duplicate permutations whose invariants are already covered by clamp, reset, applyDiff, and full-state callback tests. These tests were introduced in a pushed commit, so they're removed here rather than rewritten in history.
- Backward time_added in the Kalman filter must be rejected (#119 guard). - StateManager.reset() must preserve streamGeneration so late chunks from a previous stream can never match after a reconnect. - Reconnect timer fires at the configured base delay, not a hard-coded 5s.
Capture a tail of stderr from the aiosendspin subprocess and attach it to readLine timeouts so a Python traceback is visible in the vitest error instead of a generic timeout. Attach error/exit listeners so a spawn failure or unexpected death rejects pending readers immediately rather than waiting out the full timeout. The exit listener honours an internal closing flag so the expected exit during shutdown is not flagged as unexpected.
get_event_loop is deprecated when called inside a running loop and will be removed in a future Python release. get_running_loop is the supported form inside async functions.
The 15s default sat right at the edge of the E2E budget. Under a slow runner a hung probe could trip vitest's timeout before the inner waitForClient or time-sync deadlines, replacing the actionable error with a generic one. 30s leaves headroom.
Each E2E test file spawns its own Python aiosendspin subprocess that allocates a port via find_free_port — bind, release, then aiosendspin re-binds the same port. Two parallel vitest workers could race in that release-then-rebind window. The unit project keeps default parallelism; the e2e project sets fileParallelism: false so adding a second e2e file later cannot trip the race.
Main's recent dependency bumps (rollup, plugin-commonjs, eslint-plugin-prettier) updated transitive entries that conflicted with the test commits' lockfile additions. Regenerated to keep yarn install --frozen-lockfile green.
maximmaxim345
marked this pull request as ready for review
June 4, 2026 15:07
There was a problem hiding this comment.
Pull request overview
Adds a Vitest-based test harness for the Sendspin JS SDK, including a large unit test suite and an end-to-end suite that runs against a real aiosendspin Python server subprocess. This strengthens confidence in protocol correctness, time sync behavior, decoding, and playback scheduling without changing src/ runtime code.
Changes:
- Introduces Vitest configuration with separate unit and E2E projects and longer timeouts for E2E.
- Adds extensive unit tests across core/audio modules plus an E2E test driving a real
aiosendspinserver via a stdin/stdout control protocol. - Adds CI workflow + local bootstrap script/docs for creating a
.venvand runningyarn test.
Reviewed changes
Copilot reviewed 22 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
yarn.lock |
Adds dependency resolutions for Vitest + E2E tooling (ws, vite, etc.). |
vitest.config.ts |
Configures Vitest projects for unit vs E2E tests and test timeouts. |
tests/unit/websocket-manager.test.ts |
Unit tests for reconnect/adopt/send behavior with fake WebSocket. |
tests/unit/time-sync-manager.test.ts |
Unit tests for NTP-like burst sync, candidate selection, and timeouts. |
tests/unit/time-filter.test.ts |
Unit tests for Kalman-based time filter behavior and edge cases. |
tests/unit/state-manager.test.ts |
Unit tests for state store updates, resets, and interval handling. |
tests/unit/scheduler.test.ts |
Unit tests for AudioScheduler timing math, buffering horizon, correction logic. |
tests/unit/recorrection-monitor.test.ts |
Unit tests for sustained-drift detection, transient suppression, cooldown. |
tests/unit/protocol-handler.test.ts |
Unit tests for message routing, roles filtering, and command handling. |
tests/unit/output-latency-tracker.test.ts |
Unit tests for latency estimation smoothing and persistence behavior. |
tests/unit/decoder.test.ts |
Unit tests for PCM decoding path and message parsing. |
tests/unit/decoder-codecs.test.ts |
Unit tests for Opus (WebCodecs) + FLAC (OfflineAudioContext) decode paths. |
tests/unit/core.test.ts |
Unit tests for offline core behaviors, URL building, state/command forwarding. |
tests/unit/codec-support.test.ts |
Unit tests for UA-based codec support and format expansion/filtering. |
tests/unit/clock-source.test.ts |
Unit tests for AudioContext clock source selection/promotion/demotion. |
tests/helpers/sendspin-server.py |
Python aiosendspin test server controlled over stdin/stdout. |
tests/helpers/aiosendspin-server.ts |
Node wrapper spawning the Python server and managing the control protocol. |
tests/e2e/sendspin-core.e2e.test.ts |
E2E test suite validating handshake, time sync, streaming, commands, disconnect. |
scripts/setup.sh |
Bootstraps .venv and installs aiosendspin, then installs Node deps. |
README.md |
Documents how to bootstrap .venv and run unit/E2E tests. |
package.json |
Adds Vitest + ws dependencies and yarn test scripts. |
CLAUDE.md |
Updates contributor docs with test setup/running instructions. |
.gitignore |
Ignores .venv/ created for E2E server runs. |
.github/workflows/test.yml |
Adds a CI job to set up Python + run yarn test (unit + E2E). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a vitest test suite covering the SDK and an end-to-end run against
a real aiosendspin server. No changes to
src/.Unit tests (13 files,
tests/unit/)clock-source, codec-support, core, decoder, decoder-codecs,
output-latency-tracker, protocol-handler, recorrection-monitor,
scheduler, state-manager, time-filter, time-sync-manager,
websocket-manager.
E2E (1 file,
tests/e2e/)sendspin-core.e2e.test.tsdrives a real aiosendspin Python serverthrough a line-based stdin/stdout control protocol implemented by
tests/helpers/sendspin-server.py. The Node side spawns and controlsthe subprocess via
tests/helpers/aiosendspin-server.ts.Stats
234 tests across 14 files.
yarn test~32s locally.Bugs already caught and fixed
Added a couple more tests which were able to flag bugs in this library. Each of them was already fixed in a separate PR before this one so all tests pass: