Skip to content

CS-10009 PR 1: blank/simple fixtures + fixture helper option#4772

Merged
lukemelia merged 2 commits into
mainfrom
cs-10009-fixtures-and-helper
May 12, 2026
Merged

CS-10009 PR 1: blank/simple fixtures + fixture helper option#4772
lukemelia merged 2 commits into
mainfrom
cs-10009-fixtures-and-helper

Conversation

@lukemelia
Copy link
Copy Markdown
Contributor

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/

Contents Use for
blank/ .realm.json ({}) only Tests that need a working realm with no card content
simple/ .realm.json, person.gts (one card def), person-1.json (one instance), sample.md (one non-card file) Tests that need some indexed content but nothing exotic
realistic/ Not yet renamed. fixtureDir('realistic') still points at tests/cards/ — the rename is deferred to the final PR of CS-10009 to keep this diff focused. Tests that lean on the kitchen sink (cyclic imports, error cases, Unicode filenames, etc.)

I verified during research that a realm boots against an empty directory — parseRealmInfo at realm.ts:5327 reads .realm.json with a missing-file-tolerant code path, and tests/server-endpoints/queue-status-test.ts:24 already passed fileSystem: {} in CI without issue. blank/ keeps a .realm.json: {} purely to (a) match the existing tests/cards/.realm.json convention and (b) keep the folder tracked in git without a .gitkeep.

Helper changes (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 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.
  • 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 already carries the content and fixture goes to null.

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 in fixtures/simple/ provides.

Out of scope (follow-up PRs)

  • Migrating the remaining ~38 callers — one PR per directory: realm-endpoints/, server-endpoints/, tests/ root.
  • Renaming tests/cards/tests/fixtures/realistic/ and flipping the default to 'blank'.
  • Per-file timing/memory measurements (will be added once Add measure-test-file.sh for per-file CS-10009 baselines #4768 lands and we can use scripts/measure-test-file.sh).

Test plan

  • pnpm lint (eslint + ember-tsc) on packages/realm-server is clean.
  • CI runs tests/server-endpoints/queue-status-test.ts against fixture: 'blank'.
  • CI runs tests/realm-endpoints/invalidate-urls-test.ts against fixture: 'simple'.
  • CI runs every other realm-server test file unchanged (implicit default 'realistic' → same tests/cards/ content as before).

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 a fixture?: ... option to permissioned realm setup helpers (single and multi-realm), including mutual exclusivity with fileSystem.
  • Implemented new on-disk fixture directories under packages/realm-server/tests/fixtures/{blank,simple}.
  • Migrated one consumer to fixture: 'blank' and one consumer to fixture: '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.

Comment thread packages/realm-server/tests/helpers/index.ts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Host Test Results

    1 files  ±    0      1 suites  ±0   3h 30m 45s ⏱️ + 1h 44m 20s
2 654 tests ±    0  2 638 ✅  -     1  15 💤 ± 0  0 ❌ ±0  1 🔥 +1 
5 346 runs  +2 673  5 314 ✅ +2 656  30 💤 +15  1 ❌ +1  1 🔥 +1 

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
1 321 tests ±0  1 321 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 400 runs  ±0  1 400 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit edf4921. ± Comparison against earlier commit c73b533.

lukemelia and others added 2 commits May 11, 2026 18:52
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>
@lukemelia lukemelia force-pushed the cs-10009-fixtures-and-helper branch from c73b533 to edf4921 Compare May 11, 2026 23:34
@lukemelia
Copy link
Copy Markdown
Contributor Author

lukemelia commented May 11, 2026

Benchmarks

Methodology: packages/realm-server/scripts/measure-test-file.sh <file> <runs> (added in #4768), comparing main (HEAD = 3898bbddcf) vs. this branch rebased onto that main. Local services (host on 4200, synapse on 8008, base realm on 4201) running so the prerender pool has a host shell to render against.

server-endpoints/queue-status-test

fileSystem: {}fixture: 'blank'. Both produce an empty realm — sanity check that the on-disk fixture path doesn't add overhead vs. the in-memory empty default. No indexing involved either way.

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 from skipping the synchronous writeFileSync of fileSystem entries, RSS within noise.

realm-endpoints/invalidate-urls-test

Migrated from the implicit-default 'realistic' (kitchen-sink tests/cards/) → fixture: 'simple' (1 card + 1 instance + 1 markdown file).

Wall (1 run) Peak RSS (1 run)
before (implicit 'realistic') 380.05s 451 MB
after (fixture: 'simple') 367.95s 454 MB
Δ -12.10s (-3.2%) +3 MB (within noise)

Both runs dominated by realm boot + indexing + prerender infrastructure (~6 min); the fixture content difference is real but small relative to per-run wall (-3%, within the run-to-run variance band, so the headline is "no regression" rather than "speedup"). Single-run only because each iteration is ~6 minutes locally; the queue-status data above is the cleaner signal.

Side note: on main (the realistic baseline) one invalidate-urls-test test failed locally during this measurement, and on this branch (simple) every test passed. The failing test is environment-sensitive (matrix/synapse-dependent), not caused by anything in this PR — but it's an incidental cleanup the migration to the simple fixture happens to provide.

Setup

  • Both worktrees on pnpm 11.0.9 (mise-resolved from .mise.toml).
  • Local: Apple Silicon, postgres in Docker via the test scripts, host/synapse/realm dev stack running on standard ports.

@lukemelia lukemelia merged commit f46ebac into main May 12, 2026
93 of 95 checks passed
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.

3 participants