Skip to content

Commit 1a298dd

Browse files
fix(plugin-audit): a member removes their own comment reaction through an own-row unreact door (#26345)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XQxK8SxQ94Ud3phjAvzrrEE)_ Fixes #26161 This is the server half of ruling 6422861164 (letter A). The console half (the reaction chip calls the new route, and `feedReactionRemove` stops reading a `delete` grant) is a separate `domain:ui` card that the seat files with `Blocked-by: #26161`. Clause-②: yes (widening) Metadata-protocol: none ## What changed `AuditPlugin` mounts an own-row unreact door on the kernel's HTTP server: | | | |---|---| | Method and path | `DELETE /api/v1/comments/reactions/:id` (`:id` is the `sys_comment_reaction` row id) | | Body | none read; any query parameter is refused | | `200` | `{ success: true, data: { id, deleted: true } }` | | `400 VALIDATION_ERROR` | a query parameter, or an empty id | | `401 UNAUTHENTICATED` | the request names nobody | | `403` held-sign-in code | an expired password or MFA not yet enrolled (the auth policy's own code) | | `403 PERMISSION_DENIED` | the row is another member's reaction; it stays | | `404 RECORD_NOT_FOUND` | no such row, or a row the caller cannot read (same answer, so nothing leaks) | | `503 SERVICE_UNAVAILABLE` | the permission store cannot be read, or no data engine is registered | How it decides, in order: 1. The caller is resolved by the platform's one request-to-context composition, `resolveRequestExecutionContext`, with the settings door's choices: fail-closed for anonymous, the sign-in gate resolved onto the context, API key and session both admitted, nothing localized, no bearer carried. 2. Anonymous, held sign-in and query-parameter refusals come next. 3. The row is read **as the caller**, so the object grant, the organization wall and the reaction read gate (a reaction is readable exactly when its comment is) all decide. A row the caller cannot read answers the same `404 RECORD_NOT_FOUND` as an unknown id. That is the answer the data door gives both. 4. The row's `created_by` must be the caller. This is the column the platform's own-record floor (`owner_only_deletes`) reads, stamped by the engine with the reactor. Otherwise the door answers `403 PERMISSION_DENIED`. 5. Only then is the row removed by id, under a system context with `attributedUserId` set to the caller and the caller's `tenantId`. Step 4 is the only way in to that elevated write. If the driver reports that nothing matched (a race), the door answers `404`. What does not move: no permission set gains `delete`, `member_default` (`default-permission-sets.ts`) is untouched, and `security-anchor-high-privilege` (ADR-0090 D5) is untouched. The generic `DELETE /api/v1/data/sys_comment_reaction/:id` answers exactly what it did before. Files: - `packages/plugins/plugin-audit/src/comment-reaction-routes.ts`: the door, `removeOwnCommentReaction`, and `platformCallerResolver`. - `packages/plugins/plugin-audit/src/audit-plugin.ts`: `start()` mounts the door on `http.server` (falling back to the `http-server` alias). With no HTTP server it warns once and mounts nothing. - `packages/plugins/plugin-audit/src/comment-reaction-route-ledger.ts` plus its `.conformance.test.ts`: the package-local route ledger, using the print-door model. The row is a `gap` because `@objectstack/client` has no method yet. - `packages/plugins/plugin-audit/src/objects/sys-comment-reaction.object.ts`: the header's Delete section now names the door. - `scripts/check-single-authz-resolver.mjs`: lists the door as a delegator of `resolveRequestExecutionContext`, so a later re-inline of the resolver goes red. - `content/docs/permissions/tenant-audit-census.mdx` and `docs/audits/2026-08-tenant-audit-write-call-sites.counts.md`: the census regenerated for the door's one system-context write (243→244 sites). - `scripts/check-route-envelope.mjs`: declares the new `*-routes.ts` module with `{ responses: 0, ok: 0, err: 0 }`. Every body goes through the shared `sendOk` / `sendError` / `sendServerFault`. - `.changeset/26161-own-row-unreact-door.md`: `patch` on `@objectstack/plugin-audit`. ## Tests - `packages/plugins/plugin-security/src/comment-reaction-unreact-door.integration.test.ts` runs on the real kernel, the real `SecurityPlugin` with the shipped sets, and the real `AuditPlugin` (object, read gate and mounted door). Caller resolution is real too: the platform resolver runs over seeded `sys_user` / `sys_member` rows and an auth service whose session read names the user. The member is a plain organization member with no position. Their baseline is `member_default` composed with an app every-member set that grants read and create (never delete) on comments and reactions. Cases: - own row: `200`, and the row is gone on read-back; - foreign row: `403 PERMISSION_DENIED`, and the row stays; - a reaction on a comment the caller cannot read: `404 RECORD_NOT_FOUND`, the same status and code as an unknown id, and the row stays; - unknown id: `404 RECORD_NOT_FOUND`; - anonymous: `401`; a query parameter: `400`. In both cases the row stays; - the generic data-door delete of the member's own row still answers `403 PERMISSION_DENIED`, via the engine delete under the caller plus `mapDataError`, the data door's own path. The row stays. The test lives in plugin-security because plugin-security already has a devDependency on plugin-audit. The reverse edge would be a workspace cycle. - `packages/plugins/plugin-audit/src/comment-reaction-routes.test.ts`: the door's shell before the engine is asked (permission store outage `503`, nobody `401`, held sign-in `403`, no engine `503`, engine fault `500 INTERNAL_ERROR`), plus the `AuditPlugin` mount with and without an HTTP server. - `packages/plugins/plugin-audit/src/comment-reaction-route-ledger.conformance.test.ts`: checks ledger and registrar in both directions. Red first, on base `c4968860` with the door not mounted: 6 of 8 integration cases red, each with "no DELETE /api/v1/comments/reactions/:id is mounted". The fixture case and the generic-delete `403` case were green, which is the defect itself. Ablation of the reactor check, on `0f28b47607` (`if (row.created_by !== callerId) throw …` deleted through `scripts/ablation-replace.mjs`): plugin-audit was rebuilt and `ablation-dist-preflight.mjs --absent` reported the marker absent from all 6 dist files. Then 1 failed and 7 passed, and the failure was the foreign-row case alone. Restore: HEAD blob hash matched, the rebuild had the marker present in `dist/index.js` and `dist/index.mjs`, the tree was clean, and the run was 8 of 8. Package runs on `0f28b47607`: `pnpm --filter @objectstack/plugin-audit test` passed 64 files and 1023 tests. `pnpm --filter @objectstack/plugin-security test` passed 229 files, with 4942 passing and 45 skipped. The `--project repo` suites of core, objectql, rest, runtime, spec and types all passed. `typecheck` exited 0 for both. eslint `--no-inline-config` on both packages exited 0. Gates on `0f28b47607`: all 122 commands `dispatch-gates.mjs --commands` derives for this diff exited 0, and `--ran` reconciled 122 derived, 122 run, 0 NOT-MEASURED, 0 UNRUN. ## Acceptance notes - The route is a `gap` on the SDK: `@objectstack/client` has no method for it. The console reaches the server through `ObjectStackClient` (`ui/packages/data-objectstack`), so the console half will want a client method or a direct call. That half is the seat's `domain:ui` card. - The dogfood live-mount parity gate (`route-ledger-live-mount-parity.dogfood.test.ts`) boots the showcase without `AuditPlugin`, so this ledger is not in its union, and this route is neither probed nor flagged there. The package-local conformance test is this route's guard. Adding `AuditPlugin` to that boot is outside this card. - An impersonation session may use the door, as it may use the generic data door to add a reaction. The removal is attributed to the session's user. --- _Generated by [Claude Code](https://claude.ai/code/session_01TZQBvhyKHoq1oKrgnVx35Y)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 83e9d71 commit 1a298dd

12 files changed

Lines changed: 1048 additions & 27 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/plugin-audit': patch
3+
---
4+
5+
fix(plugin-audit): a member removes their own comment reaction through an own-row unreact door, with no object delete grant
6+
7+
A member whose grants are the every-member ones could add a comment reaction and never take it back. The console removes a reaction through the generic data door's `DELETE /api/v1/data/sys_comment_reaction/:id`, which needs an object-level `delete` grant, and no every-member set may carry one: ADR-0090 D5 keeps `delete` off the `everyone` anchor (`security-anchor-high-privilege`), and `member_default` carries none. Measured as a plain member: add a reaction → `201`, delete it → `403`.
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
`AuditPlugin` now mounts `DELETE /api/v1/comments/reactions/:id` on the kernel's HTTP server. It removes the caller's own `sys_comment_reaction` row and nothing else:
13+
14+
- The row is read as the caller, so every read gate decides. A reaction on a comment the caller cannot read answers `404 RECORD_NOT_FOUND`, the same answer as an id that names no row, so the door says nothing about a reaction the caller cannot see.
15+
- The row's reactor (`created_by`, the column the platform's own-record floor reads) must be the caller. Anyone else's reaction is refused with `403 PERMISSION_DENIED` and stays.
16+
- Only then is the row removed, under a system context attributed to the caller and kept in the caller's organization. Success answers `200` with `{ success: true, data: { id, deleted: true } }`.
17+
- Before any of that the door answers what every door answers: `401 UNAUTHENTICATED` for a request that names nobody, a held sign-in's own `403`, the permission store's `503` when it cannot be read, and `400 VALIDATION_ERROR` for any query parameter.
18+
19+
The grant model does not move. The generic data-door delete answers exactly what it answered before (`403` for a member with no delete grant), no permission set gains `delete`, and `member_default` and the `security-anchor-high-privilege` rule are unchanged. The console's reaction chip moves to the new route in a separate change; until then the route is reachable but nothing in the console calls it.

