Skip to content

Phase 3: Integration tests for daemon server lifecycle#5

Merged
schovi merged 1 commit intomainfrom
feat/phase3-integration-tests
Feb 18, 2026
Merged

Phase 3: Integration tests for daemon server lifecycle#5
schovi merged 1 commit intomainfrom
feat/phase3-integration-tests

Conversation

@schovi
Copy link
Owner

@schovi schovi commented Feb 18, 2026

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 setupTestServer helper starts a real server in-process with MemoryStorage and a temporary Unix socket directory. Tests use daemon.Client against 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):

  • setupTestServer helper: temp dir, MemoryStorage, server lifecycle management
  • waitForOutput helper: polls until expected content appears

Integration tests:

  • TestLifecycle: create -> send -> read -> stop -> read (preserved) -> kill (removed)
  • TestSearchBoundsValidation: negative before/after produces error, valid search works
  • TestConcurrentAccess: 5 parallel sessions with independent send/read
  • TestPerCursorReads: independent cursor position tracking across consumers
  • TestSessionErrorCases: invalid names, duplicates, nonexistent sessions, idempotent stop

Server/client configurability (server.go, client.go):

  • WithSocketDir server option for custom socket directory
  • Server.socketPath() method (replaces hardcoded SocketPath() in Start/Shutdown)
  • NewClientWithSocketPath constructor for connecting to non-default sockets

Bug fix (server.go):

  • Remove cmd.Wait() from handleStop goroutine and proc.Wait() from handleKill goroutine. Both raced with captureOutput which already handles process reaping. Detected by -race flag during integration tests.

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)
@schovi schovi marked this pull request as ready for review February 18, 2026 04:15
@schovi schovi merged commit 7d035ba into main Feb 18, 2026
6 checks passed
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