Skip to content

test: Durable Object harness for SessionDO - #127

Open
schmug wants to merge 1 commit into
mainfrom
claude/project-thread-904oma
Open

schmug wants to merge 1 commit into
mainfrom
claude/project-thread-904oma

Conversation

@schmug

@schmug schmug commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Requested by Schmug · project thread

Closes #31.

Before: src/session-do.ts had no direct coverage. Deleting axisCreationsInFlight, the failed-embed pump kick, or the expanded write left the suite green.

After: test/session-do.test.ts drives a real SessionDO through its own SQL, alarm pump and restarts, inside the normal npm test, with no network or credentials. Each of those three deletions now fails a test (checked by mutating the code and rerunning).

How

test/helpers/do-harness.ts fakes only what the DO touches:

  • ctx.storage.sql over a real in-memory SQLite (node:sqlite, built into Node 22, which CI already pins). Two runtime behaviours are reproduced on purpose: multi-statement exec (what migrate() relies on) and BLOBs reading back as ArrayBuffer. Node returns Uint8Array, which new Float32Array(...) would silently corrupt.
  • Alarms are a recorded time that tests fire with fireAlarm() / drainAlarms().
  • restart() builds a fresh instance over the same database, which is what eviction looks like to a DO.
  • AI goes through the production selectBudgetedAiRunner with the binding set to fakeAiRunner from dev-fake-ai.ts, wrapped so tests can count calls and fail or hold specific ones. fakeAiRunner gained an optional latencyMs; the default stays 250.

The four tests cover the acceptance criteria: construct, persist and hydrate; an axis with expanded: false surviving restart through real SQL; a failed pole embed kicking the pump and a later pass filling it; and a second concurrent create at 2/3 axes spending zero AI calls. They add about 200 ms to the suite.

Why not @cloudflare/vitest-pool-workers: it needs a second vitest pool running inside workerd, and this project's remote: true AI binding pulls in the Access-gated proxy that kills wrangler dev without credentials. The approach is documented in CLAUDE.md.

Not done: BoardDO uses key-value get/put and the stubs in test/board-guards.test.ts. Adding those to FakeStorage is a natural follow-up, and so is updating the "no DO harness (issue #31)" comments in the board files.

Gates

  • npm run typecheck: clean
  • npm test: 44 files, 892 passing, 0 failing. Node prints an ExperimentalWarning for node:sqlite; it's harmless.

🤖 Generated with Claude Code

https://claude.ai/code/session_011jTqcyCetskFRRENsms9wZ


Generated by Claude Code

A bare-node harness that drives a real SessionDO inside npm test:
ctx.storage.sql over in-memory node:sqlite (multi-statement exec and
ArrayBuffer BLOBs reproduced), explicit alarm firing, restart over
retained storage, and AI via fakeAiRunner behind selectBudgetedAiRunner
with call counting and interception.

Four tests: hydrate after restart, the expanded:false round trip through
real SQL, failed pole embed kicking the pump, and axisCreationsInFlight
blocking a second concurrent create at the cap. Each fails when the code
it guards is removed.

fakeAiRunner takes an optional latencyMs (default unchanged at 250).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011jTqcyCetskFRRENsms9wZ
@schmug schmug self-assigned this Oct 11, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
dewpt 08889bb Oct 11 2026, 06:28 PM

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.

Add a Durable Object test harness

2 participants