Skip to content

Add e2e tests for DO-to-DO sync#46

Open
bohdanbirdie wants to merge 1 commit into
mainfrom
test/e2e-do-sync
Open

Add e2e tests for DO-to-DO sync#46
bohdanbirdie wants to merge 1 commit into
mainfrom
test/e2e-do-sync

Conversation

@bohdanbirdie
Copy link
Copy Markdown
Owner

@bohdanbirdie bohdanbirdie commented Apr 16, 2026

Summary

  • Add 12 miniflare-based e2e tests covering the LinkProcessorDO ↔ SyncBackendDO sync path
  • Tests exercise store creation, link ingestion, duplicate detection, concurrent ingests, cross-org isolation, fetch trigger path, queue batch handler with real DOs, and mixed-org batch routing
  • No sleeps or real-time waits — all assertions are synchronous against DO RPC responses

Summary by CodeRabbit

  • Tests
    • Added comprehensive end-to-end tests for LinkProcessor sync flows: ingestion, duplicate detection, URL validation, concurrent ingests, cross-organization isolation, queue batch handling, and post-initialization behavior.
  • Chores
    • Improved test setup to skip redundant migrations when schema already exists and adjusted test runner pool storage configuration for worker tests.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 16, 2026

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
cloudstash c5d1111 Apr 17 2026, 07:43 PM

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Warning

Rate limit exceeded

@bohdanbirdie has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 44 minutes and 13 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 44 minutes and 13 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 43c0070e-a498-4e0a-a588-2471ee131387

📥 Commits

Reviewing files that changed from the base of the PR and between 4883d99 and c5d1111.

📒 Files selected for processing (1)
  • src/cf-worker/__tests__/e2e/do-sync.test.ts
📝 Walkthrough

Walkthrough

Adds a new end-to-end test suite for the LinkProcessor Cloudflare Durable Object and small test setup/config tweaks: an E2E test file covering ingest/fetch/queue flows, a migration pre-check in test setup, and a Vitest pool worker option change.

Changes

Cohort / File(s) Summary
New E2E test suite
src/cf-worker/__tests__/e2e/do-sync.test.ts
New Vitest E2E tests exercising LinkProcessor DO: ingestAndProcess (cold/warm), duplicate detection, invalid URL handling, concurrent ingests, cross-org isolation, fetch/init behavior, and real queue batch handler scenarios with mocked MessageBatch and ack/retry assertions.
Test setup
src/cf-worker/__tests__/e2e/setup.ts
Adds a pre-migration check that skips applying migrations if the user table already exists; otherwise retains existing migration execution logic.
Vitest config
vitest.e2e.config.ts
Sets poolOptions.workers.isolatedStorage = false in Cloudflare Workers Vitest pool worker settings.

Sequence Diagram(s)

(silently skipped)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Poem

🐰 I hopped through queues and tests tonight,

Poking DOs until the IDs felt right.
Cold boots, duplicates, orgs kept apart,
I nibbled bugs and gave each case a start.
Hooray—these tests make my whiskers bright! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provided does not follow the required template structure with 'What', 'Why', 'Justification', and 'Technical details' sections. Restructure the description to match the template with clear sections for What, Why, Justification, and Technical details (optional).
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding end-to-end tests for DO-to-DO sync functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/e2e-do-sync

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/cf-worker/__tests__/e2e/do-sync.test.ts (1)

29-61: createMockBatch omits ackAll/retryAll from the mocked MessageBatch.

The cast as unknown as MessageBatch<LinkQueueMessage> bypasses the type system. Current handleQueueBatch only uses per-message ack()/retry(), so these tests pass, but if the handler is ever extended to call batch.ackAll() or batch.retryAll() (a common pattern for terminal errors), the tests will throw TypeError: batch.ackAll is not a function at runtime with no compile-time hint. Cheap to stub defensively.

♻️ Add no-op `ackAll`/`retryAll` stubs
   const batch = {
     messages: mockMessages,
     queue: "cloudstash-link-queue",
+    ackAll() {},
+    retryAll() {},
   } as unknown as MessageBatch<LinkQueueMessage>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cf-worker/__tests__/e2e/do-sync.test.ts` around lines 29 - 61,
createMockBatch currently builds a MessageBatch stub but casts via "as unknown
as MessageBatch<LinkQueueMessage>" without implementing ackAll/retryAll, so if
handleQueueBatch later calls batch.ackAll() or batch.retryAll() tests will throw
at runtime; update createMockBatch to add no-op ackAll() and retryAll() methods
on the returned batch object (and ensure the mockMessages array remains
accessible) so the stub fully satisfies MessageBatch<LinkQueueMessage> at
runtime while keeping per-message ack()/retry() behavior intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cf-worker/__tests__/e2e/do-sync.test.ts`:
- Around line 109-133: The concurrent-ingest test doesn't exercise the
cold-start race because the shared stub is already initialized; add a new test
variant that uses signupUser() to create a fresh orgId (ensuring a new DO
instance) and then immediately fires Promise.all(urls.map(u =>
stub.ingestAndProcess(makeQueueMessage(u, orgId)))) against a newly obtained
stub from getLinkProcessorStub(orgId) so all ingestAndProcess calls run before
any prior initialization completes; this will trigger the createStoreDoPromise /
storeCreationPromise path in getStore() and verify that concurrent store
creation is properly deduplicated and serialized.

