Skip to content

Speed up the card-source-endpoints realm-server suite (per-module boots + template dedupe) - #6086

Merged
lukemelia merged 1 commit into
mainfrom
cs-12935-speed-up-the-card-source-endpoints-realm-server-suite-per
Sep 11, 2026
Merged

Speed up the card-source-endpoints realm-server suite (per-module boots + template dedupe)#6086
lukemelia merged 1 commit into
mainfrom
cs-12935-speed-up-the-card-source-endpoints-realm-server-suite-per

Conversation

@lukemelia

Copy link
Copy Markdown
Contributor

What

tests/card-source-endpoints-test.ts (55 tests) paid a full-stack realm boot per test — clone the template Postgres DB → tmp dir + fixture copy → construct a Worker → boot the RealmlogInToMatrix() → build a RealmServer → start a supertest server → tear down — because the harness default is mode: 'beforeEach'. It also built two distinct templates for size-limit modules that differ only by request-time limits.

This lands the two lowest-risk, highest-impact items from CS-12935.

1. mode: 'before' for the read-only modules

Boot once per module instead of once per test for the three modules that don't mutate shared realm state:

  • card source GET request › public readable realm (12 tests)
  • card source GET request › permissioned realm (4 tests)
  • card source HEAD request › public readable realm (3 tests)

Each test either reads fixture files that no test mutates or writes to a path unique to that test, so a shared boot stays order-independent. The harness (setupDB) already pairs before/after and clones the template DB once under mode: 'before', so this is a mechanical change that removes ~16 per-test boots.

2. Consolidate the two size-limit templates

public writable realm with size limit now carries the same {file: 512, audio: 2048, video: 8192} limits as public writable realm with size limit for binary, so both hash to one cached template. The template cache key includes the limits, but limits are request-time config and don't affect indexed content, so the extra two are inert for the .gts test and collapse two identical builds into one.

Deferred (follow-ups from the ticket)

  • Fixture downgrade (GET public-readable realistic → simple): the simple fixture lacks person-with-error.gts and hello.test.gts that the module reads, and adding them would perturb the shared simple fixture for other modules. Once mode: 'before' collapses that module to a single boot, the realistic-vs-simple boot differential is paid only once, so the remaining value is small.
  • Worker-less boots for read-only modules, Matrix-login memoization, and a pooled-realm harness — larger harness lifts.

Verification

Changes are lint-clean. End-to-end timing was intended via scripts/measure-test-file.sh per the ticket's method note, but local runs are currently blocked by an unrelated stale local dev stack; CI runs this suite against a built host and is the authoritative source for the green run and before/after shard timings. The mode: 'before' path is already exercised by existing suites, and the size-limit consolidation preserves each module's own runtime limits (only the shared template is deduped).

🤖 Generated with Claude Code

The card-source-endpoints suite paid a full-stack realm boot per test
(clone template DB, build a Worker, boot the Realm, log in to Matrix,
start a supertest server, tear down) across all 55 tests, and rebuilt a
distinct template for two size-limit modules that differed only by
request-time limits.

Boot the three read-only modules once per module instead of once per
test via `mode: 'before'`:
  - card source GET > public readable realm (12 tests)
  - card source GET > permissioned realm (4 tests)
  - card source HEAD > public readable realm (3 tests)
Each either reads fixture files no test mutates or writes to a path
unique to that test, so a shared boot stays order-independent. The
harness already pairs before/after and clones the template DB once for
`mode: 'before'`, so this removes ~16 per-test boots for a mechanical
change.

Give the .gts size-limit module the same file/audio/video limits as the
binary size-limit module so both hash to one cached template (the
template cache key includes the limits, which are request-time config
and do not affect indexed content). The extra limits are inert for the
.gts test and collapse two identical template builds into one.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014GsYGsuCqHJz9GAti4jheG
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Host Test Results

    1 files      1 suites   2h 5m 13s ⏱️
4 734 tests 4 720 ✅ 14 💤 0 ❌
4 749 runs  4 735 ✅ 14 💤 0 ❌

Results for commit 9e2992f.

Realm Server Test Results

    1 files    210 suites   1h 14m 0s ⏱️
2 764 tests 2 764 ✅ 0 💤 0 ❌
2 803 runs  2 803 ✅ 0 💤 0 ❌

Results for commit 9e2992f.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved blocking issues were identified.

Pull request overview

This pull request speeds up card-source endpoint tests by sharing read-only realm boots and deduplicating equivalent templates.

Changes:

  • Uses mode: 'before' for three read-only modules.
  • Reuses cached templates with aligned size limits.
File summaries
File Summary
packages/realm-server/tests/card-source-endpoints-test.ts Updates test setup and size-limit template reuse.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@lukemelia
lukemelia requested review from a team and backspace September 11, 2026 00:29
@lukemelia
lukemelia merged commit d8f2e3d into main Sep 11, 2026
66 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