Skip to content

Commit d463c46

Browse files
fix(comments): unreact, resolve and own-comment delete answer on a kernel with no http.server (#36539)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JpRoUZGqtwqMU5k7b4C58D)_ Part of #36469 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 托管环境里的成员现在可以撤回自己的表情回应、标记评论已解决或重新打开、删除自己的评论;以前这三个操作在托管环境一律报“找不到接口”,自托管环境不变。 - 修的是评论协作这块的托管缺口,与之前已裁定的“托管环境缺少服务端入口”一类问题同一种修法。 - 出错时只影响这三个评论操作:没装审计插件的环境会明确提示缺什么,而不是“找不到”;改动可以直接撤回。 - 无。 ## What changes The cause is in objectstack, in two layers: `AuditPlugin` mounted the three comment doors only on the kernel's own `http.server`, and the runtime dispatcher had no domain for `/comments`. A hosted tenant kernel owns no socket and registers no `http.server`, so `DELETE /api/v1/comments/reactions/:id`, `PUT /api/v1/comments/:id/resolution` and `DELETE /api/v1/comments/:id` reached the host's `createHonoApp` catch-all, whose `dispatch()` had no domain for them, so they answered the dispatcher's `404 ROUTE_NOT_FOUND`. **Premise reading.** Cloud confirmed the hosted composition on the card (comment 7084177018, cloud `apps/objectos` at `ab4358642`). The rig mounts `createHonoApp({ prefix: '/api/v1' })` under the `plugin-hono-server` raw app with `outer.route('/', inner)`, after the plugin routes. So an unclaimed `/api/v1/comments/**` request reaches the dispatcher catch-all, and the new `/comments` domain is reachable on hosted. **Unexplained:** the card read `404` with `{"code":"ENDPOINT_NOT_FOUND","message":"Not found"}`. In this tree only the `plugin-hono-server` transport's unmatched answer spells that, and the `createHonoApp` catch-all answers `ROUTE_NOT_FOUND`. Either the reading predates the pin cloud read, or a layer upstream of the catch-all answered it; that was not measured here. The code text now states the tree's answer (`ROUTE_NOT_FOUND`) and records this discrepancy instead of the old account. Shape: ruling A on #22438 (record 6079645593, applied to this member of the class; seat scope comment 7081381198). Three segments, one PR. - **spec** (`packages/spec/src/contracts/comment-doors-service.ts`): new `ICommentDoorsService` with one OPTIONAL, transport-neutral member `handleCommentDoor(request: Request)` answering a promised `Response`, the shape `IWebhookService.handleRedeliver` and `IApprovalService.handleActionPage` already use. `ServiceSlotContracts` gains `comments: ICommentDoorsService`. No comment service contract existed, so this is the smallest new one. API surface and export-origin snapshots gain the one interface. - **plugin-audit** (`comment-doors-member.ts`, `audit-plugin.ts`): `init()` registers the `comments` service. Its member runs the SAME two registrars (`registerCommentReactionRoutes`, `registerCommentDoorsRoutes`) over the same deps as the `http.server` mount, on a private `HonoHttpServer` that never listens, built on first request. The registrar body moved verbatim into a module-level `registerCommentDoors(http, ctx)` that both faces call; `mountCommentDoors` is otherwise unchanged, so the raw mount is byte-unchanged and nothing is mounted twice. The no-server branch now logs (info) that the doors are served on the `comments` service instead of warning that they are unmounted. New dependency: `@objectstack/plugin-hono-server`. - **runtime** (`domains/comments.ts`, registered in `http-dispatcher.ts`): a `/comments` segment domain for `PUT`/`DELETE` that claims exactly the three method and path shapes and forwards `context.request` with its body unread (env-scoped spellings are rewritten to the `/api/v1` wire path). Every other `/comments` shape keeps `404 ROUTE_NOT_FOUND`. No slot, or a slot without the member: `501 NOT_IMPLEMENTED` naming `@objectstack/plugin-audit`. A consumed body or a throwing member: sanitised 500, logged. No auth-gate or membership-gate exemption. Route ledger: three `server-only` rows under domain `/comments`. - **guards**: `scripts/check-route-envelope.mjs` declares `comments.ts` in `DISPATCHER_DOMAINS`; the dogfood authz matrix classifies the new ledger key (`comment-doors-session`); the live-mount parity boot pins the three rows as unexercised (that boot composes no `AuditPlugin`). Overlap: PR #36399 also edits `audit-plugin.ts`. This diff stays in the imports, the `init()` slot registration, `mountCommentDoors` and the new `registerCommentDoors` helper, and touches none of that PR's regions. Out of scope here (filed separately by the seat): the personal-views and attachments doors of the same class. ## Tests **Why `Part of`, not `Fixes` (seat, on l2-review#4 7086653795 ③):** cloud's reading (7084177018) shows that this tree's hosted composition reaches the bridged path. However, the card's own measurement read `ENDPOINT_NOT_FOUND` with no `mountCommentDoors` warning, which this tree would not produce. So no hosted evidence yet shows that the card's request took this path. #36469 stays open for one hosted live probe after this merges. That probe also checks whether a tenant kernel with no auth service answers 401. **Text rework (L2 S1), head `e7dcb26cc4`** (main merged at `f3a8a13c` in merge commit `acc0d0cd`, no rebase): the contract jsdoc, `comments.ts`, `comment-doors-member.ts`, the unreact ledger note, the conformance test header and the changeset now state the prior hosted miss as the dispatcher's `ROUTE_NOT_FOUND`, and the absence promise as never `ROUTE_NOT_FOUND` (nor `ENDPOINT_NOT_FOUND`). The member's own `ENDPOINT_NOT_FOUND` for paths outside its three routes is unchanged. The conformance pin now refuses both miss codes. Readings at `e7dcb26cc4`: - runtime `comments.test.ts` + `route-ledger.conformance.test.ts` 26/26; conformance 6/6; spec contract tests 12/12. - typecheck exit 0 for plugin-audit and http-conformance. runtime `tsc --noEmit` exit 0; its `check:test-typecheck` flagged only 3 untouched files with TS2307 on the unbuilt `@objectstack/driver-turso`. That run was green with the full build in the previous round. - eslint on the five edited source files: exit 0. The CI ESLint parse error at `604b45ec3` (an unescaped apostrophe in the ledger note) is fixed at `e7dcb26cc4`. - dispatch-gates derived for this round's six paths: 98 families, 95 exit 0. NOT MEASURED: `check:dual-build-cjs-loads` and `check:i18n` (no whole-workspace dist), and `check:type-check-debt` (its locked closure build queue-timed out). CI runs all three. Earlier readings at head `6b916dcfc` unless noted (spec and runtime source unchanged after the noted sha). - `packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts` (new, the dispatcher-only shape: `createHonoApp`, no `http.server`, real `AuditPlugin`, real ObjectQL over sqlite-wasm): **6/6 passed**. Covers unreact, resolve then reopen, own-comment delete (200, store follows), byte parity of the anonymous refusal and the refused body between the self-hosted mount and the hosted door, and a typed `501 NOT_IMPLEMENTED` per door with no `comments` service. - `packages/runtime/src/domains/comments.test.ts` (new) + `route-ledger.conformance.test.ts`: **26/26 passed** (at `2f6e249ad`). - `@objectstack/plugin-audit` full suite: **109 files, 1794 tests passed** (at `2f6e249ad`). - `@objectstack/spec` `comment-doors-service.test.ts` + `core-service-contracts.test.ts`: **12/12 passed**; spec `typecheck` (incl. `check:test-typecheck`) exit 0. - dogfood `authz-conformance.test.ts` + `authz-probe-blind-spot.test.ts`: **70/70 passed**. - typecheck exit 0: plugin-audit, runtime, http-conformance, dogfood. <details><summary>Red before, green after (two ablations, both restored)</summary> Both via `scripts/ablation-replace.mjs` (anchor hit 1 to 0, blob changed, then restored: blob == HEAD and `git diff HEAD` empty). Both subjects resolve to source (runtime tests import `../http-dispatcher.js`; http-conformance aliases `@objectstack/plugin-audit` to `src`), so no dist rebuild sits between mutation and reading. 1. Runtime domain registration removed from `http-dispatcher.ts`: `comments.test.ts` **10 failed / 3 passed** (the door shapes fall to the ordinary miss). 2. `ctx.registerService('comments', ...)` removed from `audit-plugin.ts`: conformance **4 failed / 2 passed**. Unreact, resolve and own-delete answer `501 NOT_IMPLEMENTED ... no comments service is registered`, and byte parity breaks. Not done: a conformance-level ablation of the runtime domain. That subject reaches the conformance test through `@objectstack/runtime`'s `dist/` and would need a locked rebuild per leg. The unit-level ablation (1) covers the domain. </details> <details><summary>Gates</summary> `node scripts/pm/dispatch-gates.mjs --commands` at `6b916dcfc` derived 135 families. All 135 ran locally; `--ran` reconciliation: 135 derived, 135 run, 0 unrun. Final pass, non-zero exits only: - `check:dual-build-cjs-loads` and `check:i18n` exited 3 (PREREQUISITE NOT MET: unbuilt workspace dist). Both were rerun after the full build `check:type-check-debt` performed, and both exited 0. - `check-self-test-workflow-commands.mjs` failed once with `spawnSync node ETIMEDOUT` on the loaded box. Rerun: exit 0. Fixed in this PR because a gate caught them: - `check:route-ledger-census`: 150 to 153. - `check:test-source-alias`: plugin-audit gets an anchored alias for plugin-hono-server, and the domain test imports `@objectstack/metadata` at module top. - `check-affected-docs`: the runtime door table keys `pattern`, not `path`, so it is not read as a spec API declaration. - `check:query-options-erasure`: the test's `findOne` options are typed. </details> ## Acceptance notes - The cause is in objectstack: the plugin-audit mount and the runtime dispatcher layer. Ruling A on #22438 is applied to this member of the class. The personal-views and attachments doors of the same class are not touched here; the seat files them separately. - Clause-② `yes (widening)` adds one optional member on one new contract and one new slot key. Nothing is removed or narrowed. A service without the member still satisfies the contract (pinned). - The `/comments` rows enter the route ledger as `server-only`, because the gap ratchet is 0. The live-mount parity boot pins them as unexercised, because that boot composes no `AuditPlugin`. - Unmeasured on hosted: the member resolves the caller with the tenant kernel's own `auth` service (`ctx.getService('auth')`), while the dispatcher's identity step can fall back to the host kernel. A tenant kernel with no `auth` service of its own would answer 401 after the dispatcher admitted the caller. The webhooks precedent makes the same assumption. - L2 N1, accepted deviation (also in the changeset): `@objectstack/plugin-audit` now depends on `@objectstack/plugin-hono-server` at runtime (the member's private table is a `HonoHttpServer`), and the `comments` service name is taken, so a composition that registers its own `comments` service beside `AuditPlugin` fails to boot with a duplicate-service error. L2 N2 to N4 are accepted as is. - NOT MEASURED: `route-ledger-live-mount-parity.dogfood.test.ts`. It boots the showcase app, and the box's verify lock never reached this run for that boot. CI's merge-queue dogfood shard runs it. - Deviation: the shared verify lock answered queue-timeout (exit 99) on every attempt in about 2.5 hours, under holders that each ran 10 to 80 minutes. One build closure did acquire the lock (`VERDICT command-exit 0`). Per the seat's fallback, the scoped vitest and typecheck runs above ran outside the lock, one at a time. A parked slot did not keep its place across re-queues (it reappeared at the back); that is recorded for the seat. ## Verification Read first, by risk: 1. `packages/runtime/src/domains/comments.ts`: `handleCommentsRequest` (the three-shape claim, the 501 legs, the body-unread forward). 2. `packages/plugins/plugin-audit/src/audit-plugin.ts`: the `init()` slot registration and the extracted `registerCommentDoors` (must equal the old inline body). 3. `packages/plugins/plugin-audit/src/comment-doors-member.ts`: the private never-listening table. Two-minute check: `pnpm --filter @objectstack/http-conformance exec vitest run --maxWorkers=2 src/hono-comment-doors.conformance.test.ts` after building the closure. Expected: 3 suites green; the unreact, resolve/reopen and own-delete legs answer 200 on a kernel with no `http.server`. --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmRY38EZf38Yy3zthbY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8da2b7e commit d463c46

25 files changed

Lines changed: 1176 additions & 30 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/runtime': patch
4+
'@objectstack/plugin-audit': patch
5+
---
6+
7+
fix(comments): unreact, resolve and own-comment delete work on a kernel with no `http.server` (a hosted tenant kernel) instead of answering 404
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
The three comment doors, `DELETE /api/v1/comments/reactions/:id`, `PUT /api/v1/comments/:id/resolution` and `DELETE /api/v1/comments/:id`, were mounted by `AuditPlugin` only on the kernel's `http.server`. A hosted tenant kernel owns no socket and registers no `http.server`, so the host's `createHonoApp` catch-all handed each of them to the runtime dispatcher, which had no domain for them and answered `404 ROUTE_NOT_FOUND`, and removing a reaction, resolving or reopening a thread and deleting your own comment failed there.
13+
14+
- `@objectstack/spec/contracts` declares `ICommentDoorsService` with one optional, transport-neutral member, `handleCommentDoor(request: Request): Promise<Response>`, and types the `comments` service slot with it (`ServiceSlotContracts.comments`). A service without the member still satisfies the contract.
15+
- `AuditPlugin` registers the `comments` service with that member. It runs the same registrars over the same dependencies the `http.server` mount runs, on a private route table that never listens, so every answer is the mount's own. The `http.server` mount is unchanged, and no path is mounted twice. `@objectstack/plugin-audit` now depends on `@objectstack/plugin-hono-server` at runtime (the private table is a `HonoHttpServer`), and the `comments` service name is now taken: a composition that registers its own `comments` service alongside `AuditPlugin` fails to boot with a duplicate-service error.
16+
- The runtime dispatcher gains a `/comments` domain that claims exactly the three method and path shapes and forwards the request, body unread, to the request kernel's `comments` service. Every other `/comments` shape keeps the dispatcher's `404 ROUTE_NOT_FOUND`. With no `comments` service, or one without `handleCommentDoor`, the doors answer `501 NOT_IMPLEMENTED` naming `@objectstack/plugin-audit`. The doors stay behind the dispatcher's authentication and project-membership gates.

‎packages/plugins/plugin-audit/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@objectstack/metadata-core": "workspace:*",
3131
"@objectstack/objectql": "workspace:*",
3232
"@objectstack/platform-objects": "workspace:*",
33+
"@objectstack/plugin-hono-server": "workspace:*",
3334
"@objectstack/spec": "workspace:*",
3435
"@objectstack/types": "workspace:*"
3536
},

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

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
IAuditCheckpointSink,
1313
IAuthService,
1414
IClusterService,
15+
ICommentDoorsService,
1516
ICryptoProvider,
1617
IDataEngine,
1718
IHttpServer,
@@ -70,6 +71,7 @@ import {
7071
type CommentDoorsEngine,
7172
type CommentPostingGate,
7273
} from './comment-routes.js';
74+
import { createCommentDoorMember } from './comment-doors-member.js';
7375
import { admitMentionRecipients } from './mention-recipient-gate.js';
7476
import { installActivityReadVisibility } from './activity-read-visibility.js';
7577
import { installActivityFieldRedaction } from './activity-field-redaction.js';
@@ -528,6 +530,16 @@ export class AuditPlugin implements Plugin {
528530
...createAppActivityWriter({ getEngine: getLedgerEngine, getActorSnapshot: () => this.actorSnapshotOf }),
529531
});
530532

