diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c8b43656be..8fed1d8ddc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -419,60 +419,66 @@ jobs: -d '{"context":"Matrix Playwright tests report","description":"'"$description"'","target_url":"'"$PLAYWRIGHT_REPORT_URL"'","state":"'"$state"'"}' realm-server-test: - name: Realm Server Tests + name: Realm Server Tests (shard ${{ matrix.shard }}) needs: [change-check, test-web-assets] if: needs.change-check.outputs.realm-server == 'true' || github.ref == 'refs/heads/main' || needs.change-check.outputs.run_all == 'true' runs-on: ubuntu-latest concurrency: - group: realm-server-test-${{ matrix.testModule }}-${{ github.head_ref || github.run_id }} + group: realm-server-test-${{ matrix.shard }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true strategy: fail-fast: false matrix: - testModule: - [ - "auth-client-test.ts", - "billing-test.ts", - "card-dependencies-endpoint-test.ts", - "card-endpoints-test.ts", - "card-source-endpoints-test.ts", - "definition-lookup-test.ts", - "file-watcher-events-test.ts", - "indexing-test.ts", - "transpile-test.ts", - "module-syntax-test.ts", - "permissions/permission-checker-test.ts", - "prerendering-test.ts", - "prerender-server-test.ts", - "prerender-manager-test.ts", - "prerender-proxy-test.ts", - "remote-prerenderer-test.ts", - "queue-test.ts", - "realm-endpoints/dependencies-test.ts", - "realm-endpoints/directory-test.ts", - "realm-endpoints/info-test.ts", - "realm-endpoints/lint-test.ts", - "realm-endpoints/mtimes-test.ts", - "realm-endpoints/permissions-test.ts", - "realm-endpoints/publishability-test.ts", - "realm-endpoints/search-test.ts", - "realm-endpoints/user-test.ts", - "realm-endpoints-test.ts", - "search-prerendered-test.ts", - "types-endpoint-test.ts", - "server-endpoints-test.ts", - "server-endpoints/search-test.ts", - "virtual-network-test.ts", - "atomic-endpoints-test.ts", - "request-forward-test.ts", - "publish-unpublish-realm-test.ts", - "boxel-domain-availability-test.ts", - "claim-boxel-domain-test.ts", - "delete-boxel-claimed-domain-test.ts", - "get-boxel-claimed-domain-test.ts", - "realm-auth-test.ts", - "queries-test.ts", - ] + include: + - shard: 1 + testModules: + - server-endpoints-test.ts + - atomic-endpoints-test.ts + - request-forward-test.ts + - realm-endpoints/info-test.ts + - realm-endpoints/user-test.ts + - file-watcher-events-test.ts + - types-endpoint-test.ts + - prerender-manager-test.ts + - prerender-proxy-test.ts + - transpile-test.ts + - shard: 2 + testModules: + - card-endpoints-test.ts + - publish-unpublish-realm-test.ts + - realm-endpoints/lint-test.ts + - claim-boxel-domain-test.ts + - realm-endpoints/publishability-test.ts + - boxel-domain-availability-test.ts + - realm-endpoints/dependencies-test.ts + - queue-test.ts + - remote-prerenderer-test.ts + - permissions/permission-checker-test.ts + - shard: 3 + testModules: + - realm-endpoints-test.ts + - prerendering-test.ts + - search-prerendered-test.ts + - card-dependencies-endpoint-test.ts + - delete-boxel-claimed-domain-test.ts + - get-boxel-claimed-domain-test.ts + - realm-endpoints/mtimes-test.ts + - billing-test.ts + - virtual-network-test.ts + - module-syntax-test.ts + - shard: 4 + testModules: + - indexing-test.ts + - card-source-endpoints-test.ts + - realm-endpoints/search-test.ts + - server-endpoints/search-test.ts + - realm-endpoints/permissions-test.ts + - realm-endpoints/directory-test.ts + - definition-lookup-test.ts + - prerender-server-test.ts + - realm-auth-test.ts + - auth-client-test.ts + - queries-test.ts steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 - uses: ./.github/actions/init @@ -506,7 +512,7 @@ jobs: run: pnpm test:wait-for-servers working-directory: packages/realm-server env: - TEST_MODULE: ${{matrix.testModule}} + TEST_MODULES: ${{ join(matrix.testModules, '|') }} - name: Print realm server logs if: always() run: cat /tmp/server.log @@ -514,7 +520,7 @@ jobs: id: artifact_name if: always() run: | - export SAFE_ARTIFACT_NAME=$(echo ${{ matrix.testModule }} | sed 's/[/]/_/g') + export SAFE_ARTIFACT_NAME=shard-${{ matrix.shard }} echo "artifact_name=$SAFE_ARTIFACT_NAME" >> "$GITHUB_OUTPUT" - name: Upload realm server log uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # 4.6.1 diff --git a/README.md b/README.md index 9a8d18a99c..f94bfbda4c 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ You can also use `start:development` if you want the functionality of `start:all Optional environment variables for `start:development`: -- `USE_EXTERNAL_CATALOG=1` to load `/catalog` from `packages/catalog/contents` (cloned from the `boxel-catalog` repo). +- `USE_EXTERNAL_CATALOG=1` to load `/catalog` from `packages/catalog/contents` (cloned from the `boxel-catalog` repo). ### Card Pre-rendering @@ -394,12 +394,15 @@ The tests are available at `http://localhost:4200/tests` ### Realm Server Node tests -First make sure to generate the host app's `dist/` output in order to support card pre-rendering by first starting the host app (instructions above). If you want to make the host app's `dist/` output without starting the host app, you can run `pnpm build` in the host app's workspace. - To run the `packages/realm-server/` workspace tests start: -1. `pnpm start:all` in the `packages/realm-server/` to serve _both_ the base realm and the realm that serves the test cards for node. -2. Run `pnpm test` in the `packages/realm-server/` workspace to run the realm node tests. `TEST_MODULE=realm-endpoints-test.ts pnpm test-module` is an example of how to run a single test module. +1. The host application on port 4200. You can do this by running `pnpm start` in the `packages/host/` workspace, or if you have a built folder you can serve it with a static server with `pnpm serve:dist`. +2. The base realm and associated workers, postgres and synapse. You can do this by running `pnpm start:all` in the `packages/realm-server/` workspace, or `pnpm:start-services-for-host-tests` for a more lightweight setup. +3. Run the realm server tests: + +- `pnpm test` in the `packages/realm-server/` workspace to run the realm node tests in full (~1hr). +- `TEST_MODULES="types-endpoint-test.ts|another-test-module.ts" pnpm test` in the `packages/realm-server/` workspace to run tests for a subset of modules. +- `TEST_MODULE="types-endpoint-test.ts" pnpm test-module` in the `packages/realm-server/` workspace to run tests for a specific module. ### Boxel UI diff --git a/packages/realm-server/package.json b/packages/realm-server/package.json index efaaab3aff..479a5a4c3e 100644 --- a/packages/realm-server/package.json +++ b/packages/realm-server/package.json @@ -85,7 +85,7 @@ "start:smtp": "cd ../matrix && pnpm assert-smtp-running", "start:pg": "./scripts/start-pg.sh", "stop:pg": "./scripts/stop-pg.sh", - "test:wait-for-servers": "WAIT_ON_TIMEOUT=900000 NODE_NO_WARNINGS=1 start-server-and-test 'pnpm run wait' 'http-get://localhost:4201/base/_readiness-check?acceptHeader=application%2Fvnd.api%2Bjson' 'pnpm run wait' 'http-get://localhost:4202/node-test/_readiness-check?acceptHeader=application%2Fvnd.api%2Bjson|http://localhost:8008|http://localhost:5001' 'test-module'", + "test:wait-for-servers": "WAIT_ON_TIMEOUT=900000 NODE_NO_WARNINGS=1 start-server-and-test 'pnpm run wait' 'http-get://localhost:4201/base/_readiness-check?acceptHeader=application%2Fvnd.api%2Bjson' 'pnpm run wait' 'http-get://localhost:4202/node-test/_readiness-check?acceptHeader=application%2Fvnd.api%2Bjson|http://localhost:8008|http://localhost:5001' 'test'", "setup:base-in-deployment": "mkdir -p /persistent/base && rsync --dry-run --itemize-changes --checksum --recursive --delete ../base/. /persistent/base/ && rsync --checksum --recursive --delete ../base/. /persistent/base/", "setup:experiments-in-deployment": "mkdir -p /persistent/experiments && rsync --dry-run --itemize-changes --checksum --recursive ../experiments-realm/. /persistent/experiments/ && rsync --checksum --recursive ../experiments-realm/. /persistent/experiments/", "setup:catalog-in-deployment": "mkdir -p /persistent/catalog && rsync --dry-run --itemize-changes --checksum --recursive --delete ../catalog-realm/. /persistent/catalog/ && rsync --checksum --recursive --delete ../catalog-realm/. /persistent/catalog/", diff --git a/packages/realm-server/scripts/lint-test-shards.ts b/packages/realm-server/scripts/lint-test-shards.ts index f0df182e83..4576ce5225 100755 --- a/packages/realm-server/scripts/lint-test-shards.ts +++ b/packages/realm-server/scripts/lint-test-shards.ts @@ -19,18 +19,49 @@ function getCiTestModules(yamlFilePath: string) { const yamlContent = readFileSync(yamlFilePath, 'utf8'); const yamlData = yaml.load(yamlContent) as Record; - const shardIndexes: string[] = - yamlData?.jobs?.['realm-server-test']?.strategy?.matrix?.testModule; + const matrix = yamlData?.jobs?.['realm-server-test']?.strategy?.matrix; + const testModules = matrix?.testModule; - if (!Array.isArray(shardIndexes)) { + if (Array.isArray(testModules)) { + return testModules; + } + + const include = matrix?.include; + if (!Array.isArray(include)) { throw new Error( - `Invalid 'jobs.realm-server-test.strategy.matrix.testModule' format in the YAML file.`, + `Invalid 'jobs.realm-server-test.strategy.matrix' format in the YAML file.`, ); } - return shardIndexes; + const modules = new Set(); + const invalidEntries: number[] = []; + include.forEach((entry: Record, index: number) => { + const entryModules = entry?.testModules; + if (Array.isArray(entryModules)) { + entryModules.forEach((moduleName: string) => modules.add(moduleName)); + return; + } + if (typeof entryModules === 'string') { + entryModules + .split(/[,\s]+/) + .filter(Boolean) + .forEach((moduleName) => modules.add(moduleName)); + return; + } + invalidEntries.push(index); + }); + + if (invalidEntries.length > 0) { + throw new Error( + `Invalid 'jobs.realm-server-test.strategy.matrix.include[*].testModules' entries at indexes: ${invalidEntries.join(', ')}`, + ); + } + + return Array.from(modules); } catch (error: any) { - console.error(`Error reading shardIndex from YAML file: ${error.message}`); + console.error( + `Error reading test modules from YAML file: ${error.message}`, + ); process.exit(1); } } diff --git a/packages/realm-server/scripts/run-test-modules.js b/packages/realm-server/scripts/run-test-modules.js new file mode 100644 index 0000000000..cf02471381 --- /dev/null +++ b/packages/realm-server/scripts/run-test-modules.js @@ -0,0 +1,57 @@ +#!/usr/bin/env node +'use strict'; + +const { spawnSync } = require('node:child_process'); + +function buildModuleFilter(modulesToMatch) { + const escaped = modulesToMatch + .map((moduleName) => escapeRegex(moduleName)) + .join('|'); + const pattern = `^(?:${escaped})(?:\\s>\\s|:)`; + return `/${pattern}/`; +} + +function escapeRegex(value) { + return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\//g, '\\/'); +} + +const rawModules = process.env.TEST_MODULES ?? ''; +const cleanedRaw = rawModules.trim(); + +if (!cleanedRaw) { + console.error('TEST_MODULES must be set.'); + process.exit(1); +} + +const modules = cleanedRaw + .split(/[|,]/) + .map((value) => value.trim()) + .filter(Boolean) + .map((value) => value.replace(/^['"]+|['"]+$/g, '')); + +if (modules.length === 0) { + console.error('No module names found in TEST_MODULES.'); + process.exit(1); +} + +const args = ['--require', 'ts-node/register/transpile-only']; + +args.push('--filter', buildModuleFilter(modules)); + +args.push('tests/index.ts'); + +const qunitBin = require.resolve('qunit/bin/qunit.js'); +const result = spawnSync(process.execPath, [qunitBin, ...args], { + stdio: 'inherit', + env: process.env, +}); + +if (typeof result.status === 'number') { + process.exit(result.status); +} + +if (result.error) { + console.error(result.error); +} + +process.exit(1); diff --git a/packages/realm-server/tests/atomic-endpoints-test.ts b/packages/realm-server/tests/atomic-endpoints-test.ts index caf8498c86..6fc8b9e5b4 100644 --- a/packages/realm-server/tests/atomic-endpoints-test.ts +++ b/packages/realm-server/tests/atomic-endpoints-test.ts @@ -8,19 +8,13 @@ import { type LooseSingleCardDocument, SupportedMimeType, } from '@cardstack/runtime-common'; -import { - setupBaseRealmServer, - setupPermissionedRealm, - matrixURL, - testRealmHref, - createJWT, -} from './helpers'; +import { setupPermissionedRealm, testRealmHref, createJWT } from './helpers'; import '@cardstack/runtime-common/helpers/code-equality-assertion'; module(basename(__filename), function () { module( 'Realm-specific Endpoints: can make request to post /_atomic', - function (hooks) { + function () { let testRealm: Realm; let testRealmAdapter: RealmAdapter; let request: SuperTest; @@ -37,8 +31,6 @@ module(basename(__filename), function () { request = args.request; } - setupBaseRealmServer(hooks, matrixURL); - module('writes', function (hooks) { setupPermissionedRealm(hooks, { permissions: { diff --git a/packages/realm-server/tests/boxel-domain-availability-test.ts b/packages/realm-server/tests/boxel-domain-availability-test.ts index 02414ce345..c47edb70ee 100644 --- a/packages/realm-server/tests/boxel-domain-availability-test.ts +++ b/packages/realm-server/tests/boxel-domain-availability-test.ts @@ -10,7 +10,6 @@ import { createVirtualNetwork, matrixURL, closeServer, - setupBaseRealmServer, } from './helpers'; import type { RealmServerTokenClaim } from '../utils/jwt'; import { createJWT as createRealmServerJWT } from '../utils/jwt'; @@ -25,8 +24,6 @@ const testRealmURL = new URL('http://127.0.0.1:0/test/'); module(basename(__filename), function () { module('boxel domain availability endpoint', function (hooks) { - setupBaseRealmServer(hooks, matrixURL); - let testRealmServer: Server; let request: SuperTest; let dir: DirResult; diff --git a/packages/realm-server/tests/card-dependencies-endpoint-test.ts b/packages/realm-server/tests/card-dependencies-endpoint-test.ts index 896a7baa6d..69465825de 100644 --- a/packages/realm-server/tests/card-dependencies-endpoint-test.ts +++ b/packages/realm-server/tests/card-dependencies-endpoint-test.ts @@ -5,147 +5,133 @@ import type { Server } from 'http'; import type { DirResult } from 'tmp'; import type { Realm } from '@cardstack/runtime-common'; -import { - setupBaseRealmServer, - setupPermissionedRealm, - matrixURL, - testRealmHref, - createJWT, -} from './helpers'; +import { setupPermissionedRealm, testRealmHref, createJWT } from './helpers'; import '@cardstack/runtime-common/helpers/code-equality-assertion'; module(basename(__filename), function () { - module( - 'Realm-specific Endpoints | card dependencies requests', - function (hooks) { - let testRealm: Realm; - let request: SuperTest; - - function onRealmSetup(args: { - testRealm: Realm; - testRealmHttpServer: Server; - request: SuperTest; - dir: DirResult; - }) { - testRealm = args.testRealm; - request = args.request; - } - - setupBaseRealmServer(hooks, matrixURL); - - module('card dependencies GET request', function (_hooks) { - module('public readable realm', function (hooks) { - setupPermissionedRealm(hooks, { - permissions: { - '*': ['read'], - }, - onRealmSetup, - }); - - test('serves the request', async function (assert) { - let response = await request - .get(`/_dependencies?url=${testRealm.url}person`) - .set('Accept', 'application/json') - .set( - 'Authorization', - `Bearer ${createJWT(testRealm, 'john', ['read'])}`, - ); - - assert.strictEqual(response.status, 200, 'HTTP 200 status'); - assert.strictEqual( - response.get('X-boxel-realm-url'), - testRealmHref, - 'realm url header is correct', - ); - assert.strictEqual( - response.get('X-boxel-realm-public-readable'), - 'true', - 'realm is public readable', + module('Realm-specific Endpoints | card dependencies requests', function () { + let testRealm: Realm; + let request: SuperTest; + + function onRealmSetup(args: { + testRealm: Realm; + testRealmHttpServer: Server; + request: SuperTest; + dir: DirResult; + }) { + testRealm = args.testRealm; + request = args.request; + } + + module('card dependencies GET request', function (_hooks) { + module('public readable realm', function (hooks) { + setupPermissionedRealm(hooks, { + permissions: { + '*': ['read'], + }, + onRealmSetup, + }); + + test('serves the request', async function (assert) { + let response = await request + .get(`/_dependencies?url=${testRealm.url}person`) + .set('Accept', 'application/json') + .set( + 'Authorization', + `Bearer ${createJWT(testRealm, 'john', ['read'])}`, ); - let result: string[] = JSON.parse(response.text.trim()); + assert.strictEqual(response.status, 200, 'HTTP 200 status'); + assert.strictEqual( + response.get('X-boxel-realm-url'), + testRealmHref, + 'realm url header is correct', + ); + assert.strictEqual( + response.get('X-boxel-realm-public-readable'), + 'true', + 'realm is public readable', + ); + + let result: string[] = JSON.parse(response.text.trim()); + + assert.ok( + result.includes('http://127.0.0.1:4444/person'), + 'person.gts is a dependency', + ); + }); - assert.ok( - result.includes('http://127.0.0.1:4444/person'), - 'person.gts is a dependency', - ); - }); - - test('serves the request with a .json extension', async function (assert) { - let response = await request - .get(`/_dependencies?url=${testRealm.url}person.json`) - .set('Accept', 'application/json') - .set( - 'Authorization', - `Bearer ${createJWT(testRealm, 'john', ['read'])}`, - ); - let result: string[] = JSON.parse(response.text.trim()); - - assert.ok( - result.includes('http://127.0.0.1:4444/person'), - 'person.gts is a dependency', + test('serves the request with a .json extension', async function (assert) { + let response = await request + .get(`/_dependencies?url=${testRealm.url}person.json`) + .set('Accept', 'application/json') + .set( + 'Authorization', + `Bearer ${createJWT(testRealm, 'john', ['read'])}`, ); - }); + let result: string[] = JSON.parse(response.text.trim()); - test('gives 404 for a non-existent card', async function (assert) { - let response = await request - .get(`/_dependencies?url=${testRealm.url}non-existent-card`) - .set('Accept', 'application/json'); + assert.ok( + result.includes('http://127.0.0.1:4444/person'), + 'person.gts is a dependency', + ); + }); - assert.strictEqual(response.status, 404, 'HTTP 404 status'); - }); + test('gives 404 for a non-existent card', async function (assert) { + let response = await request + .get(`/_dependencies?url=${testRealm.url}non-existent-card`) + .set('Accept', 'application/json'); + + assert.strictEqual(response.status, 404, 'HTTP 404 status'); }); + }); + + module('permissioned realm', function (hooks) { + setupPermissionedRealm(hooks, { + permissions: { + john: ['read'], + }, + onRealmSetup, + }); + + test('401 with invalid JWT', async function (assert) { + let response = await request + .get(`/_dependencies?url=${testRealm.url}person`) + .set('Accept', 'application/json') + .set('Authorization', `Bearer invalid-token`); + + assert.strictEqual(response.status, 401, 'HTTP 401 status'); + }); + + test('401 without a JWT', async function (assert) { + let response = await request + .get(`/_dependencies?url=${testRealm.url}person`) + .set('Accept', 'application/json'); // no Authorization header + + assert.strictEqual(response.status, 401, 'HTTP 401 status'); + }); + + test('403 without permission', async function (assert) { + let response = await request + .get(`/_dependencies?url=${testRealm.url}person`) + .set('Accept', 'application/json') + .set('Authorization', `Bearer ${createJWT(testRealm, 'not-john')}`); + + assert.strictEqual(response.status, 403, 'HTTP 403 status'); + }); + + test('200 with permission', async function (assert) { + let response = await request + .get(`/_dependencies?url=${testRealm.url}person`) + .set('Accept', 'application/json') + .set( + 'Authorization', + `Bearer ${createJWT(testRealm, 'john', ['read'])}`, + ); - module('permissioned realm', function (hooks) { - setupPermissionedRealm(hooks, { - permissions: { - john: ['read'], - }, - onRealmSetup, - }); - - test('401 with invalid JWT', async function (assert) { - let response = await request - .get(`/_dependencies?url=${testRealm.url}person`) - .set('Accept', 'application/json') - .set('Authorization', `Bearer invalid-token`); - - assert.strictEqual(response.status, 401, 'HTTP 401 status'); - }); - - test('401 without a JWT', async function (assert) { - let response = await request - .get(`/_dependencies?url=${testRealm.url}person`) - .set('Accept', 'application/json'); // no Authorization header - - assert.strictEqual(response.status, 401, 'HTTP 401 status'); - }); - - test('403 without permission', async function (assert) { - let response = await request - .get(`/_dependencies?url=${testRealm.url}person`) - .set('Accept', 'application/json') - .set( - 'Authorization', - `Bearer ${createJWT(testRealm, 'not-john')}`, - ); - - assert.strictEqual(response.status, 403, 'HTTP 403 status'); - }); - - test('200 with permission', async function (assert) { - let response = await request - .get(`/_dependencies?url=${testRealm.url}person`) - .set('Accept', 'application/json') - .set( - 'Authorization', - `Bearer ${createJWT(testRealm, 'john', ['read'])}`, - ); - - assert.strictEqual(response.status, 200, 'HTTP 200 status'); - }); + assert.strictEqual(response.status, 200, 'HTTP 200 status'); }); }); - }, - ); + }); + }); }); diff --git a/packages/realm-server/tests/card-endpoints-test.ts b/packages/realm-server/tests/card-endpoints-test.ts index e53d4398f5..30468155c9 100644 --- a/packages/realm-server/tests/card-endpoints-test.ts +++ b/packages/realm-server/tests/card-endpoints-test.ts @@ -14,11 +14,9 @@ import { import { stringify, parse } from 'qs'; import type { Query } from '@cardstack/runtime-common/query'; import { - setupBaseRealmServer, setupPermissionedRealm, setupPermissionedRealms, setupMatrixRoom, - matrixURL, closeServer, testRealmInfo, cleanWhiteSpace, @@ -72,8 +70,6 @@ module(basename(__filename), function () { }; } - setupBaseRealmServer(hooks, matrixURL); - hooks.afterEach(async function () { await closeServer(testRealmHttpServer); resetCatalogRealms(); @@ -703,8 +699,8 @@ module(basename(__filename), function () { attributes: {}, meta: { adoptsFrom: { - module: 'https://cardstack.com/base/card-api', - name: 'CardDef', + module: `${testRealm.url}person`, + name: 'Person', }, }, }, @@ -718,6 +714,7 @@ module(basename(__filename), function () { assert, getMessagesSince, realm: testRealmHref, + type: 'Person', }, ); let id = incrementalEventContent.invalidations[0].split('/').pop()!; @@ -746,7 +743,7 @@ module(basename(__filename), function () { assert.strictEqual( json.data.id, - `${testRealmHref}CardDef/${id}`, + `${testRealmHref}Person/${id}`, 'the id is correct', ); assert.ok(json.data.meta.lastModified, 'lastModified is populated'); @@ -754,7 +751,7 @@ module(basename(__filename), function () { dir.name, 'realm_server_1', 'test', - 'CardDef', + 'Person', `${id}.json`, ); assert.ok(existsSync(cardFile), 'card json exists'); @@ -767,8 +764,8 @@ module(basename(__filename), function () { type: 'card', meta: { adoptsFrom: { - module: 'https://cardstack.com/base/card-api', - name: 'CardDef', + module: '../person', + name: 'Person', }, }, }, @@ -1715,8 +1712,8 @@ module(basename(__filename), function () { attributes: {}, meta: { adoptsFrom: { - module: 'https://cardstack.com/base/card-api', - name: 'CardDef', + module: `${testRealm.url}person`, + name: 'Person', }, }, }, @@ -3505,8 +3502,6 @@ module(basename(__filename), function () { const UNREACHABLE_REALM_URL = 'https://example.invalid/offline/'; let consumerRequest: SuperTest; - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealms(hooks, { realms: [ { diff --git a/packages/realm-server/tests/card-source-endpoints-test.ts b/packages/realm-server/tests/card-source-endpoints-test.ts index 7a8b62b4fc..1a07b398a3 100644 --- a/packages/realm-server/tests/card-source-endpoints-test.ts +++ b/packages/realm-server/tests/card-source-endpoints-test.ts @@ -14,10 +14,8 @@ import { type LooseSingleCardDocument, } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, setupMatrixRoom, - matrixURL, testRealmHref, testRealmURL, createJWT, @@ -33,7 +31,7 @@ import type { MatrixEvent } from 'https://cardstack.com/base/matrix-event'; import isEqual from 'lodash/isEqual'; module(basename(__filename), function () { - module('Realm-specific Endpoints | card source requests', function (hooks) { + module('Realm-specific Endpoints | card source requests', function () { let testRealm: Realm; let testRealmHttpServer: Server; let request: SuperTest; @@ -63,7 +61,6 @@ module(basename(__filename), function () { dbAdapter, }; } - setupBaseRealmServer(hooks, matrixURL); module('card source GET request', function (_hooks) { module('public readable realm', function (hooks) { diff --git a/packages/realm-server/tests/claim-boxel-domain-test.ts b/packages/realm-server/tests/claim-boxel-domain-test.ts index a3f1ab4d3a..caac8a9b4c 100644 --- a/packages/realm-server/tests/claim-boxel-domain-test.ts +++ b/packages/realm-server/tests/claim-boxel-domain-test.ts @@ -10,7 +10,6 @@ import { createVirtualNetwork, matrixURL, closeServer, - setupBaseRealmServer, realmSecretSeed, } from './helpers'; import type { RealmServerTokenClaim } from '../utils/jwt'; @@ -25,8 +24,6 @@ const testRealmURL = new URL('http://127.0.0.1:0/test/'); module(basename(__filename), function () { module('claim boxel claimed domain endpoint', function (hooks) { - setupBaseRealmServer(hooks, matrixURL); - let testRealmServer: Server; let request: SuperTest; let dir: DirResult; diff --git a/packages/realm-server/tests/definition-lookup-test.ts b/packages/realm-server/tests/definition-lookup-test.ts index 98fb6dc4e8..eee22a5678 100644 --- a/packages/realm-server/tests/definition-lookup-test.ts +++ b/packages/realm-server/tests/definition-lookup-test.ts @@ -7,8 +7,6 @@ import { type VirtualNetwork, } from '@cardstack/runtime-common'; import { - matrixURL, - setupBaseRealmServer, setupPermissionedRealms, createVirtualNetwork, testCreatePrerenderAuth, @@ -94,8 +92,6 @@ module(basename(__filename), function () { }); }); - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealms(hooks, { realms: [ { diff --git a/packages/realm-server/tests/delete-boxel-claimed-domain-test.ts b/packages/realm-server/tests/delete-boxel-claimed-domain-test.ts index 7413408551..7e083772ba 100644 --- a/packages/realm-server/tests/delete-boxel-claimed-domain-test.ts +++ b/packages/realm-server/tests/delete-boxel-claimed-domain-test.ts @@ -15,7 +15,6 @@ import { createVirtualNetwork, matrixURL, closeServer, - setupBaseRealmServer, } from './helpers'; import type { RealmServerTokenClaim } from '../utils/jwt'; import { createJWT as createRealmServerJWT } from '../utils/jwt'; @@ -30,8 +29,6 @@ const testRealmURL = new URL('http://127.0.0.1:0/test/'); module(basename(__filename), function () { module('delete boxel claimed domain endpoint', function (hooks) { - setupBaseRealmServer(hooks, matrixURL); - let testRealmServer: Server; let request: SuperTest; let dir: DirResult; diff --git a/packages/realm-server/tests/file-watcher-events-test.ts b/packages/realm-server/tests/file-watcher-events-test.ts index fe24abaff7..ff851e3b10 100644 --- a/packages/realm-server/tests/file-watcher-events-test.ts +++ b/packages/realm-server/tests/file-watcher-events-test.ts @@ -6,10 +6,8 @@ import type { DirResult } from 'tmp'; import { removeSync, writeJSONSync, writeFileSync } from 'fs-extra'; import type { Realm } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, setupMatrixRoom, - matrixURL, waitForRealmEvent, waitUntil, } from './helpers'; @@ -52,7 +50,6 @@ module(basename(__filename), function () { dbAdapter, }; } - setupBaseRealmServer(hooks, matrixURL); setupPermissionedRealm(hooks, { permissions: { diff --git a/packages/realm-server/tests/get-boxel-claimed-domain-test.ts b/packages/realm-server/tests/get-boxel-claimed-domain-test.ts index 19d1b34880..715a7c062e 100644 --- a/packages/realm-server/tests/get-boxel-claimed-domain-test.ts +++ b/packages/realm-server/tests/get-boxel-claimed-domain-test.ts @@ -10,7 +10,6 @@ import { createVirtualNetwork, matrixURL, closeServer, - setupBaseRealmServer, realmSecretSeed, } from './helpers'; import type { RealmServerTokenClaim } from '../utils/jwt'; @@ -25,8 +24,6 @@ const testRealmURL = new URL('http://127.0.0.1:0/test/'); module(basename(__filename), function () { module('get boxel claimed domain endpoint', function (hooks) { - setupBaseRealmServer(hooks, matrixURL); - let testRealmServer: Server; let request: SuperTest; let dir: DirResult; diff --git a/packages/realm-server/tests/helpers/index.ts b/packages/realm-server/tests/helpers/index.ts index 3c9de61d09..dc8cb332fc 100644 --- a/packages/realm-server/tests/helpers/index.ts +++ b/packages/realm-server/tests/helpers/index.ts @@ -7,7 +7,7 @@ import { copySync, } from 'fs-extra'; import { NodeAdapter } from '../../node-realm'; -import { resolve, join } from 'path'; +import { join } from 'path'; import type { LooseSingleCardDocument, RealmPermissions, @@ -107,7 +107,7 @@ export async function waitUntil( } export const testRealm = 'http://test-realm/'; -export const localBaseRealm = 'http://localhost:4441/'; +export const localBaseRealm = 'http://localhost:4201/'; export const matrixURL = new URL('http://localhost:8008'); const testPrerenderHost = '127.0.0.1'; const testPrerenderPort = 4460; @@ -149,8 +149,6 @@ const trackedDbAdapters = new Set(); const trackedQueuePublishers = new Set(); const trackedQueueRunners = new Set(); -const basePath = resolve(join(__dirname, '..', '..', '..', 'base')); - export function cleanWhiteSpace(text: string) { return text .replace(//g, '') @@ -473,101 +471,6 @@ export async function createRealm({ return { realm, adapter }; } -export function setupBaseRealmServer(hooks: NestedHooks, matrixURL: URL) { - let baseRealmServer: Server | undefined; - setupDB(hooks, { - before: async (dbAdapter, publisher, runner) => { - let dir = dirSync(); - baseRealmServer = await runBaseRealmServer( - createVirtualNetwork(), - publisher, - runner, - dbAdapter, - matrixURL, - dir.name, - { '*': ['read'] }, - ); - }, - after: async () => { - if (baseRealmServer) { - await closeServer(baseRealmServer); - baseRealmServer = undefined; - } - }, - }); -} - -export async function runBaseRealmServer( - virtualNetwork: VirtualNetwork, - publisher: QueuePublisher, - runner: QueueRunner, - dbAdapter: PgAdapter, - matrixURL: URL, - realmsRootPath: string, - permissions: RealmPermissions = { '*': ['read'] }, -) { - let localBaseRealmURL = new URL(localBaseRealm); - virtualNetwork.addURLMapping(new URL(baseRealm.url), localBaseRealmURL); - - let prerenderer = await getTestPrerenderer(); - let definitionLookup = new CachingDefinitionLookup( - dbAdapter, - prerenderer, - virtualNetwork, - testCreatePrerenderAuth, - ); - let worker = new Worker({ - indexWriter: new IndexWriter(dbAdapter), - queue: runner, - dbAdapter, - queuePublisher: publisher, - virtualNetwork, - matrixURL, - secretSeed: realmSecretSeed, - realmServerMatrixUsername: testRealmServerMatrixUsername, - prerenderer, - createPrerenderAuth: testCreatePrerenderAuth, - }); - let { realm: testBaseRealm } = await createRealm({ - dir: basePath, - realmURL: baseRealm.url, - virtualNetwork, - publisher, - dbAdapter, - permissions, - definitionLookup, - }); - // the base realm is public readable so it doesn't need a private network - virtualNetwork.mount(testBaseRealm.handle); - await worker.run(); - await testBaseRealm.start(); - let matrixClient = new MatrixClient({ - matrixURL: realmServerTestMatrix.url, - username: realmServerTestMatrix.username, - seed: realmSecretSeed, - }); - let realms = [testBaseRealm]; - let testBaseRealmServer = new RealmServer({ - realms, - virtualNetwork, - matrixClient, - realmServerSecretSeed, - realmSecretSeed, - matrixRegistrationSecret, - realmsRootPath, - dbAdapter, - queue: publisher, - getIndexHTML, - grafanaSecret, - serverURL: new URL(localBaseRealmURL.origin), - assetsURL: new URL(`http://example.com/notional-assets-host/`), - definitionLookup, - prerenderer, - }); - let server = testBaseRealmServer.listen(parseInt(localBaseRealmURL.port)); - return trackServer(server); -} - export async function runTestRealmServer({ testRealmDir, realmsRootPath, diff --git a/packages/realm-server/tests/helpers/indexing.ts b/packages/realm-server/tests/helpers/indexing.ts index 5c8d5f36a3..e6a782b612 100644 --- a/packages/realm-server/tests/helpers/indexing.ts +++ b/packages/realm-server/tests/helpers/indexing.ts @@ -12,6 +12,7 @@ interface IncrementalIndexEventTestContext { assert: Assert; getMessagesSince: (since: number) => Promise; realm: string; + type?: string; } export async function waitForIncrementalIndexEvent( @@ -35,7 +36,9 @@ export async function expectIncrementalIndexEvent( since: number, opts: IncrementalIndexEventTestContext, ) { - let { assert, getMessagesSince, realm } = opts; + let { assert, getMessagesSince, realm, type } = opts; + + type = type ?? 'CardDef'; let endsWithSlash = url.endsWith('/'); // new card def is being created @@ -63,9 +66,9 @@ export async function expectIncrementalIndexEvent( assert.true(uuidValidate(maybeLocalId!), 'card identifier is a UUID'); assert.strictEqual( incrementalEventContent.invalidations[0], - `${realm}CardDef/${maybeLocalId}`, + `${realm}${type}/${maybeLocalId}`, ); - targetUrl = `${realm}CardDef/${maybeLocalId}.json`; + targetUrl = `${realm}${type}/${maybeLocalId}.json`; } // For instances, the updatedFile includes .json extension but invalidations don't diff --git a/packages/realm-server/tests/index.ts b/packages/realm-server/tests/index.ts index a96d6da1d5..21dc42b720 100644 --- a/packages/realm-server/tests/index.ts +++ b/packages/realm-server/tests/index.ts @@ -30,6 +30,21 @@ import * as ContentTagGlobal from 'content-tag'; import QUnit from 'qunit'; QUnit.config.testTimeout = 60000; +const testModules = process.env.TEST_MODULES?.trim(); + +if (testModules) { + const modules = parseModules(testModules); + if (modules.length > 0) { + QUnit.config.filter = buildModuleFilter(modules); + console.log( + `Filtering tests to modules from TEST_MODULES: ${modules.join(', ')}`, + ); + } else { + console.warn( + 'TEST_MODULES was provided but no module names were parsed. Running full suite.', + ); + } +} // Cleanup here ensures lingering servers/prerenderers/queues don't keep the // Node event loop alive after tests finish. @@ -155,3 +170,21 @@ import './delete-boxel-claimed-domain-test'; import './realm-auth-test'; import './queries-test'; import './remote-prerenderer-test'; + +function parseModules(value: string): string[] { + return value + .split(/[|,]/) + .map((entry) => entry.trim()) + .filter(Boolean) + .map((entry) => entry.replace(/^['"]+|['"]+$/g, '')); +} + +function buildModuleFilter(modulesToMatch: string[]): string { + const escaped = modulesToMatch.map((moduleName) => escapeRegex(moduleName)); + const pattern = `^(?:${escaped.join('|')})(?:\\s>\\s|:)`; + return `/${pattern}/`; +} + +function escapeRegex(value: string): string { + return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\//g, '\\/'); +} diff --git a/packages/realm-server/tests/indexing-test.ts b/packages/realm-server/tests/indexing-test.ts index c46f4f3afd..ceb4d6aa55 100644 --- a/packages/realm-server/tests/indexing-test.ts +++ b/packages/realm-server/tests/indexing-test.ts @@ -14,7 +14,6 @@ import type { QueueRunner, } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupDB, createVirtualNetwork, matrixURL, @@ -455,8 +454,6 @@ module(basename(__filename), function () { return maybeInstance as IndexedInstance | undefined; } - setupBaseRealmServer(hooks, matrixURL); - setupDB(hooks, { before: async (dbAdapter, publisher, runner) => { testDbAdapter = dbAdapter; @@ -898,8 +895,6 @@ module(basename(__filename), function () { let adapter: RealmAdapter; let testRealmServer: TestRealmServerResult | undefined; - setupBaseRealmServer(hooks, matrixURL); - setupDB(hooks, { beforeEach: async (dbAdapter, publisher, runner) => { testDbAdapter = dbAdapter; @@ -1635,9 +1630,7 @@ module(basename(__filename), function () { }); }); - module('permissioned realm', function (hooks) { - setupBaseRealmServer(hooks, matrixURL); - + module('permissioned realm', function () { let testRealm1URL = 'http://127.0.0.1:4447/'; let testRealm2URL = 'http://127.0.0.1:4448/'; let testRealm2: Realm; diff --git a/packages/realm-server/tests/prerender-server-test.ts b/packages/realm-server/tests/prerender-server-test.ts index dcb55c3f43..a6f80833f2 100644 --- a/packages/realm-server/tests/prerender-server-test.ts +++ b/packages/realm-server/tests/prerender-server-test.ts @@ -4,9 +4,7 @@ import supertest from 'supertest'; import { basename } from 'path'; import { - setupBaseRealmServer, setupPermissionedRealm, - matrixURL, testRealmHref, testCreatePrerenderAuth, } from './helpers'; @@ -27,8 +25,6 @@ module(basename(__filename), function () { const testUserId = '@jade:localhost'; let draining = false; - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealm(hooks, { mode: 'before', permissions: { [testUserId]: ['read', 'write', 'realm-owner'] }, diff --git a/packages/realm-server/tests/prerendering-test.ts b/packages/realm-server/tests/prerendering-test.ts index 5bccd5d9c3..a8ce334841 100644 --- a/packages/realm-server/tests/prerendering-test.ts +++ b/packages/realm-server/tests/prerendering-test.ts @@ -13,9 +13,7 @@ import { PagePool } from '../prerender/page-pool'; import { RenderRunner } from '../prerender/render-runner'; import { - setupBaseRealmServer, setupPermissionedRealms, - matrixURL, cleanWhiteSpace, testCreatePrerenderAuth, getPrerendererForTesting, @@ -104,8 +102,6 @@ module(basename(__filename), function () { await prerenderer.disposeRealm(realmURL); }); - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealms(hooks, { realms: [ { @@ -754,8 +750,6 @@ module(basename(__filename), function () { ]); }); - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealms(hooks, { mode: 'before', realms: [ @@ -975,8 +969,6 @@ module(basename(__filename), function () { await prerenderer.stop(); }); - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealms(hooks, { mode: 'before', realms: [ diff --git a/packages/realm-server/tests/publish-unpublish-realm-test.ts b/packages/realm-server/tests/publish-unpublish-realm-test.ts index 483dd30311..3d550f4b7c 100644 --- a/packages/realm-server/tests/publish-unpublish-realm-test.ts +++ b/packages/realm-server/tests/publish-unpublish-realm-test.ts @@ -28,7 +28,6 @@ import { createVirtualNetwork, realmSecretSeed, matrixURL, - setupBaseRealmServer, } from './helpers'; import { createJWT as createRealmServerJWT } from '../utils/jwt'; @@ -83,7 +82,6 @@ module(basename(__filename), function () { })); request = supertest(testRealmHttpServer); } - setupBaseRealmServer(hooks, matrixURL); setupDB(hooks, { beforeEach: async (_dbAdapter, _publisher, _runner) => { diff --git a/packages/realm-server/tests/realm-auth-test.ts b/packages/realm-server/tests/realm-auth-test.ts index 55fc0d54f0..94a6629558 100644 --- a/packages/realm-server/tests/realm-auth-test.ts +++ b/packages/realm-server/tests/realm-auth-test.ts @@ -12,8 +12,6 @@ import { insertUser, realmSecretSeed, testRealmHref, - setupBaseRealmServer, - matrixURL, } from './helpers'; import { createJWT as createRealmServerJWT } from '../utils/jwt'; @@ -23,8 +21,6 @@ module(basename(__filename), function () { let request: SuperTest; const matrixUserId = '@firsttimer:localhost'; - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealm(hooks, { permissions: { '*': ['read'], diff --git a/packages/realm-server/tests/realm-endpoints-test.ts b/packages/realm-server/tests/realm-endpoints-test.ts index 832f86e4f9..711945ff7c 100644 --- a/packages/realm-server/tests/realm-endpoints-test.ts +++ b/packages/realm-server/tests/realm-endpoints-test.ts @@ -23,7 +23,6 @@ import { type QueueRunner, } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, runTestRealmServer, setupDB, @@ -101,8 +100,6 @@ module(basename(__filename), function () { }; } - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealm(hooks, { permissions: { '*': ['read', 'write'], @@ -1184,8 +1181,6 @@ module(basename(__filename), function () { let dir: DirResult; - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); }); @@ -1683,8 +1678,6 @@ module(basename(__filename), function () { let dir: DirResult; - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); }); diff --git a/packages/realm-server/tests/realm-endpoints/dependencies-test.ts b/packages/realm-server/tests/realm-endpoints/dependencies-test.ts index f18bce605a..d1adb1f829 100644 --- a/packages/realm-server/tests/realm-endpoints/dependencies-test.ts +++ b/packages/realm-server/tests/realm-endpoints/dependencies-test.ts @@ -4,12 +4,7 @@ import { basename } from 'path'; import type { Realm } from '@cardstack/runtime-common'; import { SupportedMimeType } from '@cardstack/runtime-common'; import type { Server } from 'http'; -import { - closeServer, - matrixURL, - setupBaseRealmServer, - setupPermissionedRealm, -} from '../helpers'; +import { closeServer, setupPermissionedRealm } from '../helpers'; module(`realm-endpoints/${basename(__filename)}`, function (hooks) { let testRealm: Realm; @@ -29,8 +24,6 @@ module(`realm-endpoints/${basename(__filename)}`, function (hooks) { request = req; } - setupBaseRealmServer(hooks, matrixURL); - hooks.afterEach(async function () { await closeServer(testRealmHttpServer); }); diff --git a/packages/realm-server/tests/realm-endpoints/directory-test.ts b/packages/realm-server/tests/realm-endpoints/directory-test.ts index 045fffa556..5c146758bc 100644 --- a/packages/realm-server/tests/realm-endpoints/directory-test.ts +++ b/packages/realm-server/tests/realm-endpoints/directory-test.ts @@ -4,13 +4,7 @@ import { join, basename } from 'path'; import { dirSync, type DirResult } from 'tmp'; import { copySync } from 'fs-extra'; import type { Realm } from '@cardstack/runtime-common'; -import { - setupBaseRealmServer, - setupPermissionedRealm, - matrixURL, - testRealmHref, - createJWT, -} from '../helpers'; +import { setupPermissionedRealm, testRealmHref, createJWT } from '../helpers'; import '@cardstack/runtime-common/helpers/code-equality-assertion'; module(`realm-endpoints/${basename(__filename)}`, function () { @@ -19,8 +13,6 @@ module(`realm-endpoints/${basename(__filename)}`, function () { let request: SuperTest; let dir: DirResult; - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); copySync(join(__dirname, '..', 'cards'), dir.name); diff --git a/packages/realm-server/tests/realm-endpoints/info-test.ts b/packages/realm-server/tests/realm-endpoints/info-test.ts index 592dcec93a..45ea4962c0 100644 --- a/packages/realm-server/tests/realm-endpoints/info-test.ts +++ b/packages/realm-server/tests/realm-endpoints/info-test.ts @@ -6,9 +6,7 @@ import { dirSync, type DirResult } from 'tmp'; import { copySync } from 'fs-extra'; import type { Realm } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, - matrixURL, closeServer, testRealmInfo, testRealmHref, @@ -36,8 +34,6 @@ module(`realm-endpoints/${basename(__filename)}`, function () { dir = args.dir; } - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); copySync(join(__dirname, '..', 'cards'), dir.name); diff --git a/packages/realm-server/tests/realm-endpoints/lint-test.ts b/packages/realm-server/tests/realm-endpoints/lint-test.ts index 92eb1a8da1..56d3f52058 100644 --- a/packages/realm-server/tests/realm-endpoints/lint-test.ts +++ b/packages/realm-server/tests/realm-endpoints/lint-test.ts @@ -2,12 +2,7 @@ import { module, test } from 'qunit'; import type { Test, SuperTest } from 'supertest'; import { basename } from 'path'; import type { Realm } from '@cardstack/runtime-common'; -import { - setupBaseRealmServer, - matrixURL, - setupPermissionedRealm, - createJWT, -} from '../helpers'; +import { setupPermissionedRealm, createJWT } from '../helpers'; import { benchmarkOperation, createConcurrentTestData, @@ -30,8 +25,6 @@ module(`realm-endpoints/${basename(__filename)}`, function () { request = args.request; } - setupBaseRealmServer(hooks, matrixURL); - setupPermissionedRealm(hooks, { permissions: { john: ['read', 'write'], diff --git a/packages/realm-server/tests/realm-endpoints/mtimes-test.ts b/packages/realm-server/tests/realm-endpoints/mtimes-test.ts index fec83cd6d9..0ef403c5a0 100644 --- a/packages/realm-server/tests/realm-endpoints/mtimes-test.ts +++ b/packages/realm-server/tests/realm-endpoints/mtimes-test.ts @@ -3,9 +3,7 @@ import type { Test, SuperTest } from 'supertest'; import { basename } from 'path'; import type { Realm } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, - matrixURL, mtimes, testRealmHref, testRealmURL, @@ -28,7 +26,6 @@ module(`realm-endpoints/${basename(__filename)}`, function () { testRealmPath = args.testRealmPath; request = args.request; } - setupBaseRealmServer(hooks, matrixURL); setupPermissionedRealm(hooks, { permissions: { diff --git a/packages/realm-server/tests/realm-endpoints/permissions-test.ts b/packages/realm-server/tests/realm-endpoints/permissions-test.ts index b5aa74fbbc..eac68d6d56 100644 --- a/packages/realm-server/tests/realm-endpoints/permissions-test.ts +++ b/packages/realm-server/tests/realm-endpoints/permissions-test.ts @@ -6,9 +6,7 @@ import { copySync } from 'fs-extra'; import type { Realm } from '@cardstack/runtime-common'; import { fetchRealmPermissions } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, - matrixURL, testRealmHref, testRealmURL, createJWT, @@ -35,8 +33,6 @@ module(`realm-endpoints/${basename(__filename)}`, function () { dir = args.dir; } - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); copySync(join(__dirname, '..', 'cards'), dir.name); diff --git a/packages/realm-server/tests/realm-endpoints/publishability-test.ts b/packages/realm-server/tests/realm-endpoints/publishability-test.ts index 93b5a84fd8..41d6fe4fdf 100644 --- a/packages/realm-server/tests/realm-endpoints/publishability-test.ts +++ b/packages/realm-server/tests/realm-endpoints/publishability-test.ts @@ -10,17 +10,13 @@ import { import { createJWT, - matrixURL, - setupBaseRealmServer, setupPermissionedRealm, setupPermissionedRealms, } from '../helpers'; const ownerUserId = '@mango:localhost'; -module(`realm-endpoints/${basename(__filename)}`, function (hooks) { - setupBaseRealmServer(hooks, matrixURL); - +module(`realm-endpoints/${basename(__filename)}`, function () { module('with a publishable realm', function (hooks) { let request: SuperTest; let testRealm: Realm; diff --git a/packages/realm-server/tests/realm-endpoints/search-test.ts b/packages/realm-server/tests/realm-endpoints/search-test.ts index ded46e7ae5..e1f1fdd21d 100644 --- a/packages/realm-server/tests/realm-endpoints/search-test.ts +++ b/packages/realm-server/tests/realm-endpoints/search-test.ts @@ -4,12 +4,7 @@ import { basename } from 'path'; import type { Realm } from '@cardstack/runtime-common'; import { stringify } from 'qs'; import type { Query } from '@cardstack/runtime-common/query'; -import { - setupBaseRealmServer, - setupPermissionedRealm, - matrixURL, - createJWT, -} from '../helpers'; +import { setupPermissionedRealm, createJWT } from '../helpers'; import '@cardstack/runtime-common/helpers/code-equality-assertion'; function buildQueryParam(query: Query) { @@ -17,15 +12,13 @@ function buildQueryParam(query: Query) { } module(`realm-endpoints/${basename(__filename)}`, function () { - module('Realm-specific Endpoints | _search', function (hooks) { + module('Realm-specific Endpoints | _search', function () { let testRealm: Realm; let request: SuperTest; let realmURL: URL; let realmHref: string; let searchPath: string; - setupBaseRealmServer(hooks, matrixURL); - function onRealmSetup(args: { testRealm: Realm; request: SuperTest; diff --git a/packages/realm-server/tests/realm-endpoints/user-test.ts b/packages/realm-server/tests/realm-endpoints/user-test.ts index d124af8b9d..0aefb0df25 100644 --- a/packages/realm-server/tests/realm-endpoints/user-test.ts +++ b/packages/realm-server/tests/realm-endpoints/user-test.ts @@ -6,9 +6,7 @@ import { dirSync, type DirResult } from 'tmp'; import { copySync } from 'fs-extra'; import type { Realm } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, - matrixURL, closeServer, insertUser, insertPlan, @@ -47,8 +45,6 @@ module(`realm-endpoints/${basename(__filename)}`, function () { dir = args.dir; } - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); copySync(join(__dirname, '..', 'cards'), dir.name); @@ -289,8 +285,6 @@ module(`realm-endpoints/${basename(__filename)}`, function () { dir = args.dir; } - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); copySync(join(__dirname, '..', 'cards'), dir.name); diff --git a/packages/realm-server/tests/request-forward-test.ts b/packages/realm-server/tests/request-forward-test.ts index 86fb98396a..f8ea2a368d 100644 --- a/packages/realm-server/tests/request-forward-test.ts +++ b/packages/realm-server/tests/request-forward-test.ts @@ -7,7 +7,6 @@ import type { Server } from 'http'; import { dirSync, type DirResult } from 'tmp'; import { copySync, ensureDirSync } from 'fs-extra'; import { - setupBaseRealmServer, setupDB, runTestRealmServer, closeServer, @@ -43,8 +42,6 @@ module(basename(__filename), function () { copySync(join(__dirname, 'cards'), dir.name); }); - setupBaseRealmServer(hooks, new URL('http://localhost:8008')); - async function startRealmServer( dbAdapter: any, publisher: any, diff --git a/packages/realm-server/tests/search-prerendered-test.ts b/packages/realm-server/tests/search-prerendered-test.ts index 6ca18e7ba5..efd70c0afd 100644 --- a/packages/realm-server/tests/search-prerendered-test.ts +++ b/packages/realm-server/tests/search-prerendered-test.ts @@ -4,17 +4,11 @@ import { basename } from 'path'; import type { Realm } from '@cardstack/runtime-common'; import { stringify } from 'qs'; import type { Query } from '@cardstack/runtime-common/query'; -import { - setupBaseRealmServer, - setupPermissionedRealm, - matrixURL, - testRealmHref, - createJWT, -} from './helpers'; +import { setupPermissionedRealm, testRealmHref, createJWT } from './helpers'; import '@cardstack/runtime-common/helpers/code-equality-assertion'; module(basename(__filename), function () { - module('Realm-specific Endpoints | _search-prerendered', function (hooks) { + module('Realm-specific Endpoints | _search-prerendered', function () { let testRealm: Realm; let request: SuperTest; @@ -26,8 +20,6 @@ module(basename(__filename), function () { request = args.request; } - setupBaseRealmServer(hooks, matrixURL); - module('GET request', function (_hooks) { module( 'instances with no embedded template css of its own', diff --git a/packages/realm-server/tests/server-endpoints-test.ts b/packages/realm-server/tests/server-endpoints-test.ts index fc048b5d29..1ba612416a 100644 --- a/packages/realm-server/tests/server-endpoints-test.ts +++ b/packages/realm-server/tests/server-endpoints-test.ts @@ -22,7 +22,6 @@ import { stringify } from 'qs'; import { v4 as uuidv4 } from 'uuid'; import type { Query } from '@cardstack/runtime-common/query'; import { - setupBaseRealmServer, setupPermissionedRealm, runTestRealmServer, setupDB, @@ -115,7 +114,6 @@ module(basename(__filename), function () { dir = args.dir; dbAdapter = args.dbAdapter; } - setupBaseRealmServer(hooks, matrixURL); hooks.beforeEach(async function () { dir = dirSync(); @@ -306,11 +304,11 @@ module(basename(__filename), function () { .send({ data: { type: 'card', - attributes: { cardInfo: { title: 'Test Card' } }, + attributes: { firstName: 'My Name' }, meta: { adoptsFrom: { - module: 'https://cardstack.com/base/card-api', - name: 'CardDef', + module: `${testRealmURL}person`, + name: 'Person', }, }, }, @@ -348,7 +346,7 @@ module(basename(__filename), function () { let doc = response.body as SingleCardDocument; assert.strictEqual( doc.data.attributes?.title, - 'Test Card', + 'My Name', 'instance data is correct', ); } @@ -361,9 +359,12 @@ module(basename(__filename), function () { stringify( { filter: { - on: baseCardRef, + on: { + module: `${testRealmURL}person`, + name: 'Person', + }, eq: { - title: 'Test Card', + title: 'My Name', }, }, } as Query, @@ -511,11 +512,11 @@ module(basename(__filename), function () { .send({ data: { type: 'card', - attributes: { cardInfo: { title: 'Test Card' } }, + attributes: { firstName: 'My Name' }, meta: { adoptsFrom: { - module: 'https://cardstack.com/base/card-api', - name: 'CardDef', + module: `${testRealmURL}person`, + name: 'Person', }, }, }, @@ -566,7 +567,7 @@ module(basename(__filename), function () { let doc = response.body as SingleCardDocument; assert.strictEqual( doc.data.attributes?.title, - 'Test Card', + 'My Name', 'instance data is correct', ); } @@ -2854,8 +2855,6 @@ module(basename(__filename), function () { let request: SuperTest; let dir: DirResult; - setupBaseRealmServer(hooks, matrixURL); - hooks.beforeEach(async function () { dir = dirSync(); }); diff --git a/packages/realm-server/tests/server-endpoints/search-test.ts b/packages/realm-server/tests/server-endpoints/search-test.ts index 16fb46bbcd..79d4fac151 100644 --- a/packages/realm-server/tests/server-endpoints/search-test.ts +++ b/packages/realm-server/tests/server-endpoints/search-test.ts @@ -17,7 +17,6 @@ import { resetCatalogRealms } from '../../handlers/handle-fetch-catalog-realms'; import { closeServer, createVirtualNetwork, - setupBaseRealmServer, setupDB, insertUser, matrixURL, @@ -37,8 +36,6 @@ module(`server-endpoints/${basename(__filename)}`, function (_hooks) { let ownerUserId = '@mango:localhost'; - setupBaseRealmServer(hooks, matrixURL); - let realmFileSystem: Record = { 'test-card.json': { data: { diff --git a/packages/realm-server/tests/types-endpoint-test.ts b/packages/realm-server/tests/types-endpoint-test.ts index 4ebaf56b59..c9988c6fb3 100644 --- a/packages/realm-server/tests/types-endpoint-test.ts +++ b/packages/realm-server/tests/types-endpoint-test.ts @@ -7,7 +7,6 @@ import { copySync, ensureDirSync } from 'fs-extra'; import type { Realm } from '@cardstack/runtime-common'; import type { QueuePublisher, QueueRunner } from '@cardstack/runtime-common'; import { - setupBaseRealmServer, setupPermissionedRealm, runTestRealmServer, setupDB, @@ -59,7 +58,6 @@ module(basename(__filename), function () { dbAdapter, }; } - setupBaseRealmServer(hooks, matrixURL); hooks.afterEach(async function () { await closeServer(testRealmHttpServer);