Skip to content

Commit 241a137

Browse files
committed
test(plugin-sharing): the business-unit graph double models the keyset member read
The sys_business_unit_member reads are now a keyset walk (id > cursor, ordered by id, a page limit). The hand-rolled engine in business-unit-graph.test.ts stamps the id a stored row carries and models $and, $gt, orderBy and limit, so its 25 cases keep pinning the two tenant screens and the two widths. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbWdszDuXCYxfoR2ynB
1 parent 0443a73 commit 241a137

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎packages/plugins/plugin-sharing/src/business-unit-graph.test.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,38 @@ interface UnitRow {
6060
active?: boolean;
6161
manager_user_id?: string | null;
6262
}
63-
interface MemberRow { business_unit_id: string; user_id: string; organization_id?: string | null }
63+
interface MemberRow { id?: string; business_unit_id: string; user_id: string; organization_id?: string | null }
6464

6565
/**
6666
* Minimal engine over `sys_business_unit` + `sys_business_unit_member`.
6767
* Mirrors the real filter surface the service uses: plain equality, `$ne`,
6868
* `$in`, and `$or` (so a widened predicate would actually be exercised here
6969
* rather than silently ignored by the stub).
70+
*
71+
* [#29606] The member reads are a keyset walk (`id > cursor`, ordered by `id`,
72+
* a page `limit`), so the member side also models `$and`, `$gt`, `orderBy`
73+
* and `limit`, and every member row carries the `id` a stored row has —
74+
* stamped here when a fixture names none.
7075
*/
7176
function makeEngine(units: UnitRow[], members: MemberRow[]) {
77+
const memberRows = members.map((m, i) => ({ id: `bum_${String(i).padStart(4, '0')}`, ...m }));
7278
const matches = (row: any, filter: any): boolean => {
7379
if (!filter || typeof filter !== 'object') return true;
7480
for (const [k, v] of Object.entries(filter)) {
7581
if (k === '$or') {
7682
if (!(v as any[]).some((sub) => matches(row, sub))) return false;
7783
continue;
7884
}
85+
if (k === '$and') {
86+
if (!(v as any[]).every((sub) => matches(row, sub))) return false;
87+
continue;
88+
}
7989
if (k.startsWith('$')) throw new Error(`fake driver: unsupported operator ${k}`);
8090
const rv = row[k];
91+
if (v && typeof v === 'object' && '$gt' in (v as any)) {
92+
if (!(String(rv) > String((v as any).$gt))) return false;
93+
continue;
94+
}
8195
if (v && typeof v === 'object' && '$ne' in (v as any)) {
8296
if (rv === (v as any).$ne) return false;
8397
continue;
@@ -101,7 +115,11 @@ function makeEngine(units: UnitRow[], members: MemberRow[]) {
101115
async find(object: string, options: any) {
102116
const filter = options?.where ?? options?.filter ?? {};
103117
if (object === 'sys_business_unit') return units.filter((u) => matches(u, filter));
104-
if (object === 'sys_business_unit_member') return members.filter((m) => matches(m, filter));
118+
if (object === 'sys_business_unit_member') {
119+
const rows = memberRows.filter((m) => matches(m, filter));
120+
if (options?.orderBy?.[0]?.field === 'id') rows.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
121+
return typeof options?.limit === 'number' ? rows.slice(0, options.limit) : rows;
122+
}
105123
return [];
106124
},
107125
} as any;

0 commit comments

Comments
 (0)