‎content/docs/permissions/tenant-audit-census.mdx‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ are reported as `undecidable` rather than assumed either way.
132132

133133
The same holds twice over for the context. An options argument spelled as a
134134
literal can be read; one spelled `options`, `{ ...opts }`, or handed through a
135-
forwarding shim cannot, and **51 of the 243 sites are spelled that way**. A
135+
forwarding shim cannot, and **51 of the 244 sites are spelled that way**. A
136136
context resolved from an inline literal or a local `const` can be tested for
137137
`isSystem`; one arriving from a helper call cannot.
138138

@@ -197,10 +197,10 @@ reproduce them. Where it disagrees, it disagrees on the page:
197197

198198
| carried figure | where it survives | this census |
199199
| :--- | :--- | ---: |
200-
| 175 write call sites | quoted in the merged changeset | **243** |
200+
| 175 write call sites | quoted in the merged changeset | **244** |
201201
| 24 carrying no tenant context | quoted in the merged changeset | **2** provable and tenancy-enabled; **29** more whose options argument is unreadable |
202-
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **166 of 243** decidable, **77** undecidable |
203-
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 140 decidably elevated, 0 decidably not, 95 undecidable |
202+
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **166 of 244** decidable, **78** undecidable |
203+
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 141 decidably elevated, 0 decidably not, 95 undecidable |
204204
| 141 and 132, two independent re-derivations | the card that filed this work | — |
205205

