From c2516ef66c36af6cffa13ce3b1089d0f4d2ce403 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 21:43:16 +0000 Subject: [PATCH] test(plugin-security): give each subject state its own it in the delegated-answer posture pin The "states get, at every door, the answer the id naming no user gets" test booted one rig per state inside a single it(), so all four states shared vitest's default 5 s budget, which a loaded CI shard used up. Each posture now asks the reference state once in a beforeAll and compares every other state to it in an it.each, so each state gets its own budget and its own failure line. No assertion is weakened. Claude-Session: https://claude.ai/code/session_01ADHkmSaqpcZzCHVZRYpzpW Co-authored-by: Claude --- ...legated-admin-own-name-set.posture.test.ts | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/packages/plugins/plugin-security/src/delegated-admin-own-name-set.posture.test.ts b/packages/plugins/plugin-security/src/delegated-admin-own-name-set.posture.test.ts index 120e7a8c02d..9204ce0ee1c 100644 --- a/packages/plugins/plugin-security/src/delegated-admin-own-name-set.posture.test.ts +++ b/packages/plugins/plugin-security/src/delegated-admin-own-name-set.posture.test.ts @@ -21,7 +21,7 @@ * the gate meet: the gate admits exactly what the resolver grants. */ -import { describe, it, expect, afterEach, vi } from 'vitest'; +import { describe, it, expect, afterEach, beforeAll, vi } from 'vitest'; import { ObjectQL } from '@objectstack/objectql'; import { SqlDriver } from '@objectstack/driver-sql'; import { resolveThrownHttpError } from '@objectstack/types'; @@ -875,21 +875,34 @@ describe("[ADR-0090 D12] a delegated answer about a user the caller cannot read } }); - it(`the ${STATES.length} states get, at every door, the answer the id naming no user gets`, async () => { - const answers = []; - for (const state of STATES) answers.push(await answersFor(posture, state)); - for (const [i, answer] of answers.entries()) expect(answer, STATES[i]).toEqual(answers[0]); - // The one answer: the write gate's scope violation, and each explain door's refusal of a user the caller may not describe. - const [none] = answers; - for (const [door, answer] of Object.entries(none)) { - const expected = door.startsWith('security/explain') || door.startsWith("the subject's effective") - ? [403, 'PERMISSION_DENIED', 'PermissionDeniedError'] - : [403, 'DELEGATION_SCOPE_VIOLATION', 'DelegationScopeViolationError']; - expect([answer.status, (answer as any).code, (answer as any).class], door).toEqual(expected); - } - expect((none['security/explain for the subject'] as any).details) - .toEqual({ object: 'sys_business_unit', operation: 'read', targetUserId: SUBJECT }); - expect((none["the subject's effective access"] as any).details).toBeUndefined(); + // Every state boots a rig of its own, so each state is an `it` of its own: its own + // time budget and its own failure line. Asked in one `it`, the states shared the + // default 5 s budget, which a loaded CI shard used up. The reference, the id + // naming no user, is asked once, and every other state is compared to it. + describe(`the ${STATES.length} states get, at every door, the answer the id naming no user gets`, () => { + let reference: Awaited> | undefined; + beforeAll(async () => { + reference = await answersFor(posture, STATES[0]); + }); + + it(`${STATES[0]}: the write gate's scope violation, and each explain door's refusal of a user the caller may not describe`, () => { + expect(reference).toBeDefined(); + const none = reference!; + for (const [door, answer] of Object.entries(none)) { + const expected = door.startsWith('security/explain') || door.startsWith("the subject's effective") + ? [403, 'PERMISSION_DENIED', 'PermissionDeniedError'] + : [403, 'DELEGATION_SCOPE_VIOLATION', 'DelegationScopeViolationError']; + expect([answer.status, (answer as any).code, (answer as any).class], door).toEqual(expected); + } + expect((none['security/explain for the subject'] as any).details) + .toEqual({ object: 'sys_business_unit', operation: 'read', targetUserId: SUBJECT }); + expect((none["the subject's effective access"] as any).details).toBeUndefined(); + }); + + it.each(STATES.slice(1))(`%s: every door answers exactly what ${STATES[0]} gets`, async (state) => { + expect(reference).toBeDefined(); + expect(await answersFor(posture, state), state).toEqual(reference); + }); }); it('CONTROL: the same subject with a business unit inside the scope, read by the delegate, is served at every door', async () => {