Skip to content

Commit fb78dd2

Browse files
committed
test(plugin-sharing): pin the shareable-objects list, its door and its ledger
The list is compared with defineRule's own verdict for every registered object; the platform's credential and session objects are pinned absent and refused; the door is driven through the platform resolver. The ledger is wired into the live-mount parity gate and the envelope guard. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2f62c1GYk6XzbdtCa4
1 parent acd6367 commit fb78dd2

7 files changed

Lines changed: 499 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/plugin-sharing': patch
3+
---
4+
5+
feat(plugin-sharing): list the objects a sharing rule can take effect on
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
`SharingServicePlugin` mounts a read-only route, `GET /api/v1/sharing/shareable-objects`, for Setup's sharing-rule object picker. It answers `{ success: true, data: { objects } }`, each object `{ name, label, system }`, business objects first and then platform objects, each group by label.
11+
12+
An object is listed exactly when a sharing rule saved on it would take effect: the list asks the same check the save doors already ask (`SharingService.sharingRuleObjectRefusal`), so every object it leaves out is one a save refuses with `SHARING_NOT_ENABLED`. The platform's credential and session objects (sessions, linked accounts, API keys, verification tokens, two-factor rows, OAuth applications, tokens and consents, signing keys, secrets) are not listed.
13+
14+
Who may ask: the sharing-rule administrators, as `/api/v1/sharing/rules` admits them (`manage_sharing`, or the legacy `manage_platform_settings`, with an active organization). Anyone else is answered `403 PERMISSION_DENIED`, anonymous `401`. The route takes no query parameter and refuses one with `400 VALIDATION_ERROR`. With record-sharing enforcement off (`enforce: false`) it answers `501 NOT_IMPLEMENTED`.
15+
16+
`SharingRuleService` gains `listShareableObjects(context)`, the same list for in-process callers.
17+
18+
Nothing stored or authored changes; the `sys_sharing_rule` object field keeps its `object-ref` picker until the console's filtered picker lands.

‎packages/plugins/plugin-sharing/src/shareable-objects.test.ts‎

Lines changed: 408 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* Sharing route-ledger conformance — the package-local guard every
5+
* `*-route-ledger.ts` pairs with. `registerShareableObjectsRoutes` is a
6+
* standalone, synchronous function that calls `http.get` and touches neither
7+
* argument before a request arrives, so a capturing mock `IHttpServer`
8+
* enumerates its real surface (the seam the messaging, print, storage and
9+
* settings ledgers use), and the two directions fail here by name on every
10+
* `pnpm test` of this package.
11+
*/
12+
13+
import { describe, it, expect, vi } from 'vitest';
14+
import { registerShareableObjectsRoutes } from './shareable-objects-routes.js';
15+
import { SHARING_ROUTE_LEDGER } from './sharing-route-ledger.js';
16+
17+
function createMockServer() {
18+
return {
19+
get: vi.fn(),
20+
post: vi.fn(),
21+
put: vi.fn(),
22+
delete: vi.fn(),
23+
patch: vi.fn(),
24+
use: vi.fn(),
25+
listen: vi.fn().mockResolvedValue(undefined),
26+
close: vi.fn().mockResolvedValue(undefined),
27+
};
28+
}
29+
30+
function enumerateRoutes(): Set<string> {
31+
const server = createMockServer();
32+
registerShareableObjectsRoutes(server as any, {} as any);
33+
const keys = new Set<string>();
34+
for (const verb of ['get', 'post', 'put', 'patch', 'delete'] as const) {
35+
for (const call of server[verb].mock.calls) keys.add(`${verb.toUpperCase()} ${call[0]}`);
36+
}
37+
return keys;
38+
}
39+
40+
const ledgerKeys = (): Set<string> => new Set(SHARING_ROUTE_LEDGER.map((e) => e.route));
41+
42+
describe('sharing route ledger ↔ registerShareableObjectsRoutes enumeration', () => {
43+
it('every mounted route has a ledger entry', () => {
44+
const ledger = ledgerKeys();
45+
const missing = [...enumerateRoutes()].filter((k) => !ledger.has(k));
46+
expect(missing, `sharing routes with no ledger entry: ${missing.join(', ')}`).toEqual([]);
47+
});
48+
49+
it('every ledger entry is really mounted by the registrar', () => {
50+
const live = enumerateRoutes();
51+
const stale = [...ledgerKeys()].filter((k) => !live.has(k));
52+
expect(stale, `sharing ledger entries the registrar no longer mounts: ${stale.join(', ')}`).toEqual([]);
53+
});
54+
55+
it('the ledger is compared against a real enumeration, not an empty one', () => {
56+
const live = enumerateRoutes();
57+
expect(live.size).toBeGreaterThan(0);
58+
expect(live.size).toBe(ledgerKeys().size);
59+
expect(SHARING_ROUTE_LEDGER.every((e) => e.disposition === 'sdk' || (e.note ?? '').length > 0)).toBe(true);
60+
});
61+
});

