From 9e2992f8600710399858611dd713630a6d33e1ce Mon Sep 17 00:00:00 2001 From: ylm Date: Thu, 10 Sep 2026 19:40:32 -0400 Subject: [PATCH] Speed up card-source-endpoints suite: per-module boots + template dedupe 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) Claude-Session: https://claude.ai/code/session_014GsYGsuCqHJz9GAti4jheG --- .../tests/card-source-endpoints-test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/realm-server/tests/card-source-endpoints-test.ts b/packages/realm-server/tests/card-source-endpoints-test.ts index 5add92a9509..6b1fd802be4 100644 --- a/packages/realm-server/tests/card-source-endpoints-test.ts +++ b/packages/realm-server/tests/card-source-endpoints-test.ts @@ -78,9 +78,14 @@ module(basename(import.meta.filename), function () { module('card source GET request', function (_hooks) { module('public readable realm', function (hooks) { + // Read-only module: every test either reads fixture files that no + // test mutates or writes to a path unique to that test, so the boot + // is safe to share across tests. `mode: 'before'` boots the realm + // once for the module instead of once per test. setupPermissionedRealmCached(hooks, { fixture: 'realistic', realmURL, + mode: 'before', permissions: { '*': ['read'], '@node-test_realm:localhost': ['read', 'realm-owner'], @@ -498,9 +503,12 @@ module(basename(import.meta.filename), function () { }); module('permissioned realm', function (hooks) { + // Read-only module (auth checks on GET /person.gts): shared boot is + // safe since no test mutates realm state. setupPermissionedRealmCached(hooks, { fixture: 'simple', realmURL, + mode: 'before', permissions: { john: ['read'], '@node-test_realm:localhost': ['read', 'realm-owner'], @@ -550,9 +558,12 @@ module(basename(import.meta.filename), function () { module('card source HEAD request', function (_hooks) { module('public readable realm', function (hooks) { + // Read-only module: HEAD requests plus one write to a unique path + // (notes.md), so the boot is safe to share across tests. setupPermissionedRealmCached(hooks, { fixture: 'simple', realmURL, + mode: 'before', permissions: { '*': ['read'], '@node-test_realm:localhost': ['read', 'realm-owner'], @@ -1149,6 +1160,10 @@ module(basename(import.meta.filename), function () { }); module('public writable realm with size limit', function (hooks) { + // Carry the same file/audio/video limits as the binary size-limit + // module below so both share one cached template (the template cache + // key includes the limits). The audio/video limits are inert for this + // module's single .gts test but let it dedupe the template build. setupPermissionedRealmCached(hooks, { fixture: 'simple', realmURL, @@ -1157,6 +1172,8 @@ module(basename(import.meta.filename), function () { '@node-test_realm:localhost': ['read', 'realm-owner'], }, fileSizeLimitBytes: 512, + audioSizeLimitBytes: 2048, + videoSizeLimitBytes: 8192, onRealmSetup, });