From 25a68233b79f1f6f640a1792b858605765988253 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 20:09:26 +0000 Subject: [PATCH 1/8] feat(runtime,plugin-audit): the hosted /comments domain serves the comment threads read The member's private table already registered POST /api/v1/comments/threads/query; the member and the dispatcher's /comments domain now admit it as a fourth shape, so a hosted tenant kernel answers the list page's comment panel as a self-hosted one does. Claude-Session: https://claude.ai/code/session_01WGufzeqywuHW6vj4DU7Rgp Co-authored-by: Claude --- content/docs/api/data-api.mdx | 10 ++--- .../plugins/plugin-audit/src/audit-plugin.ts | 25 ++++++------ .../plugin-audit/src/comment-doors-member.ts | 32 ++++++++++------ ...e-ledger-live-mount-parity.dogfood.test.ts | 11 ++++-- packages/runtime/src/domains/comments.ts | 38 +++++++++++++------ packages/runtime/src/route-ledger.ts | 2 + .../src/contracts/comment-doors-service.ts | 25 ++++++++---- 7 files changed, 88 insertions(+), 55 deletions(-) diff --git a/content/docs/api/data-api.mdx b/content/docs/api/data-api.mdx index a541a5990c1..ca485fe3e81 100644 --- a/content/docs/api/data-api.mdx +++ b/content/docs/api/data-api.mdx @@ -685,8 +685,10 @@ the approvals-family read and is unchanged. ## Comment threads The discussions on the records a list shows, in one read: what a list page's -comment panel asks. Served by `@objectstack/plugin-audit` on a kernel with an -HTTP server; the SDK method is `client.comments.queryThreads`. +comment panel asks. Served by `@objectstack/plugin-audit`, on a self-hosted +kernel from its own HTTP mount and on a hosted tenant kernel through the +dispatcher's `/comments` domain, with the same caller rule, body and refusals; +the SDK method is `client.comments.queryThreads`. ### `POST /comments/threads/query` @@ -754,10 +756,6 @@ Refusals: - an object on a driver that cannot run the subquery (MongoDB, OData): `400 INVALID_FILTER`. -A kernel with no HTTP server (a hosted tenant kernel) serves the other comment -doors through the dispatcher's `/comments` domain, which does not claim this -read, so it is not served there. - --- ## Analytics diff --git a/packages/plugins/plugin-audit/src/audit-plugin.ts b/packages/plugins/plugin-audit/src/audit-plugin.ts index 95445a23cb1..9c29a78e048 100644 --- a/packages/plugins/plugin-audit/src/audit-plugin.ts +++ b/packages/plugins/plugin-audit/src/audit-plugin.ts @@ -544,7 +544,8 @@ export class AuditPlugin implements Plugin { // (`ICommentDoorsService.handleCommentDoor`): the runtime dispatcher's // `/comments` domain forwards to it on a kernel with no `http.server` (a // hosted tenant kernel), where `mountCommentDoors` has nothing to mount - // on. Same registration as the mount; nothing is read until a request. + // on. Same registration as the mount, the comment threads read included + // (#39134); nothing is read until a request. const commentDoors: ICommentDoorsService = { handleCommentDoor: createCommentDoorMember((http) => registerCommentDoors(http, ctx)), }; @@ -1162,14 +1163,13 @@ export class AuditPlugin implements Plugin { * 7063285032 and 7069889899), past the row floor and without a `delete` * grant; * - the comment threads read (`comment-threads-query.ts`): the threads on - * the records a list filter selects, as the caller. It is mounted here - * only: the dispatcher's `/comments` domain does not claim it, so a kernel - * with no HTTP server does not serve it, and the line below says so. + * the records a list filter selects, as the caller. * * Every service the doors read is read per request, so a provider that * registers after this hook is still seen. A kernel with no HTTP server (a * hosted tenant kernel) mounts nothing here: the `comments` slot serves the - * same doors to the dispatcher (#36469), and the line says so. + * same doors and the same threads read to the dispatcher (#36469, #39134), + * and the line says so. */ private mountCommentDoors(ctx: PluginContext): void { const optional = (name: string): T | undefined => { @@ -1183,15 +1183,13 @@ export class AuditPlugin implements Plugin { const http = optional('http.server') ?? optional('http-server'); if (!http) { // [#36469] The hosted shape: a tenant kernel owns no socket. The doors - // are not lost there: the `comments` slot (registered in `init()`) serves - // them to the runtime dispatcher's `/comments` domain, which the host's - // `createHonoApp` reaches. + // and the threads read (#39134) are not lost there: the `comments` slot + // (registered in `init()`) serves them to the runtime dispatcher's + // `/comments` domain, which the host's `createHonoApp` reaches. ctx.logger.info( `AuditPlugin: comment doors mounted on the 'comments' service for the dispatcher's /comments domain ` + `(no HTTP server on this kernel): DELETE ${COMMENT_REACTION_REMOVE_ROUTE}, PUT ${COMMENT_RESOLUTION_ROUTE} ` + - `and DELETE ${COMMENT_REMOVE_ROUTE}; the comment threads read POST ${COMMENT_THREADS_QUERY_ROUTE} is not ` + - `served on this kernel (the dispatcher's /comments domain does not claim it; it is mounted only on a kernel ` + - `with an HTTP server)`, + `and DELETE ${COMMENT_REMOVE_ROUTE}, and the comment threads read at POST ${COMMENT_THREADS_QUERY_ROUTE}`, ); return; } @@ -1236,9 +1234,8 @@ export class AuditPlugin implements Plugin { * on the kernel's `http.server` (`mountCommentDoors`) and the private table * behind the `comments` slot's `handleCommentDoor` (`comment-doors-member.ts`), * so the two cannot answer a request differently. `registerCommentDoorsRoutes` - * also mounts the comment threads read; the member's table carries it too, but - * the member matches only the three doors, so only the self-hosted mount - * serves it. + * also mounts the comment threads read, and the member serves it as well + * (#39134), so both faces answer it alike. */ function registerCommentDoors(http: IHttpServer, ctx: PluginContext): void { const optional = (name: string): T | undefined => { diff --git a/packages/plugins/plugin-audit/src/comment-doors-member.ts b/packages/plugins/plugin-audit/src/comment-doors-member.ts index c27e1a921bf..6e1623facda 100644 --- a/packages/plugins/plugin-audit/src/comment-doors-member.ts +++ b/packages/plugins/plugin-audit/src/comment-doors-member.ts @@ -3,6 +3,7 @@ /** * [#36469] The comment doors, served transport-neutrally: * `ICommentDoorsService.handleCommentDoor` (`@objectstack/spec/contracts`). + * [#39134] The comment threads read rides the same member. * * ## Why this exists * @@ -28,15 +29,21 @@ * no second copy of a door to drift from the first. The table is built on the * first request, and every service the doors read is still read per request. * + * The routes it serves are the three doors and the comment threads read + * (`POST /api/v1/comments/threads/query`, `comment-threads-query.ts`), which + * `registerCommentDoorsRoutes` mounts beside them: the list page's comment + * panel reads it, so a hosted kernel serves it exactly as a self-hosted one + * does (same caller, same strict body, same refusals). + * * ⛔ The table never listens and is never the kernel's `http.server`: a * self-hosted kernel keeps its own mount unchanged, and no path is mounted * twice on a socket. * - * ## What it answers outside the three routes + * ## What it answers outside the four routes * - * A method and path that match none of the three routes answers + * A method and path that match none of the four routes answers * `404 ENDPOINT_NOT_FOUND`, the transport's own unmatched answer, without - * reaching any door. The dispatcher claims exactly the three shapes and never + * reaching any door. The dispatcher claims exactly the four shapes and never * forwards one. */ @@ -45,22 +52,25 @@ import { HonoHttpServer } from '@objectstack/plugin-hono-server'; import { COMMENT_REACTION_REMOVE_ROUTE } from './comment-reaction-routes.js'; import { COMMENT_REMOVE_ROUTE, COMMENT_RESOLUTION_ROUTE } from './comment-routes.js'; +import { COMMENT_THREADS_QUERY_ROUTE } from './comment-threads-query.js'; -/** One comment door's method and route pattern. */ +/** One comment route's method and route pattern. */ export interface CommentDoorRoute { - method: 'DELETE' | 'PUT'; + method: 'DELETE' | 'PUT' | 'POST'; route: string; } /** - * The three comment doors, in the self-hosted mount's registration order (the - * order a request is matched in): the unreact door, then the resolution door, - * then the own-comment delete door. + * The four comment routes the member serves, in the self-hosted mount's + * registration order (the order a request is matched in): the unreact door, + * the resolution door, the own-comment delete door, then the comment threads + * read. */ export const COMMENT_DOOR_ROUTES: readonly CommentDoorRoute[] = [ { method: 'DELETE', route: COMMENT_REACTION_REMOVE_ROUTE }, { method: 'PUT', route: COMMENT_RESOLUTION_ROUTE }, { method: 'DELETE', route: COMMENT_REMOVE_ROUTE }, + { method: 'POST', route: COMMENT_THREADS_QUERY_ROUTE }, ]; /** Does `pathname` match `pattern`, whose `:name` segments match one non-empty segment each? */ @@ -72,8 +82,8 @@ function matchesRoute(pattern: string, pathname: string): boolean { } /** - * The comment door `method` and `pathname` name, or `undefined`. Exported so - * the runtime's claim and this member can be pinned to the same three shapes. + * The comment route `method` and `pathname` name, or `undefined`. Exported so + * the runtime's claim and this member can be pinned to the same four shapes. */ export function matchCommentDoor(method: string, pathname: string): CommentDoorRoute | undefined { const verb = method.toUpperCase(); @@ -90,7 +100,7 @@ function unmatched(): Response { /** * Build `handleCommentDoor` over `mount`, the function that registers the - * three doors on an `IHttpServer` (the one the self-hosted mount calls too). + * four routes on an `IHttpServer` (the one the self-hosted mount calls too). */ export function createCommentDoorMember(mount: (http: IHttpServer) => void): (request: Request) => Promise { let table: HonoHttpServer | undefined; diff --git a/packages/qa/dogfood/test/route-ledger-live-mount-parity.dogfood.test.ts b/packages/qa/dogfood/test/route-ledger-live-mount-parity.dogfood.test.ts index 3a3ca60ba47..d541c1a0227 100644 --- a/packages/qa/dogfood/test/route-ledger-live-mount-parity.dogfood.test.ts +++ b/packages/qa/dogfood/test/route-ledger-live-mount-parity.dogfood.test.ts @@ -177,16 +177,19 @@ const UNEXERCISED_BY_THIS_BOOT: Record = { // `rawApp.post()` on the Hono app — never through the port. 'POST /api/v1/webhooks/redeliver': 'self-hosted, plugin-webhooks mounts the redeliver door with rawApp.post() directly on Hono, so it never passes through the IHttpServer port; the dispatcher domain this row ledgers serves only a kernel with no raw app. Both doors are driven, on the real plugin, by packages/qa/http-conformance/src/hono-webhooks-redeliver.conformance.test.ts', - // [#36469] Two doors, one path, for the three comment doors. These rows - // ledger the DISPATCHER's `/comments` domain, the door for a kernel with NO - // `http.server`. Self-hosted, plugin-audit mounts the same paths on the - // port — but this boot composes no AuditPlugin, so nothing answers them here. + // [#36469] Two doors, one path, for the three comment doors and (#39134) + // the comment threads read. These rows ledger the DISPATCHER's `/comments` + // domain, the door for a kernel with NO `http.server`. Self-hosted, + // plugin-audit mounts the same paths on the port — but this boot composes no + // AuditPlugin, so nothing answers them here. 'DELETE /api/v1/comments/reactions/:id': 'self-hosted, plugin-audit mounts the comment doors on the kernel\'s http.server, and this boot composes no AuditPlugin, so nothing mounts the path; the dispatcher domain this row ledgers serves only a kernel with no http.server and mounts no route here. Both doors are driven, on the real plugin, by packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts', 'PUT /api/v1/comments/:id/resolution': 'self-hosted, plugin-audit mounts the comment doors on the kernel\'s http.server, and this boot composes no AuditPlugin, so nothing mounts the path; the dispatcher domain this row ledgers serves only a kernel with no http.server and mounts no route here. Both doors are driven, on the real plugin, by packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts', 'DELETE /api/v1/comments/:id': 'self-hosted, plugin-audit mounts the comment doors on the kernel\'s http.server, and this boot composes no AuditPlugin, so nothing mounts the path; the dispatcher domain this row ledgers serves only a kernel with no http.server and mounts no route here. Both doors are driven, on the real plugin, by packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts', + 'POST /api/v1/comments/threads/query': + 'self-hosted, plugin-audit mounts the comment threads read beside the comment doors on the kernel\'s http.server, and this boot composes no AuditPlugin, so nothing mounts the path; the dispatcher domain this row ledgers serves only a kernel with no http.server and mounts no route here. Both doors are driven, on the real plugin, by packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts', // [#22773] Two doors, one path, a third time. This row ledgers the inbound // hook as the DISPATCHER's `/automation` domain serves it, the door for a // kernel with NO raw app. Self-hosted, `@objectstack/trigger-api`'s diff --git a/packages/runtime/src/domains/comments.ts b/packages/runtime/src/domains/comments.ts index f75873f3b45..323bf300c0e 100644 --- a/packages/runtime/src/domains/comments.ts +++ b/packages/runtime/src/domains/comments.ts @@ -1,7 +1,8 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. /** - * `/comments` domain — the three comment doors, reached through the dispatcher + * `/comments` domain — the three comment doors and the comment threads read, + * reached through the dispatcher * (ADR-0076 D11 step ③'s shape: the dispatcher owns registration, and one * route bridges to one service slot; `/webhooks/redeliver` is the precedent * this mirrors). @@ -28,18 +29,27 @@ * member's `Response` as it is. The self-hosted mount is untouched and is not * a caller. * - * ## Exactly three shapes are claimed + * [#39134] The comment threads read, `POST /comments/threads/query` (the + * threads on the records a list filter selects, read as the caller: the list + * page's comment panel), is the fourth shape. plugin-audit mounts it beside + * the doors on a self-hosted kernel, and the same member serves it here, so a + * hosted kernel answers it with the same caller rule, strict body and + * refusals. Before, this domain did not claim it and a hosted kernel answered + * the dispatcher's miss. * - * The registry claims `/comments` and everything under it for `PUT` and - * `DELETE`; the handler then claims only the three method and path shapes - * ({@link matchCommentDoorPath}) and answers every other one with the + * ## Exactly four shapes are claimed + * + * The registry claims `/comments` and everything under it for `PUT`, + * `DELETE` and `POST`; the handler then claims only the four method and path + * shapes ({@link matchCommentDoorPath}) and answers every other one with the * dispatcher's ordinary miss (`404 ROUTE_NOT_FOUND`), exactly what it answered - * before this domain existed; the member never runs for one. `GET`, `POST` - * and `PATCH` are never claimed. + * before this domain existed; the member never runs for one. `GET` and + * `PATCH` are never claimed. * * ## The request is forwarded, never read * - * The resolution door reads `{ "resolved": boolean }` from the JSON body. This + * The resolution door reads `{ "resolved": boolean }` from the JSON body, and + * the threads read its query body (and refuses any query parameter). This * domain reads neither the body nor the parsed `body` the transport hands * `dispatch()`: the member owns the read, and the request it receives is the * transport's own (`context.request`). A body the transport had already @@ -82,13 +92,17 @@ import { catalogNotImplemented, readDoorSlot } from './own-door-bridge.js'; export const COMMENTS_DOMAIN_PREFIX = '/comments'; /** The methods the registry claims for the prefix; the handler narrows further. */ -export const COMMENTS_DOMAIN_METHODS = ['PUT', 'DELETE'] as const; +export const COMMENTS_DOMAIN_METHODS = ['PUT', 'DELETE', 'POST'] as const; -/** The three door shapes, as dispatcher paths (API prefix stripped), in the mount's order. */ +/** + * The four shapes (the three doors, then the comment threads read), as + * dispatcher paths (API prefix stripped), in the mount's order. + */ export const COMMENT_DOOR_PATHS = [ { method: 'DELETE', pattern: '/comments/reactions/:id' }, { method: 'PUT', pattern: '/comments/:id/resolution' }, { method: 'DELETE', pattern: '/comments/:id' }, + { method: 'POST', pattern: '/comments/threads/query' }, ] as const; /** The wire prefix the doors are mounted under by plugin-audit (its routes are fixed at `/api/v1`). */ @@ -98,7 +112,7 @@ const DOOR_WIRE_PREFIX = '/api/v1'; const COMMENTS_SLOT = 'comments'; /** - * Is `method path` one of the three comment doors? `path` is the dispatcher's + * Is `method path` one of the four comment shapes? `path` is the dispatcher's * clean path; each `:id` matches one non-empty segment. */ export function matchCommentDoorPath(method: string, path: string): boolean { @@ -152,7 +166,7 @@ export async function handleCommentsRequest( req: DomainRequest, context: HttpProtocolContext, ): Promise { - // Not one of the three doors: the dispatcher's ordinary miss, the answer + // Not one of the four shapes: the dispatcher's ordinary miss, the answer // the path got before this domain existed. if (!matchCommentDoorPath(req.method, req.path)) return { handled: true, response: deps.routeNotFound(req.path) }; diff --git a/packages/runtime/src/route-ledger.ts b/packages/runtime/src/route-ledger.ts index 4d0a072a8e6..eefca2c0eda 100644 --- a/packages/runtime/src/route-ledger.ts +++ b/packages/runtime/src/route-ledger.ts @@ -737,6 +737,8 @@ export const ROUTE_LEDGER: readonly RouteLedgerEntry[] = [ note: 'the resolution door: whoever can read a thread (and may post on it) resolves or reopens it, body exactly { resolved: boolean }. Same forwarding, credential, absence and door notes as the unreact row' }, { route: 'DELETE /comments/:id', domain: '/comments', disposition: 'server-only', note: 'the own-comment delete door: a member removes a comment they wrote, with no object delete grant. Same forwarding, credential, absence and door notes as the unreact row' }, + { route: 'POST /comments/threads/query', domain: '/comments', disposition: 'sdk', client: 'comments.queryThreads', + note: 'the comment threads read (#39134): the threads on the records a list filter selects, read as the caller, the list page\'s comment panel\'s one request. Same forwarding, credential, absence and door notes as the unreact row: the member runs the very registration the self-hosted mount runs, so the strict body, the refusal of any query parameter and every refusal (400 VALIDATION_ERROR, 401, 403, PERMISSION_DENIED, FEEDS_DISABLED, INVALID_FILTER) are the mount\'s. The SDK method is the one the mount\'s own ledger row names (plugin-audit comment-route-ledger.ts): one URL, two deployment shapes. Pinned in `domains/comments.test.ts`' }, // ── personal-view and attachment doors (the hosted doors) ──────────────── { route: 'DELETE /personal-views/:id', domain: '/personal-views', disposition: 'server-only', diff --git a/packages/spec/src/contracts/comment-doors-service.ts b/packages/spec/src/contracts/comment-doors-service.ts index f254f231ed5..e8f0331788b 100644 --- a/packages/spec/src/contracts/comment-doors-service.ts +++ b/packages/spec/src/contracts/comment-doors-service.ts @@ -16,6 +16,11 @@ * can read; * - `DELETE /api/v1/comments/:id` — remove a comment you wrote. * + * The same slot also serves the comment threads read, + * `POST /api/v1/comments/threads/query` (the threads on the records a list + * filter selects, read as the caller), which the plugin mounts beside the + * doors. + * * A self-hosted kernel serves them from the plugin's own mount on the * kernel's `http.server`. A hosted tenant kernel owns no socket and so has no * `http.server`, and the runtime dispatcher reaches it instead (#36469; the @@ -34,10 +39,10 @@ */ export interface ICommentDoorsService { /** - * **The three comment doors, served transport-neutrally.** One member for - * the three routes, because they are one family with one caller rule: the - * member matches the request's method and path against the three routes - * and runs the door that owns it. + * **The three comment doors and the comment threads read, served + * transport-neutrally.** One member for the four routes, because they are + * one family with one caller rule: the member matches the request's method + * and path against the four routes and runs the one that owns it. * * What it serves, exactly as the plugin's self-hosted mount serves it (one * body, two faces): @@ -48,8 +53,11 @@ export interface ICommentDoorsService { * - Every refusal and answer is the door's own, in the * `{ success, data | error: { code, message } }` envelope: the unreact * door and the own-comment delete door answer `{ id, deleted: true }`, - * the resolution door `{ id, is_resolved, resolved_by, resolved_at }`. - * - A request whose method and path match none of the three routes answers + * the resolution door `{ id, is_resolved, resolved_by, resolved_at }`, + * the threads read `CommentThreadsQueryResponse` + * (`@objectstack/spec/api`), its body refused as strictly as the mount + * refuses it. + * - A request whose method and path match none of the four routes answers * `404 ENDPOINT_NOT_FOUND`; the dispatcher never forwards one. * * **Transport-neutral, deliberately.** A web-standard `Request` goes in and @@ -62,7 +70,7 @@ export interface ICommentDoorsService { * place. * * **Its one caller** is the runtime `HttpDispatcher`'s `/comments` domain, - * which claims exactly the three method and path shapes and forwards the + * which claims exactly the four method and path shapes and forwards the * request with its body unread. The paths are not on the ADR-0069 * auth-gate allow-list and the project-membership gate does not skip them, * so on that shape the dispatcher door is stricter than the self-hosted @@ -77,7 +85,8 @@ export interface ICommentDoorsService { * * @param request - The forwarded request: the caller's credentials are in * its headers, the comment or reaction id in its path, and the - * resolution door's `{ "resolved": boolean }` in its JSON body + * resolution door's `{ "resolved": boolean }` or the threads read's query + * in its JSON body * @returns The door's JSON answer */ handleCommentDoor?(request: Request): Promise; From 94743ff176b9b7fa83ad2596f4ae410bda2f5eeb Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 20:12:07 +0000 Subject: [PATCH 2/8] test: pin the comment threads read on the hosted and serve-shaped hosts Claude-Session: https://claude.ai/code/session_01WGufzeqywuHW6vj4DU7Rgp Co-authored-by: Claude --- .../hono-comment-doors.conformance.test.ts | 134 ++++++++++++++++++ packages/runtime/src/domains/comments.test.ts | 76 +++++++++- 2 files changed, 205 insertions(+), 5 deletions(-) diff --git a/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts b/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts index 4f17402a211..4efa47b14a0 100644 --- a/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts +++ b/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts @@ -30,6 +30,18 @@ * byte for byte the card's hosted reading (cloud's local rig runs * `apps/objectos` under `objectstack dev`). * + * [#39134] The comment threads read (`POST /api/v1/comments/threads/query`, + * the list page's comment panel) rides the same member and the same domain: + * 5. on the hosted shape it answers the threads the self-hosted mount answers + * for the same caller and body, and every refusal — 400 (strict body, any + * query parameter, a cursor or filter it did not issue, `sys_comment`), + * 401 (anonymous), 403 (`FEEDS_DISABLED`), 404 (`OBJECT_NOT_FOUND`) and + * the object read's own `PERMISSION_DENIED` — with the mount's bytes; + * 6. a hosted kernel without plugin-audit answers it the typed 501; + * 7. the `objectstack serve`-shaped host answers it too, with the same bytes. + * Before, each answered the dispatcher's `404 ROUTE_NOT_FOUND` on the hosted + * shape, or the transport's `404 ENDPOINT_NOT_FOUND` on the serve shape. + * * The domain's own claim, gates and faults are pinned on the real dispatcher * in `packages/runtime/src/domains/comments.test.ts`. */ @@ -53,6 +65,10 @@ const BOARD = 'cdh_board'; /** The header the test auth service reads the signed-in user from. */ const SIGNED_IN_AS = 'x-test-signed-in-as'; const ALICE = 'usr_alice'; +/** [#39134] A member whose read of the board the board's own read refuses. */ +const BOB = 'usr_bob'; +/** [#39134] An object whose comments are switched off. */ +const QUIET = 'cdh_quiet'; const SYSTEM = { isSystem: true } as const; /** @@ -85,6 +101,7 @@ const identityObjects = [ ] as const; const board = { name: BOARD, label: 'Board', fields: { name: { name: 'name', label: 'Name', type: 'text' as const } } }; +const quiet = { name: QUIET, label: 'Quiet', enable: { feeds: false }, fields: { name: { name: 'name', label: 'Name', type: 'text' as const } } }; /** An auth service whose in-process session read names the user the request names. */ class TestAuth implements Plugin { @@ -136,12 +153,23 @@ async function bootKernel(opts: { selfHosted: boolean; audit?: boolean }) { liveDrivers.push(driver); (objectql as any).registerDriver(driver, true); objectql.registry.registerObject(board as any, 'comment-doors-test', 'comment-doors-test'); + objectql.registry.registerObject(quiet as any, 'comment-doors-test', 'comment-doors-test'); for (const o of identityObjects) objectql.registry.registerObject(o.def as never, o.owner); await (objectql as any).syncSchemas(); await installDefaultOrganization(objectql as any); // Alice is a current member of the organization her session names. await objectql.insert('sys_user', { id: ALICE, email: `${ALICE}@acme.test` }, { context: SYSTEM } as any); await objectql.insert('sys_member', { user_id: ALICE, organization_id: DEFAULT_ORGANIZATION_ID, role: 'member' }, { context: SYSTEM } as any); + // [#39134] Bob is a member too, but the board's read refuses him, as a + // permission set without read on the object would: the threads read must + // answer that refusal, never an empty page. + await objectql.insert('sys_user', { id: BOB, email: `${BOB}@acme.test` }, { context: SYSTEM } as any); + await objectql.insert('sys_member', { user_id: BOB, organization_id: DEFAULT_ORGANIZATION_ID, role: 'member' }, { context: SYSTEM } as any); + (objectql as any).registerHook('beforeFind', (hook: any) => { + const userId = hook.session?.userId ?? hook.context?.userId; + if (userId !== BOB) return; + throw Object.assign(new Error(`Permission denied: you cannot read '${BOARD}'`), { code: 'PERMISSION_DENIED', status: 403 }); + }, { object: BOARD }); /** A thread on a board, with one top-level comment Alice wrote and one reaction of hers on it. */ const seed = async () => { @@ -385,3 +413,109 @@ describe('[#36469] the comment doors answer on an `objectstack serve`-shaped mul } }); }); + +// ── [#39134] the comment threads read ─────────────────────────────────────── + +const THREADS = `${PREFIX}/comments/threads/query`; +const post = (userId: string | undefined, body: unknown) => as(userId, { method: 'POST', body: typeof body === 'string' ? body : JSON.stringify(body) }); + +/** The threads of an answer, without the stored ids and instants two kernels cannot share. */ +function threadsOf(json: any) { + return (json?.data?.threads ?? []).map((t: any) => ({ + body: t.comment?.body, + author: t.comment?.author_id, + record: t.record?.name, + replyCount: t.replyCount, + repliers: (t.repliers ?? []).map((r: any) => r.id ?? r.author_id ?? r), + })); +} + +/** The requests whose refusal is the same on every kernel shape, byte for byte. */ +const THREADS_REFUSALS: Array<[label: string, path: string, init: RequestInit]> = [ + ['anonymous', THREADS, post(undefined, { object: BOARD })], + ['a body that is not JSON', THREADS, post(ALICE, '{object:')], + ['an unknown key in the body', THREADS, post(ALICE, { object: BOARD, view: 'all' })], + ['a limit out of range', THREADS, post(ALICE, { object: BOARD, limit: 0 })], + ['any query parameter', `${THREADS}?limit=5`, post(ALICE, { object: BOARD })], + ['a cursor this read never issued', THREADS, post(ALICE, { object: BOARD, cursor: 'not-a-cursor' })], + ['a filter the list read cannot lower', THREADS, post(ALICE, { object: BOARD, filter: ['name', 'is like', 'x', 'y'] })], + ['the comment object itself', THREADS, post(ALICE, { object: COMMENT })], + ['an object nobody registered', THREADS, post(ALICE, { object: 'cdh_nowhere' })], + ['an object whose comments are off', THREADS, post(ALICE, { object: QUIET })], + ['a member whose read of the object is refused', THREADS, post(BOB, { object: BOARD })], +]; + +describe('[#39134] the comment threads read answers on the hosted shape (createHonoApp, no http.server, real AuditPlugin)', () => { + it('a member reads the threads on the records the filter selects: 200, the same threads the self-hosted mount answers', async () => { + const hosted = await hostedDoor(); + const selfHosted = await selfHostedDoor(); + await hosted.seed(); + await selfHosted.seed(); + + const viaHosted = await hosted.send(THREADS, post(ALICE, { object: BOARD, filter: [['name', '=', 'board']] })); + const viaMount = await selfHosted.send(THREADS, post(ALICE, { object: BOARD, filter: [['name', '=', 'board']] })); + + const hostedJson = await viaHosted.clone().json() as any; + expect(viaHosted.status, JSON.stringify(hostedJson)).toBe(200); + expect(viaMount.status, await viaMount.clone().text()).toBe(200); + expect(threadsOf(hostedJson)).toEqual([{ body: 'hello', author: ALICE, record: 'board', replyCount: 0, repliers: [] }]); + expect(threadsOf(hostedJson)).toEqual(threadsOf(await viaMount.json())); + expect(hostedJson.data.nextCursor ?? null).toBeNull(); + }); + + it('every refusal is byte-identical at the mount and at the hosted door', async () => { + const hosted = await hostedDoor(); + const selfHosted = await selfHostedDoor(); + const seen = new Set(); + for (const [label, path, init] of THREADS_REFUSALS) { + const viaHosted = await snapshot(await hosted.send(path, init)); + const viaMount = await snapshot(await selfHosted.send(path, init)); + expect(viaHosted.body, label).not.toContain('ROUTE_NOT_FOUND'); + expect(viaHosted.body, label).not.toContain('ENDPOINT_NOT_FOUND'); + expect(viaHosted, label).toEqual(viaMount); + seen.add(`${viaHosted.status} ${JSON.parse(viaHosted.body)?.error?.code}`); + } + // The refusals the card names, each reached at least once. + expect([...seen].sort()).toEqual(expect.arrayContaining([ + '400 VALIDATION_ERROR', + '400 INVALID_FILTER', + '401 UNAUTHORIZED', + '403 FEEDS_DISABLED', + '403 PERMISSION_DENIED', + '404 OBJECT_NOT_FOUND', + ])); + }); + + it('a hosted kernel without plugin-audit: 501 NOT_IMPLEMENTED naming the plugin, never a route miss', async () => { + const door = await hostedDoor({ audit: false }); + const res = await door.send(THREADS, post(ALICE, { object: BOARD })); + const body = await res.json() as any; + expect(res.status, JSON.stringify(body)).toBe(501); + expect(body.error.code).toBe('NOT_IMPLEMENTED'); + expect(body.error.message).toContain('@objectstack/plugin-audit'); + }); +}); + +describe('[#39134] the comment threads read answers on an `objectstack serve`-shaped multi-tenant host (no catch-all)', () => { + it('a member reads the threads: 200, the seeded thread', async () => { + const door = await serveShapedHost(); + await door.seed(); + + const res = await door.send(THREADS, post(ALICE, { object: BOARD })); + + const json = await res.clone().json() as any; + expect(res.status, JSON.stringify(json)).toBe(200); + expect(threadsOf(json)).toEqual([{ body: 'hello', author: ALICE, record: 'board', replyCount: 0, repliers: [] }]); + }); + + it('every refusal is byte-identical to the self-hosted mount', async () => { + const host = await serveShapedHost(); + const selfHosted = await selfHostedDoor(); + for (const [label, path, init] of THREADS_REFUSALS) { + const viaHost = await snapshot(await host.send(path, init)); + const viaMount = await snapshot(await selfHosted.send(path, init)); + expect(viaHost.body, label).not.toContain('ENDPOINT_NOT_FOUND'); + expect(viaHost, label).toEqual(viaMount); + } + }); +}); diff --git a/packages/runtime/src/domains/comments.test.ts b/packages/runtime/src/domains/comments.test.ts index e15233a1e6d..189232137cf 100644 --- a/packages/runtime/src/domains/comments.test.ts +++ b/packages/runtime/src/domains/comments.test.ts @@ -3,16 +3,18 @@ /** * [#36469] The `/comments` dispatcher domain — the three comment doors for a * kernel with no `http.server` (ruling A on #22438, applied to this member of - * the class). + * the class), and [#39134] the comment threads read beside them. * * Driven through the REAL `HttpDispatcher.dispatch()` on a kernel that * registers no `http.server` (the hosted shape), with a stub `comments` * member that reads the request it is handed (method, path, JSON body). * * What this pins: - * 1. each of the three shapes reaches the member with the transport's own + * 1. each of the four shapes reaches the member with the transport's own * request, body unread, and the member's `Response` comes back as it is; - * 2. the claim is the three method and path shapes alone: every other method + * the threads read's query string reaches it too, so the read's own + * refusal of any query parameter is the one that answers; + * 2. the claim is the four method and path shapes alone: every other method * and every other path under `/comments` keeps the dispatcher's ordinary * miss, and the member never runs for one; * 3. an absent `comments` slot, or a slot with no `handleCommentDoor`, @@ -88,9 +90,11 @@ const DOORS: Array<[method: string, path: string, body?: unknown]> = [ ['DELETE', '/comments/reactions/rx_1'], ['PUT', '/comments/c_1/resolution', { resolved: true }], ['DELETE', '/comments/c_1'], + // [#39134] The comment threads read. + ['POST', '/comments/threads/query', { object: 'account', onlyMine: true }], ]; -describe('[#36469] /comments forwards the three comment doors to the comments member on a kernel with no http.server', () => { +describe('[#36469] /comments forwards the three comment doors and the threads read to the comments member on a kernel with no http.server', () => { it.each(DOORS)('%s %s reaches the member with the transport\'s own request, body unread, and its Response comes back as it is', async (method, path, body) => { const member = stubMember(); const { dispatcher } = makeDispatcher({ comments: { handleCommentDoor: member.handleCommentDoor } }); @@ -111,7 +115,7 @@ describe('[#36469] /comments forwards the three comment doors to the comments me }); }); - it('claims exactly the three shapes: every other method and path keeps the ordinary miss, and the member never runs', async () => { + it('claims exactly the four shapes: every other method and path keeps the ordinary miss, and the member never runs', async () => { const member = stubMember(); const { dispatcher } = makeDispatcher({ comments: { handleCommentDoor: member.handleCommentDoor } }); const misses: Array<[string, string]> = [ @@ -126,6 +130,17 @@ describe('[#36469] /comments forwards the three comment doors to the comments me ['DELETE', '/comments/'], ['DELETE', '/comments/reactions/rx_1/x'], ['DELETE', '/comments/c_1/resolution/x'], + // [#39134] The threads read is exactly one method on one path. + ['GET', '/comments/threads/query'], + ['PUT', '/comments/threads/query'], + ['PATCH', '/comments/threads/query'], + ['DELETE', '/comments/threads/query'], + ['POST', '/comments/threads'], + ['POST', '/comments/threads/query/x'], + ['POST', '/comments/threads/c_1'], + ['POST', '/comments/reactions/rx_1'], + ['POST', '/comments/c_1/resolution'], + ['POST', '/comments'], ]; for (const [method, path] of misses) { const result = await dispatcher.dispatch(method, path, undefined, {}, ctx(wire(method, path))); @@ -149,6 +164,31 @@ describe('[#36469] /comments forwards the three comment doors to the comments me expect(member.seen[0]!.path).toBe('/api/v1/comments/c_9/resolution'); expect(member.seen[0]!.body).toBe('{"resolved":false}'); }); + + // [#39134] The read refuses any query parameter itself (400 + // VALIDATION_ERROR before the engine is asked), so the domain must hand it + // on, never drop it: a dropped `?limit=` would answer 200 where the mount + // answers 400. + it('the threads read reaches the member with its query string, on both spellings', async () => { + for (const path of ['/comments/threads/query', '/environments/env_1/comments/threads/query']) { + const member = stubMember(); + const { dispatcher } = makeDispatcher({ comments: { handleCommentDoor: member.handleCommentDoor } }); + const request = new Request(`${ORIGIN}/api/v1${path}?limit=5`, { + method: 'POST', + headers: JSON_HEADERS, + body: JSON.stringify({ object: 'account' }), + }); + + const result = await dispatcher.dispatch('POST', path, { object: 'account' }, { limit: '5' }, ctx(request)); + + expect(result.response, `${path} ${JSON.stringify(result.response?.body)}`).toBeUndefined(); + expect(member.seen, path).toHaveLength(1); + const seen = new URL(member.seen[0]!.request.url); + expect(seen.pathname, path).toBe('/api/v1/comments/threads/query'); + expect(seen.search, path).toBe('?limit=5'); + expect(member.seen[0]!.body, path).toBe('{"object":"account"}'); + } + }); }); describe('[#36469] absence is a typed 501, never a route miss', () => { @@ -208,6 +248,19 @@ describe('[#36469] faults are the server\'s, answered as such', () => { expect(member.handleCommentDoor).not.toHaveBeenCalled(); expect(String(logger.error.mock.calls[0]![0])).toContain('request body was consumed'); }); + + it('[#39134] a threads read whose body the transport already consumed: 500 and logged, and the member is never asked', async () => { + const member = stubMember(); + const { dispatcher, logger } = makeDispatcher({ comments: { handleCommentDoor: member.handleCommentDoor } }); + const request = wire('POST', '/comments/threads/query', { object: 'account' }); + await request.text(); + + const result = await dispatcher.dispatch('POST', '/comments/threads/query', {}, {}, ctx(request)); + + expect(envelope(result)).toEqual({ status: 500, code: 'INTERNAL_ERROR' }); + expect(member.handleCommentDoor).not.toHaveBeenCalled(); + expect(String(logger.error.mock.calls[0]![0])).toContain('request body was consumed'); + }); }); describe('[#36469] no preamble-gate exemption — the credential is the session, so both gates apply', () => { @@ -257,6 +310,19 @@ describe('[#36469] no preamble-gate exemption — the credential is the session, expect(comments.handleCommentDoor).not.toHaveBeenCalled(); }); + it('[#39134] the threads read too: a non-member is refused 403 before the member runs, a member reaches it', async () => { + const body = { object: 'account' }; + const outsider = makeTenantHost(); + const refused = await outsider.dispatcher.dispatch('POST', '/comments/threads/query', body, {}, ctx(wire('POST', '/comments/threads/query', body))); + expect(envelope(refused)).toEqual({ status: 403, code: 'PROJECT_MEMBERSHIP_REQUIRED' }); + expect(outsider.comments.handleCommentDoor).not.toHaveBeenCalled(); + + const insider = makeTenantHost({ member: true }); + const reached = await insider.dispatcher.dispatch('POST', '/comments/threads/query', body, {}, ctx(wire('POST', '/comments/threads/query', body))); + expect(reached.response, JSON.stringify(reached.response?.body)).toBeUndefined(); + expect(insider.comments.handleCommentDoor).toHaveBeenCalledTimes(1); + }); + it('⭐ control: a member of the environment reaches the member', async () => { const { dispatcher, comments } = makeTenantHost({ member: true }); const result = await dispatcher.dispatch('DELETE', '/comments/c_1', {}, {}, ctx(wire('DELETE', '/comments/c_1'))); From 3cdc2b8483e76c41631aaf83bce4694dae2256d9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 20:17:00 +0000 Subject: [PATCH 3/8] test: the threads read's refusal codes as the door spells them Claude-Session: https://claude.ai/code/session_01WGufzeqywuHW6vj4DU7Rgp Co-authored-by: Claude --- .../src/hono-comment-doors.conformance.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts b/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts index 4efa47b14a0..ba7ec3bac67 100644 --- a/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts +++ b/packages/qa/http-conformance/src/hono-comment-doors.conformance.test.ts @@ -477,9 +477,10 @@ describe('[#39134] the comment threads read answers on the hosted shape (createH } // The refusals the card names, each reached at least once. expect([...seen].sort()).toEqual(expect.arrayContaining([ + '400 INVALID_REQUEST', '400 VALIDATION_ERROR', '400 INVALID_FILTER', - '401 UNAUTHORIZED', + '401 UNAUTHENTICATED', '403 FEEDS_DISABLED', '403 PERMISSION_DENIED', '404 OBJECT_NOT_FOUND', From 4303c56107ed2115745ad33dbab28cf0ae817e3e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 20:18:59 +0000 Subject: [PATCH 4/8] chore: changeset for the hosted comment threads read Claude-Session: https://claude.ai/code/session_01WGufzeqywuHW6vj4DU7Rgp Co-authored-by: Claude --- .../39134-hosted-comment-threads-read.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .changeset/39134-hosted-comment-threads-read.md diff --git a/.changeset/39134-hosted-comment-threads-read.md b/.changeset/39134-hosted-comment-threads-read.md new file mode 100644 index 00000000000..22aaf6764ae --- /dev/null +++ b/.changeset/39134-hosted-comment-threads-read.md @@ -0,0 +1,19 @@ +--- +'@objectstack/runtime': patch +'@objectstack/plugin-audit': patch +'@objectstack/spec': patch +--- + +feat(runtime, plugin-audit): a hosted kernel serves the comment threads read + +Clause-②: yes (widening) +Metadata-protocol: none + +`POST /api/v1/comments/threads/query`, the read behind the list page's comment panel, now answers on a kernel with no HTTP server of its own (a hosted tenant kernel), as it already did on a self-hosted one: + +- the dispatcher's `/comments` domain claims it beside the three comment doors and forwards the request, body and query string unread, to the `comments` service; +- the service runs the same registration the self-hosted mount runs, so the caller, the strict body, the refusal of any query parameter and every refusal (`400`, `401`, `403`, `404`, `PERMISSION_DENIED`) are the same bytes on both shapes; +- the same holds on a host composed as `objectstack serve` / `objectstack dev` composes one, through the dispatcher plugin's fallback; +- a hosted kernel without `@objectstack/plugin-audit` answers `501 NOT_IMPLEMENTED`, never a route miss. + +Before, a hosted kernel answered the read `404 ROUTE_NOT_FOUND` and its boot log said the read was not served there; that line is gone. `client.comments.queryThreads` is unchanged and now reaches both shapes. From 498dd24da446c7c2c17757d47370ae23b8ddc6dd Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 20:49:08 +0000 Subject: [PATCH 5/8] chore(runtime): the route ledger census counts the threads read row; ledger note carries no tracker id Claude-Session: https://claude.ai/code/session_01WGufzeqywuHW6vj4DU7Rgp Co-authored-by: Claude --- packages/runtime/src/route-ledger.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/runtime/src/route-ledger.ts b/packages/runtime/src/route-ledger.ts index eefca2c0eda..0a9b11315b3 100644 --- a/packages/runtime/src/route-ledger.ts +++ b/packages/runtime/src/route-ledger.ts @@ -301,7 +301,7 @@ export const NON_DISPATCH_MOUNT_PREFIXES = [ /** * The ledger. * - * CENSUS (generated): this list holds 157 rows. + * CENSUS (generated): this list holds 158 rows. * * ⛔ THAT NUMBER IS WRITTEN BY A TOOL — never by hand. * `pnpm check:route-ledger-census` counts the rows below and fails when the two @@ -737,8 +737,9 @@ export const ROUTE_LEDGER: readonly RouteLedgerEntry[] = [ note: 'the resolution door: whoever can read a thread (and may post on it) resolves or reopens it, body exactly { resolved: boolean }. Same forwarding, credential, absence and door notes as the unreact row' }, { route: 'DELETE /comments/:id', domain: '/comments', disposition: 'server-only', note: 'the own-comment delete door: a member removes a comment they wrote, with no object delete grant. Same forwarding, credential, absence and door notes as the unreact row' }, + // [#39134] The comment threads read, on the hosted door too. { route: 'POST /comments/threads/query', domain: '/comments', disposition: 'sdk', client: 'comments.queryThreads', - note: 'the comment threads read (#39134): the threads on the records a list filter selects, read as the caller, the list page\'s comment panel\'s one request. Same forwarding, credential, absence and door notes as the unreact row: the member runs the very registration the self-hosted mount runs, so the strict body, the refusal of any query parameter and every refusal (400 VALIDATION_ERROR, 401, 403, PERMISSION_DENIED, FEEDS_DISABLED, INVALID_FILTER) are the mount\'s. The SDK method is the one the mount\'s own ledger row names (plugin-audit comment-route-ledger.ts): one URL, two deployment shapes. Pinned in `domains/comments.test.ts`' }, + note: 'the comment threads read: the threads on the records a list filter selects, read as the caller, the list page\'s comment panel\'s one request. Same forwarding, credential, absence and door notes as the unreact row: the member runs the very registration the self-hosted mount runs, so the strict body, the refusal of any query parameter and every refusal (400 VALIDATION_ERROR, 401, 403, PERMISSION_DENIED, FEEDS_DISABLED, INVALID_FILTER) are the mount\'s. The SDK method is the one the mount\'s own ledger row names (plugin-audit comment-route-ledger.ts): one URL, two deployment shapes. Pinned in `domains/comments.test.ts`' }, // ── personal-view and attachment doors (the hosted doors) ──────────────── { route: 'DELETE /personal-views/:id', domain: '/personal-views', disposition: 'server-only', From c88729f4e778995e875255de746c758f31dd6bb9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 22:13:22 +0000 Subject: [PATCH 6/8] docs(runtime, plugin-audit, client): name both shapes the comment threads read is served on, and the hosted shape's stricter gates The client JSDoc, the changeset and data-api.mdx said or implied one shape or identical refusals on both; the hosted dispatcher's preamble gates refuse a non-member of the environment and answer a held sign-in before the read runs. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK --- .../39134-hosted-comment-threads-read.md | 6 ++++-- content/docs/api/data-api.mdx | 16 +++++++++++++--- packages/client/src/index.ts | 8 ++++++-- .../plugin-audit/src/comment-threads-query.ts | 18 ++++++++++++------ packages/runtime/src/http-dispatcher.ts | 9 +++++---- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.changeset/39134-hosted-comment-threads-read.md b/.changeset/39134-hosted-comment-threads-read.md index 22aaf6764ae..402c7063fcc 100644 --- a/.changeset/39134-hosted-comment-threads-read.md +++ b/.changeset/39134-hosted-comment-threads-read.md @@ -2,6 +2,7 @@ '@objectstack/runtime': patch '@objectstack/plugin-audit': patch '@objectstack/spec': patch +'@objectstack/client': patch --- feat(runtime, plugin-audit): a hosted kernel serves the comment threads read @@ -12,8 +13,9 @@ Metadata-protocol: none `POST /api/v1/comments/threads/query`, the read behind the list page's comment panel, now answers on a kernel with no HTTP server of its own (a hosted tenant kernel), as it already did on a self-hosted one: - the dispatcher's `/comments` domain claims it beside the three comment doors and forwards the request, body and query string unread, to the `comments` service; -- the service runs the same registration the self-hosted mount runs, so the caller, the strict body, the refusal of any query parameter and every refusal (`400`, `401`, `403`, `404`, `PERMISSION_DENIED`) are the same bytes on both shapes; +- the service runs the same registration the self-hosted mount runs, so the caller, the strict body, the refusal of any query parameter and the read's own refusals (`400`, `401 UNAUTHENTICATED`, `403 FEEDS_DISABLED`, `403 PERMISSION_DENIED`, `404 OBJECT_NOT_FOUND`) are the same bytes on both shapes; +- on the hosted shape the dispatcher's two preamble gates run before the service: a signed-in caller who is not a member of the request's environment is refused `403 PROJECT_MEMBERSHIP_REQUIRED`, which the self-hosted mount does not answer, and a session that still owes a sign-in step is refused `403` with the authentication policy's own code by the dispatcher's gate instead of by the read. Stricter than the self-hosted mount, never looser; - the same holds on a host composed as `objectstack serve` / `objectstack dev` composes one, through the dispatcher plugin's fallback; - a hosted kernel without `@objectstack/plugin-audit` answers `501 NOT_IMPLEMENTED`, never a route miss. -Before, a hosted kernel answered the read `404 ROUTE_NOT_FOUND` and its boot log said the read was not served there; that line is gone. `client.comments.queryThreads` is unchanged and now reaches both shapes. +Before, a hosted kernel answered the read `404 ROUTE_NOT_FOUND` and its boot log said the read was not served there; that clause is gone. `client.comments.queryThreads` is unchanged and now reaches both shapes; its JSDoc names both. diff --git a/content/docs/api/data-api.mdx b/content/docs/api/data-api.mdx index 9e78bb0814e..cd881485e1f 100644 --- a/content/docs/api/data-api.mdx +++ b/content/docs/api/data-api.mdx @@ -687,8 +687,11 @@ the approvals-family read and is unchanged. The discussions on the records a list shows, in one read: what a list page's comment panel asks. Served by `@objectstack/plugin-audit`, on a self-hosted kernel from its own HTTP mount and on a hosted tenant kernel through the -dispatcher's `/comments` domain, with the same caller rule, body and refusals; -the SDK method is `client.comments.queryThreads`. +dispatcher's `/comments` domain. Both shapes run the same caller rule, body +and the read's own refusals; on the hosted shape the dispatcher's gates run +first and stop a held sign-in and a non-member of the environment before the +read runs (the last two refusals below). The SDK method is +`client.comments.queryThreads`. ### `POST /comments/threads/query` @@ -763,7 +766,14 @@ Refusals: cannot read: `403 PERMISSION_DENIED`, the object read's own refusal, never an empty answer; - an object on a driver that cannot run the subquery (MongoDB, OData): - `400 INVALID_FILTER`. + `400 INVALID_FILTER`; +- a session that still owes a sign-in step (a password that expired or must be + changed, a required multi-factor enrollment): `403` with the authentication + policy's own code. On a hosted tenant kernel the dispatcher's sign-in gate + answers it before the read runs; +- on a hosted tenant kernel only, before the read runs: a signed-in caller who + is not a member of the request's environment, `403 PROJECT_MEMBERSHIP_REQUIRED`; + a kernel composed without `@objectstack/plugin-audit`, `501 NOT_IMPLEMENTED`. --- diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index d7ec8b07b9d..27364b78ea8 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -7473,8 +7473,12 @@ export class ObjectStackClient { * [NOT_IMPLEMENTED] on deployments without the sharing service. */ /** - * Comment threads across records. Served by plugin-audit's comment - * registrar on a kernel with an HTTP server. + * Comment threads across records. Served by `@objectstack/plugin-audit` + * on both server shapes: on a self-hosted kernel from its own HTTP mount, + * and on a hosted tenant kernel (no HTTP server of its own) through the + * runtime dispatcher's `/comments` domain, which forwards the request to + * the same registration. A hosted kernel composed without plugin-audit + * answers `501 NOT_IMPLEMENTED`. */ comments = { /** diff --git a/packages/plugins/plugin-audit/src/comment-threads-query.ts b/packages/plugins/plugin-audit/src/comment-threads-query.ts index a863fb2c77d..ffc7d8d775f 100644 --- a/packages/plugins/plugin-audit/src/comment-threads-query.ts +++ b/packages/plugins/plugin-audit/src/comment-threads-query.ts @@ -141,13 +141,19 @@ import { COMMENT_RESOLVED_FIELD, isReplyRow } from './comment-resolution.js'; * of that millisecond read again ordered by `id`, so the page and the cursor * agree on which of them were answered, at any precision the column keeps. * - * ## What is not served here + * ## Where it is served * - * A kernel with no `http.server` (a hosted tenant kernel) reaches the other - * comment doors through the runtime dispatcher's `/comments` domain. That - * domain does not claim this route, so this read is served by the - * self-hosted mount only; `AuditPlugin` says so in its boot line on a kernel - * with no HTTP server. + * On a self-hosted kernel, from the kernel's `http.server` + * ({@link registerCommentThreadsQueryRoute}). A kernel with no `http.server` + * (a hosted tenant kernel) reaches it, as it reaches the other comment doors, + * through the runtime dispatcher's `/comments` domain, which forwards the + * request unread to the `comments` service. That service's member + * (`comment-doors-member.ts`) runs the mount's own registration, and + * `registerCommentDoorsRoutes` (`comment-routes.ts`) calls this one, so this + * handler answers on both shapes. On the hosted shape the dispatcher's two preamble gates run first: + * a signed-in caller who is not a member of the request's environment is + * refused `403 PROJECT_MEMBERSHIP_REQUIRED` there, and a held sign-in is + * refused by the dispatcher's gate before step 1 runs. */ /** The read's route. */ diff --git a/packages/runtime/src/http-dispatcher.ts b/packages/runtime/src/http-dispatcher.ts index 5d308c1621e..32763f5e2b2 100644 --- a/packages/runtime/src/http-dispatcher.ts +++ b/packages/runtime/src/http-dispatcher.ts @@ -1014,10 +1014,11 @@ export class HttpDispatcher { // `POST /webhooks/redeliver`, forwarded to the `webhooks` slot's // `handleRedeliver`, resolved per request. See `./domains/webhooks.ts`. this.domainRegistry.register(createWebhooksRedeliverDomain(this.domainDeps)); - // The three comment doors for a kernel with no `http.server` (#36469; - // ruling A on #22438): exactly their three method and path shapes, - // forwarded to the `comments` slot's `handleCommentDoor`, resolved per - // request. See `./domains/comments.ts`. + // The three comment doors and the comment threads read for a kernel + // with no `http.server` (#36469, #39134; ruling A on #22438): exactly + // their four method and path shapes, forwarded to the `comments` + // slot's `handleCommentDoor`, resolved per request. See + // `./domains/comments.ts`. this.domainRegistry.register(createCommentsDomain(this.domainDeps)); // The personal-view delete door and the attachment removal and rename // doors for a kernel with no `http.server` (#36506; ruling A on From 51929dc7b815c7ac1b2dfcbae192df8a25ef2ae0 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 22:14:16 +0000 Subject: [PATCH 7/8] test(dogfood): the comment-doors-session row names the comment threads read and its enforcement site The /comments domain claims a fourth shape, an object-data read through a sibling HTTP entry point. The row now names it, its enforcement site and the proofs that exist, and the comment records that its HIGH_RISK classification is an open decision rather than reusing the doors' write-only reason. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK --- .../dogfood/test/authz-conformance.matrix.ts | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/qa/dogfood/test/authz-conformance.matrix.ts b/packages/qa/dogfood/test/authz-conformance.matrix.ts index 86574bb4bde..920d633b71d 100644 --- a/packages/qa/dogfood/test/authz-conformance.matrix.ts +++ b/packages/qa/dogfood/test/authz-conformance.matrix.ts @@ -429,15 +429,31 @@ export const AUTHZ_CONFORMANCE: AuthzPrimitive[] = [ // credentials, and the dispatcher's two preamble gates apply unexempted. // ⛔ Ids stay in this comment, out of the row's strings. // - // Not HIGH_RISK: each door writes one row the caller owns or may resolve, - // after reading it AS THE CALLER (object grant, organization wall, the - // comment read gate), so it is no sibling read path around a data gate. Its - // proofs are the plugin-audit and plugin-security door suites and the - // two-door wire suite, none of which lives in this directory. - { id: 'comment-doors-session', summary: 'Comment doors (`DELETE /comments/reactions/:id`, `PUT /comments/:id/resolution`, `DELETE /comments/:id`) — a signed-in member removes their own reaction, resolves or reopens a thread they can read and may post on, and removes a comment they wrote with no reply under it; a row the caller cannot read answers as unknown, another member\'s row is refused 403, and an anonymous caller is refused 401 by the door itself, exactly as the self-hosted mount refuses it', state: 'enforced', - enforcement: 'core/security/own-row-delete-routes.ts (the unreact and own-comment delete doors) and plugin-audit/comment-routes.ts (the resolution door) — the caller resolved from the request\'s own credentials (ownRowDeleteCallerResolver: no signed-in user 401, a held sign-in 403), the row read AS THE CALLER (object grant, organization wall, comment read gate; unreadable = unknown 404), the owner column checked (403 PERMISSION_DENIED) or the posting gate asked (canWriteObject insert on sys_comment), then a system write attributed to the caller; reached through ICommentDoorsService.handleCommentDoor by runtime/domains/comments.ts, which claims exactly the three method and path shapes, forwards the transport\'s request UNREAD, resolves the slot per request and adds no credential of its own (an absent slot or member is a typed 501, never a route miss). The two dispatcher preamble gates apply with NO exemption: core/security/auth-gate.ts ALLOW_ROUTES does not list the paths and runtime/http-dispatcher.ts enforceProjectMembership does not skip them. The member runs the very registration the self-hosted mount runs (plugin-audit comment-doors-member.ts over registerCommentDoors in audit-plugin.ts)', + // #39134 — the domain also claims a fourth shape, the comment threads read + // (`POST /comments/threads/query`), forwarded to the same member. + // + // The three doors are not HIGH_RISK: each writes one row the caller owns or + // may resolve, after reading it AS THE CALLER (object grant, organization + // wall, the comment read gate), so it is no sibling read path around a data + // gate. Their proofs are the plugin-audit and plugin-security door suites + // and the two-door wire suite, none of which lives in this directory. + // + // ⚠️ That reason does not carry to the threads read. It answers object data + // (the comments on, and the ids and display names of, the records of any + // object a list filter selects) through a sibling HTTP entry point, which + // is the HIGH_RISK list's own definition. Every read in it runs as the + // caller (the object read planned by the engine under the caller's context, + // and an ordinary read of `sys_comment` under the comment read gate), so it + // adds no gate of its own, but that is equally true of the MCP surface the + // list does carry. Its end-to-end proof on the real SecurityPlugin is + // comment-threads-query.dogfood.test.ts, which drives the self-hosted mount + // only and claims no row. Whether the read is HIGH_RISK, as its own row or + // this one, is an open decision on #39134; until it is recorded, this row + // classifies the domain with the read named and NOT on the HIGH_RISK list. + { id: 'comment-doors-session', summary: 'Comment doors (`DELETE /comments/reactions/:id`, `PUT /comments/:id/resolution`, `DELETE /comments/:id`) and the comment threads read (`POST /comments/threads/query`) — a signed-in member removes their own reaction, resolves or reopens a thread they can read and may post on, and removes a comment they wrote with no reply under it; a row the caller cannot read answers as unknown, another member\'s row is refused 403, and an anonymous caller is refused 401 by the door itself, exactly as the self-hosted mount refuses it. The threads read answers the top-level comments on the records a list filter selects and the caller may read, with each record\'s id and display name: a record outside the caller\'s row scope is not answered, a caller with no read on the object (or a filter naming a field they cannot read) gets that read\'s own 403 PERMISSION_DENIED, an anonymous caller 401', state: 'enforced', + enforcement: 'core/security/own-row-delete-routes.ts (the unreact and own-comment delete doors) and plugin-audit/comment-routes.ts (the resolution door), for the three doors — the caller resolved from the request\'s own credentials (ownRowDeleteCallerResolver: no signed-in user 401, a held sign-in 403), the row read AS THE CALLER (object grant, organization wall, comment read gate; unreadable = unknown 404), the owner column checked (403 PERMISSION_DENIED) or the posting gate asked (canWriteObject insert on sys_comment), then a system write attributed to the caller; and plugin-audit/comment-threads-query.ts (the threads read) — the caller resolved as the doors resolve it (no signed-in user 401, a held sign-in 403), the strict body refused before any read (400 VALIDATION_ERROR), then every read AS THE CALLER and none as the system: ObjectQL planReadScope plans the caller\'s read of the object with the filter (row scope, field read, organization wall; refused: the read\'s own 403 PERMISSION_DENIED) and hands back the subquery that scopes sys_comment.record_id to it, the threads are one ordinary read of sys_comment under the comment read gate, and the records\' display names one read of the object for their ids; reached through ICommentDoorsService.handleCommentDoor by runtime/domains/comments.ts, which claims exactly the four method and path shapes, forwards the transport\'s request UNREAD, resolves the slot per request and adds no credential of its own (an absent slot or member is a typed 501, never a route miss). The two dispatcher preamble gates apply with NO exemption: core/security/auth-gate.ts ALLOW_ROUTES does not list the paths and runtime/http-dispatcher.ts enforceProjectMembership does not skip them. The member runs the very registration the self-hosted mount runs (plugin-audit comment-doors-member.ts over registerCommentDoors in audit-plugin.ts)', covers: ['dispatcher-domain:route-ledger.ts:/comments'], - note: 'The DISPATCHER domain only: on a self-hosted kernel the same paths are served from plugin-audit\'s mount on the kernel\'s http.server and never reach the dispatcher. Unit- and wire-proven, not dogfood-proven: runtime domains/comments.test.ts pins the domain on the real HttpDispatcher (the three shapes forwarded unread, every other method and path the ordinary miss, 501 for an absent slot or member, the slot read per request, the environment-scoped spelling forwarded at the wire path, a signed-in non-member and a gated session stopped before the member); http-conformance hono-comment-doors.conformance.test.ts drives the real AuditPlugin through createHonoApp on a kernel with no http.server (unreact, resolve and reopen, own-comment delete land in the store) and answers the anonymous refusal and refused bodies with the same bytes as the self-hosted mount; plugin-security comment-doors.integration.test.ts and comment-reaction-unreact-door.integration.test.ts hold the doors\' grants on the real stack.' }, + note: 'The DISPATCHER domain only: on a self-hosted kernel the same paths are served from plugin-audit\'s mount on the kernel\'s http.server and never reach the dispatcher. Unit- and wire-proven, not dogfood-proven: runtime domains/comments.test.ts pins the domain on the real HttpDispatcher (the four shapes forwarded unread, the threads read with its body and query string, every other method and path the ordinary miss, 501 for an absent slot or member, the slot read per request, the environment-scoped spelling forwarded at the wire path, a signed-in non-member stopped before the member on a door and on the threads read, a gated session on a door); http-conformance hono-comment-doors.conformance.test.ts drives the real AuditPlugin through createHonoApp on a kernel with no http.server (unreact, resolve and reopen, own-comment delete land in the store; the threads read answers a page) and answers the anonymous refusal and refused bodies, the threads read\'s own refusals included, with the same bytes as the self-hosted mount; plugin-security comment-doors.integration.test.ts and comment-reaction-unreact-door.integration.test.ts hold the doors\' grants on the real stack. The threads read on the real SecurityPlugin (a row-scoped member not answered the hidden record\'s threads, a member with no read refused 403 PERMISSION_DENIED, anonymous 401) is proven by comment-threads-query.dogfood.test.ts on the self-hosted mount only; that file claims no row here and the row cites no proof.' }, // #36506 — the `/personal-views` and `/attachments` dispatcher domains (ruling // A on #22438, applied to the personal-view delete door and the attachment From df819c4e7e534ba48e06849b6901feff24b55ed9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 01:01:59 +0000 Subject: [PATCH 8/8] test(dogfood): the comment threads read is its own HIGH_RISK row, proven on the hosted dispatcher too Ruling B on the card (comment 7363771779): split comment-threads-read-session out of comment-doors-session, list it in HIGH_RISK, and have comment-threads-query.dogfood.test.ts claim it with a [hosted] group that drives the read through a dispatcher alone over the real stack. Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK Co-authored-by: Claude --- .../dogfood/test/authz-conformance.matrix.ts | 47 ++++--- .../qa/dogfood/test/authz-conformance.test.ts | 5 + .../comment-threads-query.dogfood.test.ts | 131 +++++++++++++++++- 3 files changed, 164 insertions(+), 19 deletions(-) diff --git a/packages/qa/dogfood/test/authz-conformance.matrix.ts b/packages/qa/dogfood/test/authz-conformance.matrix.ts index 920d633b71d..4898df808b3 100644 --- a/packages/qa/dogfood/test/authz-conformance.matrix.ts +++ b/packages/qa/dogfood/test/authz-conformance.matrix.ts @@ -429,31 +429,42 @@ export const AUTHZ_CONFORMANCE: AuthzPrimitive[] = [ // credentials, and the dispatcher's two preamble gates apply unexempted. // ⛔ Ids stay in this comment, out of the row's strings. // - // #39134 — the domain also claims a fourth shape, the comment threads read - // (`POST /comments/threads/query`), forwarded to the same member. - // // The three doors are not HIGH_RISK: each writes one row the caller owns or // may resolve, after reading it AS THE CALLER (object grant, organization // wall, the comment read gate), so it is no sibling read path around a data // gate. Their proofs are the plugin-audit and plugin-security door suites // and the two-door wire suite, none of which lives in this directory. // - // ⚠️ That reason does not carry to the threads read. It answers object data - // (the comments on, and the ids and display names of, the records of any - // object a list filter selects) through a sibling HTTP entry point, which - // is the HIGH_RISK list's own definition. Every read in it runs as the - // caller (the object read planned by the engine under the caller's context, - // and an ordinary read of `sys_comment` under the comment read gate), so it - // adds no gate of its own, but that is equally true of the MCP surface the - // list does carry. Its end-to-end proof on the real SecurityPlugin is - // comment-threads-query.dogfood.test.ts, which drives the self-hosted mount - // only and claims no row. Whether the read is HIGH_RISK, as its own row or - // this one, is an open decision on #39134; until it is recorded, this row - // classifies the domain with the read named and NOT on the HIGH_RISK list. - { id: 'comment-doors-session', summary: 'Comment doors (`DELETE /comments/reactions/:id`, `PUT /comments/:id/resolution`, `DELETE /comments/:id`) and the comment threads read (`POST /comments/threads/query`) — a signed-in member removes their own reaction, resolves or reopens a thread they can read and may post on, and removes a comment they wrote with no reply under it; a row the caller cannot read answers as unknown, another member\'s row is refused 403, and an anonymous caller is refused 401 by the door itself, exactly as the self-hosted mount refuses it. The threads read answers the top-level comments on the records a list filter selects and the caller may read, with each record\'s id and display name: a record outside the caller\'s row scope is not answered, a caller with no read on the object (or a filter naming a field they cannot read) gets that read\'s own 403 PERMISSION_DENIED, an anonymous caller 401', state: 'enforced', - enforcement: 'core/security/own-row-delete-routes.ts (the unreact and own-comment delete doors) and plugin-audit/comment-routes.ts (the resolution door), for the three doors — the caller resolved from the request\'s own credentials (ownRowDeleteCallerResolver: no signed-in user 401, a held sign-in 403), the row read AS THE CALLER (object grant, organization wall, comment read gate; unreadable = unknown 404), the owner column checked (403 PERMISSION_DENIED) or the posting gate asked (canWriteObject insert on sys_comment), then a system write attributed to the caller; and plugin-audit/comment-threads-query.ts (the threads read) — the caller resolved as the doors resolve it (no signed-in user 401, a held sign-in 403), the strict body refused before any read (400 VALIDATION_ERROR), then every read AS THE CALLER and none as the system: ObjectQL planReadScope plans the caller\'s read of the object with the filter (row scope, field read, organization wall; refused: the read\'s own 403 PERMISSION_DENIED) and hands back the subquery that scopes sys_comment.record_id to it, the threads are one ordinary read of sys_comment under the comment read gate, and the records\' display names one read of the object for their ids; reached through ICommentDoorsService.handleCommentDoor by runtime/domains/comments.ts, which claims exactly the four method and path shapes, forwards the transport\'s request UNREAD, resolves the slot per request and adds no credential of its own (an absent slot or member is a typed 501, never a route miss). The two dispatcher preamble gates apply with NO exemption: core/security/auth-gate.ts ALLOW_ROUTES does not list the paths and runtime/http-dispatcher.ts enforceProjectMembership does not skip them. The member runs the very registration the self-hosted mount runs (plugin-audit comment-doors-member.ts over registerCommentDoors in audit-plugin.ts)', + // This row keeps the domain's ledger key: the population is minted per + // dispatcher DOMAIN, one key is classified by one row, and the domain also + // serves the threads read below, which is classified on its own row. + { id: 'comment-doors-session', summary: 'Comment doors (`DELETE /comments/reactions/:id`, `PUT /comments/:id/resolution`, `DELETE /comments/:id`) — a signed-in member removes their own reaction, resolves or reopens a thread they can read and may post on, and removes a comment they wrote with no reply under it; a row the caller cannot read answers as unknown, another member\'s row is refused 403, and an anonymous caller is refused 401 by the door itself, exactly as the self-hosted mount refuses it. The domain\'s fourth shape, the comment threads read (`POST /comments/threads/query`), is classified by comment-threads-read-session', state: 'enforced', + enforcement: 'core/security/own-row-delete-routes.ts (the unreact and own-comment delete doors) and plugin-audit/comment-routes.ts (the resolution door) — the caller resolved from the request\'s own credentials (ownRowDeleteCallerResolver: no signed-in user 401, a held sign-in 403), the row read AS THE CALLER (object grant, organization wall, comment read gate; unreadable = unknown 404), the owner column checked (403 PERMISSION_DENIED) or the posting gate asked (canWriteObject insert on sys_comment), then a system write attributed to the caller; reached through ICommentDoorsService.handleCommentDoor by runtime/domains/comments.ts, which claims exactly the four method and path shapes (the three doors and the threads read), forwards the transport\'s request UNREAD, resolves the slot per request and adds no credential of its own (an absent slot or member is a typed 501, never a route miss). The two dispatcher preamble gates apply with NO exemption: core/security/auth-gate.ts ALLOW_ROUTES does not list the paths and runtime/http-dispatcher.ts enforceProjectMembership does not skip them. The member runs the very registration the self-hosted mount runs (plugin-audit comment-doors-member.ts over registerCommentDoors in audit-plugin.ts)', covers: ['dispatcher-domain:route-ledger.ts:/comments'], - note: 'The DISPATCHER domain only: on a self-hosted kernel the same paths are served from plugin-audit\'s mount on the kernel\'s http.server and never reach the dispatcher. Unit- and wire-proven, not dogfood-proven: runtime domains/comments.test.ts pins the domain on the real HttpDispatcher (the four shapes forwarded unread, the threads read with its body and query string, every other method and path the ordinary miss, 501 for an absent slot or member, the slot read per request, the environment-scoped spelling forwarded at the wire path, a signed-in non-member stopped before the member on a door and on the threads read, a gated session on a door); http-conformance hono-comment-doors.conformance.test.ts drives the real AuditPlugin through createHonoApp on a kernel with no http.server (unreact, resolve and reopen, own-comment delete land in the store; the threads read answers a page) and answers the anonymous refusal and refused bodies, the threads read\'s own refusals included, with the same bytes as the self-hosted mount; plugin-security comment-doors.integration.test.ts and comment-reaction-unreact-door.integration.test.ts hold the doors\' grants on the real stack. The threads read on the real SecurityPlugin (a row-scoped member not answered the hidden record\'s threads, a member with no read refused 403 PERMISSION_DENIED, anonymous 401) is proven by comment-threads-query.dogfood.test.ts on the self-hosted mount only; that file claims no row here and the row cites no proof.' }, + note: 'The DISPATCHER domain only: on a self-hosted kernel the same paths are served from plugin-audit\'s mount on the kernel\'s http.server and never reach the dispatcher. Unit- and wire-proven, not dogfood-proven: runtime domains/comments.test.ts pins the domain on the real HttpDispatcher (the four shapes forwarded unread, every other method and path the ordinary miss, 501 for an absent slot or member, the slot read per request, the environment-scoped spelling forwarded at the wire path, a signed-in non-member and a gated session stopped before the member); http-conformance hono-comment-doors.conformance.test.ts drives the real AuditPlugin through createHonoApp on a kernel with no http.server (unreact, resolve and reopen, own-comment delete land in the store) and answers the anonymous refusal and refused bodies with the same bytes as the self-hosted mount; plugin-security comment-doors.integration.test.ts and comment-reaction-unreact-door.integration.test.ts hold the doors\' grants on the real stack. The threads read the domain also serves carries its own row and its own end-to-end proof (comment-threads-read-session).' }, + + // #39134 — the comment threads read (`POST /comments/threads/query`), split + // out of `comment-doors-session` by the maintainer's ruling recorded on + // #39134 (card comment 7363771779, option B of analysis 7361405247): it is + // its own HIGH_RISK row, proved end to end on the hosted door too. ⛔ Ids + // stay in this comment, out of the row's strings. + // + // HIGH_RISK for the list's own reason: unlike the three doors above it + // ANSWERS object data — the comments on, and the ids and display names of, + // the records of any object a list filter selects — through a sibling HTTP + // entry point, on the self-hosted mount and on the hosted dispatcher. + // + // No `covers`, on purpose. The ratchet discovers entry points per REST + // route family and per dispatcher DOMAIN (plus the named probes), and this + // read lives inside the `/comments` domain, whose one key stays classified + // by `comment-doors-session` above (a key is classified by exactly one row, + // and the classified-keys pin lists it there). A shape added inside a + // classified domain mints no key, so the binding that holds this read is + // the HIGH_RISK list plus the mutual row ↔ proof attribution, not `covers`. + { id: 'comment-threads-read-session', summary: 'The comment threads read (`POST /comments/threads/query`), on the self-hosted mount and on the hosted dispatcher — a signed-in member is answered the top-level comments on the records a list filter selects and they may read, with each record\'s id and display name: a record outside the caller\'s row scope is not answered, a caller with no read on the object (or a filter naming a field they cannot read) gets that read\'s own 403 PERMISSION_DENIED, and an anonymous caller is refused 401 by the read itself; on the hosted dispatcher a signed-in caller who is not a member of the environment is refused 403 PROJECT_MEMBERSHIP_REQUIRED before the read runs', state: 'enforced', + enforcement: 'plugin-audit/comment-threads-query.ts — the caller resolved as the comment doors resolve it (no signed-in user 401, a held sign-in 403), the strict body refused before any read (400 VALIDATION_ERROR), then every read AS THE CALLER and none as the system: ObjectQL planReadScope plans the caller\'s read of the object with the filter (row scope, field read, organization wall; refused: the read\'s own 403 PERMISSION_DENIED) and hands back the subquery that scopes sys_comment.record_id to it, the threads are one ordinary read of sys_comment under the comment read gate, and the records\' display names one read of the object for their ids. Self-hosted: served from plugin-audit\'s mount on the kernel\'s http.server (registerCommentDoors in audit-plugin.ts). Hosted: reached through ICommentDoorsService.handleCommentDoor by runtime/domains/comments.ts, which forwards the transport\'s request UNREAD, body and query string included, and adds no credential of its own, behind the two dispatcher preamble gates with NO exemption (core/security/auth-gate.ts ALLOW_ROUTES does not list the path; runtime/http-dispatcher.ts enforceProjectMembership does not skip it); the member runs the very registration the self-hosted mount runs (plugin-audit comment-doors-member.ts)', + proof: 'comment-threads-query.dogfood.test.ts', + note: 'HIGH-RISK, proven end to end on both faces by comment-threads-query.dogfood.test.ts, which boots a real org-bound stack with the real SecurityPlugin and AuditPlugin. Self-hosted mount, at HTTP: a row-scoped member is not answered the hidden record\'s thread, a member with no read on the object is refused 403 PERMISSION_DENIED, a filter on a field the caller cannot read 403 PERMISSION_DENIED, anonymous 401. Hosted (`[hosted]`): the same read through a runtime HttpDispatcher alone over the same stack, the way a hosted tenant kernel with no http.server is reached: a full reader and a row-scoped member each answered exactly their readable records\' threads, the member with no read 403 PERMISSION_DENIED, anonymous 401 UNAUTHENTICATED, and, behind a host whose kernel resolver places the request in an environment, a signed-in non-member 403 PROJECT_MEMBERSHIP_REQUIRED with the read never planned while a member of it is answered. The membership store there is a fixture standing in for the cloud-provided sys_environment_member; the judgment over it is the dispatcher\'s own. Unit and wire pins beside it: runtime domains/comments.test.ts (the read forwarded with its body and query string, a non-member stopped before the member) and http-conformance hono-comment-doors.conformance.test.ts (the read answers a page, and its own refusals answer the same bytes at both doors with a permission stand-in).' }, // #36506 — the `/personal-views` and `/attachments` dispatcher domains (ruling // A on #22438, applied to the personal-view delete door and the attachment diff --git a/packages/qa/dogfood/test/authz-conformance.test.ts b/packages/qa/dogfood/test/authz-conformance.test.ts index 5512bdbab04..729d2cc5237 100644 --- a/packages/qa/dogfood/test/authz-conformance.test.ts +++ b/packages/qa/dogfood/test/authz-conformance.test.ts @@ -904,6 +904,11 @@ const HIGH_RISK = [ // through a sibling execution surface (tool dispatch); proven e2e that a // member's MCP tools/call is RLS-scoped and anonymous is denied. 'mcp-http-identity', + // #39134 — the comment threads read answers object data (the comments on, + // and the ids and display names of, the records of any object a list filter + // selects) through a sibling entry point on both faces; proven e2e on the + // real SecurityPlugin at the self-hosted mount and on the hosted dispatcher. + 'comment-threads-read-session', // ADR-0138 D2 — the six door classes. Each SERVES object data, or a file's // bytes, to a caller with no session, so each owes the end-to-end proof // that it admits exactly its declared subject and refuses the rest. diff --git a/packages/qa/dogfood/test/comment-threads-query.dogfood.test.ts b/packages/qa/dogfood/test/comment-threads-query.dogfood.test.ts index 76ef4edcb86..d93604d3662 100644 --- a/packages/qa/dogfood/test/comment-threads-query.dogfood.test.ts +++ b/packages/qa/dogfood/test/comment-threads-query.dogfood.test.ts @@ -29,6 +29,21 @@ // full, the threads read reaching the driver as ONE statement carrying // the planned read as a subquery (the driver's call log is the query log). // +// Inside it, `[hosted]` drives the same read on the same boot through a runtime +// `HttpDispatcher` alone (`hosted-dispatcher.testkit.ts`), the way a hosted +// tenant kernel with no `http.server` is reached: the dispatcher's `/comments` +// domain forwards the request to the kernel's comment member. A full reader +// and the row-scoped member are each answered exactly the threads on the +// records they read; the member with no read gets `403 PERMISSION_DENIED`; +// anonymous `401`; and behind a host whose kernel resolver places the request +// in an environment, a signed-in non-member is refused +// `403 PROJECT_MEMBERSHIP_REQUIRED` before the read is planned while a member +// of it is answered. The membership store is a fixture standing in for the +// cloud-provided `sys_environment_member`; the judgment over it is the +// dispatcher's own. Without the domain's `POST` shape each of those answers, +// except the membership refusal (the preamble answers it before any route is +// matched), is the dispatcher's route miss instead. +// // The second describe drives the same read (`queryCommentThreads`, the body // the route runs after its shell) on the real engine, the real SecurityPlugin // and the SQL driver, one cell per dialect: the past-the-cap view and the one @@ -49,6 +64,10 @@ // // `@objectstack/plugin-audit` resolves through its BUILT output here. // Fixtures are synthetic. +// +// The authorization conformance matrix row this file proves (the +// `authz-row:` line below is the row id, read by `authz-conformance.test.ts`): +// authz-row: comment-threads-read-session import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import { bootStack, type VerifyStack } from '@objectstack/verify'; @@ -62,6 +81,7 @@ import { defineStack } from '@objectstack/spec'; import { ObjectSchema, Field, isComposedReadableIds } from '@objectstack/spec/data'; import { PermissionSetSchema, type PermissionSet } from '@objectstack/spec/security'; import { catalogPermissionSet } from './catalog-permission-set.js'; +import { hostedDispatcherDoor, type HostedDoorCall } from './hosted-dispatcher.testkit.js'; const SYS = { isSystem: true } as const; const COMMENT = 'sys_comment'; @@ -198,6 +218,66 @@ const ctqNoDealSet: PermissionSet = PermissionSetSchema.parse({ objects: { [QUIET]: { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false } }, }); +/** The environment-membership store a hosted host judges against (cloud-provided; a fixture here). */ +const ENV_MEMBER = 'sys_environment_member'; +/** The environment the `[hosted]` environment host places every request in. */ +const HOSTED_ENV = 'env_ctq_hosted'; + +/** + * Registers `sys_environment_member` with the two columns the dispatcher's + * membership judgment reads (`environment_id`, `user_id`). The object is + * provided by the cloud runtime and absent from an open-source boot, where the + * judgment does not apply at all; this fixture stands in for that store so the + * dispatcher's own gate can be driven over the real stack. + */ +function environmentMembersPlugin(): Plugin { + return { + name: 'test.ctq.environment-members', + type: 'standard', + version: '1.0.0', + dependencies: ['com.objectstack.engine.objectql'], + async init(ctx: PluginContext) { + ctx.getService<{ register(m: unknown): unknown }>('manifest').register({ + id: 'test.ctq.environment-members', + namespace: 'ctqh', + version: '1.0.0', + type: 'plugin', + name: 'Environment membership store fixture', + objects: [ + { + name: ENV_MEMBER, + label: 'Environment Member', + fields: { + environment_id: { type: 'text', label: 'Environment' }, + user_id: { type: 'text', label: 'User' }, + }, + }, + ], + }); + }, + }; +} + +/** + * A hosted host's kernel: it serves nothing itself, and its `kernel-resolver` + * places every request in {@link HOSTED_ENV} on `tenant` — the shape a cloud + * host hands the dispatcher, so its environment-membership gate applies. + */ +function environmentHostKernel(tenant: unknown): unknown { + const resolver = { + resolveKernel: async (context: { environmentId?: string }) => { + context.environmentId = HOSTED_ENV; + return tenant; + }, + }; + return { + getService(name: string) { + if (name === 'kernel-resolver') return resolver; + throw new Error(`the host kernel serves no '${name}'`); + }, + }; +} + describe('POST /comments/threads/query — at HTTP, as members with different row scope', () => { let stack: VerifyStack; let ql: any; @@ -246,7 +326,7 @@ describe('POST /comments/threads/query — at HTTP, as members with different ro // read on deals at all. Each member holds exactly the set granted below. defaultPermissionSets: [...securityDefaultPermissionSets, ctqMemberSet, ctqScopedSet, ctqNoDealSet], }), - extraPlugins: [new AuditPlugin()], + extraPlugins: [new AuditPlugin(), environmentMembersPlugin()], orgContext: true, }); ql = await stack.kernel.getServiceAsync('objectql'); @@ -426,6 +506,55 @@ describe('POST /comments/threads/query — at HTTP, as members with different ro expect(dealReads).toHaveLength(1); expect(dealReads[0].query?.limit ?? 0).toBeLessThanOrEqual(2); }, 120_000); + + describe('[hosted] the same read on the dispatcher alone: a hosted tenant kernel with no http.server', () => { + let hosted: HostedDoorCall; + let environmentHost: HostedDoorCall; + const hostedCall = async (door: HostedDoorCall, who: string | undefined, body: unknown): Promise => { + const res = await door(who ? tok[who] : undefined, 'POST', ROUTE, body); + return { status: res.status, json: await res.json().catch(() => ({})) }; + }; + + beforeAll(async () => { + hosted = hostedDispatcherDoor(stack); + environmentHost = hostedDispatcherDoor({ kernel: environmentHostKernel(stack.kernel) } as VerifyStack); + // Dee is a member of the environment; Erin, who reads every deal, is not. + await ql.insert(ENV_MEMBER, { environment_id: HOSTED_ENV, user_id: uid.dee }, { context: SYS }); + }); + + it('[hosted] a full reader and a row-scoped member: each answered exactly the threads on the records they read — not a route miss', async () => { + const admin = await hostedCall(hosted, 'admin', OPEN); + expect(admin.status, JSON.stringify(admin.json)).toBe(200); + expect(ids(admin.json.data)).toEqual([t.d2, t.d3, t.d1]); + const bob = await hostedCall(hosted, 'bob', OPEN); + expect(bob.status, JSON.stringify(bob.json)).toBe(200); + expect(ids(bob.json.data)).toEqual([t.d2, t.d1]); + expect(bob.json.data.threads.map((x: Row) => x.record.id)).toEqual([deal.d2, deal.d1]); + }); + + it('[hosted] a member with no read on the object: that read\'s 403 PERMISSION_DENIED; anonymous: 401 UNAUTHENTICATED', async () => { + const carol = await hostedCall(hosted, 'carol', OPEN); + expect(carol.status, JSON.stringify(carol.json)).toBe(403); + expect(carol.json?.error?.code).toBe('PERMISSION_DENIED'); + const anonymous = await hostedCall(hosted, undefined, OPEN); + expect(anonymous.status, JSON.stringify(anonymous.json)).toBe(401); + expect(anonymous.json?.error?.code).toBe('UNAUTHENTICATED'); + }); + + it('[hosted] behind a host that places the request in an environment: a signed-in non-member is refused 403 PROJECT_MEMBERSHIP_REQUIRED before the read is planned; a member is answered', async () => { + let refused: Answer | undefined; + const calls = await engineCallsDuring(async () => { + refused = await hostedCall(environmentHost, 'erin', OPEN); + }); + expect(refused!.status, JSON.stringify(refused!.json)).toBe(403); + expect(refused!.json?.error?.code).toBe('PROJECT_MEMBERSHIP_REQUIRED'); + expect(calls).toEqual([]); + // CONTROL a member of the environment is answered the read, through the same host. + const member = await hostedCall(environmentHost, 'dee', OPEN); + expect(member.status, JSON.stringify(member.json)).toBe(200); + expect(ids(member.json.data)).toEqual([t.d2, t.d3, t.d1]); + }); + }); }); // ─────────────────── the engine cells: SQLite and PostgreSQL ───────────────────