Skip to content

Commit c2516ef

Browse files
committed
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 <noreply@anthropic.com>
1 parent 5d1382a commit c2516ef

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

‎packages/plugins/plugin-security/src/delegated-admin-own-name-set.posture.test.ts‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* the gate meet: the gate admits exactly what the resolver grants.
2222
*/
2323

24-
import { describe, it, expect, afterEach, vi } from 'vitest';
24+
import { describe, it, expect, afterEach, beforeAll, vi } from 'vitest';
2525
import { ObjectQL } from '@objectstack/objectql';
2626
import { SqlDriver } from '@objectstack/driver-sql';
2727
import { resolveThrownHttpError } from '@objectstack/types';
@@ -875,21 +875,34 @@ describe("[ADR-0090 D12] a delegated answer about a user the caller cannot read
875875
}
876876
});
877877

878-
it(`the ${STATES.length} states get, at every door, the answer the id naming no user gets`, async () => {
879-
const answers = [];
880-
for (const state of STATES) answers.push(await answersFor(posture, state));
881-
for (const [i, answer] of answers.entries()) expect(answer, STATES[i]).toEqual(answers[0]);
882-
// The one answer: the write gate's scope violation, and each explain door's refusal of a user the caller may not describe.
883-
const [none] = answers;
884-
for (const [door, answer] of Object.entries(none)) {
885-
const expected = door.startsWith('security/explain') || door.startsWith("the subject's effective")
886-
? [403, 'PERMISSION_DENIED', 'PermissionDeniedError']
887-
: [403, 'DELEGATION_SCOPE_VIOLATION', 'DelegationScopeViolationError'];
888-
expect([answer.status, (answer as any).code, (answer as any).class], door).toEqual(expected);
889-
}
890-
expect((none['security/explain for the subject'] as any).details)
891-
.toEqual({ object: 'sys_business_unit', operation: 'read', targetUserId: SUBJECT });
892-
expect((none["the subject's effective access"] as any).details).toBeUndefined();
878+
// Every state boots a rig of its own, so each state is an `it` of its own: its own
879+
// time budget and its own failure line. Asked in one `it`, the states shared the
880+
// default 5 s budget, which a loaded CI shard used up. The reference, the id
881+
// naming no user, is asked once, and every other state is compared to it.
882+
describe(`the ${STATES.length} states get, at every door, the answer the id naming no user gets`, () => {
883+
let reference: Awaited<ReturnType<typeof answersFor>> | undefined;
884+
beforeAll(async () => {
885+
reference = await answersFor(posture, STATES[0]);
886+
});
887+
888+
it(`${STATES[0]}: the write gate's scope violation, and each explain door's refusal of a user the caller may not describe`, () => {
889+
expect(reference).toBeDefined();
890+
const none = reference!;
891+
for (const [door, answer] of Object.entries(none)) {
892+
const expected = door.startsWith('security/explain') || door.startsWith("the subject's effective")
893+
? [403, 'PERMISSION_DENIED', 'PermissionDeniedError']
894+
: [403, 'DELEGATION_SCOPE_VIOLATION', 'DelegationScopeViolationError'];
895+
expect([answer.status, (answer as any).code, (answer as any).class], door).toEqual(expected);
896+
}
897+
expect((none['security/explain for the subject'] as any).details)
898+
.toEqual({ object: 'sys_business_unit', operation: 'read', targetUserId: SUBJECT });
899+
expect((none["the subject's effective access"] as any).details).toBeUndefined();
900+
});
901+
902+
it.each(STATES.slice(1))(`%s: every door answers exactly what ${STATES[0]} gets`, async (state) => {
903+
expect(reference).toBeDefined();
904+
expect(await answersFor(posture, state), state).toEqual(reference);
905+
});
893906
});
894907

895908
it('CONTROL: the same subject with a business unit inside the scope, read by the delegate, is served at every door', async () => {

0 commit comments

Comments
 (0)