Phase 3: Integration tests for daemon server lifecycle#5
Merged
Conversation
Add full-pipeline integration tests covering CLI client -> Unix socket -> server -> PTY -> storage -> read. These are the first tests that exercise the complete data flow end-to-end. - Add setupTestServer helper with temp socket dir and MemoryStorage - Add WithSocketDir server option and NewClientWithSocketPath for testability - TestLifecycle: create -> send -> read -> stop -> read -> kill - TestSearchBoundsValidation: negative before/after produces error (not panic) - TestConcurrentAccess: 5 parallel sessions with send/read - TestPerCursorReads: independent cursor position tracking - TestSessionErrorCases: invalid names, duplicates, nonexistent sessions - Fix data race: remove duplicate cmd.Wait()/proc.Wait() from handleStop and handleKill goroutines (captureOutput already handles process reaping)
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.
Enhancement
The daemon server had zero automated tests for the full pipeline: client -> socket -> server -> PTY -> storage -> read. All existing tests were unit-level for leaf packages. This adds end-to-end integration tests that exercise the complete data flow and verify correctness under concurrent access.
Solution
A
setupTestServerhelper starts a real server in-process withMemoryStorageand a temporary Unix socket directory. Tests usedaemon.Clientagainst the socket, exercising the same code path as CLI and MCP consumers. The server and client gain minimal configurability (WithSocketDir,NewClientWithSocketPath) to support isolated test instances.Changes
Test infrastructure (
internal/daemon/server_test.go):setupTestServerhelper: temp dir, MemoryStorage, server lifecycle managementwaitForOutputhelper: polls until expected content appearsIntegration tests:
TestLifecycle: create -> send -> read -> stop -> read (preserved) -> kill (removed)TestSearchBoundsValidation: negative before/after produces error, valid search worksTestConcurrentAccess: 5 parallel sessions with independent send/readTestPerCursorReads: independent cursor position tracking across consumersTestSessionErrorCases: invalid names, duplicates, nonexistent sessions, idempotent stopServer/client configurability (
server.go,client.go):WithSocketDirserver option for custom socket directoryServer.socketPath()method (replaces hardcodedSocketPath()inStart/Shutdown)NewClientWithSocketPathconstructor for connecting to non-default socketsBug fix (
server.go):cmd.Wait()fromhandleStopgoroutine andproc.Wait()fromhandleKillgoroutine. Both raced withcaptureOutputwhich already handles process reaping. Detected by-raceflag during integration tests.