1
0
Fork 0

test(interior): harden cleanup afterAll, raise decay timeouts, and fix seed typing

This commit is contained in:
Jason Fraley 2026-10-20 19:50:19 -04:00
parent e52cc83198
commit 0af105e055
3 changed files with 104 additions and 124 deletions

View file

@ -116,15 +116,13 @@ export const seedInteriorContent = async (): Promise<number> => {
// Labor class the barracks/workshop upgrade gates reference. Key must // Labor class the barracks/workshop upgrade gates reference. Key must
// match the requiredLaborClass strings below. // match the requiredLaborClass strings below.
let engineerClass = await payload.find({ const engineerFound = await payload.find({
collection: "labor-classifications", collection: "labor-classifications",
where: { key: { equals: "engineer" } }, where: { key: { equals: "engineer" } },
limit: 1, limit: 1,
overrideAccess: true, overrideAccess: true,
}); });
if (!engineerClass.docs[0]) { if (!engineerFound.docs[0]) {
engineerClass = {
docs: [
await payload.create({ await payload.create({
collection: "labor-classifications", collection: "labor-classifications",
data: { data: {
@ -135,25 +133,22 @@ export const seedInteriorContent = async (): Promise<number> => {
description: "Trades crew for Superstructure interior work (upgrades, repairs, stations).", description: "Trades crew for Superstructure interior work (upgrades, repairs, stations).",
}, },
overrideAccess: true, overrideAccess: true,
}), });
],
};
payload.logger.info("[seed-interior] created labor class engineer"); payload.logger.info("[seed-interior] created labor class engineer");
} }
// Technology gate for the barracks L2 upgrade. Left unresearched on // Technology gate for the barracks L2 upgrade. Left unresearched on
// purpose so the gate is live; research it from the tech tree to open L2. // purpose so the gate is live; research it from the tech tree to open L2.
const techName = "Modular Habitation"; const techName = "Modular Habitation";
let tech = await payload.find({ const techFound = await payload.find({
collection: "technologies", collection: "technologies",
where: { name: { equals: techName } }, where: { name: { equals: techName } },
limit: 1, limit: 1,
overrideAccess: true, overrideAccess: true,
}); });
if (!tech.docs[0]) { let techId = techFound.docs[0]?.id as number | undefined;
tech = { if (!techId) {
docs: [ const techCreated = await payload.create({
await payload.create({
collection: "technologies", collection: "technologies",
data: { data: {
name: techName, name: techName,
@ -164,43 +159,39 @@ export const seedInteriorContent = async (): Promise<number> => {
researchCosts: { minimumResearchDuration: 240 }, researchCosts: { minimumResearchDuration: 240 },
}, },
overrideAccess: true, overrideAccess: true,
}), });
], techId = techCreated.id as number;
};
payload.logger.info("[seed-interior] created technology 'Modular Habitation' (unresearched)"); payload.logger.info("[seed-interior] created technology 'Modular Habitation' (unresearched)");
} }
const techId = tech.docs[0]!.id as number;
// Asset produced by the disabled template recipe. // Asset produced by the disabled template recipe.
const assetName = "Field Repair Kit"; const assetName = "Field Repair Kit";
let kit = await payload.find({ const kitFound = await payload.find({
collection: "assets", collection: "assets",
where: { name: { equals: assetName } }, where: { name: { equals: assetName } },
limit: 1, limit: 1,
overrideAccess: true, overrideAccess: true,
}); });
if (!kit.docs[0]) { let kitId = kitFound.docs[0]?.id as number | undefined;
kit = { if (!kitId) {
docs: [ const kitCreated = await payload.create({
await payload.create({
collection: "assets", collection: "assets",
data: { data: {
name: assetName, name: assetName,
approvalStatus: "approved", approvalStatus: "approved",
className: "ptf_repair_kit", className: "ptf_repair_kit",
assetType: "tool", assetType: "tool",
description: "A packed kit of shims, sealant, and hand tools for interior fixture repairs.", tradeable: true,
crafting: { craftable: false }, isLive: true,
gridWidth: 1, marketTrading: { Rarity: "common", perceivedValue: { baseBuyPrice: 500, baseSellPrice: 400 } },
gridHeight: 1, crafting: { craftable: false, craftingData: { craftingTimePerUnit: 0, batchSize: 1 } },
storageDimensions: { gridWidth: 1, gridHeight: 1 },
}, },
overrideAccess: true, overrideAccess: true,
}), });
], kitId = kitCreated.id as number;
};
payload.logger.info(`[seed-interior] created asset ${assetName}`); payload.logger.info(`[seed-interior] created asset ${assetName}`);
} }
const kitId = kit.docs[0]!.id as number;
// --- Blueprint ----------------------------------------------------------- // --- Blueprint -----------------------------------------------------------
@ -441,12 +432,21 @@ export const seedInteriorContent = async (): Promise<number> => {
description: { description: {
root: { root: {
type: "root", type: "root",
version: 1,
direction: null,
format: "",
indent: 0,
children: [ children: [
{ {
type: "paragraph", type: "paragraph",
version: 1,
direction: null,
format: "",
indent: 0,
children: [ children: [
{ {
type: "text", type: "text",
version: 1,
text: "The unit's main base structure. Its interior is the Superstructure Interior System.", text: "The unit's main base structure. Its interior is the Superstructure Interior System.",
}, },
], ],

View file

@ -116,7 +116,22 @@ async function makeFixture(): Promise<void> {
codeName: `${CODE_NAME_BASE}-${Date.now()}`, codeName: `${CODE_NAME_BASE}-${Date.now()}`,
approvalStatus: "approved", approvalStatus: "approved",
category: "civilian", category: "civilian",
description: { root: { type: "root", children: [{ type: "text", text: "E2E fixture" }] } }, description: {
root: {
type: "root",
version: 1,
direction: null,
format: "",
indent: 0,
children: [
{
type: "text",
version: 1,
text: "E2E fixture",
},
],
},
},
materials: [{ resource: scrapId, amount: 1 }], materials: [{ resource: scrapId, amount: 1 }],
constructionDurationMinutes: 1, constructionDurationMinutes: 1,
terrainType: "land", terrainType: "land",
@ -145,7 +160,7 @@ async function makeFixture(): Promise<void> {
], ],
}, },
], ],
} as Record<string, unknown>, },
draft: false, draft: false,
overrideAccess: true, overrideAccess: true,
}); });

View file

@ -338,59 +338,27 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
const structureIds = created.structures; const structureIds = created.structures;
// Staffing rows reference game-structures, so they must go first. // Bulk where-deletes (not per-row round-trips): this hook races vitest's
for (const id of created.staffing) { // timeout otherwise, and orphan deletes bleeding into the next file
await payload.delete({ collection: "npc-staffing", id, overrideAccess: true }).catch(() => {}); // cross-contaminate its row counts.
} const bulk = (collection: Parameters<typeof payload.delete>[0]["collection"], where: unknown) =>
payload.delete({ collection, where: where as never, overrideAccess: true } as never).catch(() => {});
if (created.staffing.length > 0) await bulk("npc-staffing", { id: { in: created.staffing } });
if (structureIds.length > 0) { if (structureIds.length > 0) {
const rooms = await payload // Rooms and jobs cross-reference each other (room.pendingJob -> job,
.find({ // job.room -> room): clear the pointer first, then children, then parents.
collection: "structure-rooms",
where: { structure: { in: structureIds } },
limit: 200,
depth: 0,
overrideAccess: true,
})
.catch(() => null);
for (const room of rooms?.docs ?? []) {
await payload await payload
.update({ .update({
collection: "structure-rooms", collection: "structure-rooms",
id: room.id, where: { structure: { in: structureIds } },
data: { pendingJob: null }, data: { pendingJob: null },
overrideAccess: true, overrideAccess: true,
}) } as never)
.catch(() => {}); .catch(() => {});
} await bulk("interior-jobs", { structure: { in: structureIds } });
await bulk("structure-rooms", { structure: { in: structureIds } });
const jobs = await payload await bulk("game-structures", { id: { in: structureIds } });
.find({
collection: "interior-jobs",
where: { structure: { in: structureIds } },
limit: 200,
depth: 0,
overrideAccess: true,
})
.catch(() => null);
for (const job of jobs?.docs ?? []) {
await payload
.delete({ collection: "interior-jobs", id: job.id, overrideAccess: true })
.catch(() => {});
}
for (const room of rooms?.docs ?? []) {
await payload
.delete({ collection: "structure-rooms", id: room.id, overrideAccess: true })
.catch(() => {});
}
for (const id of structureIds) {
await payload
.delete({ collection: "game-structures", id, overrideAccess: true })
.catch(() => {});
}
const events = await payload const events = await payload
.find({ .find({
@ -401,10 +369,11 @@ afterAll(async () => {
overrideAccess: true, overrideAccess: true,
}) })
.catch(() => null); .catch(() => null);
for (const event of events?.docs ?? []) { if (events && events.totalDocs > 0) {
await payload await bulk(
.delete({ collection: "game-event-logs", id: event.id, overrideAccess: true }) "game-event-logs",
.catch(() => {}); { id: { in: events.docs.map((e) => e.id) } },
);
} }
} }
@ -436,21 +405,15 @@ afterAll(async () => {
} }
if (created.users.length > 0) { if (created.users.length > 0) {
const notifications = await payload // Bulk-delete notifications (where-based) so this hook never trips its timeout.
.find({ await payload
.delete({
collection: "user-notifications", collection: "user-notifications",
where: { user: { in: created.users } }, where: { user: { in: created.users } },
limit: 200,
depth: 0,
overrideAccess: true, overrideAccess: true,
}) } as never)
.catch(() => null);
for (const notification of notifications?.docs ?? []) {
await payload
.delete({ collection: "user-notifications", id: notification.id, overrideAccess: true })
.catch(() => {}); .catch(() => {});
} }
}
for (const id of created.users) { for (const id of created.users) {
await payload.delete({ collection: "users", id, overrideAccess: true }).catch(() => {}); await payload.delete({ collection: "users", id, overrideAccess: true }).catch(() => {});
@ -458,7 +421,7 @@ afterAll(async () => {
for (const id of created.roles) { for (const id of created.roles) {
await payload.delete({ collection: "roles", id, overrideAccess: true }).catch(() => {}); await payload.delete({ collection: "roles", id, overrideAccess: true }).catch(() => {});
} }
}); }, 60_000);
// --- tests ----------------------------------------------------------------- // --- tests -----------------------------------------------------------------
@ -1780,7 +1743,9 @@ describe("Interior repair completion", () => {
}); });
}); });
describe("Interior decay", () => { // Heavy suite: each test builds a full blueprint + instance and runs sweeps;
// under full-suite load the default 5s test budget flakes. Give them room.
describe("Interior decay", { timeout: 60_000 }, () => {
let decayWasEnabled = false; let decayWasEnabled = false;
let multiplierWas = 1; let multiplierWas = 1;