Skip to content

Commit 30778f3

Browse files
fix(sharing): a declared sharing rule grants in an organization created after boot, without a restart (#37012)
Fixes #36982 Clause-②: no Metadata-protocol: none ## 维护者速读 - 新建的组织(例如新环境的第一次注册)里,应用自带的共享规则从创建那一刻就生效,被指派人立即能看到并编辑任务,不再需要重启服务器。 - 属于平台记录共享这条线,替任务与备忘那张卡(内置任务对象的被指派人授权)解决新组织里授权缺失的问题。 - 出错时表现为新组织里某条应用自带规则没有授权(只会少给,不会多给;每个组织的授权仍只落在本组织内);这次改动可以直接撤回,撤回后回到重启才生效的旧行为。 - 无 ## What changes `SharingServicePlugin` bound its per-record rule hooks once at boot, on the objects of the rules it served then. Under a walled posture a declared rule is served once per organization that exists (ADR-0131 D2), so a kernel that booted with no organization bound no hook on a declared rule's object. The organization-created middleware (`addDeclaredRuleScope`) added the new organization's scope and bound nothing, so a record written in that organization got no `sys_record_share` grant until the next restart. It under-granted; it never over-granted. - `SharingRuleService.listRuleHookObjects()` (new): the objects the record hooks bind on — every object an active `sys_sharing_rule` row names, plus every object an active DECLARATION names, whatever organizations serve it at that moment and whatever the activation ledger says of it. The binding is per object and organization-agnostic; the organization is resolved when a record is evaluated (`evaluateAllForRecord` lists the projections live, each sweeping inside its own organization at the driver), so isolation is unchanged. - `rule-hooks.ts`: new `rebindRuleHooks(engine, service, logger)` reads `listRuleHookObjects()`, then unbinds and calls `bindRuleHooks` with that object set; the read runs before the unbind, so a failed read keeps the previous bindings (as before). `bindRuleHooks`' `rules` parameter widens to the two fields it reads (`object_name`, `active`), a non-breaking widening; its hook bodies are unchanged and stay in that symbol (the system-context census row keys the `afterDelete` elevation read to it). - `sharing-plugin.ts`: boot and the `sys_sharing_rule` data-change rebind both go through one private `bindRuleHooks` method (the binding site ADR-0057 anchors as `sharing-plugin.ts#bindRuleHooks`), which calls `rebindRuleHooks`, so the two cannot derive different object sets. The organization-created middleware is unchanged: it still adds the scope, and the hooks already bound now serve it. - Same derivation closes the sibling shape: a declared rule switched off in the activation ledger at boot and on later keeps its object bound (the ledger reconcile never rebinds). Why per object rather than a rebind in the organization-created middleware: a rebind there would re-derive the hook set from the served projections each time, which is exactly the snapshot that drifted (and an unknown-scope boot, or a ledger switch, would still bind nothing). Binding from the declaration cannot drift with the organizations at all. A hook on an object no projection serves yet evaluates no rule and grants nothing. ## Tests - `packages/plugins/plugin-sharing/src/declared-rule-late-organization.test.ts` (new, real stack, ONE boot): `ObjectKernel` + `ObjectQLPlugin` over better-sqlite3 + `SharingServicePlugin`, `isolated` posture (the `tenancy` service plus the engine posture accessor the security plugin hands it), a package-declared `field` rule (`assignee_id`, edit) on a private object; every organization is inserted after `bootstrap()`. - Case 1: in the first organization created after boot, a task's assignee gets exactly one edit grant from the declared rule and reads the record; a member the rule does not name still reads nothing. RED on origin/main `57445a69981` (`expected [] to deeply equal [ ObjectContaining ]`), green with the fix. - Case 2 (isolation, both directions): organization A authors its own rule on the same object; control — it grants on A's record; B's record matching A's criteria gets exactly one grant, B's projection of the declared rule, stamped `organization_id` B; A's watcher does not read it. Green on origin/main and with the fix. - `sharing-rule.test.ts` (walled describe): `listRuleHookObjects()` names the declared rule's object with no scope, with unknown scopes, and with the rule switched off in the ledger (while `listRules` serves nothing in each); a stored row's object joins; an inactive declaration binds nothing. - `rule-rebind.test.ts`: mocks moved from `listRules` to `listRuleHookObjects`, the rebind seam's new read; assertions unchanged. - Ablation at head `e67a0507ced` (fix committed first; `scripts/ablation-replace.mjs`, anchor x1 to x0, blob `6558c83dc6c3` to `d440ba76857c`): the declaration loop in `listRuleHookObjects` removed, so only served projections bind. Over the three touched suites: `Tests 2 failed | 160 passed` — exactly the two new pins (the one-boot late-organization case and the `listRuleHookObjects` pin). Restored: blob `6558c83dc6c3` equals the HEAD blob, `git diff HEAD` empty. No dist rebuild needed: the suites import the subject from `src`. - At head `e67a0507ced`: `pnpm --filter @objectstack/plugin-sharing test` — Test Files 78 passed, Tests 1629 passed, 11 skipped; `pnpm --filter @objectstack/plugin-sharing typecheck` — exit 0, `check:test-typecheck: OK` (the new test is in the `tsconfig.test.json` program, `--listFilesOnly` 1 hit). <details><summary>Derived gates at e67a050</summary> `node scripts/pm/dispatch-gates.mjs --commands` (7 paths vs merge base `57445a699`): 73 families, all run after a full `pnpm build` (120 tasks, lock VERDICT command-exit 0), each exit captured before any pipe: 73 exit 0. `--ran`: 73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN (exit 0). On the first pass two families were red and are green now: `check:adr-symbol-anchors` (ADR-0057 anchors the plugin's binding site as `sharing-plugin.ts#bindRuleHooks`; kept as the private method) and `check:system-context-census` (row 31 keys the rule hooks' `afterDelete` elevation read to `bindRuleHooks`; the hook bodies stay in that symbol). `test:repo` is CI's (Test Core). </details> ## Acceptance notes - PR #36965's runtime test boots twice because of this defect. With this fix on `main`, one boot should do: the declared `sys_task_assignee` object is bound at boot from the declaration, and the organization inserted afterwards is served by those hooks. Not measured here (that test lives in plugin-security on #36965's branch, outside this card's surface); left to #36942's follow-up. - A composition with `SharingServicePlugin` but no engine posture accessor (no security plugin) reads its sharing posture as walled while the engine applies no tenant scope, so an organization-authored rule's per-record pass matches records of other organizations there. Seen while building this fixture; the fixture now sets the posture as a deployment does. No tenant wall exists in that composition either, so nothing crosses one; noted, not filed. ## Verification Read first: `packages/plugins/plugin-sharing/src/sharing-rule-service.ts` (`listRuleHookObjects`, the derivation), `packages/plugins/plugin-sharing/src/rule-hooks.ts` (`rebindRuleHooks`), `packages/plugins/plugin-sharing/src/sharing-plugin.ts` (the private `bindRuleHooks` and its two callers). Two minutes: `pnpm --filter @objectstack/plugin-sharing exec vitest run src/declared-rule-late-organization.test.ts` — expect 2 passed; on `origin/main` the first case fails with no grant row. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7abf25f commit 30778f3

7 files changed

Lines changed: 349 additions & 27 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/plugin-sharing': patch
3+
---
4+
5+
fix(sharing): a declared sharing rule grants in an organization created after boot, without a restart
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- **A package-declared sharing rule now grants in an organization created after the server booted.** The per-record rule hooks bound once at boot on the objects of the rules served then, and under a walled posture a declared rule is served once per organization that exists. A server that booted with no organization (a fresh environment, before its first sign-up) bound no hook on a declared rule's object, so a record written in the organization created afterwards got no `sys_record_share` grant and its recipient could not read it until the next restart. The hooks now bind on every object an active declaration names, whatever organizations serve it at that moment; the organization is resolved when a record is evaluated, so each grant stays inside its own organization.
11+
- **The same binding covers a declared rule switched off at boot and on again later** through the activation ledger: its object stays bound, and records written after the switch are evaluated.
12+
- Boot and the `sys_sharing_rule` data-change rebind bind through one function (`rebindRuleHooks`, reading `SharingRuleService.listRuleHookObjects()`), so the two cannot derive different object sets. `bindRuleHooks` now accepts any rows carrying `object_name` and `active` (a widening; existing callers are unaffected).
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* A package-declared sharing rule grants in an organization created AFTER the
5+
* server booted, exactly as in one present at boot — without a restart.
6+
*
7+
* ## The defect this pins
8+
*
9+
* The per-record rule hooks (`bindRuleHooks`) bind on the objects of the rules
10+
* the service serves. Under a walled posture a declared rule is served once per
11+
* organization (ADR-0131 D2), so a kernel that booted with no organization
12+
* served no declared rule and bound no hook on its object. The middleware that
13+
* serves a newly created organization (`addDeclaredRuleScope`) added the scope
14+
* and bound nothing, so a record written in that organization reached no
15+
* hook: no `sys_record_share` row, and the recipient could not read it until
16+
* the next boot. That is a fresh environment's first sign-up.
17+
*
18+
* The hooks now bind on every object a DECLARATION names, whatever
19+
* organizations it is served in at the moment of binding; the organization is
20+
* resolved when a record is evaluated.
21+
*
22+
* ## Tenant isolation, both directions
23+
*
24+
* Binding on the object is organization-agnostic; evaluation is not. A rule of
25+
* organization A must never grant on a record of organization B — neither an
26+
* organization-authored row nor A's projection of the declared rule. The
27+
* second case pins both, beside the control that proves the organization-A row
28+
* is live at all.
29+
*
30+
* Real stack, ONE boot: an `ObjectKernel` with `ObjectQLPlugin` over
31+
* better-sqlite3 and `SharingServicePlugin`, under the `isolated` posture —
32+
* the `tenancy` service the sharing plugin reads, and the engine's posture
33+
* accessor the security plugin hands it in a deployment, so a rule's criteria
34+
* sweep runs inside its organization at the driver. Every organization is
35+
* created after `bootstrap()`.
36+
*/
37+
38+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
39+
import { ObjectKernel, type Plugin, type PluginContext } from '@objectstack/core';
40+
import { ObjectQL, ObjectQLPlugin } from '@objectstack/objectql';
41+
import { SqlDriver } from '@objectstack/driver-sql';
42+
import { SysMember, SysOrganization, SysUser } from '@objectstack/platform-objects/identity';
43+
import { SharingServicePlugin } from './sharing-plugin.js';
44+
45+
const TASK = 'qa_lateorg_task';
46+
const RULE = 'qa_lateorg_task_assignee';
47+
const ORG_A = 'org_lateorg_a';
48+
const ORG_B = 'org_lateorg_b';
49+
const CREATOR_A = 'usr_lateorg_creator_a';
50+
const ASSIGNEE_A = 'usr_lateorg_assignee_a';
51+
const CREATOR_B = 'usr_lateorg_creator_b';
52+
const ASSIGNEE_B = 'usr_lateorg_assignee_b';
53+
/** The recipient of organization A's own authored rule. */
54+
const WATCHER_A = 'usr_lateorg_watcher_a';
55+
const PEOPLE = [CREATOR_A, ASSIGNEE_A, CREATOR_B, ASSIGNEE_B, WATCHER_A];
56+
57+
const SYSTEM = { isSystem: true } as const;
58+
const as = (userId: string, organizationId: string) => ({ userId, tenantId: organizationId, positions: [], permissions: [] });
59+
60+
function sqliteDriverPlugin(): Plugin {
61+
return {
62+
name: 'test.driver.sqlite',
63+
type: 'standard',
64+
version: '1.0.0',
65+
async init(ctx: PluginContext) {
66+
ctx.registerService(
67+
'driver.default',
68+
new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true }),
69+
);
70+
},
71+
};
72+
}
73+
74+
/** The `isolated` posture, read by the sharing plugin and the engine alike. */
75+
function isolatedPosturePlugin(): Plugin {
76+
return {
77+
name: 'test.lateorg.posture',
78+
type: 'standard',
79+
version: '1.0.0',
80+
dependencies: ['com.objectstack.engine.objectql'],
81+
async init(ctx: PluginContext) {
82+
ctx.registerService('tenancy', { posture: 'isolated' });
83+
ctx.getService<ObjectQL>('objectql').setTenancyPostureProvider(() => 'isolated');
84+
},
85+
};
86+
}
87+
88+
/** The identity objects, a private task object, and the package's declared `field` rule on it. */
89+
function packagePlugin(): Plugin {
90+
return {
91+
name: 'test.lateorg.package',
92+
type: 'standard',
93+
version: '1.0.0',
94+
dependencies: ['com.objectstack.engine.objectql'],
95+
async init(ctx: PluginContext) {
96+
ctx.getService<{ register(m: unknown): unknown }>('manifest').register({
97+
id: 'test.declared-rule-late-organization',
98+
namespace: 'qa_lateorg',
99+
version: '1.0.0',
100+
type: 'plugin',
101+
name: 'Declared rule, late organization',
102+
objects: [
103+
SysUser,
104+
SysMember,
105+
SysOrganization,
106+
{
107+
name: TASK,
108+
label: 'Task',
109+
sharingModel: 'private',
110+
fields: {
111+
title: { type: 'text', label: 'Title' },
112+
owner_id: { type: 'lookup', reference: 'sys_user', label: 'Owner' },
113+
assignee_id: { type: 'lookup', reference: 'sys_user', label: 'Assignee' },
114+
// The tenant column: the wall and a rule's criteria sweep scope by it.
115+
organization_id: { type: 'lookup', reference: 'sys_organization', label: 'Organization' },
116+
},
117+
},
118+
],
119+
sharingRules: [
120+
{
121+
name: RULE,
122+
label: 'Task assignee',
123+
object: TASK,
124+
type: 'criteria',
125+
condition: 'record.assignee_id != null',
126+
sharedWith: { type: 'field', value: 'assignee_id' },
127+
accessLevel: 'edit',
128+
},
129+
],
130+
});
131+
},
132+
};
133+
}
134+
135+
type Grant = { record_id: string; recipient_id: string; access_level: string; source: string; source_id: string; organization_id?: string | null };
136+
137+
describe('a declared sharing rule grants in an organization created after boot (one boot, walled posture)', () => {
138+
let kernel: ObjectKernel | undefined;
139+
let ql: ObjectQL;
140+
141+
beforeAll(async () => {
142+
kernel = new ObjectKernel({ logger: { level: 'silent' } } as never);
143+
await kernel.use(sqliteDriverPlugin());
144+
await kernel.use(new ObjectQLPlugin());
145+
await kernel.use(isolatedPosturePlugin());
146+
await kernel.use(packagePlugin());
147+
await kernel.use(new SharingServicePlugin({ registerShareLinkRoutes: false }));
148+
await kernel.bootstrap();
149+
ql = kernel.getService<ObjectQL>('objectql');
150+
for (const userId of PEOPLE) {
151+
await ql.insert('sys_user', { id: userId, name: userId, email: `${userId}@lateorg.test`, email_verified: true }, { context: SYSTEM } as never);
152+
}
153+
}, 120_000);
154+
155+
afterAll(async () => {
156+
if (kernel) await Promise.race([kernel.shutdown(), new Promise<void>((r) => setTimeout(r, 10_000))]);
157+
}, 30_000);
158+
159+
/** Every rule grant on one record, read unscoped. */
160+
const grantsOn = async (recordId: string): Promise<Grant[]> =>
161+
(await ql.find('sys_record_share', { where: { object_name: TASK, record_id: recordId }, context: SYSTEM } as never)) as Grant[];
162+
const readAs = async (userId: string, organizationId: string, id: string) =>
163+
(await ql.findOne(TASK, { where: { id }, context: as(userId, organizationId) } as never)) as Record<string, unknown> | null;
164+
const createOrganization = async (id: string) => {
165+
await ql.insert('sys_organization', { id, name: id, slug: id.replace(/_/g, '-') }, { context: SYSTEM } as never);
166+
};
167+
const createTask = async (id: string, organizationId: string, creator: string, assignee: string, title = `task ${id}`) => {
168+
await ql.insert(TASK, { id, title, assignee_id: assignee }, { context: as(creator, organizationId) } as never);
169+
// The record is stamped with its organization, so the isolation below is about organizations at all.
170+
const stored = (await ql.find(TASK, { where: { id }, context: SYSTEM } as never)) as Array<Record<string, unknown>>;
171+
expect(stored[0]?.organization_id).toBe(organizationId);
172+
return id;
173+
};
174+
175+
it('grants the assignee edit on a record of the first organization, created after bootstrap, with no rule write and no restart', async () => {
176+
await createOrganization(ORG_A);
177+
const id = await createTask('task_lateorg_a1', ORG_A, CREATOR_A, ASSIGNEE_A);
178+
179+
expect(await grantsOn(id)).toEqual([
180+
expect.objectContaining({ recipient_id: ASSIGNEE_A, access_level: 'edit', source: 'rule', source_id: RULE }),
181+
]);
182+
expect(await readAs(ASSIGNEE_A, ORG_A, id)).toMatchObject({ id, assignee_id: ASSIGNEE_A });
183+
// Under-grant fixed, no over-grant: a member the rule does not name still reads nothing.
184+
expect(await readAs(WATCHER_A, ORG_A, id)).toBeNull();
185+
});
186+
187+
it('keeps every grant inside its own organization: organization A\'s rules grant nothing on organization B\'s records', async () => {
188+
await createOrganization(ORG_B);
189+
// Organization A authors a rule of its own on the same object.
190+
await ql.insert('sys_sharing_rule', {
191+
name: 'qa_lateorg_a_shared_to_watcher',
192+
label: 'Shared tasks to the watcher',
193+
object_name: TASK,
194+
criteria_json: JSON.stringify({ title: 'shared' }),
195+
recipient_type: 'user',
196+
recipient_id: WATCHER_A,
197+
access_level: 'read',
198+
active: true,
199+
organization_id: ORG_A,
200+
}, { context: { isSystem: true, tenantId: ORG_A } } as never);
201+
202+
// Control: the organization-A row is live on organization A's records.
203+
const inA = await createTask('task_lateorg_a2', ORG_A, CREATOR_A, ASSIGNEE_A, 'shared');
204+
expect((await grantsOn(inA)).map((g) => g.recipient_id).sort()).toEqual([ASSIGNEE_A, WATCHER_A].sort());
205+
206+
// Organization B's record matches A's criteria and names an assignee.
207+
const inB = await createTask('task_lateorg_b1', ORG_B, CREATOR_B, ASSIGNEE_B, 'shared');
208+
const grants = await grantsOn(inB);
209+
// One grant: B's projection of the declared rule. Neither A's authored row
210+
// nor A's projection of the declared rule wrote one here.
211+
expect(grants).toEqual([
212+
expect.objectContaining({ recipient_id: ASSIGNEE_B, access_level: 'edit', source: 'rule', source_id: RULE }),
213+
]);
214+
expect(grants[0]?.organization_id).toBe(ORG_B);
215+
expect(await readAs(ASSIGNEE_B, ORG_B, inB)).toMatchObject({ id: inB });
216+
expect(await readAs(WATCHER_A, ORG_A, inB)).toBeNull();
217+
});
218+
});