‎packages/qa/dogfood/test/route-ledger-live-mount-parity.dogfood.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import { SETTINGS_ROUTE_LEDGER } from '../../../services/service-settings/src/se
7474
import { PRINT_ROUTE_LEDGER } from '../../../services/service-print/src/print-route-ledger.js';
7575
import { MESSAGING_ROUTE_LEDGER } from '../../../services/service-messaging/src/messaging-route-ledger.js';
7676
import { PERSONAL_VIEW_ROUTE_LEDGER } from '../../../plugins/plugin-auth/src/personal-view-route-ledger.js';
77+
import { SHARING_ROUTE_LEDGER } from '../../../plugins/plugin-sharing/src/sharing-route-ledger.js';
7778

7879
/** One ledger row, normalized to a wire pattern this gate can probe. */
7980
interface LedgerRow {
@@ -114,6 +115,8 @@ function collectLedgerRows(): LedgerRow[] {
114115
// [#29443] AuthPlugin's own-row delete door for a personal view, mounted on
115116
// the IHttpServer port (unlike its raw-app `/auth/*` catch-all above).
116117
for (const r of PERSONAL_VIEW_ROUTE_LEDGER) add('plugin-auth/personal-view-route-ledger.ts', r.route, '');
118+
// [#30209] SharingServicePlugin's shareable-objects list, on the IHttpServer port.
119+
for (const r of SHARING_ROUTE_LEDGER) add('plugin-sharing/sharing-route-ledger.ts', r.route, '');
117120
return rows;
118121
}
119122

‎scripts/check-route-envelope.mjs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ const MODULES = {
282282
// `sendServerFault`), so it builds none itself.
283283
'packages/services/service-messaging/src/preference-options-routes.ts': { responses: 0, ok: 0, err: 0 },
284284

285+
// [#30209] The shareable-objects door (`GET /api/v1/sharing/shareable-objects`),
286+
// mounted by `SharingServicePlugin` straight on `IHttpServer`. Every body it
287+
// answers is written by the shared pair (`sendOk` / `sendError` /
288+
// `sendServerFault`), so it builds none itself.
289+
'packages/plugins/plugin-sharing/src/shareable-objects-routes.ts': { responses: 0, ok: 0, err: 0 },
290+
285291
// The unreact door (`DELETE /api/v1/comments/reactions/:id`), mounted by
286292
// `AuditPlugin` straight on `IHttpServer`. It supplies its part of the shared
287293
// own-row delete door below and answers nothing itself, so it builds no body.

‎scripts/cross-package-test-inputs.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,8 @@ export const CROSS_PACKAGE_TEST_INPUTS = {
13081308
'packages/services/service-messaging/src/messaging-route-ledger.ts',
13091309
// [#29443] The personal-view door's ledger, imported the same way.
13101310
'packages/plugins/plugin-auth/src/personal-view-route-ledger.ts',
1311+
// [#30209] The shareable-objects door's ledger, imported the same way.
1312+
'packages/plugins/plugin-sharing/src/sharing-route-ledger.ts',
13111313
// flow-trigger / validation conformance pin spec's zod schemas.
13121314
'packages/spec/src/automation/**',
13131315
'packages/spec/src/data/**',

‎turbo.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@
615615
"$TURBO_ROOT$/packages/services/service-settings/src/settings-route-ledger.ts",
616616
"$TURBO_ROOT$/packages/services/service-messaging/src/messaging-route-ledger.ts",
617617
"$TURBO_ROOT$/packages/plugins/plugin-auth/src/personal-view-route-ledger.ts",
618+
"$TURBO_ROOT$/packages/plugins/plugin-sharing/src/sharing-route-ledger.ts",
618619
"$TURBO_ROOT$/packages/spec/src/automation/**",
619620
"$TURBO_ROOT$/packages/spec/src/data/**",
620621
"$TURBO_ROOT$/examples/app-showcase/**",

0 commit comments

Comments
 (0)