206206
**The differences are not reconciled, and deliberately so.** The old census's
@@ -217,11 +217,11 @@ would report a smaller number and would not say so.
217217

218218
The fourth row is the one worth flagging to anyone citing it. **The 135 / 77%
219219
figure has no surviving corroboration anywhere in the tree.** This census reads
220-
140 of 243 (58%) as decidably elevated, with 95 more whose elevation is a
220+
141 of 244 (58%) as decidably elevated, with 95 more whose elevation is a
221221
run-time fact — so the claim is neither confirmed nor refuted, and the honest
222222
answer is that a static reading cannot settle it.
223223

224-
⇒ **Cite `2 / 243`, and say what it is**: the sites whose options argument was
224+
⇒ **Cite `2 / 244`, and say what it is**: the sites whose options argument was
225225
READ and holds no tenant context, against a decidably tenancy-enabled object.
226226
That is the control's provable yield surface. ⛔ Do not cite it as "the sites
227227
without tenant context" — **29 further sites** have an options argument this
@@ -233,31 +233,31 @@ cannot read, and they are neither in nor out.
233233

234234
| what | count |
235235
| :--- | ---: |
236-
| write call sites on the application surface | **243** |
236+
| write call sites on the application surface | **244** |
237237
| …whose object name is statically decidable | 166 |
238-
| …whose object name is chosen at run time | 77 |
238+
| …whose object name is chosen at run time | 78 |
239239
| …against an object with tenancy ENABLED | 165 |
240240
| …against an object that declares tenancy off | 1 |
241-
| threading a tenant context | 184 |
241+
| threading a tenant context | 185 |
242242
| PROVABLY carrying none (options read, no context key) | **8** |
243243
| …of those, against a decidably tenancy-enabled object | **2** |
244244
| options argument UNREADABLE — may or may not carry one | 51 |
245245
| …of those, against a decidably tenancy-enabled object | 29 |
246-
| threading a decidably ELEVATED (`isSystem`) context | 140 |
246+
| threading a decidably ELEVATED (`isSystem`) context | 141 |
247247
| threading a context that is decidably NOT elevated | 0 |
248248
| threading a context whose elevation is a run-time fact | 95 |
249249

