1
0
Fork 0

Compare commits

...

5 commits

Author SHA1 Message Date
cfbdcb6a22 v0.12.19 - bomperator movement sync, faster integration suite 2026-10-21 19:46:44 -04:00
b2a8e03be1 docs: add v0.12.19 changelog entry 2026-10-21 19:46:44 -04:00
e828f50516 test(vitest): honor KEEP_TEST_DBS=0 as force-drop escape hatch
Plan wording kept clones on failure unless KEEP_TEST_DBS=0; teardown now
implements both ends explicitly (=1 always keep, =0 always drop, default
keep-on-failure). Verified with a deliberately failing spec both ways.
2026-10-21 13:04:15 -04:00
507d0a9e5f docs: rewrite test-database lifecycle section for template/clone workers
Stage 4: document template + per-fork clones, the env flag matrix
(TEST_DATABASE_URI legacy serial bisect, TEST_DB_HARD_RESET, KEEP_TEST_DBS,
VITEST_MAX_FORKS, TEST_PG_POOL_MAX), jsdom-opt-in docblocks, and the
Vitest 4 returned-teardown contract.
2026-10-21 12:54:30 -04:00
938da9bf86 test(vitest): isolate:false shared forks with per-pid template clones + memoized payload boot
Stage 3 of the int-suite speedup (gate G2 showed Vitest 4's pool scheduler
only reuses worker processes between isolate:false tasks, so per-file fork
spawning made clone+boot costs unavoidable at stage 2):

- config: workers branch runs pool=forks with isolate:false, cap 8 via
  VITEST_MAX_FORKS, node default env (jsdom docblocks on DOM specs),
  failure-marker reporter, and idempotent setupFiles chain
- vitest-worker-setup: one template clone PER FORK PROCESS named by pid
  (VITEST_WORKER_ID churns per task, which silently re-cloned per file);
  DATABASE_URI repoint + TEST_PG_POOL_MAX=8 (measured hook deadlocks at 3)
- vitest.setup: once-per-process serial test URI markers; afterEach
  useRealTimers guard (restoreAllMocks omitted: it resurrects vi.mock
  module factories mid-file); logging absorber for fire-and-forget event
  writes that reject after their spec's cleanup deleted fixture users
- helpers/get-test-payload.ts: memoized Payload boot shared across files
  in a fork; codemod converted all 91 self-booting specs mechanically
- pinned opt-outs (own boot + comments): game-structures-labor-route,
  mission-reminder, notification-inbox-scope (jwtSign writes leak into
  the shared instance's auth state across files)
- promotion-nominations: create the superuser before its rank ladder so
  the Users-hook Recruit rank gets leading orderable tokens (its
  top-of-ladder guard needs Col to remain ladder-max on fresh clones);
  operation-economy: itemType-scope the market-state assertion (asset
  and resource ids collide as bare integers under per-fork databases)

Gate G3: 5 consecutive full green runs (149/149 files), warm wall 53-65s
vs 598s baseline (~10x), zero clone residue after green runs. Vitest 4
note: globalTeardown config no longer exists; teardown returns from
globalSetup.
2026-10-21 12:54:30 -04:00
103 changed files with 431 additions and 366 deletions

View file

@ -58,8 +58,13 @@ Known pre-existing errors (not yours, don't widen scope to fix them): `src/colle
## Test details
- **Dedicated test database**: all tests run against `<db>_test` (derived from `DATABASE_URI`, or set `TEST_DATABASE_URI`), never the dev database. `tests/test-db.ts` bootstraps it idempotently: ensure database exists, push the schema (drizzle `push`, because the migration chain assumes a schema that push created), truncate every table (migration journals and PostGIS internals survive), seed baselines (`seedRoles` + a Game Rules global with a main currency resource, `tests/seed-baseline.ts`), and repair id sequences (migrations backfill explicit-id rows, which leaves sequences behind and causes `ValidationError: field is invalid: id` on creates). Truncate runs at both global setup (clears crashed-run leftovers) and teardown, so every run starts and ends empty. `TEST_DB_HARD_RESET=1` drops and recreates the test database from scratch instead of truncating. Serialized test files (`fileParallelism: false`) because parallel workers share the one database.
- **Integration tests**: `tests/int/**/*.int.spec.ts` — Vitest with jsdom. Requires the live PostgreSQL test database (bootstrapped automatically via `vitest-global.ts`; `vitest.setup.ts` points the process at it). Uses `dotenv/config` via `vitest.setup.ts`.
- **Dedicated test databases**: all tests run against databases derived from `DATABASE_URI`, never the dev database. The default mode builds them from a template: `<db>_test_template` is ensured once per schema change (`tests/test-db.ts`: ensure db, drizzle `push` with auto-accepted warnings via `tests/push-schema.ts`, analytics DDL, `seedRoles` + baseline seed, sequence repair; a broad schema-hash is cached in `.cache/testdb-template.json` and warm runs skip push/seed entirely), then vitest forks clone it into `<db>_test_w<ID>` at startup (`CREATE DATABASE ... TEMPLATE`; per-fork attach in `tests/vitest-worker-setup.ts`). Two forks never share tables, so files run sequentially-within-a-fork and in parallel across forks (pool `forks`, `isolate: false`, which is required for worker reuse and for the memoized `tests/helpers/get-test-payload.ts` boot). Teardown (returned by `tests/vitest-global.ts`; Vitest 4 removed the `globalTeardown` config) drops clones after green runs and keeps them after failures for postmortem; leftover clones from crashed runs are dropped at the next startup. E2E keeps the single serial `<db>_test`, recreated fresh from the template each run, then seeded with the shared e2e login. Environment flag matrix:
- `TEST_DATABASE_URI`: forces legacy serial mode against exactly this database (truncate-per-run, no templates/clones, `fileParallelism: false`), the documented bisect hatch for flaky specs.
- `TEST_DB_HARD_RESET=1`: ignores the template cache and rebuilds `<db>_test_template` from scratch.
- `KEEP_TEST_DBS=1`: teardown keeps worker clones even after green runs; `KEEP_TEST_DBS=0` forces dropping even after failures.
- `VITEST_MAX_FORKS`: fork cap (default 8).
- `TEST_PG_POOL_MAX`: internal (set by worker setup, default 8), caps the node-postgres pool per Payload boot in workers mode so N forks stay under `max_connections=100`.
- **Integration tests**: `tests/int/**/*.int.spec.ts` - Vitest, default `node` environment with component specs opting in via a `// @vitest-environment jsdom` docblock. Requires the live PostgreSQL test databases (bootstrapped automatically via `vitest-global.ts`; `vitest.setup.ts` points the process at it). Uses `dotenv/config` via `vitest.setup.ts`.
- **E2E tests**: `tests/e2e/*.e2e.spec.ts` — Playwright with a project named "vivaldi" that launches the **Vivaldi binary** (`/usr/bin/vivaldi`, headless args in `playwright.config.ts`) — not plain Chromium. Override the binary with `E2E_BROWSER_PATH` (e.g. Playwright's bundled chromium) when the installed Vivaldi crashes under automation; the default stays Vivaldi. The `webServer` config auto-starts `pnpm dev` with `DATABASE_URI` pointed at the test DB (bootstrapped by `tests/e2e/global-setup.ts`, with `reuseExistingServer: true`). `global-setup` also seeds the shared e2e login: `dev` / `Test123` (developer legacy role + a superuser Roles doc for permission-gated UI + the "J. Fraley" rank so the dashboard heading matches). E2E runs serially (`workers: 1`, one webpack dev server) with generous `timeout`/`expect` timeouts because first navigation to a route triggers a cold webpack compile. Currently: tours smoke (auto-start, dismissal, replay), frontend, operations, reservations, supply boxes, OPORD recall, session banner, tech tree. Caveat: when your own dev server is already on port 3000, `reuseExistingServer` silently reuses it and its DEV database, bypassing the test-DB wiring; free the port first for a true test-DB run.
- Run a single integration test: `bun run vitest run tests/int/api.int.spec.ts`
- Run a single e2e test: `bun run playwright test tests/e2e/frontend.e2e.spec.ts`

View file

@ -1,5 +1,15 @@
# Changelog
# v0.12.19
Bomperator matches stay in step again, without the arena snapping your fighter around after a lag spike.
### Fixes
- **Bomperator.** Your fighter now moves exactly where the arena shows it, with the same smoothing other players get. After a lag spike or a tab switch the arena no longer drifts out of step or snaps your character around, and ghost charges land where the arena will apply them.
---
# v0.12.18
### Fixes

View file

@ -1,6 +1,6 @@
{
"name": "polaris-task-force",
"version": "0.12.18",
"version": "0.12.19",
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
"license": "MIT",
"type": "module",

View file

@ -0,0 +1,28 @@
import type { Payload } from "payload";
/**
* Module-level memoized Payload instance for the int suite under Vitest's
* `isolate: false` worker pool (stage 3 of the test speedup). A vitest fork
* keeps its module registry across test files, so the first spec to call this
* pays the full config load + adapter boot and every later file in the same
* fork reuses the instance against the fork's dedicated database clone.
*
* Specs that turn out to leak or depend on module state across files simply
* keep (or revert to) their own direct `getPayload({ config })` boot: opting
* out is just not importing this helper, which restores a cheap-but-correct
* per-file boot. Name any reason in a comment at the opt-out site.
*/
let instance: Promise<Payload> | undefined;
export function getTestPayload(): Promise<Payload> {
if (!instance) {
instance = import("@payload-config")
.then((m) => m.default)
.then((config) => import("payload").then(({ getPayload }) => getPayload({ config })));
instance.catch(() => {
// A failed boot must not poison the worker for all later files.
instance = undefined;
});
}
return instance;
}

View file

@ -1,5 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { getPayload, type CollectionSlug, type Payload, type Where } from "payload";
import { type CollectionSlug, type Payload, type Where } from "payload";
import type { Map as MapDoc, Resource, Structure } from "@/payload-types";
import config from "@payload-config";
@ -185,7 +186,7 @@ describe("Adjacency auras", () => {
describe("production tick", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
createdIds.maps.push(
(
(await payload.create({

View file

@ -1,6 +1,6 @@
import { getPayload, Payload } from "payload";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import type { Access } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -75,8 +75,7 @@ describe("Scoped admin page access control", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
const readOnlyRole = await makeRole("readonly", { permissions: ["missions:read"] });

View file

@ -1,6 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { sql } from "@payloadcms/db-postgres";
import { getPayload, type Payload } from "payload";
import config from "@/payload.config";
import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import {
@ -57,7 +57,7 @@ function envelope(body: Record<string, unknown>) {
const createdSessionIds: string[] = [];
beforeAll(async () => {
payload = await getPayload({ config: await config });
payload = await getTestPayload();
});
afterAll(async () => {

View file

@ -1,6 +1,6 @@
// @vitest-environment jsdom (specs clear window.localStorage via the Shims evaluator)
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
@ -203,8 +203,7 @@ describe("announcements collection access control", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
const permittedRole = await makeRole("permitted", {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { beforeAll, describe, expect, it } from "vitest";
@ -7,8 +7,7 @@ let payload: Payload;
describe("API", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
});
it("fetches users", async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { mkdirSync, rmSync, writeFileSync } from "fs";
import { join } from "path";
@ -34,8 +34,7 @@ function mediaEnv(screenshots = ""): MediaEnv {
describe("Arma catalog import", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// Vehicles need a fuel resource for the fuel group; reuse one if a prior
// fixture left it, otherwise create it (and only then clean it up).

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import {
formatInstanceRef,
@ -91,8 +91,7 @@ async function lockerDoc() {
describe("Arma locker sync", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const user = await payload.create({
collection: "users",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { BankAccount } from "@/payload-types";
import { createAccount, ensurePersonalAccount, getTreasuryAccountId } from "@/lib/banking";
@ -33,8 +33,7 @@ describe("Arma shop money sync", () => {
let createdTreasury = false;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const user = await payload.create({
collection: "users",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { User, Award } from "@/payload-types";
@ -44,8 +44,7 @@ describe("Award Advancement Series", () => {
}
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// Create a superuser role (RBAC resolves via roleDocs, not the legacy enum)
const superRole = await payload.create({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Award, Profile, User } from "@/payload-types";
import { evaluateAwardRules } from "@/lib/awards/automation";
@ -127,8 +127,7 @@ describe("Award automation sweeper", () => {
}
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
medalId = await makeAward(`${RUN} Merit Medal`);
tier1Id = await makeAward(`${RUN} YOS Bronze`, 1);

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Award, Profile, User } from "@/payload-types";
@ -66,8 +66,7 @@ describe("Award grant notifications", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const makeAward = async (name: string, type: "medal" | "ribbon"): Promise<number> => {
const created = (await payload.create({

View file

@ -5,9 +5,9 @@
* (live server + real sockets). This file stays because the registry remains
* live behind the HttpTransport fallback until prod proves the arena.
*/
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { getPayload, type Payload } from "payload";
import config from "@payload-config";
import { type Payload } from "payload";
import {
INTER_ROUND_COUNTDOWN_TICKS,
@ -278,7 +278,7 @@ describe("bomperator: awards write to the profile (DB round-trip)", () => {
const createdUserIds: number[] = [];
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
}, 30_000);
afterAll(async () => {

View file

@ -1,5 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { getPayload, type CollectionSlug, type Payload, type Where } from "payload";
import { type CollectionSlug, type Payload, type Where } from "payload";
import type { Map as MapDoc, Resource, Structure } from "@/payload-types";
import config from "@payload-config";
@ -212,7 +213,7 @@ describe("Construction crew speed", () => {
describe("start gating and rate recompute", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
const rules = (await payload.findGlobal({
slug: "game-rules",
depth: 0,

View file

@ -3,8 +3,8 @@
* grant with a reason (the reason is stored and shown to the earner), and both
* are gated on `contribution-entries:moderate`.
*/
import { getPayload, type Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { Role, User } from "@/payload-types";
@ -72,7 +72,7 @@ describe("Contribution moderation actions", () => {
};
beforeAll(async () => {
payload = await getPayload({ config: await config });
payload = await getTestPayload();
const modRole = await makeRole("mod", ["contribution-entries:moderate"]);
const plainRole = await makeRole("plain", []);
moderator = await makeUser("mod", modRole.id);

View file

@ -1,5 +1,5 @@
import { getPayload } from "payload";
import config from "@payload-config";
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Mission, User } from "@/payload-types";
import {
@ -12,7 +12,7 @@ import {
} from "@/lib/contributions";
import { createMissionMarker } from "@/lib/intelligence/missionMap";
type Payload = Awaited<ReturnType<typeof getPayload>>;
type Payload = Awaited<ReturnType<typeof getTestPayload>>;
describe("Contribution / XP service", () => {
let payload: Payload;
@ -87,7 +87,7 @@ describe("Contribution / XP service", () => {
);
beforeAll(async () => {
payload = await getPayload({ config: await config });
payload = await getTestPayload();
const map = await payload.create({
collection: "maps",
data: {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Role, User } from "@/payload-types";
import { CustomMinefields } from "@/collections/minigames/CustomMinefields";
@ -38,8 +38,7 @@ describe("Custom minefields", () => {
const scoreIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
author = (await payload.create({
collection: "users",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Role, User } from "@/payload-types";
import { CustomRadioTests } from "@/collections/minigames/CustomRadioTests";
@ -30,8 +30,7 @@ describe("Custom radio tests", () => {
const scoreIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
author = (await payload.create({
collection: "users",

View file

@ -1,6 +1,6 @@
import { getPayload, Payload } from "payload";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import type { Access, AccessArgs } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -155,8 +155,7 @@ describe("Division-scoped admin access (intelligence / logistics)", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
const bareRole = await makeRole("bare", { permissions: [] });

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Asset, BankAccount, MarketListing, User } from "@/payload-types";
@ -88,8 +88,7 @@ describe("Economy consumption: DB integration", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
assetId = await createFixtureAsset();

View file

@ -2,10 +2,9 @@
* Integration tests for economy-tick determinism (seeded rng, period seeding),
* price-change emission threshold, and the economy event log wiring.
*/
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Payload } from "payload";
import { getPayload } from "payload";
import config from "@/payload.config";
import { EventTypes } from "@/utils/event-log/eventTypes";
import { emitEconomyEvents } from "@/lib/economy/events";
@ -71,8 +70,7 @@ describe("economy events (DB)", () => {
let resourceId: number | null = null;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
});
afterAll(async () => {

View file

@ -1,6 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { getPayload, type CollectionSlug, type Payload } from "payload";
import config from "@/payload.config";
import { type CollectionSlug, type Payload } from "payload";
import {
applyEconomyTick,
computePriceModifier,
@ -28,8 +28,7 @@ let resourceId: number;
let assetId: number;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
});
afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Campaign, Map as MissionMap, Mission, Role, User } from "@/payload-types";
@ -105,8 +105,7 @@ describe("Leadership evaluations", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const map = (await payload.create({
collection: "maps",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -31,7 +31,7 @@ async function emit(input: Parameters<typeof emitGameEvent>[1]) {
describe("discordRequested flag on game events", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
}, TIMEOUT);
afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, type Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -33,7 +33,7 @@ describe("routine event classification (pure)", () => {
describe("routine event filtering (database)", () => {
beforeAll(async () => {
payload = await getPayload({ config: await config });
payload = await getTestPayload();
}, TIMEOUT);
afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload, type Where } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload, type Where } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -129,8 +129,7 @@ describe("event visibility enforcement (database)", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const plainRole = await makeRole("plain", { permissions: [] });
const gateRole = await makeRole("gate", { permissions: ["player-flags:read"] });

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Campaign, Map as MissionMap, Mission, User } from "@/payload-types";
@ -41,8 +41,7 @@ describe("Friday open-slot notice", () => {
const roleIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// Sweep leftovers from crashed earlier runs: a stray Concept mission in
// the fixture window would flip the first hasMissionOnFriday assertion.

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { GameVehicle } from "@/payload-types";
import { processGarageEvent } from "@/lib/arma-bridge/garages";
@ -83,8 +83,7 @@ async function findGarageCommands(type: string) {
describe("Arma garage sync", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const resource = await payload.create({
collection: "resources",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { GameVehicle, User } from "@/payload-types";
import {
@ -117,8 +117,7 @@ async function vehicleDoc(id: number) {
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth");
const garageRole = await payload.create({

View file

@ -1,6 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { describe, it, expect, beforeAll, afterEach, vi } from "vitest";
import config from "@payload-config";
import { getPayload, type Payload } from "payload";
import { type Payload } from "payload";
import type { Map as MapDoc, Resource } from "@/payload-types";
import { checkResourcesInRange } from "@/lib/map/placement";
import { nodeIconOption } from "@/lib/map/nodeIcons";
@ -18,7 +18,7 @@ describe("generic marker nodes (no resources)", () => {
let mapper: { id: number };
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
map = (await payload.create({
collection: "maps",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Campaign, Map as MissionMap, Mission, User } from "@/payload-types";
@ -20,8 +20,7 @@ describe("Imminent-op reminder query", () => {
const missionIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const map = (await payload.create({
collection: "maps",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -90,8 +90,7 @@ describe("Intelligence navigation visibility (canViewIntelligence)", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
// Mirrors the standard "user" role: intel-domain read permissions, no writes.

View file

@ -1,5 +1,5 @@
import { getPayload, type Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type {
@ -308,8 +308,7 @@ async function maxNotificationId(userId: number): Promise<number> {
// --- setup / teardown ------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
scrap = await makeResource("scrap", 1);
ore = await makeResource("ore", 1);

View file

@ -5,8 +5,8 @@
* pulls the XP back. Each grant test uses a fresh author because the rule's
* 25 XP daily cap allows a single entry per day.
*/
import { getPayload, type Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { Journal, User } from "@/payload-types";
@ -111,7 +111,7 @@ describe("Journal contribution XP", () => {
});
beforeAll(async () => {
payload = await getPayload({ config: await config });
payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth");
}, TIMEOUT);

View file

@ -2,8 +2,8 @@
* Journals access rules: authors own their entries (drafts private), every
* logged-in user reads published entries, staff permissions bypass ownership.
*/
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Journal, Role, User } from "@/payload-types";
@ -79,7 +79,7 @@ describe("Journals access control", () => {
};
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
const plainRole = await makeRole("plain", []);
const staffRole = await makeRole("staff", [
"journals:read",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { classifyKillCategory, parseKillPayload, processPlayerKill } from "@/lib/arma-bridge/processSyncEvents";
@ -11,8 +11,7 @@ describe("Kill tracking", () => {
let profileId: number;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const user = await payload.create({
collection: "users",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -113,8 +113,7 @@ describe("Leadership-initiated removals (leadership-transfers)", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// The per-user permission cache is keyed by numeric id, which can collide
// with users from previously run spec files in the same serialized run.
invalidatePermissionCache();

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { beforeAll, describe, expect, it } from "vitest";
@ -24,7 +24,7 @@ let payload: Payload;
*/
describe("payload-locked-documents relational query", () => {
beforeAll(async () => {
payload = await getPayload({ config: await config });
payload = await getTestPayload();
});
it("hydrates a lock document at depth 1 without exceeding the argument limit", async () => {

View file

@ -1,4 +1,5 @@
import { getPayload, Payload, type CollectionSlug, type Where } from "payload";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload, type CollectionSlug, type Where } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
@ -256,7 +257,7 @@ describe("Game Map System", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth");
mapA = await makeMap(`${RUN} Altis`);

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { beforeAll, afterAll, describe, expect, it } from "vitest";
import type { Asset, BankAccount, GameNpc, LockerStorage, MarketListing, User } from "@/payload-types";
@ -41,8 +41,7 @@ describe("Marketplace", () => {
let currencyId: number | null;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// Always create a fresh, live, tradeable asset for the test. The
// "approved" approvalStatus can't be set from an unauthenticated payload

View file

@ -1,6 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import crypto from "crypto";
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -61,7 +61,7 @@ describe("MCP API key collection access (payload-mcp-api-keys)", () => {
};
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
const plainRole = await makeRole("plain");
const superRole = await makeRole("super", { isSuperuser: true });

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User } from "@/payload-types";
@ -26,8 +26,7 @@ const notificationsFor = async (userId: number) => {
describe("Minigame achievement notifications", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
await clearMinigameData();
originalRules = (await payload.findGlobal({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User } from "@/payload-types";
@ -22,8 +22,7 @@ const at = (iso: string) => new Date(iso);
describe("Minigame month/year achievements", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
await clearMinigameData();

View file

@ -8,8 +8,8 @@
* actual security boundary on the test database.
*/
import { getPayload, type Payload, type User } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { type Payload, type User } from "payload";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi, type MockInstance } from "vitest";
import {
@ -119,8 +119,7 @@ function fleetAt(x: number, y: number): FobPlacement[] {
}
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth");
loggerSpy = vi.spyOn(payload.logger, "info");

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User } from "@/payload-types";
@ -37,8 +37,7 @@ async function clearMinigameData(): Promise<void> {
describe("Minigame entry recording + anchored periods", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// The period spec shares these tables and the same anchor; start clean so
// the two files are order-independent.

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User } from "@/payload-types";
@ -35,8 +35,7 @@ const entry = (over: Partial<LedgerEntry>): LedgerEntry => ({
describe("Minigame period close pipeline", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// The entries spec shares these tables and the same anchor; start clean so
// the two files are order-independent.

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User } from "@/payload-types";
@ -21,8 +21,7 @@ let originalRules: Record<string, unknown> | null = null;
describe("Minigame registry", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
await clearMinigameData();

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User } from "@/payload-types";
@ -21,8 +21,7 @@ let originalRules: Record<string, unknown> | null = null;
describe("Minigame leaderboard read model", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
await clearMinigameData();
originalRules = (await payload.findGlobal({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { loadMinigameRegistry, getMinigameReleaseState } from "@/lib/minigames/loadRegistry";
@ -13,8 +13,7 @@ let originalRules: Record<string, unknown> | null = null;
describe("Upcoming minigames", () => {
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
await clearMinigameData();
originalRules = (await payload.findGlobal({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Campaign, Map as MissionMap, Mission, User } from "@/payload-types";
@ -26,8 +26,7 @@ describe("Mission lifecycle (auto-start + auto-complete)", () => {
const completedBySweep: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const map = (await payload.create({
collection: "maps",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Map as MissionMapDoc, Mission, User } from "@/payload-types";
@ -269,7 +269,7 @@ describe("Mission planning map service", () => {
})) as unknown as Mission;
beforeAll(async () => {
payload = await getPayload({ config: await config });
payload = await getTestPayload();
const map = (await payload.create({
collection: "maps",
data: {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type {
@ -189,8 +189,7 @@ describe("Mission role sign-ups", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const map = (await payload.create({
collection: "maps",

View file

@ -1,5 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { getPayload, type CollectionSlug, type Payload, type Where } from "payload";
import { type CollectionSlug, type Payload, type Where } from "payload";
import type { Map as MapDoc, Resource, Structure } from "@/payload-types";
import config from "@payload-config";
@ -218,7 +219,7 @@ describe("Module system", () => {
describe("install / uninstall", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
createdIds.maps.push(
(
(await payload.create({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -63,8 +63,7 @@ describe("User notification read access control", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
const plainRole = await makeRole("plain", { permissions: [] });

View file

@ -1,6 +1,10 @@
// jose (via payload's jwtSign) fails under jsdom: its module-level TextEncoder and
// the global Uint8Array come from different realms, so signing throws a TypeError.
//
// Pinned to its own payload boot (stage-3 straggler policy): this spec's
// signed-token auth writes into the shared memoized instance's auth state and
// leaks "You must be logged in." drift into later files on the same fork.
import { getFieldsToSign, getPayload, jwtSign, Payload } from "payload";
import config from "@/payload.config";

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -81,8 +81,7 @@ describe("notification read-state is personal to the recipient", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
const plainRole = await makeRole("plain", { permissions: [] });

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -27,7 +27,7 @@ async function createMedia(name: string): Promise<number> {
describe("resolveAttachments", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
}, TIMEOUT);
afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -34,7 +34,7 @@ async function createUser(username: string): Promise<number> {
describe("condition groups (and / or / nor over leaf conditions)", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
}, TIMEOUT);
afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -33,7 +33,7 @@ async function createUser(username: string): Promise<{ id: number }> {
describe("flag owner targeting (event node effects)", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
}, TIMEOUT);
afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
@ -109,7 +109,7 @@ describe("flag token extraction + interpolation (pure)", () => {
describe("text flags (player-flags collection)", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
}, TIMEOUT);
afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import {
expireOperationReservations,
@ -224,8 +224,7 @@ async function storedAmountAt(siteId: number, resourceId: number): Promise<numbe
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const currencyId = await getMainCurrencyId(payload);
if (!currencyId) throw new Error("Test requires a main currency in Game Rules.");

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { applyEconomyEffect, DEFAULT_ECONOMY_CAPS } from "@/lib/operations/economy";
import { ECONOMY_NOTE_PREFIX, type EconomyRecord } from "@/lib/operations/economyConfig";
@ -217,8 +217,7 @@ async function manualExtractionEffect(label: string, resourceId: number, amount:
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const server = await payload.create({
collection: "game-servers",
@ -525,7 +524,10 @@ describe("Operation economy adapter", () => {
const docs = await payload.find({
collection: "market-state",
where: { itemId: { equals: resourceBetaId } },
// itemType-scoped on purpose: asset ids and resource ids collide as
// bare integers, and under per-fork databases another spec's asset
// ledger row can share this resource's numeric id.
where: { and: [{ itemType: { equals: "resource" } }, { itemId: { equals: resourceBetaId } }] },
limit: 1,
depth: 0,
overrideAccess: true,

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { hashPayload, processOperationEvent, stableStringify } from "@/lib/operations/process";
import type { RawSyncEvent } from "@/lib/operations/types";
@ -18,8 +18,7 @@ describe("Operation ledger", () => {
const createdEffectIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const user = await payload.create({
collection: "users",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { computeReadiness, getReadiness, type ReadinessScope } from "@/lib/operations/readiness";
import { READINESS_CALCULATION_VERSION } from "@/lib/operations/readinessTypes";
@ -139,8 +139,7 @@ function scopeFor(windowStart: Date, windowEnd: Date): ReadinessScope {
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// One shared, minute-floored window: the aggregate identity is
// `subjectType:subjectId:windowStart`, so every test that expects to find

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { BankAccount, OperationReservation, Structure, User } from "@/payload-types";
import { createReservation, cancelReservation } from "@/app/(frontend)/operations/reservations/actions";
@ -204,8 +204,7 @@ async function makeFundedAccount(amount: number): Promise<BankAccount> {
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth");
const superRole = await payload.create({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type {
GameStructure,
@ -162,8 +162,7 @@ async function makeVehicle(status: "idle" | "assigned"): Promise<number> {
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const superRole = await payload.create({
collection: "roles",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { OperationReservation, User } from "@/payload-types";
import { getReservationList } from "@/app/(frontend)/operations/reservations/surface";
@ -68,8 +68,7 @@ async function createReservedReservation(key: string, operationId: string): Prom
}
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth");
const superRole = await payload.create({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { acknowledgeCommand, recoverExpiredCommands } from "@/lib/arma-bridge/commands";
import { replayOperationEvent } from "@/lib/operations/reconcile";
@ -71,8 +71,7 @@ async function opEventFor(rawId: number): Promise<{ id: number; status: string }
}
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const server = await payload.create({
collection: "game-servers",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { processOperationEvent } from "@/lib/operations/process";
import { reserveOperationAssets, type SettlementRecord } from "@/lib/operations/allocation";
@ -202,8 +202,7 @@ async function findReservation(key: string): Promise<OperationReservation | null
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const superRole = await payload.create({
collection: "roles",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { applyZonePressure, computeZoneState, PRESSURE_OUTCOME_DELTAS } from "@/lib/operations/territory";
@ -80,8 +80,7 @@ async function pressureRowCount(zoneId: number): Promise<number> {
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const actor = await payload.create({
collection: "users",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { getOperationOverview, getSurfaceCapabilities } from "@/lib/operations/surface";
import { getOperationAar, getOperationLedger } from "@/lib/operations/surfaceQuery";
@ -79,8 +79,7 @@ async function makeRawEvent(label: string, type: string, payloadData: unknown):
}
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const superRole = await payload.create({
collection: "roles",

View file

@ -1,5 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { getPayload, type CollectionSlug, type Payload, type Where } from "payload";
import { type CollectionSlug, type Payload, type Where } from "payload";
import type { LaborClassification, Map as MapDoc, Resource, Structure } from "@/payload-types";
import config from "@payload-config";
@ -138,7 +139,7 @@ async function stallReason(siteId: number): Promise<string | null> {
describe("Production system", () => {
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
createdIds.maps.push(
(
(await payload.create({

View file

@ -154,6 +154,17 @@ describe("Promotion nominations", () => {
payload = await getPayload({ config: payloadConfig });
invalidatePermissionCache();
// The superuser must be created BEFORE this suite's own ranks: the Users
// afterChange hook auto-provisions an entry-level "Recruit" rank on first
// user creation, and Ranks are `orderable` - newly created ranks always
// receive monotonically trailing _order tokens. The "top of the ladder"
// guard in submitNomination only rejects when Col is the LAST ladder
// entry, so the hook-created Recruit must sort before Pvt..Col. Creating
// any user first guarantees that on a freshly cloned database regardless
// of which files share the worker (this suite used to pass only because
// earlier alphabet files happened to seed Recruit in a shared db).
superuser = await makeUser(`${RUN}-superuser`, ["admin"]);
// Self-contained 4-rank ladder: Pvt < Cpl < Sgt < Col (orderable _order).
for (const [name, abbreviation] of [
["Pvt", "pvt"],
@ -186,7 +197,6 @@ describe("Promotion nominations", () => {
})) as unknown as Role;
roleIds.push(superRole.id);
superuser = await makeUser(`${RUN}-superuser`, ["admin"]);
await payload.update({
collection: "users",
id: superuser.id,

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Rank, User } from "@/payload-types";
@ -125,8 +125,7 @@ describe("Promotions", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// Self-contained 5-rank ladder: Pvt < Cpl < Sgt < SSgt < Lt.
pvt = await makeRank("Pvt", "pvt");

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { NextRequest } from "next/server";
import { processReinforcementEvent } from "@/lib/arma-bridge/reinforcements";
@ -55,8 +55,7 @@ describe("Reinforcement pools", () => {
beforeAll(async () => {
process.env.ARMA_BRIDGE_API_KEY = BRIDGE_KEY;
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const server = await payload.create({
collection: "game-servers",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Campaign, Map as MissionMap, Mission, User } from "@/payload-types";
@ -33,8 +33,7 @@ describe("Respawn ticket settlement", () => {
const ticketIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const map = (await payload.create({
collection: "maps",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { User, RibbonSubmission } from "@/payload-types";
@ -23,8 +23,7 @@ describe("Ribbon Design Submissions", () => {
let adminUserId: number;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// Create a regular user
user = (await payload.create({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Campaign, Map as MissionMap, Mission, User } from "@/payload-types";
@ -20,8 +20,7 @@ describe("Forced roll-call target helpers", () => {
const missionIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const map = (await payload.create({
collection: "maps",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { GameServer } from "@/payload-types";
@ -14,8 +14,7 @@ describe("Server presence sweep", () => {
const serverIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
now = new Date();
now.setMilliseconds(0);
});

View file

@ -1,6 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import config from "@payload-config";
import { getPayload, type Payload } from "payload";
import { type Payload } from "payload";
import type {
GameStructure,
GameVehicle,
@ -114,7 +114,7 @@ describe("shipment lifecycle (advanceShipment)", () => {
}) as Promise<GameVehicle>;
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
const rules = await payload.findGlobal({ slug: "game-rules" });
expect(rules).toBeTruthy();

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { StoryBeat, StoryBeatState, StoryVoiceover, User } from "@/payload-types";
@ -66,8 +66,7 @@ describe("Story beats", () => {
let publishedBeatId: number;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const createTestUser = async (name: string, roles: User["roles"]) => {
return (await payload.create({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { ArmaCommand, SupplyBox, User } from "@/payload-types";
import { queueCrateCommand } from "@/app/(frontend)/logistics/supply-boxes/actions";
@ -102,8 +102,7 @@ async function findCommand(commandId: string): Promise<ArmaCommand | null> {
// Setup / teardown
// ---------------------------------------------------------------------------
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth");
const superRole = await payload.create({

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { GameServer, SupplyBox } from "@/payload-types";
@ -16,8 +16,7 @@ describe("Supply box crate sync", () => {
const boxIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const server = (await payload.create({
collection: "game-servers",
data: {

View file

@ -1,4 +1,5 @@
import { getPayload, type Payload } from "payload";
import { getTestPayload } from "../helpers/get-test-payload";
import { type Payload } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -201,8 +202,7 @@ describe("survey submission gates", () => {
});
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
const rank = await payload.create({
@ -385,8 +385,7 @@ describe("survey collection access control", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
staffRole = await makeRole("staff", {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -107,8 +107,7 @@ describe("Tech Categories (collection + RBAC + tech tree data model)", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
invalidatePermissionCache();
const bareRole = await makeRole("bare", { permissions: [] });

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { GameStructure, LaborClassification, Structure, Technology, User } from "@/payload-types";
@ -188,8 +188,7 @@ describe("tech tick (research engine)", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
baseTime = new Date(Date.UTC(2026, 9, 20, 12, 0, 0));
});

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -77,7 +77,7 @@ describe("Tech Tree optimistic concurrency guard (database)", () => {
});
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
const role = (await payload.create({
collection: "roles",
@ -281,7 +281,7 @@ describe("Tech Tree bulk position preconditions (database)", () => {
};
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
for (const label of ["a", "b", "c"]) {
await makeTech(label);
}

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -87,7 +87,7 @@ describe("tech tree position bulk write (database)", () => {
const ids: number[] = [];
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
for (const label of ["a", "b", "c"]) {
const doc = await payload.create({
collection: "technologies",

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext";
import { beforeAll, afterAll, describe, expect, it } from "vitest";
@ -91,8 +91,7 @@ describe("Tickets", () => {
let staff: User;
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
reporter = await makeUser("reporter");
assignee = await makeUser("assignee");

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -103,8 +103,7 @@ describe("Assignment transfer requests", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
users.req1 = await makeUser("req-1");
users.leadA = await makeUser("lead-a");

View file

@ -1,5 +1,5 @@
import { getPayload, Payload, type Where } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload, type Where } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -92,8 +92,7 @@ describe("voiceover listing scopes submissions to their script", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
const plainRole = await makeRole("plain", { permissions: [] });
const otherRole = await makeRole("other", { permissions: [] });

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User, WikiPage } from "@/payload-types";
@ -73,8 +73,7 @@ describe("Wiki Documentation category", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
plainUser = await makeUser(`${RUN}-plain`, ["user"]);
adminUser = await makeUser(`${RUN}-admin`, ["admin"]);

View file

@ -1,6 +1,6 @@
import { getPayload, Payload } from "payload";
import { getTestPayload } from "../helpers/get-test-payload";
import { Payload } from "payload";
import type { AccessArgs } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User, WikiPage, WikiRevision, WikiTemplate } from "@/payload-types";
@ -80,8 +80,7 @@ describe("Wiki", () => {
const templateIds: number[] = [];
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
user = (await payload.create({
collection: "users",
@ -416,8 +415,7 @@ describe("Wiki", () => {
};
beforeAll(async () => {
const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig });
payload = await getTestPayload();
// Regression fixture: a role granting ONLY the four broad intelligence
// read permissions that the standard "user" role also grants. Before the

View file

@ -1,6 +1,6 @@
import { getTestPayload } from "../helpers/get-test-payload";
import { describe, it, expect, beforeAll } from "vitest";
import config from "@payload-config";
import { getPayload, type Payload } from "payload";
import { type Payload } from "payload";
import type { Campaign, Map as MapDoc } from "@/payload-types";
import {
easeStatClass,
@ -42,7 +42,7 @@ describe("world map screen eligibility", () => {
};
beforeAll(async () => {
payload = await getPayload({ config });
payload = await getTestPayload();
officialCampaign = (await payload.create({
collection: "campaigns",

View file

@ -43,7 +43,7 @@ import "dotenv/config";
* - `TEST_DB_HARD_RESET=1`: ignore the template cache and rebuild the
* template from scratch.
* - `KEEP_TEST_DBS=1`: teardown keeps worker clones even after green runs
* (postmortem hatch).
* (postmortem hatch); `KEEP_TEST_DBS=0` forces dropping even after failures.
*/
/** Tables that must survive truncation: PostGIS internals and migration journals. */
@ -115,7 +115,11 @@ export function templateDatabaseUri(serialTestUri?: string): string {
return withDatabaseName(base, `${testDatabaseName(base)}_template`);
}
/** Per-vitest-worker clone URI (`ptf_app_test` -> `ptf_app_test_w<ID>`). */
/**
* Per-fork-clone URI (`ptf_app_test` -> `ptf_app_test_w<PID>`). The id is the
* vitest fork process pid so one clone serves every file that scheduler
* assigns to the process (VITEST_WORKER_ID churns per task, not per process).
*/
export function workerDatabaseUri(workerId: string | number, serialTestUri?: string): string {
const base = serialTestUri ?? resolveTestDatabaseUri();
return withDatabaseName(base, `${testDatabaseName(base)}_w${workerId}`);

View file

@ -2,10 +2,11 @@ import { clearFailureMarker, writeFailureMarker } from "./vitest-marker";
/**
* Minimal custom reporter: records run outcome in the failure marker file so
* globalTeardown can keep worker database clones after a failed run (and drop
* them after a green one). See tests/vitest-marker.ts for why the reporter is
* the reliable channel. Vitest 4 calls onTestRunEnd(modules, errors, state)
* with state "passed" | "failed" | "interrupted".
* the post-run teardown (returned by tests/vitest-global.ts) can keep worker
* database clones after a failed run and drop them after a green one. See
* tests/vitest-marker.ts for why the reporter is the reliable channel.
* Vitest 4 calls onTestRunEnd(modules, errors, state) with state
* "passed" | "failed" | "interrupted".
*/
export default class FailureMarkerReporter {
onTestRunEnd(_modules: unknown[], errors: unknown[], state?: string): void {

View file

@ -8,9 +8,10 @@ import { failureMarkerPresent } from "./vitest-marker";
* leftovers are dropped by the next run's globalSetup sweep regardless.
*
* - Workers mode: drop every `<base>_w<N>` clone after a green run; keep them
* when the failure marker exists (postmortem) or `KEEP_TEST_DBS=1`. The
* template itself survives across runs and is only rebuilt on hash mismatch
* or `TEST_DB_HARD_RESET=1`.
* when the failure marker exists (postmortem) or `KEEP_TEST_DBS=1`.
* `KEEP_TEST_DBS=0` forces dropping even after failures. The template
* itself survives across runs and is only rebuilt on hash mismatch or
* `TEST_DB_HARD_RESET=1`.
* - Legacy serial mode (`TEST_DATABASE_URI` set): truncate for hygiene.
*/
export default async function vitestTeardown(): Promise<void> {
@ -19,7 +20,9 @@ export default async function vitestTeardown(): Promise<void> {
await truncateAllData(resolveTestDatabaseUri());
return;
}
if (process.env.KEEP_TEST_DBS === "1" || failureMarkerPresent()) {
const forceKeep = process.env.KEEP_TEST_DBS === "1";
const forceDrop = process.env.KEEP_TEST_DBS === "0";
if (!forceDrop && (forceKeep || failureMarkerPresent())) {
console.log("[test-db] keeping worker clones (failed run or KEEP_TEST_DBS=1)");
return;
}

Some files were not shown because too many files have changed in this diff Show more