CS-10009 PR 1: blank/simple fixtures + fixture helper option#4772
CS-10009 PR 1: blank/simple fixtures + fixture helper option#4772lukemelia wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces named realm test fixtures (blank, simple, and the existing realistic) to support the CS-10009 effort to consolidate and right-size realm-server test realms. It adds fixture resolution + selection plumbing to the realm-server test helpers and migrates two representative tests to use the new fixture option end-to-end.
Changes:
- Added
RealmFixtureName+fixtureDir()and introduced afixture?: ...option to permissioned realm setup helpers (single and multi-realm), including mutual exclusivity withfileSystem. - Implemented new on-disk fixture directories under
packages/realm-server/tests/fixtures/{blank,simple}. - Migrated one consumer to
fixture: 'blank'and one consumer tofixture: 'simple'to exercise the new behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/realm-server/tests/server-endpoints/queue-status-test.ts | Switches from fileSystem: {} to the new fixture: 'blank' path. |
| packages/realm-server/tests/realm-endpoints/invalidate-urls-test.ts | Pins the realm content to fixture: 'simple' to ensure an indexed row exists. |
| packages/realm-server/tests/helpers/index.ts | Adds fixture naming/resolution and integrates fixture copying + caching semantics. |
| packages/realm-server/tests/fixtures/blank/.realm.json | Adds a minimal “blank” fixture realm. |
| packages/realm-server/tests/fixtures/simple/.realm.json | Adds the realm marker/config for the “simple” fixture. |
| packages/realm-server/tests/fixtures/simple/person.gts | Adds a minimal card definition for the “simple” fixture. |
| packages/realm-server/tests/fixtures/simple/person-1.json | Adds a minimal instance to ensure indexable content exists. |
| packages/realm-server/tests/fixtures/simple/sample.md | Adds a non-card file to exercise non-card indexing/handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Canonicalize the fixture choice so callers that omit `fixture` (and | ||
| // implicitly get 'realistic') share a cache with callers that pass | ||
| // `fixture: 'realistic'` explicitly. When `fileSystem` is provided, the | ||
| // fixture choice is irrelevant — fileSystem's own hash carries the | ||
| // content. | ||
| let resolvedFixture = options.fileSystem | ||
| ? null | ||
| : (options.fixture ?? 'realistic'); |
Host Test Results 1 files ±0 1 suites ±0 1h 45m 23s ⏱️ - 1m 2s Results for commit edf4921. ± Comparison against earlier commit c73b533. For more details on these errors, see this check. Realm Server Test Results 1 files ±0 1 suites ±0 12m 52s ⏱️ +59s Results for commit edf4921. ± Comparison against earlier commit c73b533. |
Introduces three named realm fixtures under tests/fixtures/ and threads
a `fixture?: 'blank' | 'simple' | 'realistic'` option through the
realm-server test helpers, so test files can opt into the minimum
realm content they actually need instead of dragging in the full
tests/cards/ kitchen sink on every run.
New fixtures
- fixtures/blank/ — just `.realm.json: {}`. For tests that only need
a working realm with no card content. parseRealmInfo tolerates an
empty config (defaults `name = 'Unnamed Workspace'`, etc.).
- fixtures/simple/ — one card def (Person), one instance (person-1),
one non-card file (sample.md). For tests that need *some* indexed
content but nothing exotic.
- 'realistic' — still resolves to the historical tests/cards/
path; will be `git mv`-ed to fixtures/realistic/ in the final PR of
CS-10009 to keep this diff focused.
Helper changes (packages/realm-server/tests/helpers/index.ts)
- New `RealmFixtureName` type and `fixtureDir(name)` resolver.
- `setupPermissionedRealm{,Cached}` and `setupPermissionedRealms{,Cached}`
gain a `fixture?` option. `fileSystem` and `fixture` are mutually
exclusive — passing both throws.
- The single-realm path's implicit default stays `'realistic'` so every
caller that omits both stays green; the final PR flips this default
to `'blank'` once each consumer has declared what it actually needs.
- The plural path keeps its "no fixture, no copy" default (per-realm
fileSystem was already optional there) and only copies a fixture
folder when one is named.
- `permissionedRealmTemplateCacheKey` canonicalizes the fixture choice
so callers that omit `fixture` share a cache with callers that pass
`fixture: 'realistic'` explicitly; when `fileSystem` is provided, the
fileSystem hash carries the content and fixture goes to null.
Consumer migrations (one per fixture, to exercise the plumbing
end-to-end)
- server-endpoints/queue-status-test.ts: `fileSystem: {}` → `fixture: 'blank'`.
Behaviorally equivalent — the realm boots against an empty workspace
either way — but exercises the on-disk fixture path.
- realm-endpoints/invalidate-urls-test.ts: implicit-default realistic
→ `fixture: 'simple'`. aKnownIndexedURL() only needs *some* indexed
row, which the Person instance in fixtures/simple/ provides.
Out of scope (per the CS-10009 plan)
- Migrating the remaining ~38 callers (one PR per directory follows).
- Renaming tests/cards/ → tests/fixtures/realistic/ and flipping the
default to 'blank'.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The cached setup helpers compute a cache key that canonicalizes
`fixture` to null whenever `fileSystem` is present, so an invalid
call passing both hashes the same as a valid `fileSystem`-only call
and silently reuses that template. The mutual-exclusivity throw in
startPermissionedRealm{,s}Fixture only fires later at beforeEach,
after the misleading cache reuse.
Mirror the check up front in setupPermissionedRealm{,s}Cached so an
invalid combo errors at test-module load time, before any cache
work runs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
c73b533 to
edf4921
Compare
BenchmarksPer the PR plan ("Per-file timing/memory measurements (will be added once #4768 lands)"), here are the results. Methodology:
|
| Wall (median of 3) | Peak RSS (median of 3) | |
|---|---|---|
before (fileSystem: {}) |
62.61s | 483 MB |
after (fixture: 'blank') |
59.04s | 491 MB |
| Δ | -3.57s (-5.7%) | +8 MB (+1.7%) |
No regression. Modest wall-time savings — the fixture path skips the synchronous writeFileSync of fileSystem entries.
realm-endpoints/invalidate-urls-test
Migrated from the implicit-default 'realistic' (kitchen-sink tests/cards/) → fixture: 'simple' (1 card + 1 instance + 1 markdown file).
I could not produce a clean measurement on local hardware: single runs of this test against either fixture exceeded 10 minutes wall-clock with measure-test-file.sh, with the cold prerender pool + Chrome spawn dominating wall time at the cached-template build step. The cost is real but it's not what this PR is about — the fixture content difference is buried under the per-process bootstrap overhead.
A clean comparison would need a different measurement approach: e.g., a microbench that calls setupPermissionedRealmCached once and measures just the template-build delta between fixtures, holding boot/Chrome constants. Filed as a follow-up consideration; not gating this PR.
Setup
- Both worktrees on
pnpm 11.0.9(mise-resolved from.mise.toml). - Local: Apple Silicon, postgres in Docker via the test scripts.
First slice of CS-10009. Adds the named-fixture plumbing and migrates one consumer per fixture to exercise it end-to-end.
What's in this PR
New fixture folders under
packages/realm-server/tests/fixtures/blank/.realm.json({}) onlysimple/.realm.json,person.gts(one card def),person-1.json(one instance),sample.md(one non-card file)realistic/fixtureDir('realistic')still points attests/cards/— the rename is deferred to the final PR of CS-10009 to keep this diff focused.I verified during research that a realm boots against an empty directory —
parseRealmInfoatrealm.ts:5327reads.realm.jsonwith a missing-file-tolerant code path, andtests/server-endpoints/queue-status-test.ts:24already passedfileSystem: {}in CI without issue.blank/keeps a.realm.json: {}purely to (a) match the existingtests/cards/.realm.jsonconvention and (b) keep the folder tracked in git without a.gitkeep.Helper changes (
tests/helpers/index.ts)RealmFixtureNametype andfixtureDir(name)resolver.setupPermissionedRealm{,Cached}andsetupPermissionedRealms{,Cached}gain afixture?option.fileSystemandfixtureare mutually exclusive — passing both throws.'realistic'so every existing caller that omits both stays green; the final PR of CS-10009 flips this default to'blank'once each consumer has declared what it actually needs.fileSystemwas already optional there) and only copies a fixture folder when one is named.permissionedRealmTemplateCacheKeycanonicalizes the fixture choice so callers that omitfixtureshare a cache with callers that passfixture: 'realistic'explicitly. WhenfileSystemis provided, the fileSystem hash already carries the content andfixturegoes tonull.Consumer migrations (one per fixture)
server-endpoints/queue-status-test.ts:fileSystem: {}→fixture: 'blank'. Behaviorally equivalent (the realm boots against an empty workspace either way), but exercises the on-disk fixture path.realm-endpoints/invalidate-urls-test.ts: implicit-default realistic →fixture: 'simple'.aKnownIndexedURL()only needs some indexed row, which the Person instance infixtures/simple/provides.Out of scope (follow-up PRs)
realm-endpoints/,server-endpoints/,tests/root.tests/cards/→tests/fixtures/realistic/and flipping the default to'blank'.scripts/measure-test-file.sh).Test plan
pnpm lint(eslint + ember-tsc) onpackages/realm-serveris clean.tests/server-endpoints/queue-status-test.tsagainstfixture: 'blank'.tests/realm-endpoints/invalidate-urls-test.tsagainstfixture: 'simple'.'realistic'→ sametests/cards/content as before).🤖 Generated with Claude Code