250250
| how the instrument reached the site | count |
251251
| :--- | ---: |
252-
| receiver carried a readable engine type | 188 |
252+
| receiver carried a readable engine type | 189 |
253253
| receiver erased, placed by the object NAME | 45 |
254254
| receiver erased, placed by an `object: string` PARAMETER | 5 |
255255
| receiver erased, placed by an `UNTYPED_RECEIVERS` row | 5 |
256256

257257
| object name spelled inline | 115 |
258258
| object name spelled through a `const` | 51 |
259259
| object name is an `object: string` parameter | 7 |
260-
| object name is some other run-time expression | 70 |
260+
| object name is some other run-time expression | 71 |
261261

262262
### Subtractions the census could NOT defend — enforced
263263

@@ -307,13 +307,13 @@ holds still. They are required to be HERE and to say WHEN they were true;
307307
their values are not compared. The reasoning, and the measurement behind it,
308308
are in `scripts/check-tenant-audit-census.mjs`.
309309

310-
Measured on 2026-10-25 at `85aabb332`.
310+
Measured on 2026-10-26 at `700904cd5`.
311311

312312
| corpus scale (not enforced) | count |
313313
| :--- | ---: |
314-
| tracked non-test sources scanned | 769 |
315-
| engine-shaped types recognised | 88 |
314+
| tracked non-test sources scanned | 779 |
315+
| engine-shaped types recognised | 89 |
316316
| declared objects in the registry | 117 |
317-
| same-named calls subtracted as non-engine | 176 |
317+
| same-named calls subtracted as non-engine | 177 |
318318

319319
{/* END GENERATED: tenant-audit-census */}

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts.md‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ silent, and `node scripts/tenant-audit-census.mjs --write` is the resolution.
3333

3434
| Measure | Value |
3535
|---|---:|
36-
| Write call sites | 243 |
36+
| Write call sites | 244 |
3737
| Object name statically decidable | 166 |
38-
| Object name chosen at run time | 77 |
38+
| Object name chosen at run time | 78 |
3939
| Against a tenancy-enabled object | 165 |
4040
| Against an object declaring tenancy off | 1 |
41-
| Threading a tenant context | 184 |
41+
| Threading a tenant context | 185 |
4242
| Provably carrying none | 8 |
4343
| …and decidably tenancy-enabled | 2 |
4444
| Options argument unreadable | 51 |
4545
| …and decidably tenancy-enabled | 29 |
46-
| Threading a decidably elevated context | 140 |
46+
| Threading a decidably elevated context | 141 |
4747
| Threading a decidably non-elevated context | 0 |
4848
| Threading a context of undecidable elevation | 95 |
4949

