Skip to content

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

Open
lukemelia wants to merge 2 commits into
mainfrom
cs-10009-fixtures-and-helper
Open

CS-10009 PR 1: blank/simple fixtures + fixture helper option#4772
lukemelia wants to merge 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 on lines +2062 to +2069
// 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');
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Host Test Results

    1 files  ±0      1 suites  ±0   1h 45m 23s ⏱️ - 1m 2s
2 654 tests ±0  2 638 ✅  - 1  15 💤 ±0  0 ❌ ±0  1 🔥 +1 
2 673 runs  ±0  2 656 ✅  - 2  15 💤 ±0  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

Benchmarks

Per the PR plan ("Per-file timing/memory measurements (will be added once #4768 lands)"), here are the results. Methodology: packages/realm-server/scripts/measure-test-file.sh <file> <runs> (now on main), comparing main (HEAD = 6eec89bbc5) vs. this branch rebased onto that main.

server-endpoints/queue-status-test

fileSystem: {}fixture: 'blank'. Both produce an empty realm, so this is a sanity check that the fixture-on-disk path doesn't add overhead vs. the in-memory empty default.

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.

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.

2 participants