Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

ci: run the tests beside the gates, and the client and server suites in shards

Maurice97b748555f9d
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 3d540db1f..8e844eac3 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -9,23 +9,36 @@ permissions:
# analysis; pull requests get PR analysis with decoration on the PR itself
# (the scanner picks the context up from the Actions environment).
#
-# Job layout — three tiers:
-# - Preflight: plugin-facts, i18n-parity and the quality jobs
-# (server-quality, client-quality, plugin-sdk-quality) hold the cheap
-# generated-code/typecheck/lint/smoke gates. Every test job `needs:` all
-# of them, so a gate failure stops the run before the expensive coverage
-# fan-out spends ~15 runner-minutes on a result the gates already sank.
-# - Tests: the *-coverage jobs run the suites and upload lcov; s3-contract
-# runs the MinIO contract suite. Coverage jobs run tests only — with the
-# gates cleared in preflight, they can only fail because tests failed.
-# client-e2e drives the real app in Chromium and WebKit, client-bundle
-# builds the client and checks each map engine keeps a chunk of its own,
-# and postgres-probe runs the dialect helpers and the repository
-# statements it reaches against a Postgres service. None of them feeds the scan.
-# - Scan `needs:` exactly the four coverage jobs. A coverage job failing
-# must stop the scan — a missing lcov file would make every line of that
-# package report as uncovered, and the dashboard would show a collapse
-# that did not happen. (The preflight gates stop it transitively.)
+# Job layout:
+# - Gates: plugin-facts, i18n-parity and the quality jobs (server-quality,
+# client-quality, plugin-sdk-quality) hold the generated-code, typecheck,
+# lint and smoke gates.
+# - Tests run beside the gates, not after them, so a run takes as long as
+# its slowest job and not the gates plus the tests. They used to wait for
+# the gates, which put ~9 minutes in front of every test result. The
+# client and server suites are split into shards (client-tests,
+# server-tests), each running a slice with coverage and uploading a blob
+# report; client-coverage and server-coverage merge the blobs, check the
+# thresholds against the whole and upload lcov. A red shard is usually a
+# failing test, a red merge job usually a threshold. shared-coverage and
+# plugin-sdk-coverage are small enough to run in one job each, and
+# s3-contract runs the MinIO contract suite. client-e2e drives the real
+# app in Chromium and WebKit, client-bundle builds the client and checks
+# each map engine keeps a chunk of its own, and postgres-probe runs the
+# dialect helpers and the repository statements it reaches against a
+# Postgres service. None of these feeds the scan.
+# - Shard counts: GitHub runs at most 20 jobs of the organisation at once.
+# A code change starts about a dozen jobs besides the shards; eight of
+# them (the parity, facts and SDK checks, the bundle, the S3 and Postgres
+# jobs, the small coverage jobs) are done within a minute or two, so the
+# few shards that queue at the start wait about that long. The counts are
+# sized so the coverage merges finish about when the quality jobs do
+# (~9 minutes); more shards would wait in the queue rather than finish
+# sooner.
+# - Scan `needs:` the gates and the four coverage jobs. A coverage job
+# failing must stop the scan — a missing lcov file would make every line
+# of that package report as uncovered, and the dashboard would show a
+# collapse that did not happen.
# - Fork PRs and runs Dependabot triggers don't receive the repo's Actions
# secrets, so the two jobs that need them skip themselves: s3-contract
# (MINIO_LICENSE_KEY) and scan (SONAR_TOKEN). ci-ok counts a skip as
@@ -38,7 +51,7 @@ permissions:
# required check that never reports blocks the PR for good.
# - docker-image builds the Dockerfile and boots the result, and
# deploy-manifests lints and renders the Helm chart and checks the
-# compose files. Both run beside the preflight rather than after it.
+# compose files. Both run beside the gates rather than after them.
# - ci-ok `needs:` every gate, test, image and chart job, and is the one
# check the branch ruleset requires. It fails when any of them failed or
# was cancelled and passes when they passed or were skipped (by changes,
@@ -514,9 +527,10 @@ jobs:
client-bundle:
name: Client Bundle
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 45
- needs: [plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
steps:
- uses: actions/checkout@v6
@@ -544,9 +558,10 @@ jobs:
client-e2e:
name: Client End-to-End
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 45
- needs: [plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
steps:
- uses: actions/checkout@v6
@@ -603,14 +618,14 @@ jobs:
name: S3 Driver Contract (MinIO)
runs-on: ubuntu-24.04
timeout-minutes: 45
- needs: [plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
+ needs: changes
# Fork PRs don't get repo secrets, so MINIO_LICENSE_KEY would be empty and
# the AIStor container would fail to boot. A run Dependabot triggers gets
# only Dependabot secrets, so its PRs (same repo, not a fork) hit the same
# wall. Pushes and manual dispatches by anyone else do have secrets, so
- # only those two are filtered out. (The implicit success() on this
- # expression also keeps the job skipped when a preflight fails.)
+ # only those two are filtered out.
if: >-
+ needs.changes.outputs.code == 'true' &&
github.actor != 'dependabot[bot]' &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
@@ -694,7 +709,7 @@ jobs:
name: Postgres Probe
runs-on: ubuntu-24.04
timeout-minutes: 10
- needs: [changes, plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
+ needs: changes
if: needs.changes.outputs.code == 'true'
services:
postgres:
@@ -747,11 +762,20 @@ jobs:
if-no-files-found: ignore
retention-days: 14
- server-coverage:
- name: Server Coverage
+ # The server suite in six slices. vitest.shard.config.ts is vitest.config.ts
+ # without the thresholds and the coverage reports: a slice's blob carries
+ # its coverage to server-coverage, which checks the whole. fail-fast is off,
+ # so one red run shows every failing slice and not just the first.
+ server-tests:
+ name: Server Tests (${{ matrix.shard }}/6)
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
- timeout-minutes: 45
- needs: [plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
+ timeout-minutes: 30
+ strategy:
+ fail-fast: false
+ matrix:
+ shard: [1, 2, 3, 4, 5, 6]
steps:
- uses: actions/checkout@v6
@@ -776,8 +800,57 @@ jobs:
- name: Build shared
run: npm run build --workspace=shared
- - name: Run tests with coverage
- run: cd server && npm run test:coverage
+ - name: Run a slice of the tests with coverage
+ run: >-
+ cd server && npx vitest run --config vitest.shard.config.ts --coverage
+ --shard=${{ matrix.shard }}/6
+ --reporter=default --reporter=github-actions --reporter=blob
+
+ - name: Upload the blob report
+ uses: actions/upload-artifact@v6
+ with:
+ name: server-blob-${{ matrix.shard }}
+ path: server/.vitest-reports/
+ include-hidden-files: true
+ if-no-files-found: error
+ retention-days: 1
+
+ server-coverage:
+ name: Server Coverage
+ needs: server-tests
+ runs-on: ubuntu-24.04
+ timeout-minutes: 15
+ steps:
+ - uses: actions/checkout@v6
+
+ - uses: actions/setup-node@v6
+ with:
+ node-version-file: .nvmrc
+ cache: npm
+ cache-dependency-path: package-lock.json
+
+ - name: Install dependencies
+ run: npm ci
+
+ - name: Ensure @swc/core's Linux binary for unplugin-swc
+ # vitest.config.ts loads unplugin-swc even when it only merges.
+ run: |
+ SWC_VERSION=$(node -p "require('@swc/core/package.json').version")
+ npm install --no-save --legacy-peer-deps "@swc/core-linux-x64-gnu@$SWC_VERSION"
+
+ - name: Download the blob reports
+ uses: actions/download-artifact@v7
+ with:
+ pattern: server-blob-*
+ path: server/.vitest-reports/
+ merge-multiple: true
+
+ - name: Merge the slices and check the thresholds
+ # Every blob holds a whole coverage map, and the merge reads them all
+ # into one process.
+ env:
+ NODE_OPTIONS: --max-old-space-size=6144
+ run: cd server && npx vitest run --merge-reports --coverage
- name: Upload coverage
uses: actions/upload-artifact@v6
@@ -786,11 +859,18 @@ jobs:
path: server/coverage/
retention-days: 1
- client-coverage:
- name: Client Coverage
+ # The client suite in eight slices, the same way as server-tests. It is the
+ # slowest suite (~35 minutes on one runner), so it gets the most.
+ client-tests:
+ name: Client Tests (${{ matrix.shard }}/8)
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
- timeout-minutes: 45
- needs: [plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
+ timeout-minutes: 30
+ strategy:
+ fail-fast: false
+ matrix:
+ shard: [1, 2, 3, 4, 5, 6, 7, 8]
steps:
- uses: actions/checkout@v6
@@ -810,8 +890,51 @@ jobs:
- name: Build shared
run: npm run build --workspace=shared
- - name: Run tests with coverage
- run: cd client && npm run test:coverage
+ - name: Run a slice of the tests with coverage
+ run: >-
+ cd client && npx vitest run --config vitest.shard.config.ts --coverage
+ --shard=${{ matrix.shard }}/8
+ --reporter=default --reporter=github-actions --reporter=blob
+
+ - name: Upload the blob report
+ uses: actions/upload-artifact@v6
+ with:
+ name: client-blob-${{ matrix.shard }}
+ path: client/.vitest-reports/
+ include-hidden-files: true
+ if-no-files-found: error
+ retention-days: 1
+
+ client-coverage:
+ name: Client Coverage
+ needs: client-tests
+ runs-on: ubuntu-24.04
+ timeout-minutes: 15
+ steps:
+ - uses: actions/checkout@v6
+
+ - uses: actions/setup-node@v6
+ with:
+ node-version-file: .nvmrc
+ cache: npm
+ cache-dependency-path: package-lock.json
+
+ - name: Install dependencies
+ run: npm ci --workspace shared && npm ci --workspace client
+
+ - name: Download the blob reports
+ uses: actions/download-artifact@v7
+ with:
+ pattern: client-blob-*
+ path: client/.vitest-reports/
+ merge-multiple: true
+
+ - name: Merge the slices and check the thresholds
+ # Every blob holds a whole coverage map, and the merge reads them all
+ # into one process.
+ env:
+ NODE_OPTIONS: --max-old-space-size=6144
+ run: cd client && npx vitest run --merge-reports --coverage
- name: Upload coverage
uses: actions/upload-artifact@v6
@@ -822,9 +945,10 @@ jobs:
shared-coverage:
name: Shared Coverage
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 45
- needs: [plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
steps:
- uses: actions/checkout@v6
@@ -849,9 +973,10 @@ jobs:
plugin-sdk-coverage:
name: Plugin SDK Coverage
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 45
- needs: [plugin-facts, i18n-parity, server-quality, client-quality, plugin-sdk-quality]
defaults:
run:
working-directory: plugin-sdk
@@ -891,9 +1016,18 @@ jobs:
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
# Coverage jobs failing must stop the scan: a missing lcov file would make
# every line of that package report as uncovered, and the dashboard would
- # show a collapse that did not happen. The preflight gates already stop it
- # transitively through these four, so they aren't repeated here.
- needs: [server-coverage, client-coverage, shared-coverage, plugin-sdk-coverage]
+ # show a collapse that did not happen. The gates run beside the tests now,
+ # so they are listed here too, and a failed gate still stops the scan.
+ needs:
+ - plugin-facts
+ - i18n-parity
+ - server-quality
+ - client-quality
+ - plugin-sdk-quality
+ - server-coverage
+ - client-coverage
+ - shared-coverage
+ - plugin-sdk-coverage
steps:
- uses: actions/checkout@v6
@@ -1111,7 +1245,9 @@ jobs:
- client-e2e
- s3-contract
- postgres-probe
+ - server-tests
- server-coverage
+ - client-tests
- client-coverage
- shared-coverage
- plugin-sdk-coverage
diff --git a/.gitignore b/.gitignore
index df2d80872..96436cb6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,8 @@ coverage
coverage-*/
*.lcov
.nyc_output
+# Blob reports of a sharded vitest run (test.yml)
+.vitest-reports
# Cache
.npm
diff --git a/CLAUDE.md b/CLAUDE.md
index d5c184afd..89dbfabe5 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -136,6 +136,7 @@ These principles come out of a full-repo audit and shape all new code:
`.github/workflows/test.yml` runs, per package: typecheck (server also `typecheck:tests`, client also the strict-mode ratchet `lint:strict`), lint (client and server through `lint:warnings`, which also holds the warning count per rule), `lint:pages`, `lint:rtl`, `lint:size` (client and server), the server's `lint:strict`, `lint:boundaries`, `lint:tx`, `lint:dialect`, `lint:test-sql`, `lint:test-mocks`, `lint:test-new-service`, `lint:query-api`, `lint:mcp-zod`, `lint:service-http` and `lint:response-contracts`, the client's and server's `lint:format`, `lint:layers`, `lint:offline`, `lint:dup`, `lint:pairs`, `lint:skips`, `lint:i18n-keys` and `theme:lint`, shared's `contracts:open`, the repo-wide `lint:knip` (in server-quality), `check:plugin-facts`, `i18n:parity:strict` (with the untranslated-strings ratchet), the S3 contract suite, the Postgres probe (`postgres-probe`: every dialect helper on SQLite and Postgres, and the statements every repository method reaches with sample arguments against a Postgres service; the SQL errors per method and the list of methods it cannot measure are held to a baseline that only shrinks and fails while it is still unmeasured; see `server/CLAUDE.md`), the browser end-to-end flows (Chromium and WebKit), a client build with `check:gl-split`, coverage for all four packages, then a SonarCloud scan. It also builds the Docker image and boots it until `/api/health/ready` answers (`docker-image`), and lints and renders the Helm chart against the Kubernetes schemas and runs `docker compose config` on every compose file (`deploy-manifests`). `lint-prettier.yml` additionally runs `lint` + `lint:format` on `shared/`, both check-only. `plugin-sdk` has no lint script and is outside the eslint gates. **Not in CI**: the screenshot and help-media Playwright projects; run them locally. There are no git hooks; nothing runs before a commit except you. Other workflows build Docker images, scan them, and publish `trek-plugin-sdk` on `plugin-sdk-v*` tags.
+- **Tests run beside the gates, in shards.** The client and server suites run in slices on parallel runners (`client-tests`, `server-tests`, through each package's `vitest.shard.config.ts`), and `client-coverage`/`server-coverage` merge their blob reports and check the thresholds against the whole. A red slice is usually a failing test, a red merge job usually a threshold.
- **`ci-ok` is the required check.** The branch ruleset requires `ci-ok` (plus `lint` and `check-target` from their own workflows), and `ci-ok` needs every job above except the scan. It fails if any of them failed or was cancelled and passes if they passed or were skipped. A new gate job counts only once it is listed in `ci-ok`'s `needs:`.
- **Guides name paths that exist**: the `changes` job runs `scripts/ci/doc-paths.mjs`, which resolves every backtick path in the CLAUDE.md files, `README.md`, `server/src/nest/README.md` and the wiki against the tracked files; the missing ones are listed in `scripts/ci/doc-paths-baseline.json`, which only shrinks (`--update` after a fix).
- **What runs is decided by `changes`, not by `on.paths`**: `scripts/ci/changed-areas.mjs` maps the changed files to the `code`, `image` and `deploy` areas (tests: `npm run test:ci-scripts`). A path filter on the workflow would leave `ci-ok` unreported on a docs-only PR and block it. Add a new top-level file the build reads to the right area there.
diff --git a/client/vitest.shard.config.ts b/client/vitest.shard.config.ts
new file mode 100644
index 000000000..31dc279aa
--- /dev/null
+++ b/client/vitest.shard.config.ts
@@ -0,0 +1,16 @@
+import { defineConfig } from 'vitest/config';
+import base from './vitest.config';
+
+// One slice of the suite, for a Client Tests shard in test.yml
+// (`vitest run --config vitest.shard.config.ts --coverage --shard=i/n`). The
+// slice hands its coverage on in a blob report, and the Client Coverage job
+// merges the blobs and checks the whole against the thresholds in
+// vitest.config.ts. A slice alone sits far below them, so it neither checks
+// them nor writes a report of its own.
+export default defineConfig({
+ ...base,
+ test: {
+ ...base.test,
+ coverage: { ...base.test?.coverage, thresholds: undefined, reporter: [] },
+ },
+});
diff --git a/server/vitest.shard.config.ts b/server/vitest.shard.config.ts
new file mode 100644
index 000000000..8cd96ff5f
--- /dev/null
+++ b/server/vitest.shard.config.ts
@@ -0,0 +1,17 @@
+import { defineConfig } from 'vitest/config';
+import base from './vitest.config';
+
+// One slice of the suite, for a Server Tests shard in test.yml
+// (`vitest run --config vitest.shard.config.ts --coverage --shard=i/n`). The
+// slice hands its coverage on in a blob report, and the Server Coverage job
+// merges the blobs and checks the whole against the per-domain thresholds in
+// vitest.config.ts. A slice alone sits far below them, so it neither checks
+// them nor writes a report of its own. tests/unit/coverage-thresholds.test.ts
+// reads vitest.config.ts itself, so it still sees every entry.
+export default defineConfig({
+ ...base,
+ test: {
+ ...base.test,
+ coverage: { ...base.test?.coverage, thresholds: undefined, reporter: [] },
+ },
+});
diff --git a/wiki/Development-environment.md b/wiki/Development-environment.md
index 1f6af1d5e..7cfb97000 100644
--- a/wiki/Development-environment.md
+++ b/wiki/Development-environment.md
@@ -249,7 +249,7 @@ Then open a Pull Request from your fork to `liketrek/TREK` targeting the `dev` b
## Tips
- Always branch off from an up-to-date `dev` — run `git fetch upstream && git rebase upstream/dev` before starting new work.
-- Run tests before pushing: `npm test` at the repo root runs all workspaces. That alone is not the full CI gate. With `shared` built, these are the checks CI runs before any test (`.github/workflows/test.yml` is the source of truth):
+- Run tests before pushing: `npm test` at the repo root runs all workspaces. That alone is not the full CI gate. With `shared` built, these are the checks CI runs beside the tests (`.github/workflows/test.yml` is the source of truth):
- in `shared/`: `npm run typecheck && npm run contracts:open`
- in `server/`: `npm run build && npm run typecheck && npm run typecheck:tests && npm run typecheck:scripts && npm run check:entities && npm run check:db-types && npm run lint:check && npm run db:call-graph -- --sync --tx && npm run lint:size && npm run lint:boundaries && npm run lint:tx && npm run lint:test-sql && npm run lint:query-api && npm run lint:dialect && npm run check:plugin-facts`
- in `client/`: `npm run typecheck && npm run lint:warnings && npm run lint:pages && npm run lint:rtl && npm run lint:size && npm run lint:format && npm run lint:layers && npm run lint:offline && npm run lint:dup && npm run lint:pairs && npm run lint:skips && npm run lint:i18n-keys`