@@ -90,14 +90,14 @@ holds still. They are required to be HERE and to say WHEN they were true;
9090
their values are not compared. The reasoning, and the measurement behind it,
9191
are in `scripts/check-tenant-audit-census.mjs`.
9292

93-
Measured on 2026-10-25 at `85aabb332`.
93+
Measured on 2026-10-26 at `700904cd5`.
9494

9595
| corpus scale (not enforced) | count |
9696
| :--- | ---: |
97-
| tracked non-test sources scanned | 769 |
98-
| engine-shaped types recognised | 88 |
97+
| tracked non-test sources scanned | 779 |
98+
| engine-shaped types recognised | 89 |
9999
| declared objects in the registry | 117 |
100-
| same-named calls subtracted as non-engine | 176 |
100+
| same-named calls subtracted as non-engine | 177 |
101101

102102
## Every site
103103

@@ -119,6 +119,7 @@ Measured on 2026-10-25 at `85aabb332`.
119119
| `packages/plugins/plugin-audit/src/activity-changed-fields-backfill.ts` | `update` | `sys_activity` | enabled | elevated | 1 |
120120
| `packages/plugins/plugin-audit/src/auth-event-audit.ts` | `insert` | `sys_audit_log` | enabled | options unreadable | 1 |
121121
| `packages/plugins/plugin-audit/src/comment-parent-pair-backfill.ts` | `update` | `sys_comment` | enabled | elevated | 1 |
122+
| `packages/plugins/plugin-audit/src/comment-reaction-routes.ts` | `delete` | `COMMENT_REACTION_OBJECT` | undecidable | elevated | 1 |
122123
| `packages/plugins/plugin-audit/src/mail-log-body-migration.ts` | `update` | `object` | undecidable | elevated | 1 |
123124
| `packages/plugins/plugin-audit/src/mail-log-body-migration.ts` | `update` | `object` | undecidable | options unreadable | 1 |
124125
| `packages/plugins/plugin-audit/src/read-audit.ts` | `insert` | `sys_audit_log` | enabled | options unreadable | 1 |

‎packages/plugins/plugin-audit/src/audit-plugin.ts‎

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import type { Plugin, PluginContext } from '@objectstack/core';
4-
import { effectiveTenancyPosture, resolveLocalizationContext, type TenancyPostureSource } from '@objectstack/core';
5-
import type { IDataEngine, II18nService, ISecurityService, ISharingService } from '@objectstack/spec/contracts';
4+
import {
5+
effectiveTenancyPosture,
6+
resolveLocalizationContext,
7+
type TenancyPostureSource,
8+
type TenancyServiceResolver,
9+
} from '@objectstack/core';
10+
import type {
11+
IAuthService,
12+
IDataEngine,
13+
IHttpServer,
14+
II18nService,
15+
ISecurityService,
16+
ISharingService,
17+
} from '@objectstack/spec/contracts';
618
import { SysAuditLog, SysActivity, SysComment, SysCommentReaction } from './objects/index.js';
719
// `sys_notification` was parked here "until that [ADR-0030] migration lands".
820
// It has landed, so the contribution moved to @objectstack/service-messaging —
@@ -17,6 +29,12 @@ import { installAuditWriters, type AuditI18nSurface, type MessagingEmitSurface }
1729
import { installReadAuditWriter, type ReadAuditWriterHandle } from './read-audit.js';
1830
import { createAuthEventAuditSink } from './auth-event-audit.js';
1931
import { installCommentAccessHooks, installCommentReadVisibility } from './comment-access-hooks.js';
32+
import {
33+
COMMENT_REACTION_REMOVE_ROUTE,
34+
platformCallerResolver,
35+
registerCommentReactionRoutes,
36+
type CommentReactionEngine,
37+
} from './comment-reaction-routes.js';
2038
import { admitMentionRecipients } from './mention-recipient-gate.js';
2139
import { installActivityReadVisibility } from './activity-read-visibility.js';
2240
import { installActivityFieldRedaction } from './activity-field-redaction.js';
@@ -329,6 +347,7 @@ export class AuditPlugin implements Plugin {
329347
}
330348

