Skip to content

Phase 2: Testing seams (database, server Workers pool, CLI handlers) #31

Description

@soorya-u

Implementation

Parent

Sub-issue of the testing strategy epic.

Goal

Test the critical seams: persistence, server runtime (Workers), and CLI handler logic.

Scope

Database strategy (implement here)

CLI / @cyrus/database — in-memory Turso

  • Integration tests in shared/database/__tests__/integration/
  • Use temp-file or in-memory Turso per test via existing connection.open() + pushSchema
  • Test repositories: threads, conversations, projects
  • Bun test runner

Server / apps/server — Docker Postgres (not Neon HTTP)

  • Refactor apps/server/src/db/index.tscreateDb() factory with env-based driver:
    • Production: drizzle-orm/neon-http (unchanged)
    • Test: drizzle-orm/postgres-js against Docker Postgres
  • Add docker-compose.test.yml (or CI service) for Postgres 16
  • Run drizzle migrations before server integration suite
  • Document: neon-http does not speak to local Postgres — test driver must differ

Nightly (optional, can defer to Phase 5)

  • Neon test branch smoke with production driver

@cyrus/server — Vitest + @cloudflare/vitest-pool-workers

  • Add vitest.config.ts + Workers pool
  • Integration tests for Hub Durable Object (cloudflare/partyserver.ts)
  • Integration tests for signaling handler message routing
  • Auth middleware tests with seeded session (real better-auth + test Postgres)

@cyrus/cli — Bun test

  • Extract runTurn from handlers/controller/chat.ts → testable module
  • Unit test stream persistence helpers (utils/streams.ts)
  • Unit test ACP event mappers (core/acp/events.ts) with fixture payloads
  • Integration test controller handlers with fake ControllerDeps (DB + mock runtime)

@cyrus/connections — Bun test

  • Unit test peer.ts: ICE buffer, createSignalingEvents fan-out
  • Unit test session.ts normalizeHost
  • Integration test signaling session with mock WebSocket (no real WebRTC)

CI

  • Add test-integration job to ci.yml
  • Postgres service container for server integration job
  • Server Workers pool job (separate or combined)

Runner

  • Bun test: database, cli, connections
  • Vitest + Workers pool: server

Auth approach (failproof)

  • Integration tests use real better-auth against test Postgres
  • Seed a test user + programmatic session; do not use bare bearer token mocks at handler boundaries

Acceptance criteria

  • Repository integration tests pass with isolated Turso per test
  • Server integration tests pass against Docker Postgres with migrated schema
  • Signaling handler + Hub DO covered in Workers pool
  • runTurn testable without spawning ACP subprocess

Depends on

Phase 1 (turbo tasks + tooling)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions