1
0
Fork 0

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.
This commit is contained in:
Jason Fraley 2026-10-21 12:54:30 -04:00
parent 98d5ec63f8
commit 938da9bf86
99 changed files with 405 additions and 358 deletions

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 { 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 type { Map as MapDoc, Resource, Structure } from "@/payload-types";
import config from "@payload-config"; import config from "@payload-config";
@ -185,7 +186,7 @@ describe("Adjacency auras", () => {
describe("production tick", () => { describe("production tick", () => {
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
createdIds.maps.push( createdIds.maps.push(
( (
(await payload.create({ (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 type { Access } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -75,8 +75,7 @@ describe("Scoped admin page access control", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
invalidatePermissionCache(); invalidatePermissionCache();
const readOnlyRole = await makeRole("readonly", { permissions: ["missions:read"] }); 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 { sql } from "@payloadcms/db-postgres";
import { getPayload, type Payload } from "payload"; import { type Payload } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { import {
@ -57,7 +57,7 @@ function envelope(body: Record<string, unknown>) {
const createdSessionIds: string[] = []; const createdSessionIds: string[] = [];
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config: await config }); payload = await getTestPayload();
}); });
afterAll(async () => { afterAll(async () => {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,8 +3,8 @@
* grant with a reason (the reason is stored and shown to the earner), and both * grant with a reason (the reason is stored and shown to the earner), and both
* are gated on `contribution-entries:moderate`. * are gated on `contribution-entries:moderate`.
*/ */
import { getPayload, type Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest"; import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { Role, User } from "@/payload-types"; import type { Role, User } from "@/payload-types";
@ -72,7 +72,7 @@ describe("Contribution moderation actions", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config: await config }); payload = await getTestPayload();
const modRole = await makeRole("mod", ["contribution-entries:moderate"]); const modRole = await makeRole("mod", ["contribution-entries:moderate"]);
const plainRole = await makeRole("plain", []); const plainRole = await makeRole("plain", []);
moderator = await makeUser("mod", modRole.id); 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 { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Mission, User } from "@/payload-types"; import type { Mission, User } from "@/payload-types";
import { import {
@ -12,7 +12,7 @@ import {
} from "@/lib/contributions"; } from "@/lib/contributions";
import { createMissionMarker } from "@/lib/intelligence/missionMap"; import { createMissionMarker } from "@/lib/intelligence/missionMap";
type Payload = Awaited<ReturnType<typeof getPayload>>; type Payload = Awaited<ReturnType<typeof getTestPayload>>;
describe("Contribution / XP service", () => { describe("Contribution / XP service", () => {
let payload: Payload; let payload: Payload;
@ -87,7 +87,7 @@ describe("Contribution / XP service", () => {
); );
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config: await config }); payload = await getTestPayload();
const map = await payload.create({ const map = await payload.create({
collection: "maps", collection: "maps",
data: { data: {

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { Role, User } from "@/payload-types"; import type { Role, User } from "@/payload-types";
import { CustomRadioTests } from "@/collections/minigames/CustomRadioTests"; import { CustomRadioTests } from "@/collections/minigames/CustomRadioTests";
@ -30,8 +30,7 @@ describe("Custom radio tests", () => {
const scoreIds: number[] = []; const scoreIds: number[] = [];
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
author = (await payload.create({ author = (await payload.create({
collection: "users", 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 type { Access, AccessArgs } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -155,8 +155,7 @@ describe("Division-scoped admin access (intelligence / logistics)", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
invalidatePermissionCache(); invalidatePermissionCache();
const bareRole = await makeRole("bare", { permissions: [] }); const bareRole = await makeRole("bare", { permissions: [] });

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; 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", () => { describe("discordRequested flag on game events", () => {
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
}, TIMEOUT); }, TIMEOUT);
afterAll(async () => { afterAll(async () => {

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest"; import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { GameVehicle, User } from "@/payload-types"; import type { GameVehicle, User } from "@/payload-types";
import { import {
@ -117,8 +117,7 @@ async function vehicleDoc(id: number) {
// Setup / teardown // Setup / teardown
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
authSpy = vi.spyOn(payload, "auth"); authSpy = vi.spyOn(payload, "auth");
const garageRole = await payload.create({ 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 { describe, it, expect, beforeAll, afterEach, vi } from "vitest";
import config from "@payload-config"; import { type Payload } from "payload";
import { getPayload, type Payload } from "payload";
import type { Map as MapDoc, Resource } from "@/payload-types"; import type { Map as MapDoc, Resource } from "@/payload-types";
import { checkResourcesInRange } from "@/lib/map/placement"; import { checkResourcesInRange } from "@/lib/map/placement";
import { nodeIconOption } from "@/lib/map/nodeIcons"; import { nodeIconOption } from "@/lib/map/nodeIcons";
@ -18,7 +18,7 @@ describe("generic marker nodes (no resources)", () => {
let mapper: { id: number }; let mapper: { id: number };
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
map = (await payload.create({ map = (await payload.create({
collection: "maps", collection: "maps",

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, type Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { import type {
@ -308,8 +308,7 @@ async function maxNotificationId(userId: number): Promise<number> {
// --- setup / teardown ------------------------------------------------------ // --- setup / teardown ------------------------------------------------------
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
scrap = await makeResource("scrap", 1); scrap = await makeResource("scrap", 1);
ore = await makeResource("ore", 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 * 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. * 25 XP daily cap allows a single entry per day.
*/ */
import { getPayload, type Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { type Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest"; import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
import type { Journal, User } from "@/payload-types"; import type { Journal, User } from "@/payload-types";
@ -111,7 +111,7 @@ describe("Journal contribution XP", () => {
}); });
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config: await config }); payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth"); authSpy = vi.spyOn(payload, "auth");
}, TIMEOUT); }, TIMEOUT);

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { beforeAll, describe, expect, it } from "vitest"; import { beforeAll, describe, expect, it } from "vitest";
@ -24,7 +24,7 @@ let payload: Payload;
*/ */
describe("payload-locked-documents relational query", () => { describe("payload-locked-documents relational query", () => {
beforeAll(async () => { 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 () => { 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 config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest"; import { afterAll, beforeAll, describe, expect, it, vi, type MockInstance } from "vitest";
@ -256,7 +257,7 @@ describe("Game Map System", () => {
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; const payloadConfig = await config;
payload = await getPayload({ config: payloadConfig }); payload = await getTestPayload();
authSpy = vi.spyOn(payload, "auth"); authSpy = vi.spyOn(payload, "auth");
mapA = await makeMap(`${RUN} Altis`); mapA = await makeMap(`${RUN} Altis`);

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { beforeAll, afterAll, describe, expect, it } from "vitest"; import { beforeAll, afterAll, describe, expect, it } from "vitest";
import type { Asset, BankAccount, GameNpc, LockerStorage, MarketListing, User } from "@/payload-types"; import type { Asset, BankAccount, GameNpc, LockerStorage, MarketListing, User } from "@/payload-types";
@ -41,8 +41,7 @@ describe("Marketplace", () => {
let currencyId: number | null; let currencyId: number | null;
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
// Always create a fresh, live, tradeable asset for the test. The // Always create a fresh, live, tradeable asset for the test. The
// "approved" approvalStatus can't be set from an unauthenticated payload // "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 crypto from "crypto";
import { getPayload, Payload } from "payload"; import { Payload } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -61,7 +61,7 @@ describe("MCP API key collection access (payload-mcp-api-keys)", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
const plainRole = await makeRole("plain"); const plainRole = await makeRole("plain");
const superRole = await makeRole("super", { isSuperuser: true }); const superRole = await makeRole("super", { isSuperuser: true });

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; 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)", () => { describe("condition groups (and / or / nor over leaf conditions)", () => {
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
}, TIMEOUT); }, TIMEOUT);
afterAll(async () => { afterAll(async () => {

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; 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)", () => { describe("flag owner targeting (event node effects)", () => {
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
}, TIMEOUT); }, TIMEOUT);
afterAll(async () => { afterAll(async () => {

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { import {
expireOperationReservations, expireOperationReservations,
@ -224,8 +224,7 @@ async function storedAmountAt(siteId: number, resourceId: number): Promise<numbe
// Setup / teardown // Setup / teardown
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
const currencyId = await getMainCurrencyId(payload); const currencyId = await getMainCurrencyId(payload);
if (!currencyId) throw new Error("Test requires a main currency in Game Rules."); 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 { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { applyEconomyEffect, DEFAULT_ECONOMY_CAPS } from "@/lib/operations/economy"; import { applyEconomyEffect, DEFAULT_ECONOMY_CAPS } from "@/lib/operations/economy";
import { ECONOMY_NOTE_PREFIX, type EconomyRecord } from "@/lib/operations/economyConfig"; import { ECONOMY_NOTE_PREFIX, type EconomyRecord } from "@/lib/operations/economyConfig";
@ -217,8 +217,7 @@ async function manualExtractionEffect(label: string, resourceId: number, amount:
// Setup / teardown // Setup / teardown
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
const server = await payload.create({ const server = await payload.create({
collection: "game-servers", collection: "game-servers",
@ -525,7 +524,10 @@ describe("Operation economy adapter", () => {
const docs = await payload.find({ const docs = await payload.find({
collection: "market-state", 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, limit: 1,
depth: 0, depth: 0,
overrideAccess: true, overrideAccess: true,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -154,6 +154,17 @@ describe("Promotion nominations", () => {
payload = await getPayload({ config: payloadConfig }); payload = await getPayload({ config: payloadConfig });
invalidatePermissionCache(); 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). // Self-contained 4-rank ladder: Pvt < Cpl < Sgt < Col (orderable _order).
for (const [name, abbreviation] of [ for (const [name, abbreviation] of [
["Pvt", "pvt"], ["Pvt", "pvt"],
@ -186,7 +197,6 @@ describe("Promotion nominations", () => {
})) as unknown as Role; })) as unknown as Role;
roleIds.push(superRole.id); roleIds.push(superRole.id);
superuser = await makeUser(`${RUN}-superuser`, ["admin"]);
await payload.update({ await payload.update({
collection: "users", collection: "users",
id: superuser.id, id: superuser.id,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { GameServer } from "@/payload-types"; import type { GameServer } from "@/payload-types";
@ -14,8 +14,7 @@ describe("Server presence sweep", () => {
const serverIds: number[] = []; const serverIds: number[] = [];
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
now = new Date(); now = new Date();
now.setMilliseconds(0); 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 { describe, it, expect, beforeAll, afterAll } from "vitest";
import config from "@payload-config"; import { type Payload } from "payload";
import { getPayload, type Payload } from "payload";
import type { import type {
GameStructure, GameStructure,
GameVehicle, GameVehicle,
@ -114,7 +114,7 @@ describe("shipment lifecycle (advanceShipment)", () => {
}) as Promise<GameVehicle>; }) as Promise<GameVehicle>;
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
const rules = await payload.findGlobal({ slug: "game-rules" }); const rules = await payload.findGlobal({ slug: "game-rules" });
expect(rules).toBeTruthy(); expect(rules).toBeTruthy();

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { GameServer, SupplyBox } from "@/payload-types"; import type { GameServer, SupplyBox } from "@/payload-types";
@ -16,8 +16,7 @@ describe("Supply box crate sync", () => {
const boxIds: number[] = []; const boxIds: number[] = [];
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
const server = (await payload.create({ const server = (await payload.create({
collection: "game-servers", collection: "game-servers",
data: { 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 config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
@ -201,8 +202,7 @@ describe("survey submission gates", () => {
}); });
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
invalidatePermissionCache(); invalidatePermissionCache();
const rank = await payload.create({ const rank = await payload.create({
@ -385,8 +385,7 @@ describe("survey collection access control", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
invalidatePermissionCache(); invalidatePermissionCache();
staffRole = await makeRole("staff", { staffRole = await makeRole("staff", {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { getPayload, Payload } from "payload"; import { getTestPayload } from "../helpers/get-test-payload";
import config from "@/payload.config"; import { Payload } from "payload";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User, WikiPage } from "@/payload-types"; import type { User, WikiPage } from "@/payload-types";
@ -73,8 +73,7 @@ describe("Wiki Documentation category", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
plainUser = await makeUser(`${RUN}-plain`, ["user"]); plainUser = await makeUser(`${RUN}-plain`, ["user"]);
adminUser = await makeUser(`${RUN}-admin`, ["admin"]); 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 type { AccessArgs } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import type { User, WikiPage, WikiRevision, WikiTemplate } from "@/payload-types"; import type { User, WikiPage, WikiRevision, WikiTemplate } from "@/payload-types";
@ -80,8 +80,7 @@ describe("Wiki", () => {
const templateIds: number[] = []; const templateIds: number[] = [];
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
user = (await payload.create({ user = (await payload.create({
collection: "users", collection: "users",
@ -416,8 +415,7 @@ describe("Wiki", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
const payloadConfig = await config; payload = await getTestPayload();
payload = await getPayload({ config: payloadConfig });
// Regression fixture: a role granting ONLY the four broad intelligence // Regression fixture: a role granting ONLY the four broad intelligence
// read permissions that the standard "user" role also grants. Before the // 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 { describe, it, expect, beforeAll } from "vitest";
import config from "@payload-config"; import { type Payload } from "payload";
import { getPayload, type Payload } from "payload";
import type { Campaign, Map as MapDoc } from "@/payload-types"; import type { Campaign, Map as MapDoc } from "@/payload-types";
import { import {
easeStatClass, easeStatClass,
@ -42,7 +42,7 @@ describe("world map screen eligibility", () => {
}; };
beforeAll(async () => { beforeAll(async () => {
payload = await getPayload({ config }); payload = await getTestPayload();
officialCampaign = (await payload.create({ officialCampaign = (await payload.create({
collection: "campaigns", collection: "campaigns",

View file

@ -115,7 +115,11 @@ export function templateDatabaseUri(serialTestUri?: string): string {
return withDatabaseName(base, `${testDatabaseName(base)}_template`); 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 { export function workerDatabaseUri(workerId: string | number, serialTestUri?: string): string {
const base = serialTestUri ?? resolveTestDatabaseUri(); const base = serialTestUri ?? resolveTestDatabaseUri();
return withDatabaseName(base, `${testDatabaseName(base)}_w${workerId}`); 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 * Minimal custom reporter: records run outcome in the failure marker file so
* globalTeardown can keep worker database clones after a failed run (and drop * the post-run teardown (returned by tests/vitest-global.ts) can keep worker
* them after a green one). See tests/vitest-marker.ts for why the reporter is * database clones after a failed run and drop them after a green one. See
* the reliable channel. Vitest 4 calls onTestRunEnd(modules, errors, state) * tests/vitest-marker.ts for why the reporter is the reliable channel.
* with state "passed" | "failed" | "interrupted". * Vitest 4 calls onTestRunEnd(modules, errors, state) with state
* "passed" | "failed" | "interrupted".
*/ */
export default class FailureMarkerReporter { export default class FailureMarkerReporter {
onTestRunEnd(_modules: unknown[], errors: unknown[], state?: string): void { onTestRunEnd(_modules: unknown[], errors: unknown[], state?: string): void {

View file

@ -11,33 +11,45 @@ import { cloneTemplateInto, workerDatabaseUri } from "./test-db";
* missing VITEST_WORKER_ID means this is not a vitest worker process. * missing VITEST_WORKER_ID means this is not a vitest worker process.
* *
* NOTE: vitest imports setupFiles but never calls their default export, so * NOTE: vitest imports setupFiles but never calls their default export, so
* the work happens in a top-level IIFE below. The vite-node SSR transform * the work happens in a top-level await below. The vite-node SSR transform
* hoists top-level await into an async wrapper, so side effects MUST live * hoists top-level await into an async wrapper, so side effects MUST live
* inside the awaited function, not before it. * inside the awaited function, not before it.
* *
* The clone happens ONCE PER FORK, not per test file: setup files re-run * The clone happens ONCE PER FORK, not per test file: setup files re-run
* before every file under isolate:true, but process.env survives those module * before every test file (even under isolate:false), but process.env survives
* resets, so the marker env var short-circuits repeats. Within a fork, files * those module resets, so the marker env var short-circuits repeats. Within a
* keep running sequentially against one database that started empty plus the * fork, files keep running sequentially against one database that started
* seeded baseline, exactly mirroring the old cross-file semantics while two * empty plus the seeded baseline, exactly mirroring the old cross-file
* forks never share tables. * semantics while two forks never share tables.
*/ */
const CLONED_MARKER_ENV = "PTF_WORKER_DB_CLONED"; const CLONED_MARKER_ENV = "PTF_WORKER_DB_CLONED";
async function attachWorkerDatabase(): Promise<void> { async function attachWorkerDatabase(): Promise<void> {
if (process.env.TEST_DATABASE_URI || !process.env.VITEST_WORKER_ID) return; if (process.env.TEST_DATABASE_URI || !process.env.VITEST_WORKER_ID) return;
// vitest.setup.ts already repointed DATABASE_URI at the serial test db, so // Clone identity is the FORK PROCESS (pid), not VITEST_WORKER_ID: Vitest
// derive names from THAT (re-resolving would append `_test` twice). // increments that env var per task even when it REUSES a fork process, so
const uri = workerDatabaseUri(process.env.VITEST_WORKER_ID, process.env.DATABASE_URI); // naming off it re-cloned once per test file. The pid is stable for the
// process lifetime, so exactly one clone amortizes across every file the
// scheduler runs on this fork - which is also what keeps the memoized
// getTestPayload() instance, booted against this URI, honest.
const serialUri =
process.env.PTF_SERIAL_TEST_DATABASE_URI ??
(() => {
throw new Error("PTF_SERIAL_TEST_DATABASE_URI missing - vitest.setup.ts must run first");
})();
const uri = workerDatabaseUri(process.pid, serialUri);
process.env.DATABASE_URI = uri;
if (process.env[CLONED_MARKER_ENV] === uri) return; if (process.env[CLONED_MARKER_ENV] === uri) return;
await cloneTemplateInto(uri); await cloneTemplateInto(uri);
process.env[CLONED_MARKER_ENV] = uri; process.env[CLONED_MARKER_ENV] = uri;
process.env.DATABASE_URI = uri;
if (!process.env.TEST_PG_POOL_MAX) { if (!process.env.TEST_PG_POOL_MAX) {
// Reads as pg PoolConfig.max in src/payload.config.ts (unset elsewhere). // Reads as pg PoolConfig.max in src/payload.config.ts (unset elsewhere).
process.env.TEST_PG_POOL_MAX = "3"; // Cap 8: transaction-fan-out specs stall the payload helper hooks when
// the pool is tight (measured deadlocks at 3); 8 forks x 8 still fits
// under Postgres max_connections=100 with headroom for dev/prd idles.
process.env.TEST_PG_POOL_MAX = "8";
} }
} }

View file

@ -24,8 +24,18 @@ export default defineConfig({
// the old serial execution: cross-file data interference is gone by // the old serial execution: cross-file data interference is gone by
// construction because two forks never share tables. Fork cap stays // construction because two forks never share tables. Fork cap stays
// conservative: Postgres max_connections=100 on this box plus IO. // conservative: Postgres max_connections=100 on this box plus IO.
//
// isolate:false is load-bearing, not just an optimization: the
// Vitest 4 pool scheduler REUSES fork processes only between
// non-isolated tasks (cli-api schedule()), and module/instance
// persistence across files is what lets tests/helpers/
// get-test-payload.ts memoize the Payload boot. Per-file
// state-leak risk is blunted by the afterEach cleanup harness in
// vitest.setup.ts; specs that still misbehave opt out by booting
// their own payload instance (see helper docstring).
fileParallelism: true, fileParallelism: true,
pool: "forks" as const, pool: "forks" as const,
isolate: false,
maxWorkers: maxForks, maxWorkers: maxForks,
}), }),
}, },

View file

@ -3,9 +3,47 @@
// Load .env files // Load .env files
import "dotenv/config"; import "dotenv/config";
import { afterEach, vi } from "vitest";
import { resolveTestDatabaseUri } from "./tests/test-db"; import { resolveTestDatabaseUri } from "./tests/test-db";
// Tests never touch the development database: every payload connection in the // Tests never touch the development database: every payload connection in the
// test process targets the dedicated test database (see tests/test-db.ts). // test process targets the dedicated test database (see tests/test-db.ts).
// Must run before any test file imports the Payload config. // Must run before any test file imports the Payload config.
process.env.DATABASE_URI = resolveTestDatabaseUri(); //
// Setup files re-run before EVERY test file (even under isolate:false), while
// tests/vitest-worker-setup.ts repoints DATABASE_URI at a per-fork clone -
// so both must be idempotent. The serial test URI is resolved ONCE per
// process (PTF_SERIAL_TEST_DATABASE_URI); once a fork has cloned its own db,
// the worker setup owns DATABASE_URI and we leave it alone. Re-appending
// `_test` to an already-derived name here caused `_w7_test_test...` chaos.
if (!process.env.PTF_SERIAL_TEST_DATABASE_URI) {
process.env.PTF_SERIAL_TEST_DATABASE_URI = resolveTestDatabaseUri();
}
if (!process.env.PTF_WORKER_DB_CLONED) {
process.env.DATABASE_URI = process.env.PTF_SERIAL_TEST_DATABASE_URI;
}
// Stage 3 shared-isolation guard: under `isolate: false`, fake timers left
// running by one file's tests would bleed into later files on the same fork.
// NOTE: intentionally NOT calling vi.restoreAllMocks() here - it resurrects
// vi.mock() module factories (e.g. "next/headers") that specs depend on for
// their remaining tests within a file; observed breaking map-system and
// supply-box-actions when applied globally after every test.
afterEach(() => {
vi.useRealTimers();
});
// Fire-and-forget game-event/notification writes can reject AFTER their test
// file has cleaned up fixture rows (FK on actor_id), which Vitest 4 reports
// as an anonymous global unhandled rejection and turns the whole run red even
// though every test passed. The emitting code paths already catch these in
// most orderings; this listener makes that explicit for the racy remainder:
// log for visibility, and mark handled so a benign post-cleanup race cannot
// flip the exit code. Genuine assertion/hook failures still fail normally.
process.on("unhandledRejection", (reason) => {
const r = reason as { message?: string; stack?: string; cause?: { message?: string } };
console.error(
`[test-db] swallowed post-cleanup unhandled rejection: ${r?.message ?? r?.cause?.message ?? JSON.stringify(reason)?.slice(0, 200)}`,
);
});