331349
async start(ctx: PluginContext): Promise<void> {
350+
this.mountUnreactDoor(ctx);
332351
// ObjectQL engine is only resolvable after the kernel is ready.
333352
ctx.hook('kernel:ready', async () => {
334353
let engine: IDataEngine | null = null;
@@ -760,6 +779,43 @@ export class AuditPlugin implements Plugin {
760779
}
761780
}
762781

782+
/**
783+
* Mount the unreact door (`comment-reaction-routes.ts`) on the kernel's HTTP
784+
* server: a member removes their own comment reaction, and only theirs,
785+
* without an object-level `delete` grant (maintainer ruling 6422861164,
786+
* letter A). Every service the door reads is read per request, so a provider
787+
* that registers after this hook is still seen. A kernel with no HTTP server
788+
* mounts nothing, and says so.
789+
*/
790+
private mountUnreactDoor(ctx: PluginContext): void {
791+
const optional = <T>(name: string): T | undefined => {
792+
try {
793+
return ctx.getService<T>(name) ?? undefined;
794+
} catch {
795+
return undefined;
796+
}
797+
};
798+
// `http.server` is the canonical name; `http-server` the deprecated alias.
799+
const http = optional<IHttpServer>('http.server') ?? optional<IHttpServer>('http-server');
800+
if (!http) {
801+
ctx.logger.warn(
802+
`AuditPlugin: no HTTP server is registered, so the unreact door (DELETE ${COMMENT_REACTION_REMOVE_ROUTE}) ` +
803+
'is not mounted, and a member whose grants carry no delete on sys_comment_reaction cannot remove their own reaction.',
804+
);
805+
return;
806+
}
807+
const getEngine = () => optional<IDataEngine>('objectql') ?? optional<IDataEngine>('data');
808+
registerCommentReactionRoutes(http, {
809+
getEngine: () => getEngine() as unknown as CommentReactionEngine | undefined,
810+
resolveCaller: platformCallerResolver({
811+
getEngine,
812+
getAuth: () => optional<IAuthService>('auth'),
813+
tenancy: tenancyServiceResolver(ctx),
814+
}),
815+
});
816+
ctx.logger.info(`AuditPlugin: unreact door mounted at DELETE ${COMMENT_REACTION_REMOVE_ROUTE}`);
817+
}
818+
763819
/**
764820
* [#8992] Flush the record-view tail on shutdown.
765821
*
@@ -776,3 +832,19 @@ export class AuditPlugin implements Plugin {
776832
if (writer) await writer.stop();
777833
}
778834
}
835+
836+
/**
837+
* How the unreact door reaches the `tenancy` service: the kernel's async
838+
* accessor, read per request and classified by the composition
839+
* (`classifyAdmissionTenancyPosture`). A `tenancy` service never registered is
840+
* a kernel with no organization wall; one that is registered and cannot answer
841+
* is the outage the door answers. A host with no async accessor registers no
842+
* `tenancy` service either, and no posture is read.
843+
*/
844+
function tenancyServiceResolver(ctx: PluginContext): TenancyServiceResolver | undefined {
845+
const kernel = ctx.getKernel?.() as
846+
| { getServiceAsync?: <T>(name: string, scopeId?: string) => Promise<T> }
847+
| undefined;
848+
if (!kernel || typeof kernel.getServiceAsync !== 'function') return undefined;
849+
return () => kernel.getServiceAsync!<TenancyPostureSource>('tenancy');
850+
}
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+
* Comment-reaction route-ledger conformance — the package-local guard every
5+
* `*-route-ledger.ts` pairs with. `registerCommentReactionRoutes` is a
6+
* standalone, synchronous function that calls `http.delete` and touches neither
7+
* argument before a request arrives, so a capturing mock `IHttpServer`
8+
* enumerates its real surface (the seam the print, storage and settings ledgers
9+
* use), and the two directions fail here by name on every `pnpm test` of this
10+
* package.
11+
*/
12+
13+
import { describe, it, expect, vi } from 'vitest';
14+
import { registerCommentReactionRoutes } from './comment-reaction-routes.js';
15+
import { COMMENT_REACTION_ROUTE_LEDGER } from './comment-reaction-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+
registerCommentReactionRoutes(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(COMMENT_REACTION_ROUTE_LEDGER.map((e) => e.route));
41+
42+
describe('comment-reaction route ledger ↔ registerCommentReactionRoutes 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, `comment-reaction 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, `comment-reaction 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(COMMENT_REACTION_ROUTE_LEDGER.every((e) => e.disposition === 'sdk' || (e.note ?? '').length > 0)).toBe(true);
60+
});
61+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* Comment-reaction route ledger — the audited disposition of every HTTP route
5+
* `registerCommentReactionRoutes` (`comment-reaction-routes.ts`) mounts.
6+
*
7+
* WHY THIS EXISTS. `AuditPlugin` reaches for the `http.server` service and
8+
* registers straight on `IHttpServer`, so neither the dispatcher ledger nor the
9+
* REST ledger sees its route, the same shape as the print, storage and settings
10+
* families. `comment-reaction-route-ledger.conformance.test.ts` fails when the
11+
* registrar mounts a route with no row here, and when a row names a route it no
12+
* longer mounts.
13+
*
14+
* A GAP, NOT SDK SURFACE YET. The consumer is the console's reaction chip,
15+
* which removes a reaction today through the generic data door's `delete` and
16+
* moves to this route in the console half of the same ruling. `@objectstack/client`
17+
* has no method for it yet, so the row is an acknowledged `gap`.
18+
*
19+
* This module is package-internal (not exported from the index): it is the
20+
* guard's data, not public API. It stays import-free, so a guard in another
21+
* package can read it as a relative SOURCE file.
22+
*/
23+
24+
/** Disposition of a single route. Same vocabulary as the REST ledger. */
25+
export type CommentReactionRouteDisposition =
26+
/** Expressed by the SDK — `client` names the method (dotted path). */
27+
| 'sdk'
28+
/** Should be in the SDK and is not — an open, acknowledged gap. */
29+
| 'gap'
30+
/** Deliberately not SDK surface. */
31+
| 'server-only'
32+
/** Public, unauthenticated browser-facing route. */
33+
| 'public'
34+
/** Server and client disagree on the shape — needs reconciliation. */
35+
| 'mismatch';
36+
37+
export interface CommentReactionRouteLedgerEntry {
38+
/** `VERB /api/v1/...` — the full wire path. */
39+
route: string;
40+
/** Registrar family, for grouping and diff messages. */
41+
family: string;
42+
disposition: CommentReactionRouteDisposition;
43+
/** Dotted method path on `ObjectStackClient` — required when disposition is `sdk`. */
44+
client?: string;
45+
/** One-line rationale. Required for every non-`sdk` disposition. */
46+
note?: string;
47+
}
48+
49+
export const COMMENT_REACTION_ROUTE_LEDGER: readonly CommentReactionRouteLedgerEntry[] = [
50+
{ route: 'DELETE /api/v1/comments/reactions/:id', family: 'comment-reactions', disposition: 'gap',
51+
note: "remove the caller's own sys_comment_reaction row, needing no object delete grant; the console's reaction chip is the consumer and the SDK has no method yet" },
52+
];

0 commit comments

Comments
 (0)