‎packages/plugins/plugin-sharing/src/rule-hooks.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const ruleRegrantQueue = new RuleRegrantQueue();
167167
export function bindRuleHooks(
168168
engine: MinimalEngine,
169169
service: SharingRuleService,
170-
rules: SharingRuleRow[],
170+
rules: ReadonlyArray<Pick<SharingRuleRow, 'object_name' | 'active'>>,
171171
logger?: MinimalLogger,
172172
): void {
173173
const objects = new Set<string>();
@@ -310,7 +310,33 @@ export function bindRuleHooks(
310310
}
311311
}, opts);
312312
}
313-
logger?.info?.('[sharing-rule] hooks bound', { objects: Array.from(objects), ruleCount: rules.length });
313+
logger?.info?.('[sharing-rule] hooks bound', { objects: Array.from(objects) });
314+
}
315+
316+
/**
317+
* Unbind the rule-hook package and bind it again on
318+
* {@link SharingRuleService.listRuleHookObjects} — how the plugin binds the
319+
* per-record rule hooks, at boot and on every `sys_sharing_rule` rebind
320+
* (`SharingServicePlugin`'s private `bindRuleHooks`), so the two can never
321+
* derive different object sets.
322+
*
323+
* The object set is read from the rules' DECLARATIONS and rows, never from the
324+
* organizations a declared rule is served in right now: the binding is per
325+
* object and organization-agnostic, and the organization is resolved when a
326+
* record is evaluated. An organization created after the bind is therefore
327+
* served by the hooks already bound, with no rebind and no restart.
328+
*
329+
* The read runs before the unbind, so a failed read leaves the previous
330+
* bindings in place.
331+
*/
332+
export async function rebindRuleHooks(
333+
engine: MinimalEngine,
334+
service: SharingRuleService,
335+
logger?: MinimalLogger,
336+
): Promise<void> {
337+
const objects = await service.listRuleHookObjects();
338+
unbindAllRuleHooks(engine);
339+
bindRuleHooks(engine, service, objects.map((object_name) => ({ object_name, active: true })), logger);
314340
}
315341

