Skip to content

Comments

Cache realm setup for host acceptance/integration tests#4034

Draft
IanCal wants to merge 9 commits intomainfrom
cache-host-realm-setup
Draft

Cache realm setup for host acceptance/integration tests#4034
IanCal wants to merge 9 commits intomainfrom
cache-host-realm-setup

Conversation

@IanCal
Copy link
Contributor

@IanCal IanCal commented Feb 20, 2026

Summary

This PR centralizes SQLite snapshot caching for host test realm setup so we get speedups across the whole host suite without requiring per-test wrapper plumbing.

What changed

  • Added snapshot lifecycle support to SQLiteAdapter (packages/host/app/lib/sqlite-adapter.ts):
    • exportSnapshot(snapshotName?)
    • importSnapshot(snapshotName)
    • hasSnapshot(snapshotName)
    • deleteSnapshot(snapshotName)
    • deleteSnapshotsByPrefix(prefix)
  • Added robust snapshot copy/restore internals in SQLiteAdapter:
    • schema-aware table cloning/copy helpers
    • batched import transaction with rollback on failure
    • tracked snapshot metadata and cleanup on close()
  • Added centralized cache helpers in packages/host/tests/helpers/index.gts:
    • withCachedRealmSetup(...)
    • module-derived cache key resolution via QUnit module name
    • deterministic snapshot naming with simpleHash
    • additional key support (for setup variants)
  • Added automatic cache teardown by module prefix:
    • explicit hook helper: setupRealmCacheTeardown(...)
    • global registration via QUnit.moduleDone(...) so snapshots are cleaned per module and don’t grow unbounded during long runs
  • Wired caching directly into realm setup entry points:
    • setupAcceptanceTestRealm(...) now goes through withCachedRealmSetup(...)
    • setupIntegrationTestRealm(...) now goes through withCachedRealmSetup(...)
    • additional cache key is derived from setup inputs (contents, realmURL, permissions, startMatrix) using stable serialization + hash

Why this approach

  • The previous approach required opt-in per module/test file, which is easy to miss and hard to keep consistent.
  • Centralizing at setupAcceptanceTestRealm / setupIntegrationTestRealm guarantees coverage for all current callers.
  • Using module name + hashed setup inputs gives safe cache partitioning between different setups.
  • Automatic teardown prevents snapshot accumulation from becoming an unbounded memory/perf issue during long test sessions.

Behavior impact

  • No test behavior changes intended.
  • Primary effect is faster repeated setup during test runs.
  • Snapshot state is now bounded by module lifecycle cleanup.

Notes

  • The branch also contains a minor whitespace-only cleanup in packages/host/tests/acceptance/host-mode-test.gts.
  • Full suite was intentionally not run locally due runtime constraints; CI should validate full coverage.

@IanCal IanCal marked this pull request as draft February 20, 2026 00:37
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 480ef88244

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return setup();
}
let result = await setup();
await dbAdapter.exportSnapshot(snapshotName);

Choose a reason for hiding this comment

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

P1 Badge Detach snapshots after export to avoid attach-limit failures

withCachedRealmSetup() now writes a new snapshot for every cache miss, but each snapshot stays attached until module teardown, so distinct setup variants accumulate throughout the module. SQLite permits only 10 attached databases; modules with many setupIntegrationTestRealm variants (for example packages/host/tests/integration/realm-test.gts, which calls it many times) can hit too many attached databases before moduleDone cleanup runs. This turns the cache into a hard test failure path once enough unique keys are seen in one module.

Useful? React with 👍 / 👎.

@github-actions
Copy link

Preview deployments

@github-actions
Copy link

Host Test Results

    1 files  ±0      1 suites  ±0   1h 16m 35s ⏱️ - 29m 47s
1 854 tests ±0  1 697 ✅  - 142  14 💤 ±0    0 ❌ ±  0  143 🔥 +142 
1 869 runs  ±0  1 569 ✅  - 284  14 💤 ±0  143 ❌ +142  143 🔥 +142 

For more details on these errors, see this check.

Results for commit 4677c09. ± Comparison against base commit e7401f2.

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