Skip to content

Commit 4437a32

Browse files
committed
test(approvals): the exposure pin's engine double answers a table whole (check:objectql-double-limit)
Claude-Session: https://claude.ai/code/session_01JfJfBUC3cQ6hhgm9MQK76T Co-authored-by: Claude <noreply@anthropic.com>
1 parent fb7da54 commit 4437a32

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎packages/plugins/plugin-approvals/src/payload-display-target-exposure.test.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,27 @@ const tables: Record<string, Row[]> = {
3737
...Object.fromEntries(Object.keys(TARGETS).map((k) => [`t_${k}`, [{ id: `${k}_1`, name: `${k} title` }]])),
3838
};
3939

40-
function makeService(unreadable?: string) {
40+
/** The two engine members the enrichment reads; `unreadable` names a target whose declaration throws. */
41+
function makeEngine(rows: Record<string, Row[]>, unreadable?: string) {
4142
const reads: string[] = [];
42-
const warn = vi.fn();
4343
const engine = {
4444
getSchema(object: string) {
4545
if (object === unreadable) throw new Error('declaration unavailable');
4646
return schemas[object];
4747
},
48-
async find(object: string, options?: { where?: { id?: { $in?: string[] } } }) {
48+
// Each table holds the one row a read can ask for, so the double answers the
49+
// table whole: what is pinned is WHICH objects are read, not the query.
50+
async find(object: string) {
4951
reads.push(object);
50-
const wanted = options?.where?.id?.$in;
51-
return (tables[object] ?? []).filter((r) => !wanted || wanted.includes(String(r.id)));
52+
return rows[object] ?? [];
5253
},
5354
};
55+
return { engine, reads };
56+
}
57+
58+
function makeService(unreadable?: string) {
59+
const warn = vi.fn();
60+
const { engine, reads } = makeEngine(tables, unreadable);
5461
const service = new ApprovalService({ engine: engine as any, logger: { info() {}, warn, error() {}, debug() {} } });
5562
// `enrichRows` is private; its public callers drag the whole request lifecycle in.
5663
const enrich = (rows: Row[]) => (service as unknown as { enrichRows(r: Row[]): Promise<void> }).enrichRows(rows);

0 commit comments

Comments
 (0)