316342
export function unbindAllRuleHooks(engine: MinimalEngine): number {

‎packages/plugins/plugin-sharing/src/rule-rebind.test.ts‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* insert (not a metadata publish), the `metadata:reloaded` rebind pattern
1111
* never fires. The plugin now binds afterInsert/afterUpdate/afterDelete
1212
* triggers on `sys_sharing_rule` itself that unbind + re-bind the whole
13-
* rule-hook package from a fresh `listRules()`.
13+
* rule-hook package from a fresh `listRuleHookObjects()`.
1414
*/
1515

1616
import { describe, it, expect, vi, beforeEach } from 'vitest';
@@ -75,7 +75,7 @@ describe('SharingServicePlugin sys_sharing_rule data-change rebind (#2592)', ()
7575
plugin = new SharingServicePlugin();
7676
rules = [];
7777
ruleService = {
78-
listRules: vi.fn(async () => rules),
78+
listRuleHookObjects: vi.fn(async () => rules.map((r) => r.object_name)),
7979
evaluateRule: vi.fn(async () => ({ ruleId: 'r1', matchedRecords: 0, expandedUsers: 0, grantsCreated: 0, grantsUpdated: 0, grantsRevoked: 0 })),
8080
revokeRuleGrants: vi.fn(async () => 0),
8181
};
@@ -126,12 +126,12 @@ describe('SharingServicePlugin sys_sharing_rule data-change rebind (#2592)', ()
126126
expect(engine.boundFor(RULE_REBIND_TRIGGER_PACKAGE)).toHaveLength(3);
127127
});
128128

129-
it('keeps previous bindings and does not throw when listRules fails', async () => {
129+
it('keeps previous bindings and does not throw when the object read fails', async () => {
130130
rules = [{ name: 'r1', object_name: 'project', active: true }];
131131
await engine.fire('afterInsert', 'sys_sharing_rule', {});
132132
expect(engine.boundFor(SHARING_RULE_HOOK_PACKAGE)).toHaveLength(RULE_HOOKS_PER_OBJECT);
133133

134-
ruleService.listRules = vi.fn(async () => { throw new Error('db gone'); });
134+
ruleService.listRuleHookObjects = vi.fn(async () => { throw new Error('db gone'); });
135135
await expect(
136136
engine.fire('afterUpdate', 'sys_sharing_rule', {}),
137137
).resolves.toBeUndefined(); // the write must not fail
@@ -144,13 +144,13 @@ describe('SharingServicePlugin sys_sharing_rule data-change rebind (#2592)', ()
144144
let release!: () => void;
145145
const gate = new Promise<void>((r) => { release = r; });
146146
let call = 0;
147-
ruleService.listRules = vi.fn(async () => {
147+
ruleService.listRuleHookObjects = vi.fn(async () => {
148148
call++;
149149
if (call === 1) {
150150
await gate; // first rebind stalls on its read
151-
return [{ name: 'r1', object_name: 'alpha', active: true }];
151+
return ['alpha'];
152152
}
153-
return [{ name: 'r2', object_name: 'beta', active: true }];
153+
return ['beta'];
154154
});
155155

156156
const first = engine.fire('afterInsert', 'sys_sharing_rule', {});
@@ -181,7 +181,7 @@ describe('SharingServicePlugin reconciles grants on rule writes (#3821)', () =>
181181
engine = makeEngine();
182182
plugin = new SharingServicePlugin();
183183
ruleService = {
184-
listRules: vi.fn(async () => []),
184+
listRuleHookObjects: vi.fn(async () => []),
185185
evaluateRule: vi.fn(async () => ({ ruleId: 'r1', matchedRecords: 2, expandedUsers: 1, grantsCreated: 2, grantsUpdated: 0, grantsRevoked: 0 })),
186186
revokeRuleGrants: vi.fn(async () => 2),
187187
sweepOrphanedRuleGrants: vi.fn(async () => 0),
@@ -252,7 +252,7 @@ describe('SharingServicePlugin reconciles grants on rule writes (#3821)', () =>
252252

253253
it('serializes reconciles behind the rebind chain', async () => {
254254
const order: string[] = [];
255-
ruleService.listRules = vi.fn(async () => { order.push('rebind'); return []; });
255+
ruleService.listRuleHookObjects = vi.fn(async () => { order.push('rebind'); return []; });
256256
ruleService.evaluateRule = vi.fn(async () => { order.push('reconcile'); return {} as any; });
257257

258258
await engine.fire('afterInsert', 'sys_sharing_rule', { result: { id: 'r1' } });
@@ -279,7 +279,7 @@ describe('SharingServicePlugin defers reconciliation to the boot backfill (#4433
279279
engine = makeEngine();
280280
plugin = new SharingServicePlugin();
281281
ruleService = {
282-
listRules: vi.fn(async () => []),
282+
listRuleHookObjects: vi.fn(async () => []),
283283
evaluateRule: vi.fn(async () => ({ ruleId: 'r1', matchedRecords: 0, expandedUsers: 0, grantsCreated: 0, grantsUpdated: 0, grantsRevoked: 0 })),
284284
revokeRuleGrants: vi.fn(async () => 0),
285285
sweepOrphanedRuleGrants: vi.fn(async () => 0),
@@ -298,7 +298,7 @@ describe('SharingServicePlugin defers reconciliation to the boot backfill (#4433
298298
// Deferring the reconcile must not defer the binding — a rule seeded at
299299
// boot has to be enforceable for records written straight afterwards.
300300
await engine.fire('afterInsert', 'sys_sharing_rule', { result: { id: 'seeded' } });
301-
expect(ruleService.listRules).toHaveBeenCalled();
301+
expect(ruleService.listRuleHookObjects).toHaveBeenCalled();
302302
});
303303

304304
it('reconciles every write once the backfill has run — user session', async () => {

0 commit comments

Comments
 (0)