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.
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import { getTestPayload } from "../helpers/get-test-payload";
|
|
import { Payload } from "payload";
|
|
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
|
|
import { emitGameEvent } from "@/utils/event-log/emit";
|
|
import { EventTypes } from "@/utils/event-log/eventTypes";
|
|
|
|
let payload: Payload;
|
|
|
|
const RUN = `evdisc-${Date.now().toString(36)}`;
|
|
const TIMEOUT = 30_000;
|
|
const eventIds: number[] = [];
|
|
|
|
/** Emit an event and return its persisted document. */
|
|
async function emit(input: Parameters<typeof emitGameEvent>[1]) {
|
|
await emitGameEvent(payload, input);
|
|
const res = await payload.find({
|
|
collection: "game-event-logs",
|
|
where: { message: { equals: input.message } },
|
|
sort: "-id",
|
|
limit: 1,
|
|
overrideAccess: true,
|
|
depth: 0,
|
|
});
|
|
const doc = res.docs[0];
|
|
expect(doc).toBeDefined();
|
|
eventIds.push(doc.id);
|
|
return doc;
|
|
}
|
|
|
|
describe("discordRequested flag on game events", () => {
|
|
beforeAll(async () => {
|
|
payload = await getTestPayload();
|
|
}, TIMEOUT);
|
|
|
|
afterAll(async () => {
|
|
for (const id of eventIds) {
|
|
await payload
|
|
.delete({ collection: "game-event-logs", id, overrideAccess: true })
|
|
.catch(() => {});
|
|
}
|
|
});
|
|
|
|
it(
|
|
"persists discordRequested when the emitter opts in",
|
|
async () => {
|
|
const doc = await emit({
|
|
type: EventTypes.NpcDialogue,
|
|
message: `${RUN} opted in`,
|
|
discordRequested: true,
|
|
});
|
|
expect(doc.discordRequested).toBe(true);
|
|
// The bot stamps these only after posting; emitting must leave them clear.
|
|
expect(doc.discordAnnouncedAt).toBeFalsy();
|
|
expect(doc.discordMessageId).toBeFalsy();
|
|
},
|
|
TIMEOUT,
|
|
);
|
|
|
|
it(
|
|
"defaults to false when omitted or explicitly false",
|
|
async () => {
|
|
const omitted = await emit({
|
|
type: EventTypes.NpcDialogue,
|
|
message: `${RUN} omitted`,
|
|
});
|
|
expect(omitted.discordRequested).toBe(false);
|
|
|
|
const explicitFalse = await emit({
|
|
type: EventTypes.NpcDialogue,
|
|
message: `${RUN} explicit false`,
|
|
discordRequested: false,
|
|
});
|
|
expect(explicitFalse.discordRequested).toBe(false);
|
|
},
|
|
TIMEOUT,
|
|
);
|
|
});
|