Skip to content

Commit 9795169

Browse files
committed
test(plugins): give the team and position fixtures their row ids
The team and position reads page by id now and refuse a row they cannot resume after; stored rows always carry one. The position control seeds 9,999 matching rows (the lapsed assignment matches the predicate too). Claude-Session: https://claude.ai/code/session_01ADHkmT6XzrVS2iPpNyXNYL Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec9e8bb commit 9795169

3 files changed

Lines changed: 29 additions & 24 deletions

File tree

‎packages/plugins/plugin-sharing/src/ownership-queue.test.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ function makeEngine(opts: {
104104
const SUPPORT_DECLARED = [{ name: 'support_tier1', label: 'Support Tier 1', members: [{ type: 'position', value: 'support_agent' }], _packageId: 'com.acme.support' }];
105105

106106
const BASE_TABLES = (): Record<string, Row[]> => ({
107+
// Every membership row carries its `id`, as a stored one does: the team and
108+
// position reads page by it (#29503) and refuse a row they cannot resume after.
107109
sys_user_position: [
108-
{ position: 'support_agent', user_id: 'u_b', organization_id: 'org_a' },
109-
{ position: 'support_agent', user_id: 'u_a', organization_id: 'org_a' },
110-
{ position: 'support_agent', user_id: 'u_other_org', organization_id: 'org_b' },
111-
{ position: 'billing_clerk', user_id: 'u_c', organization_id: 'org_a' },
110+
{ id: 'up_1', position: 'support_agent', user_id: 'u_b', organization_id: 'org_a' },
111+
{ id: 'up_2', position: 'support_agent', user_id: 'u_a', organization_id: 'org_a' },
112+
{ id: 'up_3', position: 'support_agent', user_id: 'u_other_org', organization_id: 'org_b' },
113+
{ id: 'up_4', position: 'billing_clerk', user_id: 'u_c', organization_id: 'org_a' },
112114
],
113-
sys_team_member: [{ team_id: 't_night', user_id: 'u_d' }, { team_id: 't_night', user_id: 'u_a' }],
115+
sys_team_member: [{ id: 'tm_1', team_id: 't_night', user_id: 'u_d' }, { id: 'tm_2', team_id: 't_night', user_id: 'u_a' }],
114116
sys_queue: [
115117
{ id: 'q1', name: 'billing', label: 'Billing', organization_id: 'org_a' },
116118
{ id: 'q2', name: 'billing', label: 'Billing B', organization_id: 'org_b' },

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PositionGraphService } from './position-graph.js';
88

99
// Minimal engine: resolves find('sys_user_position') and find('sys_member').
1010
function makeEngine(
11-
assignments: Array<{ position: string; user_id: string; organization_id?: string | null }>,
11+
assignments: Array<{ id: string; position: string; user_id: string; organization_id?: string | null }>,
1212
members: Array<{ role: string; user_id: string }>,
1313
) {
1414
return {
@@ -27,10 +27,12 @@ function makeEngine(
2727
} as any;
2828
}
2929

30+
// Every `sys_user_position` row carries its `id`, as a stored one does: the
31+
// assignment read pages by it (#29503) and refuses a row it cannot resume after.
3032
const ASSIGNMENTS = [
31-
{ position: 'sales_manager', user_id: 'u_mgr' },
32-
{ position: 'sales_rep', user_id: 'u_rep1' },
33-
{ position: 'sales_rep', user_id: 'u_rep2' },
33+
{ id: 'up_1', position: 'sales_manager', user_id: 'u_mgr' },
34+
{ id: 'up_2', position: 'sales_rep', user_id: 'u_rep1' },
35+
{ id: 'up_3', position: 'sales_rep', user_id: 'u_rep2' },
3436
];
3537
// Every `sys_member` row carries its `id`, as a stored one does: the role read
3638
// pages by it (#29362) and refuses a row it cannot resume after.
@@ -48,7 +50,7 @@ describe('PositionGraphService (ADR-0090 D3 — flat expansion)', () => {
4850

4951
it('unions the better-auth membership transition source (no duplicates)', async () => {
5052
const g = new PositionGraphService({
51-
engine: makeEngine([...ASSIGNMENTS, { position: 'sales_rep', user_id: 'u_legacy_rep' }], MEMBERS),
53+
engine: makeEngine([...ASSIGNMENTS, { id: 'up_4', position: 'sales_rep', user_id: 'u_legacy_rep' }], MEMBERS),
5254
});
5355
const users = (await g.expandPositionUsers('sales_rep')).sort();
5456
expect(users).toEqual(['u_legacy_rep', 'u_rep1', 'u_rep2']);
@@ -71,10 +73,10 @@ describe('PositionGraphService (ADR-0090 D3 — flat expansion)', () => {
7173
const g = new PositionGraphService({
7274
engine: makeEngine(
7375
[
74-
{ position: 'sales_rep', user_id: 'u_active' },
75-
{ position: 'sales_rep', user_id: 'u_expired', valid_until: past } as any,
76-
{ position: 'sales_rep', user_id: 'u_pending', valid_from: future } as any,
77-
{ position: 'sales_rep', user_id: 'u_windowed', valid_from: past, valid_until: future } as any,
76+
{ id: 'up_5', position: 'sales_rep', user_id: 'u_active' },
77+
{ id: 'up_6', position: 'sales_rep', user_id: 'u_expired', valid_until: past } as any,
78+
{ id: 'up_7', position: 'sales_rep', user_id: 'u_pending', valid_from: future } as any,
79+
{ id: 'up_8', position: 'sales_rep', user_id: 'u_windowed', valid_from: past, valid_until: future } as any,
7880
],
7981
[],
8082
),
@@ -87,7 +89,7 @@ describe('PositionGraphService (ADR-0090 D3 — flat expansion)', () => {
8789
const engine = {
8890
async find(object: string, options: any) {
8991
calls++;
90-
if (object === 'sys_user_position') return [{ position: 'p', user_id: 'u1' }];
92+
if (object === 'sys_user_position') return [{ id: 'up_9', position: 'p', user_id: 'u1' }];
9193
return [];
9294
},
9395
} as any;
@@ -103,14 +105,14 @@ describe('PositionGraphService.holdsPosition — the user-scoped twin of the exp
103105
const past = '2000-01-01T00:00:00Z';
104106
const future = '2999-01-01T00:00:00Z';
105107
const ASSIGN = [
106-
{ position: 'rep', user_id: 'u_a', organization_id: 'org_a' },
107-
{ position: 'rep', user_id: 'u_b', organization_id: 'org_b' },
108-
{ position: 'rep', user_id: 'u_global', organization_id: null },
109-
{ position: 'rep', user_id: 'u_expired', organization_id: 'org_a', valid_until: past },
110-
{ position: 'rep', user_id: 'u_pending', organization_id: 'org_a', valid_from: future },
111-
{ position: 'rep', user_id: 'u_mixed', organization_id: 'org_a', valid_until: past },
112-
{ position: 'rep', user_id: 'u_mixed', organization_id: 'org_a', valid_from: past, valid_until: future },
113-
{ position: 'mgr', user_id: 'u_a', organization_id: 'org_a' },
108+
{ id: 'up_10', position: 'rep', user_id: 'u_a', organization_id: 'org_a' },
109+
{ id: 'up_11', position: 'rep', user_id: 'u_b', organization_id: 'org_b' },
110+
{ id: 'up_12', position: 'rep', user_id: 'u_global', organization_id: null },
111+
{ id: 'up_13', position: 'rep', user_id: 'u_expired', organization_id: 'org_a', valid_until: past },
112+
{ id: 'up_14', position: 'rep', user_id: 'u_pending', organization_id: 'org_a', valid_from: future },
113+
{ id: 'up_15', position: 'rep', user_id: 'u_mixed', organization_id: 'org_a', valid_until: past },
114+
{ id: 'up_16', position: 'rep', user_id: 'u_mixed', organization_id: 'org_a', valid_from: past, valid_until: future },
115+
{ id: 'up_17', position: 'mgr', user_id: 'u_a', organization_id: 'org_a' },
114116
];
115117
const MEMBER = [
116118
{ id: 'm_role_a', role: 'rep', user_id: 'u_role_a', organization_id: 'org_a' },

‎packages/plugins/plugin-sharing/src/recipient-reads-complete.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ describe('[#29503] site 2 — PositionGraphService.expandPositionUsers reads eve
212212
}, 30_000);
213213

214214
it('control — under the bound: one read, the same set as before', async () => {
215-
const rig = await boot('position', PAGE - 1);
215+
// 9,998 holders + the lapsed row = 9,999 rows the predicate matches.
216+
const rig = await boot('position', PAGE - 2);
216217
const users = await positions(rig).expandPositionUsers(POSITION, ORG);
217218

218219
expect([...users].sort()).toEqual(rig.holders);

0 commit comments

Comments
 (0)