Skip to content

Commit 5d01679

Browse files
fix(plugin-sharing)!: a share granted directly by a non-system caller is always a manual share (#34031)
Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none — no page under `skills/**` teaches the direct-grant door or its `source` / `sourceId` fields; the rule is stated in `content/docs/kernel/runtime-services/sharing-service.mdx`. ## 维护者速读 - 改了什么:非系统调用方直接授予的记录共享一律是手动共享;`grant` 对非 `'manual'` 的 `source` 或任何 `sourceId` 返回 400 `VALIDATION_FAILED`,不读不写。 - 为什么改:规则、团队与系统来源的共享只应由平台自身路径(系统上下文)写入,直接授权入口不应接受调用方自选来源。 - 风险与回滚:曾在直接授权请求里带非手动 `source` 或 `sourceId` 的客户端改收 400(BREAKING,changeset 写明迁移);系统路径与撤销规则不变;回滚即还原本 PR。 - 先看:`packages/plugins/plugin-sharing/src/sharing-service.ts`(`assertDirectGrantIsManual` 及其在 `grant` 非系统分支的调用点),`packages/plugins/plugin-sharing/src/sharing-service.test.ts`(新 describe),`packages/qa/dogfood/test/direct-share-grant-is-manual.dogfood.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/plugin-sharing exec vitest run src/sharing-service.test.ts -t "a direct grant is always a manual share"`,预期 14 个用例全绿。 - 需要你做的:无,席位落地。 ## What changes A share a non-system caller grants is always a manual share. - `SharingService.grant`, on the non-system path only, refuses an input whose `source` is present and is not `'manual'`, and an input that carries any `sourceId`, with `VALIDATION_FAILED` (REST 400) and a rule-level message. It refuses rather than rewrites, so a caller that sent a source learns it was not honoured. The check runs ahead of the authorization pre-flight, before anything is read or written. - An absent `source` (`undefined` / `null`), or an explicit `'manual'` with no `sourceId`, is unchanged. The system path is unchanged. - `POST /api/v1/data/:object/:id/shares` is covered by the service rule as is; `packages/rest` is not edited. - Docs: one rule sentence in `content/docs/kernel/runtime-services/sharing-service.mdx` (Management authority). - Changeset: `@objectstack/plugin-sharing` patch, `!`, BREAKING with Who moves, ADR-0087 `not-required (no-migration-prescription)`. ## Tests - `plugin-sharing/src/sharing-service.test.ts`, new top-level describe "a direct grant is always a manual share": refused for a non-system caller with `source` `'rule'` (with and without a `sourceId`), `'team'`, `'inherited'`, an unknown string, an empty string, a `sourceId` with no source and a `sourceId` with `'manual'`, each asserting `VALIDATION_FAILED`, no row and zero engine reads; the same for a caller without manage-shares rights. CONTROLS: no source, `null` source and `sourceId`, explicit `'manual'` (and its revoke), the system context writing a rule share with its `sourceId`, and the CONFLICT on a non-system revoke of that rule share. - Two tests from the "no inert grants" suite that pinned a non-system grant carrying `sourceId` (and a non-manual `source`) were removed: they pinned the accepting branch this rule removes; a comment points to the new suite. - `qa/dogfood/test/direct-share-grant-is-manual.dogfood.test.ts` (shared-showcase project): through the real REST door on the booted showcase, six refused shapes each answer 400 with nested `error.code` `VALIDATION_FAILED` and write no `sys_record_share` row; controls for no source (201, then the owner's DELETE 204), explicit `'manual'` (201), and a system-written rule share whose DELETE through the door is still 409 `CONFLICT`; and the generic data door on `sys_record_share` refusing the caller's create (405, no row). - The rule evaluator's reconcile is unchanged and still materialises through `grant` under the system context: `plugin-sharing/src/sharing-rule.test.ts` and the rest of the package pass. ## Acceptance notes - The dogfood file sits outside the two edited source files' directories because only the booted runtime composes the REST door with the real service; it is registered in the `shared-showcase` project (`packages/qa/dogfood/vitest.config.ts`, one line). - The client SDK's `shares.grant` options (`packages/client/src/index.ts`) still declare `source?` and `sourceId?`. After this rule only an absent `source` or `'manual'` with no `sourceId` is accepted there; narrowing that type is a separate change in `packages/client`, not made here. ## Verification All readings below are on head `6e8e34751d` (after merging `origin/main`), unless a line says otherwise. <details><summary>Package tests and typecheck</summary> - `pnpm --filter @objectstack/plugin-sharing test`: exit 0, Test Files 74 passed (74), Tests 1537 passed (1537). - `pnpm --filter @objectstack/plugin-sharing typecheck`: exit 0 (includes `check:test-typecheck`: ledger held, 3 pinned signatures unchanged). - `pnpm --filter @objectstack/dogfood typecheck`: exit 0. - `pnpm --filter @objectstack/spec check:generated`: exit 0 (spec moved on `main`; nothing in this diff touches it). - `packages/rest` is not edited; its suite is left to CI. </details> <details><summary>Dogfood battery (narrowing arm), final head, under the verify lock</summary> - `pnpm --filter @objectstack/dogfood test` (no shard, no path): lock VERDICT command-exit 0; Test Files 468 passed, 3 skipped (471); Tests 3969 passed, 42 skipped (4011); no failures. </details> <details><summary>Ablation (one pass: remove the new check, rebuild, read, restore, rebuild, read)</summary> - Mutation through `scripts/ablation-replace.mjs` (anchor hit 1, then 0 on disk); `scripts/ablation-dist-preflight.mjs --absent` confirmed the check gone from `plugin-sharing/dist`. - Check removed: `sharing-service.test.ts` 9 failed / 159 passed (every refusal case red, every control green); the dogfood file 6 failed / 4 passed (every refusal case red, every control green). - Restored (`git checkout HEAD`, blob hash equal to HEAD, `git diff HEAD` empty), rebuilt, preflight confirmed the check back in `dist`: both suites green. - Taken at `76b6189b6a`, before the merge; the rule code is unchanged since. </details> <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 100 families; all 100 run at the final head, every one exit 0; `--ran` reconciliation: 100 derived, 100 run, 0 NOT-MEASURED, 0 UNRUN (a derived zero: every family recorded an exit code). - `check:adr-0087-registration`: 1 declared-breaking changeset, disposition `not-required (no-migration-prescription)`. - The full lint workflow sweep and `pnpm lint` are CI's. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_ <!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a209074 commit 5d01679

6 files changed

Lines changed: 275 additions & 21 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-sharing': patch
3+
---
4+
5+
fix(plugin-sharing)!: a share granted directly by a non-system caller is always a manual share
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. The moved answer is a refusal of two input fields on one service method and the door that calls it: no stored row changes, so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** for a client that sends a non-manual `source` or a `sourceId` on the direct-grant door. `SharingService.grant` called by a non-system caller, and so `POST /api/v1/data/:object/:id/shares`, now refuses an input whose `source` is present and is not `'manual'`, and an input that carries any `sourceId`, with `VALIDATION_FAILED` (400), and writes nothing. The refusal comes before any other check reads anything. Only the platform's own sharing-rule, team and system paths, which run under a system context, write a share of another source.
13+
14+
**Who moves:** a client that sent a non-manual `source` (`'rule'`, `'team'`, `'inherited'` or any other string) or a `sourceId` on the direct-grant door. FROM 201 with the row written TO 400 `VALIDATION_FAILED`, nothing written. The fix is one line: drop `source` and `sourceId` from the request (or send `source: 'manual'` with no `sourceId`); a share that should follow a rule is declared as a sharing rule.
15+
16+
**Not moved.** A grant with no `source`, or with `source: 'manual'` and no `sourceId`, answers as before. The system path (the sharing-rule evaluator and other platform callers under a system context) writes its shares as before, and the revoke door answers as before.

‎content/docs/kernel/runtime-services/sharing-service.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ manager** whose effective write DEPTH (`unit` / `unit_and_below` /
3737
`@objectstack/plugin-security` fails closed to owner-only; without the
3838
enterprise resolver the DEPTH path is inert and authority stays owner +
3939
Modify-All. Pass `{ isSystem: true }` only from platform-internal machinery.
40+
A share a non-system caller grants is always a **manual** share: `grant` refuses
41+
a `source` other than `'manual'`, and any `sourceId`, with `VALIDATION_FAILED`
42+
(400), because only the platform's own sharing-rule, team and system paths write
43+
a share of another source.
4044

4145
## The verb boundary (ADR-0111 D3)
4246

‎packages/plugins/plugin-sharing/src/sharing-service.test.ts‎

Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,29 +1382,89 @@ describe('[ADR-0111 D7] no inert grants', () => {
13821382
.toEqual(['srule_1:edit', 'srule_2:edit']);
13831383
});
13841384

1385-
it('a manual grant keeps one row per recipient whatever `sourceId` the caller sends', async () => {
1386-
const a = await svc.grant({ object: 'account', recordId: 'a1', recipientId: 'bob', sourceId: 'x' } as any, { userId: 'alice' });
1387-
const b = await svc.grant(
1388-
{ object: 'account', recordId: 'a1', recipientId: 'bob', accessLevel: 'edit', sourceId: 'y' } as any,
1389-
{ userId: 'alice' },
1390-
);
1391-
expect(engine._tables.sys_record_share.length).toBe(1);
1392-
expect(b.id).toBe(a.id);
1393-
expect(b.access_level).toBe('edit');
1385+
// A direct (non-system) grant that carries a `source` other than 'manual',
1386+
// or any `sourceId`, is refused before the upsert is reached, so it has no
1387+
// key to keep — pinned in "a direct grant is always a manual share" below.
1388+
});
1389+
1390+
describe('[ADR-0111 D7] a direct grant is always a manual share', () => {
1391+
let engine: ReturnType<typeof makeFakeEngine>;
1392+
let svc: SharingService;
1393+
let reads: number;
1394+
const OWNER = { userId: 'alice' };
1395+
const SYSTEM = { isSystem: true } as any;
1396+
const base = { object: 'account', recordId: 'a1', recipientId: 'bob', accessLevel: 'read' as const };
1397+
beforeEach(() => {
1398+
engine = makeFakeEngine({ account: ACCOUNT_SCHEMA, sys_record_share: {} });
1399+
svc = new SharingService({ engine });
1400+
engine._tables.account = [{ id: 'a1', owner_id: 'alice' }];
1401+
reads = 0;
1402+
const find = engine.find.bind(engine);
1403+
engine.find = async (object: string, options?: any) => { reads += 1; return find(object, options); };
1404+
});
1405+
1406+
const refused: Array<[string, Record<string, unknown>]> = [
1407+
["source 'rule' with a sourceId", { source: 'rule', sourceId: 'srule_1' }],
1408+
["source 'rule' alone", { source: 'rule' }],
1409+
["source 'team'", { source: 'team', sourceId: 'team_1' }],
1410+
["source 'inherited'", { source: 'inherited' }],
1411+
['an unknown source string', { source: 'bogus' }],
1412+
['an empty source string', { source: '' }],
1413+
['a sourceId with no source', { sourceId: 'srule_1' }],
1414+
["a sourceId with source 'manual'", { source: 'manual', sourceId: 'srule_1' }],
1415+
];
1416+
1417+
for (const [label, extra] of refused) {
1418+
it(`refuses a non-system caller's grant with ${label}: VALIDATION_FAILED, nothing read, no row`, async () => {
1419+
await expect(svc.grant({ ...base, ...extra } as any, OWNER)).rejects.toThrow(/^VALIDATION_FAILED: /);
1420+
expect(engine._tables.sys_record_share ?? []).toHaveLength(0);
1421+
// Refused ahead of the authorization pre-flight's record read and the
1422+
// upsert's lookup: a refused caller pays nothing.
1423+
expect(reads).toBe(0);
1424+
});
1425+
}
1426+
1427+
it('refuses a caller without manage-shares rights the same way, before authorization reads anything', async () => {
1428+
await expect(
1429+
svc.grant({ ...base, source: 'rule', sourceId: 'srule_1' } as any, { userId: 'mallory' }),
1430+
).rejects.toThrow(/^VALIDATION_FAILED: /);
1431+
expect(reads).toBe(0);
1432+
expect(engine._tables.sys_record_share ?? []).toHaveLength(0);
13941433
});
13951434

1396-
it('a direct (non-system) grant keeps one row per recipient whatever non-manual `source` and `sourceId` it sends', async () => {
1397-
const a = await svc.grant(
1398-
{ object: 'account', recordId: 'a1', recipientId: 'bob', source: 'rule', sourceId: 'srule_x' } as any,
1399-
{ userId: 'alice' },
1400-
);
1401-
const b = await svc.grant(
1402-
{ object: 'account', recordId: 'a1', recipientId: 'bob', accessLevel: 'edit', source: 'rule', sourceId: 'srule_y' } as any,
1403-
{ userId: 'alice' },
1404-
);
1405-
expect(engine._tables.sys_record_share.length).toBe(1);
1406-
expect(b.id).toBe(a.id);
1407-
expect(b.access_level).toBe('edit');
1435+
it('CONTROL: no source grants a manual share', async () => {
1436+
const r = await svc.grant(base, OWNER);
1437+
expect(r.source).toBe('manual');
1438+
expect(engine._tables.sys_record_share).toHaveLength(1);
1439+
expect(engine._tables.sys_record_share[0]).toMatchObject({ source: 'manual', source_id: null });
1440+
});
1441+
1442+
it('CONTROL: a null source and a null sourceId read as absent and grant a manual share', async () => {
1443+
const r = await svc.grant({ ...base, source: null, sourceId: null } as any, OWNER);
1444+
expect(r.source).toBe('manual');
1445+
expect(engine._tables.sys_record_share[0]).toMatchObject({ source: 'manual', source_id: null });
1446+
});
1447+
1448+
it("CONTROL: an explicit 'manual' source grants a manual share, and its revoke still works", async () => {
1449+
const r = await svc.grant({ ...base, source: 'manual' }, OWNER);
1450+
expect(engine._tables.sys_record_share[0]).toMatchObject({ source: 'manual', source_id: null });
1451+
await svc.revoke(r.id, OWNER, { object: 'account', recordId: 'a1' });
1452+
expect(engine._tables.sys_record_share).toHaveLength(0);
1453+
});
1454+
1455+
it('CONTROL: the system context still writes a rule share with its sourceId', async () => {
1456+
const r = await svc.grant({ ...base, source: 'rule', sourceId: 'srule_1' }, SYSTEM);
1457+
expect(r).toMatchObject({ source: 'rule', source_id: 'srule_1' });
1458+
expect(engine._tables.sys_record_share).toHaveLength(1);
1459+
expect(engine._tables.sys_record_share[0]).toMatchObject({ source: 'rule', source_id: 'srule_1' });
1460+
});
1461+
1462+
it('CONTROL: a non-system revoke of a system-written rule share is still CONFLICT', async () => {
1463+
const r = await svc.grant({ ...base, source: 'rule', sourceId: 'srule_1' }, SYSTEM);
1464+
await expect(
1465+
svc.revoke(r.id, OWNER, { object: 'account', recordId: 'a1' }),
1466+
).rejects.toThrow(/^CONFLICT: /);
1467+
expect(engine._tables.sys_record_share).toHaveLength(1);
14081468
});
14091469
});
14101470

‎packages/plugins/plugin-sharing/src/sharing-service.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,39 @@ function nonUserRecipientTypeRemedy(value: unknown): string {
183183
+ ' (ADR-0111 D7)';
184184
}
185185

186+
/**
187+
* [ADR-0111 D7] A share a non-system caller grants is always a MANUAL share.
188+
* Only the platform's own paths — the sharing-rule evaluator, team and system
189+
* machinery, each running under a system context — write a share with another
190+
* `source` or with a `sourceId`.
191+
*
192+
* So the non-system path refuses, rather than rewrites, an input whose
193+
* `source` is present and is not `'manual'`, and an input that carries any
194+
* `sourceId`: a caller that sent a source learns it was not honoured. An
195+
* absent `source` (`undefined` or `null`, which `grant` reads as `'manual'`)
196+
* and an explicit `'manual'` with no `sourceId` pass unchanged.
197+
*
198+
* Called before any read or write, so a refused caller pays nothing.
199+
*/
200+
function assertDirectGrantIsManual(input: GrantShareInput): void {
201+
const source: unknown = input.source;
202+
if (source != null && source !== 'manual') {
203+
throw new Error(
204+
`VALIDATION_FAILED: a share granted directly is a manual share — send no source, or source 'manual' `
205+
+ `(received ${JSON.stringify(source)}); a share with any other source is written only by the `
206+
+ `platform's own sharing-rule, team and system paths (ADR-0111 D7)`,
207+
);
208+
}
209+
const sourceId: unknown = input.sourceId;
210+
if (sourceId != null) {
211+
throw new Error(
212+
`VALIDATION_FAILED: a share granted directly is a manual share and carries no sourceId `
213+
+ `(received ${JSON.stringify(sourceId)}); a share with a sourceId is written only by the `
214+
+ `platform's own sharing-rule, team and system paths (ADR-0111 D7)`,
215+
);
216+
}
217+
}
218+
186219
/**
187220
* Owner field convention. Hard-coded to `owner_id` for MVP — the
188221
* sharing model in Salesforce / ServiceNow / Dynamics all assume a
@@ -1992,6 +2025,9 @@ export class SharingService implements ISharingService {
19922025
this.assertNotInertGrant(input.object);
19932026
organizationId = await this.resolveSystemGrantOrganization(input, context);
19942027
} else {
2028+
// [ADR-0111 D7] A direct grant is a manual share — refused here, ahead
2029+
// of every read, so a refused caller pays nothing.
2030+
assertDirectGrantIsManual(input);
19952031
this.assertSharingEnforced(input.object);
19962032
await this.assertCanManageShares(input.object, input.recordId, context);
19972033
organizationId = await this.resolveDirectGrantOrganization(input, context);
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// [ADR-0111 D7] A share a non-system caller grants is always a MANUAL share,
4+
// pinned at the direct-grant door of the booted showcase:
5+
// `POST /api/v1/data/:object/:id/shares`.
6+
//
7+
// The door forwards the caller's `source` / `sourceId` to `SharingService.grant`,
8+
// and the service refuses, on its non-system path, an input whose `source` is
9+
// present and is not `'manual'` and an input that carries any `sourceId`: 400
10+
// `VALIDATION_FAILED`, nothing written. The service-level pins (every refused
11+
// shape, nothing read, the system-path controls) live beside the service in
12+
// `plugin-sharing/src/sharing-service.test.ts`; this file holds the composed
13+
// door — the real REST route, the real service, the real engine — because only
14+
// the booted runtime has all three.
15+
//
16+
// Controls: no source and an explicit 'manual' are granted (and the manual
17+
// share revokes); the system context still writes a rule share with its
18+
// sourceId, and that share's revoke through the door is still CONFLICT. The
19+
// generic data door on `sys_record_share` itself is pinned as refused too.
20+
21+
import { describe, it, expect, beforeAll } from 'vitest';
22+
import { type VerifyStack } from '@objectstack/verify';
23+
import type { ISharingService } from '@objectstack/spec/contracts';
24+
import type { ExecutionContext } from '@objectstack/spec/kernel';
25+
import { getSharedShowcase } from './shared-showcase.js';
26+
27+
const OBJECT = 'showcase_private_note';
28+
const SYS = { isSystem: true } as const;
29+
const idOf = (b: any) => b?.id ?? b?.record?.id;
30+
31+
describe('[ADR-0111 D7] a share granted directly by a non-system caller is always a manual share', () => {
32+
let stack: VerifyStack;
33+
let ql: any;
34+
let sharing: ISharingService;
35+
let ownerToken: string;
36+
let recipientId: string;
37+
let organizationId: string | undefined;
38+
39+
const sharesOn = async (recordId: string) =>
40+
ql.find('sys_record_share', { where: { object_name: OBJECT, record_id: recordId }, context: SYS });
41+
42+
const newNote = async (title: string): Promise<string> => {
43+
const res = await stack.apiAs(ownerToken, 'POST', `/data/${OBJECT}`, { title });
44+
expect(res.status, await res.clone().text()).toBe(201);
45+
return String(idOf(await res.json()));
46+
};
47+
48+
const grant = (recordId: string, extra: Record<string, unknown>) =>
49+
stack.apiAs(ownerToken, 'POST', `/data/${OBJECT}/${recordId}/shares`, {
50+
recipientId, accessLevel: 'read', ...extra,
51+
});
52+
53+
beforeAll(async () => {
54+
stack = await getSharedShowcase();
55+
ql = await stack.kernel.getServiceAsync('objectql');
56+
sharing = stack.kernel.getService<ISharingService>('sharing');
57+
ownerToken = await stack.signUp('dsm-owner@verify.test');
58+
await stack.signUp('dsm-recipient@verify.test');
59+
const user = await ql.findOne('sys_user', { where: { email: 'dsm-recipient@verify.test' }, context: SYS });
60+
recipientId = String(user?.id);
61+
}, 120_000);
62+
63+
const refused: Array<[string, Record<string, unknown>]> = [
64+
["source 'rule' with a sourceId", { source: 'rule', sourceId: 'srule_dsm' }],
65+
["source 'team'", { source: 'team' }],
66+
['an unknown source string', { source: 'bogus' }],
67+
['a sourceId with no source', { sourceId: 'srule_dsm' }],
68+
['a snake_case source_id with no source', { source_id: 'srule_dsm' }],
69+
["a sourceId with source 'manual'", { source: 'manual', sourceId: 'srule_dsm' }],
70+
];
71+
72+
for (const [label, extra] of refused) {
73+
it(`refuses ${label}: 400 VALIDATION_FAILED, no share written`, async () => {
74+
const recordId = await newNote(`dsm refused ${label}`);
75+
const res = await grant(recordId, extra);
76+
const body = await res.json() as { error?: { code?: string } };
77+
expect(res.status, JSON.stringify(body)).toBe(400);
78+
expect(body.error?.code).toBe('VALIDATION_FAILED');
79+
expect(await sharesOn(recordId)).toHaveLength(0);
80+
});
81+
}
82+
83+
it('CONTROL: no source is granted as a manual share, and the owner revokes it', async () => {
84+
const recordId = await newNote('dsm control no source');
85+
const res = await grant(recordId, {});
86+
expect(res.status, await res.clone().text()).toBe(201);
87+
const share = await res.json() as { id: string; source: string };
88+
expect(share.source).toBe('manual');
89+
const rows = await sharesOn(recordId);
90+
expect(rows).toHaveLength(1);
91+
expect(rows[0]).toMatchObject({ source: 'manual', recipient_id: recipientId });
92+
organizationId = rows[0].organization_id ?? undefined;
93+
94+
const revoke = await stack.apiAs(ownerToken, 'DELETE', `/data/${OBJECT}/${recordId}/shares/${share.id}`);
95+
expect(revoke.status, await revoke.clone().text()).toBe(204);
96+
expect(await sharesOn(recordId)).toHaveLength(0);
97+
});
98+
99+
it("CONTROL: an explicit 'manual' source is granted as a manual share", async () => {
100+
const recordId = await newNote('dsm control manual');
101+
const res = await grant(recordId, { source: 'manual' });
102+
expect(res.status, await res.clone().text()).toBe(201);
103+
const rows = await sharesOn(recordId);
104+
expect(rows).toHaveLength(1);
105+
expect(rows[0]).toMatchObject({ source: 'manual', source_id: null });
106+
});
107+
108+
it('CONTROL: the system context still writes a rule share, and its revoke through the door is still CONFLICT', async () => {
109+
const recordId = await newNote('dsm control system rule share');
110+
const share = await sharing.grant(
111+
{ object: OBJECT, recordId, recipientId, accessLevel: 'read', source: 'rule', sourceId: 'srule_dsm' },
112+
{ ...SYS, ...(organizationId ? { tenantId: organizationId } : {}) } as ExecutionContext,
113+
);
114+
const rows = await sharesOn(recordId);
115+
expect(rows).toHaveLength(1);
116+
expect(rows[0]).toMatchObject({ source: 'rule', source_id: 'srule_dsm' });
117+
118+
const revoke = await stack.apiAs(ownerToken, 'DELETE', `/data/${OBJECT}/${recordId}/shares/${share.id}`);
119+
const body = await revoke.json() as { error?: { code?: string } };
120+
expect(revoke.status, JSON.stringify(body)).toBe(409);
121+
expect(body.error?.code).toBe('CONFLICT');
122+
expect(await sharesOn(recordId)).toHaveLength(1);
123+
});
124+
125+
it('the generic data door on sys_record_share refuses the caller\'s create and writes no share row', async () => {
126+
const recordId = await newNote('dsm generic door');
127+
const res = await stack.apiAs(ownerToken, 'POST', '/data/sys_record_share', {
128+
object_name: OBJECT, record_id: recordId, recipient_type: 'user', recipient_id: recipientId,
129+
access_level: 'read', source: 'rule', source_id: 'srule_dsm',
130+
});
131+
const text = await res.text();
132+
// `enable.apiMethods` on `sys_record_share` grants no create (ADR-0103).
133+
expect(res.status, text).toBe(405);
134+
expect(text).toContain('OBJECT_API_METHOD_NOT_ALLOWED');
135+
expect(await sharesOn(recordId)).toHaveLength(0);
136+
});
137+
});

‎packages/qa/dogfood/vitest.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
// Files proven eligible for the worker-shared plain showcase stack.
8888
const SHARED_SHOWCASE = [
8989
'test/create-caller-id-collision.dogfood.test.ts',
90+
'test/direct-share-grant-is-manual.dogfood.test.ts',
9091
'test/form-self-auth.dogfood.test.ts',
9192
'test/showcase-agent-intersection.dogfood.test.ts',
9293
'test/showcase-agent-scope-ceiling.dogfood.test.ts',

0 commit comments

Comments
 (0)