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.
81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
import { getTestPayload } from "../helpers/get-test-payload";
|
|
import { Payload } from "payload";
|
|
|
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
|
|
let payload: Payload;
|
|
|
|
/**
|
|
* Regression test for the Postgres `FUNC_MAX_ARGS` limit (error 54023,
|
|
* "cannot pass more than 100 arguments to a function").
|
|
*
|
|
* Document locking stores one foreign-key column per collection in
|
|
* `payload_locked_documents_rels`. Drizzle hydrates polymorphic relationships
|
|
* with a single `json_build_array(...)` that includes every one of those
|
|
* columns; once the unit has more than ~100 collections that call exceeds
|
|
* Postgres' hard limit and every admin edit view throws while a lock row
|
|
* exists. The local bun patch on drizzle-orm chunks the call into groups of
|
|
* 100 joined with `||`.
|
|
*
|
|
* This test creates a real lock row so the hydration query actually runs
|
|
* (with zero matching locks Payload skips the wide relational select), then
|
|
* reads it back with `depth: 1`, which is exactly what `getIsLocked` and
|
|
* `handleFormStateLocking` do.
|
|
*/
|
|
describe("payload-locked-documents relational query", () => {
|
|
beforeAll(async () => {
|
|
payload = await getTestPayload();
|
|
});
|
|
|
|
it("hydrates a lock document at depth 1 without exceeding the argument limit", async () => {
|
|
const roles = await payload.find({ collection: "roles", limit: 1, overrideAccess: true });
|
|
expect(roles.docs.length).toBeGreaterThan(0);
|
|
const roleId = roles.docs[0].id;
|
|
|
|
const username = `lock-query-${Date.now()}`;
|
|
const user = await payload.create({
|
|
collection: "users",
|
|
overrideAccess: true,
|
|
data: {
|
|
username,
|
|
discordUsername: username,
|
|
displayName: "Lock Query Tester",
|
|
steamId: `7656119${Math.floor(Math.random() * 1e9)}`,
|
|
password: "Test123",
|
|
},
|
|
});
|
|
|
|
const lock = await payload.create({
|
|
collection: "payload-locked-documents",
|
|
overrideAccess: true,
|
|
data: {
|
|
document: { relationTo: "roles", value: roleId },
|
|
user: { relationTo: "users", value: user.id },
|
|
},
|
|
});
|
|
|
|
try {
|
|
const lockDocs = await payload.find({
|
|
collection: "payload-locked-documents",
|
|
depth: 1,
|
|
limit: 1,
|
|
overrideAccess: true,
|
|
where: {
|
|
and: [
|
|
{ "document.relationTo": { equals: "roles" } },
|
|
{ "document.value": { equals: roleId } },
|
|
],
|
|
},
|
|
});
|
|
|
|
expect(lockDocs.docs).toHaveLength(1);
|
|
expect(lockDocs.docs[0].id).toBe(lock.id);
|
|
} finally {
|
|
await payload.delete({
|
|
collection: "payload-locked-documents",
|
|
id: lock.id,
|
|
overrideAccess: true,
|
|
});
|
|
}
|
|
});
|
|
});
|