Skip to content

Commit 0500ca4

Browse files
committed
test(plugin-security): pin buildExistingByName's predicate-less key set at the function (#15204 stage 6b-2, T1)
The #11451 fence rode the declared-permission seeder's suite, which this PR deletes; the behaviour survives in permission-set-projection's overlay pass. Pinned on both reads, with a predicate-carrying positive control. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013XKtmoR5QCUSTMjiQ3os49
1 parent bc63d8b commit 0500ca4

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎packages/plugins/plugin-security/src/seed-name-lookup-degradation-audible.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,48 @@ describe('[#18570] batched seed existence read — its own failure is audible wi
199199
expect(String(seen[0]?.[0])).toContain(BATCHED_READ_FAILED);
200200
});
201201
});
202+
203+
/**
204+
* [#11451, commit c33f18592] A caller that passes no `equals` predicate emits
205+
* exactly the `where` key set it emitted before the predicate existed:
206+
* `['name']`, not `['name']` plus `undefined`-valued keys that `toEqual`
207+
* would quietly accept. `permission-set-projection.ts`' overlay pass is such
208+
* a caller. The fence used to ride the declared-permission seeder's suite and
209+
* is pinned here, at the function, now that the seeder is retiring.
210+
*
211+
* Both reads are pinned: the batched page and the per-item degradation read
212+
* it falls back to. The predicate-carrying case is the positive control: it
213+
* proves this instrument sees a spread key when one is there.
214+
*/
215+
describe('#11451: a caller that passes no predicate emits its old key set', () => {
216+
it('the batched read emits only `name`', async () => {
217+
const ql = emptyPageQl();
218+
await buildExistingByName(ql as any, 'sys_permission_set', ['alpha', 'beta']);
219+
expect(ql.calls).toHaveLength(1);
220+
expect(Object.keys((ql.calls[0]![1] as any).where)).toEqual(['name']);
221+
});
222+
223+
it('the per-item degradation read emits only `name`', async () => {
224+
const wheres: Record<string, unknown>[] = [];
225+
// The batched `$in` read is refused, so the per-item path is taken; each
226+
// per-item read is recorded and answered "no such row".
227+
const ql = {
228+
find: async (_object: string, q?: { where?: Record<string, unknown> }) => {
229+
const name = q?.where?.name;
230+
if (name && typeof name === 'object' && '$in' in (name as object)) throw new Error('batched read refused (trigger)');
231+
wheres.push(q?.where ?? {});
232+
return [] as any[];
233+
},
234+
};
235+
const index = await buildExistingByName(ql as any, 'sys_permission_set', ['alpha'], { warn: () => {} });
236+
expect((await index.get('alpha')).status).toBe('absent');
237+
expect(wheres).toHaveLength(1);
238+
expect(Object.keys(wheres[0]!)).toEqual(['name']);
239+
});
240+
241+
it('positive control: a caller that passes a predicate emits it', async () => {
242+
const ql = emptyPageQl();
243+
await buildExistingByName(ql as any, 'sys_permission_set', ['alpha'], undefined, undefined, { managed_by: 'platform' });
244+
expect(Object.keys((ql.calls[0]![1] as any).where)).toEqual(['name', 'managed_by']);
245+
});
246+
});

0 commit comments

Comments
 (0)