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,91 +116,82 @@ export const seedInteriorContent = async (): Promise<number> => {
// Labor class the barracks/workshop upgrade gates reference. Key must
// match the requiredLaborClass strings below.
let engineerClass = await payload.find({
const engineerFound = await payload.find({
collection: "labor-classifications",
where: { key: { equals: "engineer" } },
limit: 1,
overrideAccess: true,
});
if (!engineerClass.docs[0]) {
engineerClass = {
docs: [
await payload.create({
collection: "labor-classifications",
data: {
name: "Interior Engineer",
key: "engineer",
defaultUnitSalary: 20,
availableHeadcount: 8,
description: "Trades crew for Superstructure interior work (upgrades, repairs, stations).",
},
overrideAccess: true,
}),
],
};
if (!engineerFound.docs[0]) {
await payload.create({
collection: "labor-classifications",
data: {
name: "Interior Engineer",
key: "engineer",
defaultUnitSalary: 20,
availableHeadcount: 8,
description: "Trades crew for Superstructure interior work (upgrades, repairs, stations).",
},
overrideAccess: true,
});
payload.logger.info("[seed-interior] created labor class engineer");
}
// 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.
const techName = "Modular Habitation";
let tech = await payload.find({
const techFound = await payload.find({
collection: "technologies",
where: { name: { equals: techName } },
limit: 1,
overrideAccess: true,
});
if (!tech.docs[0]) {
tech = {
docs: [
await payload.create({
collection: "technologies",
data: {
name: techName,
approvalStatus: "approved",
type: "upgrade",
summary:
"Prefab habitation modules; unlocks expanded berths in the Superstructure barracks.",
researchCosts: { minimumResearchDuration: 240 },
},
overrideAccess: true,
}),
],
};
let techId = techFound.docs[0]?.id as number | undefined;
if (!techId) {
const techCreated = await payload.create({
collection: "technologies",
data: {
name: techName,
approvalStatus: "approved",
type: "upgrade",
summary:
"Prefab habitation modules; unlocks expanded berths in the Superstructure barracks.",
researchCosts: { minimumResearchDuration: 240 },
},
overrideAccess: true,
});
techId = techCreated.id as number;
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.
const assetName = "Field Repair Kit";
let kit = await payload.find({
const kitFound = await payload.find({
collection: "assets",
where: { name: { equals: assetName } },
limit: 1,
overrideAccess: true,
});
if (!kit.docs[0]) {
kit = {
docs: [
await payload.create({
collection: "assets",
data: {
name: assetName,
approvalStatus: "approved",
className: "ptf_repair_kit",
assetType: "tool",
description: "A packed kit of shims, sealant, and hand tools for interior fixture repairs.",
crafting: { craftable: false },
gridWidth: 1,
gridHeight: 1,
},
overrideAccess: true,
}),
],
};
let kitId = kitFound.docs[0]?.id as number | undefined;
if (!kitId) {
const kitCreated = await payload.create({
collection: "assets",
data: {
name: assetName,
approvalStatus: "approved",
className: "ptf_repair_kit",
assetType: "tool",
tradeable: true,
isLive: true,
marketTrading: { Rarity: "common", perceivedValue: { baseBuyPrice: 500, baseSellPrice: 400 } },
crafting: { craftable: false, craftingData: { craftingTimePerUnit: 0, batchSize: 1 } },
storageDimensions: { gridWidth: 1, gridHeight: 1 },
},
overrideAccess: true,
});
kitId = kitCreated.id as number;
payload.logger.info(`[seed-interior] created asset ${assetName}`);
}
const kitId = kit.docs[0]!.id as number;
// --- Blueprint -----------------------------------------------------------
@ -441,12 +432,21 @@ export const seedInteriorContent = async (): Promise<number> => {
description: {
root: {
type: "root",
version: 1,
direction: null,
format: "",
indent: 0,
children: [
{
type: "paragraph",
version: 1,
direction: null,
format: "",
indent: 0,
children: [
{
type: "text",
version: 1,
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()}`,
approvalStatus: "approved",
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 }],
constructionDurationMinutes: 1,
terrainType: "land",
@ -145,7 +160,7 @@ async function makeFixture(): Promise<void> {
],
},
],
} as Record<string, unknown>,
},
draft: false,
overrideAccess: true,
});

View file

@ -338,59 +338,27 @@ beforeAll(async () => {
afterAll(async () => {
const structureIds = created.structures;
// Staffing rows reference game-structures, so they must go first.
for (const id of created.staffing) {
await payload.delete({ collection: "npc-staffing", id, overrideAccess: true }).catch(() => {});
}
// Bulk where-deletes (not per-row round-trips): this hook races vitest's
// timeout otherwise, and orphan deletes bleeding into the next file
// 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) {
const rooms = await payload
.find({
// Rooms and jobs cross-reference each other (room.pendingJob -> job,
// job.room -> room): clear the pointer first, then children, then parents.
await payload
.update({
collection: "structure-rooms",
where: { structure: { in: structureIds } },
limit: 200,
depth: 0,
data: { pendingJob: null },
overrideAccess: true,
})
.catch(() => null);
for (const room of rooms?.docs ?? []) {
await payload
.update({
collection: "structure-rooms",
id: room.id,
data: { pendingJob: null },
overrideAccess: true,
})
.catch(() => {});
}
const jobs = await payload
.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(() => {});
}
} as never)
.catch(() => {});
await bulk("interior-jobs", { structure: { in: structureIds } });
await bulk("structure-rooms", { structure: { in: structureIds } });
await bulk("game-structures", { id: { in: structureIds } });
const events = await payload
.find({
@ -401,10 +369,11 @@ afterAll(async () => {
overrideAccess: true,
})
.catch(() => null);
for (const event of events?.docs ?? []) {
await payload
.delete({ collection: "game-event-logs", id: event.id, overrideAccess: true })
.catch(() => {});
if (events && events.totalDocs > 0) {
await bulk(
"game-event-logs",
{ id: { in: events.docs.map((e) => e.id) } },
);
}
}
@ -436,20 +405,14 @@ afterAll(async () => {
}
if (created.users.length > 0) {
const notifications = await payload
.find({
// Bulk-delete notifications (where-based) so this hook never trips its timeout.
await payload
.delete({
collection: "user-notifications",
where: { user: { in: created.users } },
limit: 200,
depth: 0,
overrideAccess: true,
})
.catch(() => null);
for (const notification of notifications?.docs ?? []) {
await payload
.delete({ collection: "user-notifications", id: notification.id, overrideAccess: true })
.catch(() => {});
}
} as never)
.catch(() => {});
}
for (const id of created.users) {
@ -458,7 +421,7 @@ afterAll(async () => {
for (const id of created.roles) {
await payload.delete({ collection: "roles", id, overrideAccess: true }).catch(() => {});
}
});
}, 60_000);
// --- 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 multiplierWas = 1;