533+
// [#36469] The comment doors on the `comments` slot, transport-neutrally
534+
// (`ICommentDoorsService.handleCommentDoor`): the runtime dispatcher's
535+
// `/comments` domain forwards to it on a kernel with no `http.server` (a
536+
// hosted tenant kernel), where `mountCommentDoors` has nothing to mount
537+
// on. Same registration as the mount; nothing is read until a request.
538+
const commentDoors: ICommentDoorsService = {
539+
handleCommentDoor: createCommentDoorMember((http) => registerCommentDoors(http, ctx)),
540+
};
541+
ctx.registerService('comments', commentDoors);
542+
531543
// ADR-0029 D8 — contribute this plugin's object translations to the i18n
532544
// service on kernel:ready (the i18n plugin may register after this one).
533545
if (typeof (ctx as any).hook === 'function') {
@@ -1083,8 +1095,9 @@ export class AuditPlugin implements Plugin {
10831095
* grant.
10841096
*
10851097
* Every service the doors read is read per request, so a provider that
1086-
* registers after this hook is still seen. A kernel with no HTTP server
1087-
* mounts nothing, and says so.
1098+
* registers after this hook is still seen. A kernel with no HTTP server (a
1099+
* hosted tenant kernel) mounts nothing here: the `comments` slot serves the
1100+
* same doors to the dispatcher (#36469), and the line says so.
10881101
*/
10891102
private mountCommentDoors(ctx: PluginContext): void {
10901103
const optional = <T>(name: string): T | undefined => {
@@ -1097,28 +1110,18 @@ export class AuditPlugin implements Plugin {
10971110
// `http.server` is the canonical name; `http-server` the deprecated alias.
10981111
const http = optional<IHttpServer>('http.server') ?? optional<IHttpServer>('http-server');
10991112
if (!http) {
1100-
ctx.logger.warn(
1101-
`AuditPlugin: no HTTP server is registered, so the comment doors (DELETE ${COMMENT_REACTION_REMOVE_ROUTE}, ` +
1102-
`PUT ${COMMENT_RESOLUTION_ROUTE}, DELETE ${COMMENT_REMOVE_ROUTE}) are not mounted: a member whose grants carry ` +
1103-
'no delete cannot remove their own reaction or comment, and resolves only the threads they started.',
1113+
// [#36469] The hosted shape: a tenant kernel owns no socket. The doors
1114+
// are not lost there: the `comments` slot (registered in `init()`) serves
1115+
// them to the runtime dispatcher's `/comments` domain, which the host's
1116+
// `createHonoApp` reaches.
1117+
ctx.logger.info(
1118+
`AuditPlugin: comment doors mounted on the 'comments' service for the dispatcher's /comments domain ` +
1119+
`(no HTTP server on this kernel): DELETE ${COMMENT_REACTION_REMOVE_ROUTE}, PUT ${COMMENT_RESOLUTION_ROUTE} ` +
1120+
`and DELETE ${COMMENT_REMOVE_ROUTE}`,
11041121
);
11051122
return;
11061123
}
1107-
const getEngine = () => optional<IDataEngine>('objectql') ?? optional<IDataEngine>('data');
1108-
const resolveCaller = platformCallerResolver({
1109-
getEngine,
1110-
getAuth: () => optional<IAuthService>('auth'),
1111-
tenancy: tenancyServiceResolver(ctx),
1112-
});
1113-
registerCommentReactionRoutes(http, {
1114-
getEngine: () => getEngine() as unknown as CommentReactionEngine | undefined,
1115-
resolveCaller,
1116-
});
1117-
registerCommentDoorsRoutes(http, {
1118-
getEngine: () => getEngine() as unknown as CommentDoorsEngine | undefined,
1119-
resolveCaller,
1120-
getSecurity: () => optional<CommentPostingGate>('security'),
1121-
});
1124+
registerCommentDoors(http, ctx);
11221125
ctx.logger.info(
11231126
`AuditPlugin: comment doors mounted at DELETE ${COMMENT_REACTION_REMOVE_ROUTE}, PUT ${COMMENT_RESOLUTION_ROUTE} ` +
11241127
`and DELETE ${COMMENT_REMOVE_ROUTE}`,
@@ -1150,6 +1153,38 @@ export class AuditPlugin implements Plugin {
11501153
}
11511154
}
11521155

1156+
/**
1157+
* Register the three comment doors on `http`, over this kernel's services, each
1158+
* read per request. The ONE registration both faces run: the self-hosted mount
1159+
* on the kernel's `http.server` (`mountCommentDoors`) and the private table
1160+
* behind the `comments` slot's `handleCommentDoor` (`comment-doors-member.ts`),
1161+
* so the two cannot answer a request differently.
1162+
*/
1163+
function registerCommentDoors(http: IHttpServer, ctx: PluginContext): void {
1164+
const optional = <T>(name: string): T | undefined => {
1165+
try {
1166+
return ctx.getService<T>(name) ?? undefined;
1167+
} catch {
1168+
return undefined;
1169+
}
1170+
};
1171+
const getEngine = () => optional<IDataEngine>('objectql') ?? optional<IDataEngine>('data');
1172+
const resolveCaller = platformCallerResolver({
1173+
getEngine,
1174+
getAuth: () => optional<IAuthService>('auth'),
1175+
tenancy: tenancyServiceResolver(ctx),
1176+
});
1177+
registerCommentReactionRoutes(http, {
1178+
getEngine: () => getEngine() as unknown as CommentReactionEngine | undefined,
1179+
resolveCaller,
1180+
});
1181+
registerCommentDoorsRoutes(http, {
1182+
getEngine: () => getEngine() as unknown as CommentDoorsEngine | undefined,
1183+
resolveCaller,
1184+
getSecurity: () => optional<CommentPostingGate>('security'),
1185+
});
1186+
}
1187+
11531188
/**
11541189
* How the unreact door reaches the `tenancy` service: the kernel's async
11551190
* accessor, read per request and classified by the composition
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#36469] The comment doors, served transport-neutrally:
5+
* `ICommentDoorsService.handleCommentDoor` (`@objectstack/spec/contracts`).
6+
*
7+
* ## Why this exists
8+
*
9+
* `AuditPlugin` mounts the three comment doors on the kernel's `http.server`
10+
* (`mountCommentDoors`). A hosted tenant kernel owns no socket and registers no
11+
* `http.server`, so on that shape the doors were never mounted. Its host's
12+
* `createHonoApp` catch-all handed each unreact, resolve and own-comment
13+
* delete to the runtime dispatcher, where no domain claimed it, and the
14+
* answer was the dispatcher's `404 ROUTE_NOT_FOUND`. (The card's hosted
15+
* reading of `404 ENDPOINT_NOT_FOUND` is not explained by this tree.) The
16+
* runtime dispatcher reaches that
17+
* kernel instead, through its `/comments` domain, which forwards the request
18+
* to this member on the kernel's `comments` slot (ruling A on #22438, applied
19+
* to this member of the class).
20+
*
21+
* ## One body, two faces
22+
*
23+
* The member runs the SAME registrars the self-hosted mount runs
24+
* (`registerCommentReactionRoutes`, `registerCommentDoorsRoutes`) over the SAME
25+
* deps, on a private route table of its own: a `HonoHttpServer` that never
26+
* listens. So the caller resolution, every refusal, the request-body reading
27+
* (and its refusal) and every answer are byte-for-byte the mount's: there is
28+
* no second copy of a door to drift from the first. The table is built on the
29+
* first request, and every service the doors read is still read per request.
30+
*
31+
* ⛔ The table never listens and is never the kernel's `http.server`: a
32+
* self-hosted kernel keeps its own mount unchanged, and no path is mounted
33+
* twice on a socket.
34+
*
35+
* ## What it answers outside the three routes
36+
*
37+
* A method and path that match none of the three routes answers
38+
* `404 ENDPOINT_NOT_FOUND`, the transport's own unmatched answer, without
39+
* reaching any door. The dispatcher claims exactly the three shapes and never
40+
* forwards one.
41+
*/
42+
43+
import type { IHttpServer } from '@objectstack/spec/contracts';
44+
import { HonoHttpServer } from '@objectstack/plugin-hono-server';
45+
46+
import { COMMENT_REACTION_REMOVE_ROUTE } from './comment-reaction-routes.js';
47+
import { COMMENT_REMOVE_ROUTE, COMMENT_RESOLUTION_ROUTE } from './comment-routes.js';
48+
49+
/** One comment door's method and route pattern. */
50+
export interface CommentDoorRoute {
51+
method: 'DELETE' | 'PUT';
52+
route: string;
53+
}
54+
55+
/**
56+
* The three comment doors, in the self-hosted mount's registration order (the
57+
* order a request is matched in): the unreact door, then the resolution door,
58+
* then the own-comment delete door.
59+
*/
60+
export const COMMENT_DOOR_ROUTES: readonly CommentDoorRoute[] = [
61+
{ method: 'DELETE', route: COMMENT_REACTION_REMOVE_ROUTE },
62+
{ method: 'PUT', route: COMMENT_RESOLUTION_ROUTE },
63+
{ method: 'DELETE', route: COMMENT_REMOVE_ROUTE },
64+
];
65+
66+
/** Does `pathname` match `pattern`, whose `:name` segments match one non-empty segment each? */
67+
function matchesRoute(pattern: string, pathname: string): boolean {
68+
const want = pattern.split('/');
69+
const got = pathname.split('/');
70+
if (want.length !== got.length) return false;
71+
return want.every((segment, i) => (segment.startsWith(':') ? got[i].length > 0 : segment === got[i]));
72+
}
73+
74+
/**
75+
* The comment door `method` and `pathname` name, or `undefined`. Exported so
76+
* the runtime's claim and this member can be pinned to the same three shapes.
77+
*/
78+
export function matchCommentDoor(method: string, pathname: string): CommentDoorRoute | undefined {
79+
const verb = method.toUpperCase();
80+
return COMMENT_DOOR_ROUTES.find((door) => door.method === verb && matchesRoute(door.route, pathname));
81+
}
82+
83+
/** The transport's unmatched answer, as `plugin-hono-server`'s `unmatchedResponse` writes it. */
84+
function unmatched(): Response {
85+
return new Response(JSON.stringify({ success: false, error: { code: 'ENDPOINT_NOT_FOUND', message: 'Not found' } }), {
86+
status: 404,
87+
headers: { 'content-type': 'application/json' },
88+
});
89+
}
90+
91+
/**
92+
* Build `handleCommentDoor` over `mount`, the function that registers the
93+
* three doors on an `IHttpServer` (the one the self-hosted mount calls too).
94+
*/
95+
export function createCommentDoorMember(mount: (http: IHttpServer) => void): (request: Request) => Promise<Response> {
96+
let table: HonoHttpServer | undefined;
97+
return async (request: Request): Promise<Response> => {
98+
if (!matchCommentDoor(request.method, new URL(request.url).pathname)) return unmatched();
99+
if (!table) {
100+
const built = new HonoHttpServer(0);
101+
mount(built);
102+
table = built;
103+
}
104+
return table.getRawApp().fetch(request);
105+
};
106+
}

‎packages/plugins/plugin-audit/vitest.config.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export default defineConfig({
4040
// One rule for all namespaces cannot go stale that way.
4141
alias: [
4242
{ find: /^@objectstack\/core$/, replacement: path.resolve(__dirname, '../../core/src/index.ts') },
43+
// The never-listening route table `comment-doors-member.ts` serves the
44+
// comment doors on for a kernel with no `http.server`: to source, so the
45+
// suite's verdict is about the checkout (`pnpm check:test-source-alias`).
46+
{
47+
find: /^@objectstack\/plugin-hono-server$/,
48+
replacement: path.resolve(__dirname, '../plugin-hono-server/src/index.ts'),
49+
},
4350
// [#16829] The real driver `read-audit-view-instant-preservation.integration.test.ts`
4451
// boots. That file exists to judge the ledger row AFTER the real
4552
// `sys_stamp_audit_insert` hook and a real driver have both run, so

0 commit comments

Comments
 (0)