---

Nitpick comments:
In `@src/cf-worker/__tests__/e2e/do-sync.test.ts`:
- Around line 29-61: createMockBatch currently builds a MessageBatch stub but
casts via "as unknown as MessageBatch<LinkQueueMessage>" without implementing
ackAll/retryAll, so if handleQueueBatch later calls batch.ackAll() or
batch.retryAll() tests will throw at runtime; update createMockBatch to add
no-op ackAll() and retryAll() methods on the returned batch object (and ensure
the mockMessages array remains accessible) so the stub fully satisfies
MessageBatch<LinkQueueMessage> at runtime while keeping per-message
ack()/retry() behavior intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dfae712a-7f29-48c7-8824-10eade3ea7c5

📥 Commits

Reviewing files that changed from the base of the PR and between 3eea65f and 2736ea4.

📒 Files selected for processing (1)
  • src/cf-worker/__tests__/e2e/do-sync.test.ts

Comment on lines +109 to +133
describe("concurrent ingests", () => {
it("ingests multiple links simultaneously", async () => {
const stub = getLinkProcessorStub(user.orgId);
const urls = [
"https://example.com/concurrent-1",
"https://example.com/concurrent-2",
"https://example.com/concurrent-3",
];

const results = await Promise.all(
urls.map((url) =>
stub.ingestAndProcess(makeQueueMessage(url, user.orgId))
)
);

for (const result of results) {
expect(result.status).toBe("ingested");
expect(result.linkId).toBeDefined();
}

const linkIds = results.map((r) => r.linkId);
const uniqueIds = new Set(linkIds);
expect(uniqueIds.size).toBe(urls.length);
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Locate ingestAndProcess / createStoreDoPromise and inspect serialization/guarding logic
fd -e ts -e tsx | xargs rg -nP -C4 '\b(ingestAndProcess|createStoreDoPromise)\b'

Repository: bohdanbirdie/cloudstash

Length of output: 19148


🏁 Script executed:

sed -n '500,545p' src/cf-worker/link-processor/durable-object.ts

Repository: bohdanbirdie/cloudstash

Length of output: 1251


🏁 Script executed:

sed -n '130,160p' src/cf-worker/link-processor/durable-object.ts

Repository: bohdanbirdie/cloudstash

Length of output: 911


🏁 Script executed:

rg -n 'async getStore|getStore\(' src/cf-worker/link-processor/durable-object.ts | head -20

Repository: bohdanbirdie/cloudstash

Length of output: 219


🏁 Script executed:

sed -n '82,95p' src/cf-worker/link-processor/durable-object.ts

Repository: bohdanbirdie/cloudstash

Length of output: 410


🏁 Script executed:

sed -n '82,100p' src/cf-worker/link-processor/durable-object.ts

Repository: bohdanbirdie/cloudstash

Length of output: 516


🏁 Script executed:

cat -n src/cf-worker/__tests__/e2e/do-sync.test.ts | sed -n '60,135p'

Repository: bohdanbirdie/cloudstash

Length of output: 2950


Add a test variant with fresh DO to exercise true cold-boot race condition.

The current concurrent-ingest test does not exercise the initialization race it appears to test. By the time this it runs, the shared stub has already been initialized by preceding tests ("cold boot", "warm DO", "duplicate detection"), so all three concurrent ingestAndProcess calls hit an already-cached store. The actual hazard from the learning—concurrent createStoreDoPromise calls corrupting the eventlog—only occurs during initialization.

Add a variant that:

  • Calls signupUser() to create a fresh orgId (new DO instance)
  • Fires Promise.all(urls.map(...ingestAndProcess...)) before any prior call runs

This will verify that concurrent RPCs during cold-boot properly serialize via the deduplication in getStore() (which reuses this.storeCreationPromise).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cf-worker/__tests__/e2e/do-sync.test.ts` around lines 109 - 133, The
concurrent-ingest test doesn't exercise the cold-start race because the shared
stub is already initialized; add a new test variant that uses signupUser() to
create a fresh orgId (ensuring a new DO instance) and then immediately fires
Promise.all(urls.map(u => stub.ingestAndProcess(makeQueueMessage(u, orgId))))
against a newly obtained stub from getLinkProcessorStub(orgId) so all
ingestAndProcess calls run before any prior initialization completes; this will
trigger the createStoreDoPromise / storeCreationPromise path in getStore() and
verify that concurrent store creation is properly deduplicated and serialized.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/cf-worker/__tests__/e2e/setup.ts (1)

9-16: Migration skip check may stale out when new migrations are added.

The guard only checks for the user table (created by the first migration). With isolatedStorage: false, a D1 database populated by an earlier test run will cause all subsequent migrations — including any newly added ones — to be silently skipped on later runs until the persistent storage is wiped. Consider keying off the full migration set (e.g., a drizzle_migrations tracking table, or checking the last migration's tag/table) so newly added migrations get applied against an already-initialized DB.

As per coding guidelines: "Avoid code comments unless absolutely necessary for complex logic" — the comment on lines 7-8 is arguably necessary here, so no action needed on that front.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cf-worker/__tests__/e2e/setup.ts` around lines 9 - 16, The migration
guard currently detects initialization by querying for the 'user' table via
db.prepare(...).first(), which will incorrectly skip newly added migrations if
the DB was created by an earlier run; change the guard to verify the actual
migration tracking state instead (for example query for a drizzle_migrations or
migration tracking table, or check for the last migration's tag/table used by
your migration runner) so that presence of the initial 'user' table no longer
short-circuits applying any newer migrations; update the check that uses
db.prepare and the SQL string to look up the migrations table or last-applied
migration marker (e.g., check for 'drizzle_migrations' or the latest migration
identifier) and return only when that tracking entry indicates all migrations
have been applied.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/cf-worker/__tests__/e2e/setup.ts`:
- Around line 9-16: The migration guard currently detects initialization by
querying for the 'user' table via db.prepare(...).first(), which will
incorrectly skip newly added migrations if the DB was created by an earlier run;
change the guard to verify the actual migration tracking state instead (for
example query for a drizzle_migrations or migration tracking table, or check for
the last migration's tag/table used by your migration runner) so that presence
of the initial 'user' table no longer short-circuits applying any newer
migrations; update the check that uses db.prepare and the SQL string to look up
the migrations table or last-applied migration marker (e.g., check for
'drizzle_migrations' or the latest migration identifier) and return only when
that tracking entry indicates all migrations have been applied.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fcdbfb5f-c70c-42b1-838d-9025c68a96eb

📥 Commits

Reviewing files that changed from the base of the PR and between 2736ea4 and 4883d99.

📒 Files selected for processing (2)
  • src/cf-worker/__tests__/e2e/setup.ts
  • vitest.e2e.config.ts
✅ Files skipped from review due to trivial changes (1)
  • vitest.e2e.config.ts

Tests the LinkProcessorDO ↔ SyncBackendDO sync path end-to-end:
store creation, link ingestion, duplicate detection, concurrent
ingests, cross-org isolation, fetch trigger path, queue batch
handler with real DOs, and mixed-org batch routing.
@bohdanbirdie
Copy link
Copy Markdown
Owner Author

Blocker: CI hangs on DO storage cleanup

Tests pass locally on macOS but CI on Linux hangs indefinitely after throwing:

Failed to pop isolated storage stack frame ...
AssertionError: Expected .sqlite, got .../LinkProcessorDO/...sqlite-shm

Root cause

vitest-pool-workers per-test storage isolation snapshots/pops DO SQLite state between tests. LinkProcessorDO's livestore opens SQLite in WAL mode, creating .sqlite-shm/.sqlite-wal sidecars. The pool's pop logic asserts filenames end in .sqlite and throws on the sidecars. After that assertion, the livestore push fiber is left mid-push against inconsistent state and retries forever — that's the hang.

It passes locally because macOS SQLite checkpoints WAL more eagerly than Linux, so the sidecars often don't exist at pop time. Same code, different filesystem behavior → environmental flake.

Upgrade path is blocked

  • @cloudflare/vitest-pool-workers@0.13+ removes isolated storage entirely (fixes this)
  • But 0.13+ requires vitest ^4.1.0
  • @effect/vitest stable is pinned to vitest ^3.2.0 — no stable release supports vitest 4
  • Betas exist but not worth adopting on an unrelated PR

Alternatives considered

  • isolatedStorage: false — works, but loosens isolation for all other e2e tests (rejected)
  • Upgrade path — blocked by @effect/vitest (above)
  • Skip on CI — defeats the purpose

Plan

Leave PR open until @effect/vitest stable supports vitest 4, then upgrade vitest + @cloudflare/vitest-pool-workers together and merge.

Full diagnosis in issue #11031 and related.

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