From f7b991b7d2b6d0fe332bc4fea7ee4650db3c8599 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 18:56:26 +0000 Subject: [PATCH 1/4] fix(examples): showcase record write actions write as the caller instead of through an elevated script body Mark Done, Submit for Sign-off and Reopen were script actions whose body wrote through ctx.api, which runs system-elevated, so any reader of a task or invoice could change it through the button. They are now declared writes (operation: 'update' + patch): the platform action route performs the write as the caller, so the edit grant, row and field security, hooks and validations apply exactly as for the Edit button. Claude-Session: https://claude.ai/code/session_01SGzB5Np4fydLKpGjZm1dNr Co-authored-by: Claude --- examples/app-showcase/src/data/hooks/index.ts | 13 +-- examples/app-showcase/src/ui/actions/index.ts | 102 +++++++++--------- .../app-showcase/src/ui/views/task.view.ts | 5 +- examples/app-showcase/test/actions.test.ts | 89 ++++++++------- .../test/task-reopen-hook-refusal.test.ts | 50 +++------ 5 files changed, 123 insertions(+), 136 deletions(-) diff --git a/examples/app-showcase/src/data/hooks/index.ts b/examples/app-showcase/src/data/hooks/index.ts index 05302b524ee..74392b4dad5 100644 --- a/examples/app-showcase/src/data/hooks/index.ts +++ b/examples/app-showcase/src/data/hooks/index.ts @@ -133,12 +133,13 @@ export const TASK_REOPEN_REFUSAL = * * `throw new Error('')` from a sandboxed body is the business-refusal * shape: the write is aborted (`onError: 'abort'`) and the sentence travels to - * the caller as a 4xx — on `/data`, and through a script action's `ctx.api` - * write on `/actions` too (`packages/runtime/src/sandbox/ - * nested-hook-refusal-is-a-rejection.test.ts`). `showcase_reopen_task` - * (`src/ui/actions/index.ts`) is the script action that reaches it, and the - * platform checklist item `records-forms.script-action-hook-refusal-toast` - * drives that action in the console. + * the caller as a 4xx — on `/data`, and on `/actions` too, whether the write is + * an action's declared `operation: 'update'` or a script action's `ctx.api` + * write (`packages/runtime/src/sandbox/nested-hook-refusal-is-a-rejection.test.ts`). + * `showcase_reopen_task` (`src/ui/actions/index.ts`) is the action whose + * declared write reaches it, and the platform checklist item + * `records-forms.script-action-hook-refusal-toast` drives that action in the + * console. * * The condition is the two-root transition form (same lesson as * {@link AuditTaskCompletionHook}): only the write that flips `done` from true diff --git a/examples/app-showcase/src/ui/actions/index.ts b/examples/app-showcase/src/ui/actions/index.ts index 2615c8b3c4b..e17b0b244c0 100644 --- a/examples/app-showcase/src/ui/actions/index.ts +++ b/examples/app-showcase/src/ui/actions/index.ts @@ -23,13 +23,29 @@ const fieldZoo = 'showcase_field_zoo'; */ /** - * script — inline sandboxed handler, shown on each row and the record header. + * The declarative record write (`operation: 'update'` + `patch`), shown on each + * row and the record header. * - * The `body` (L2 sandboxed JS) is what makes this action *executable*: AppPlugin - * walks the bundle's actions on bind and only registers an engine handler for - * those carrying a `body` (or `target` -> bundle function). Without it the - * runtime has nothing to invoke and `POST /actions/showcase_task/showcase_mark_done` - * fails with "Action ... not found". + * ## Why a declared write and not a script body + * + * The platform action route performs this write itself, ONCE, on the current + * record, as the CALLER — never system-elevated — so the caller's object, row + * and field permissions, the task's hooks and its validations apply exactly as + * they do to the Edit button (`executeDeclarativeUpdateAction`, + * `packages/runtime/src/action-execution.ts`). A member who may read a task but + * not edit it is refused here with the same `403 PERMISSION_DENIED` an edit + * gets, and nothing is written. + * + * It used to be a `type: 'script'` body writing through `ctx.api`. A body is + * trusted application code: its `ctx.api` runs `isSystem` + * (`buildActionExecutionContext`), outside the caller's RLS and FLS, so a body + * that writes is an elevation for everyone who can see the button. The rule + * this app models: + * - a record action that only sets fields of the current record DECLARES the + * write, as here, and inherits the edit grant it is a shortcut for; + * - a script body is for logic the caller's own permissions cannot express; + * one that writes gates itself with `requiredPermissions` (ADR-0066 D4), + * because nothing else stands between a caller and its elevated `ctx.api`. * * It flips the dedicated `done` flag and `progress` rather than the `status` * select on purpose: `status` is governed by the `task_status_flow` @@ -42,21 +58,13 @@ export const MarkDoneAction = defineAction({ label: 'Mark Done', icon: 'check', objectName: task, - type: 'script', - body: { - language: 'js', - source: - "var id = ctx.recordId || (ctx.record && ctx.record.id) || input.recordId;" + - "if (!id) throw new Error('No record to mark done');" + - "await ctx.api.object('showcase_task').update({ id: id, done: true, progress: 100 });" + - "return { ok: true, id: id };", - capabilities: ['api.write'], - }, - // #17319 — the dispatch contract this BODY is written for. It reads - // `ctx.recordId` and throws 'No record to mark done' without one, so an - // aggregate wiring would fail on every click with a message that reads like - // a selection bug. Declaring it makes that wiring a build-time refusal - // (`action-dispatch-contract-mismatch`) instead. + operation: 'update', + patch: { done: true, progress: 100 }, + // #17319 — the dispatch contract this write is declared for: it writes the + // CURRENT record, and the route refuses an update with no record id (400). + // An aggregate wiring would dispatch once with none, so declaring it makes + // that wiring a build-time refusal (`action-dispatch-contract-mismatch`) + // instead of a failure on every click. execution: 'perRecord', successMessage: 'Task marked done.', // Hide once the task is complete. Gate on `record.done` (the boolean this @@ -85,14 +93,16 @@ export const MarkDoneAction = defineAction({ }); /** - * script — the hook-REFUSAL specimen. Reopening a finished task is refused by - * the `showcase_guard_task_reopen` beforeUpdate hook - * (`src/data/hooks/index.ts`), so a click on this action always fails, by - * design: the body's `ctx.api` write is aborted and the hook's sentence is what - * the user must be told. The action route answers it as a 4xx carrying that - * sentence, and the console owes exactly one error toast that contains it. - * Platform checklist item `records-forms.script-action-hook-refusal-toast` - * drives this. + * The hook-REFUSAL specimen, a declarative record write like Mark Done above. + * Reopening a finished task is refused by the `showcase_guard_task_reopen` + * beforeUpdate hook (`src/data/hooks/index.ts`), so a click on this action + * always fails, by design: the write the platform performs as the caller is + * aborted and the hook's sentence is what the user must be told. The action + * route answers it as a 4xx carrying that sentence, and the console owes + * exactly one error toast that contains it. Platform checklist item + * `records-forms.script-action-hook-refusal-toast` drives this. A caller who may + * not edit the task never reaches the hook: the write is refused `403` first, + * as an edit would be. * * Shown only on finished tasks — the only records the refusal applies to. */ @@ -101,16 +111,8 @@ export const ReopenTaskAction = defineAction({ label: 'Reopen', icon: 'rotate-ccw', objectName: task, - type: 'script', - body: { - language: 'js', - source: - "var id = ctx.recordId || (ctx.record && ctx.record.id) || input.recordId;" + - "if (!id) throw new Error('No record to reopen');" + - "await ctx.api.object('showcase_task').update({ id: id, done: false });" + - "return { ok: true, id: id };", - capabilities: ['api.write'], - }, + operation: 'update', + patch: { done: false }, execution: 'perRecord', // #8990 — `has()` guards the sparse `list_item` face, as on Mark Done. visible: 'has(record.done) && record.done == true', @@ -307,30 +309,26 @@ export const NewTaskAction = defineAction({ }); /** - * script — Submit an invoice for finance + legal sign-off (§1 demo entry point). + * Submit an invoice for finance + legal sign-off (§1 demo entry point), a + * declarative record write like Mark Done above. * * Flipping `status` to `sent` is exactly the transition the `showcase_invoice_signoff` * flow's start gate watches (`status == "sent" && previous.status != "sent"`), so * this button opens a fresh 会签 (finance ∧ legal) approval request from the record * header — the same request the boot-time demo seeds (src/security/seed-approval-demo.ts), - * but on demand. The sandboxed body's write fires the record-change trigger like any - * user edit. Gated to draft invoices so it disappears once submitted. + * but on demand. The write is an edit of the invoice performed as the caller, so + * it fires the record-change trigger like any user edit, and only someone who + * may edit the invoice can submit it: a read-only holder (the auditor's + * View-All, the ops set's read) is refused `403`. Gated to draft invoices so it + * disappears once submitted. */ export const SubmitForSignoffAction = defineAction({ name: 'showcase_submit_signoff', label: 'Submit for Sign-off', icon: 'send', objectName: invoice, - type: 'script', - body: { - language: 'js', - source: - "var id = ctx.recordId || (ctx.record && ctx.record.id) || input.recordId;" + - "if (!id) throw new Error('No invoice to submit');" + - "await ctx.api.object('showcase_invoice').update({ id: id, status: 'sent' });" + - "return { ok: true, id: id };", - capabilities: ['api.write'], - }, + operation: 'update', + patch: { status: 'sent' }, successMessage: 'Invoice submitted for finance + legal sign-off.', // Only on invoices not yet sent. `record.`-prefixed comparison, per the // ActionEngine's fail-closed CEL evaluation (see MarkDoneAction's note). diff --git a/examples/app-showcase/src/ui/views/task.view.ts b/examples/app-showcase/src/ui/views/task.view.ts index e46a8d5362a..e50d0f30691 100644 --- a/examples/app-showcase/src/ui/views/task.view.ts +++ b/examples/app-showcase/src/ui/views/task.view.ts @@ -153,8 +153,9 @@ export const TaskViews = defineView({ // Runner-dispatched bulk actions come in TWO execution modes: // // Per-record (default) — each selected record is one dispatch: - // `showcase_mark_done` — type `script`; its sandboxed body flips - // `done`/`progress` per record via the platform action route. + // `showcase_mark_done` — a declared write (`operation: 'update'`); + // the platform action route writes `done`/`progress` per record, as + // the caller. // `showcase_recalc_estimate` — type `api`; POSTs the showcase's declared // `/api/v1/apps/showcase/recalc` endpoint, with `recordIdParam: 'recordId'` // (already declared for the row surface) carrying each record's id. diff --git a/examples/app-showcase/test/actions.test.ts b/examples/app-showcase/test/actions.test.ts index b7b7d55688c..b11373f392d 100644 --- a/examples/app-showcase/test/actions.test.ts +++ b/examples/app-showcase/test/actions.test.ts @@ -16,63 +16,72 @@ import { allActions, MarkDoneAction, NewTaskAction, PortfolioSnapshotAction } fr * registered no engine handler and clicking "Mark Done" failed at runtime with * `Action 'showcase_mark_done' on object '*' not found`. * - * These tests drive the **real** runtime path — `actionBodyRunnerFactory` + - * the QuickJS sandbox, the exact bridge AppPlugin uses — against the actions as - * shipped. A body that fails to parse, references the wrong field, or is missing - * entirely fails here, not in production. + * A `script` action is executable in exactly three shapes: a `body` + * (auto-registered by AppPlugin), a `target` (a handler wired imperatively), or + * the declarative record write `operation: 'update'` + `patch`, which carries + * neither because the platform action route performs the write itself, as the + * caller (`isHeadlessInvokableAction` asks for it first). Mark Done is that + * third shape now, so the #2169 regression is pinned on the bodies that remain: + * these tests drive the **real** runtime path — `actionBodyRunnerFactory` + + * the QuickJS sandbox, the exact bridge AppPlugin uses — against them as + * shipped. A body that fails to parse, or is missing entirely, fails here, not + * in production. */ describe('showcase actions — executability', () => { const runner = new QuickJSScriptRunner(); + const scriptActions = allActions.filter((a) => a.type === 'script'); + const isDeclaredWrite = (a: object) => (a as { operation?: unknown }).operation === 'update'; + const bodyActions = scriptActions.filter((a) => Boolean((a as { body?: unknown }).body)); - it('every declared `script` action is executable (has a body or a target)', () => { + it('every declared `script` action is executable (a body, a target, or a declared write)', () => { // Mirrors the platform invariant enforced by ActionSchema: a script action // must be bound to *something* runnable. `target` actions are wired - // imperatively (e.g. via onEnable); `body` actions are auto-registered. - const scriptActions = allActions.filter((a) => a.type === 'script'); + // imperatively (e.g. via onEnable); `body` actions are auto-registered; a + // declared write is performed by the route and must say what it writes. expect(scriptActions.length).toBeGreaterThan(0); for (const a of scriptActions) { + const declaredWrite = isDeclaredWrite(a) && Object.keys((a as { patch?: object }).patch ?? {}).length > 0; expect( - Boolean((a as { body?: unknown }).body) || Boolean((a as { target?: unknown }).target), - `script action '${a.name}' has neither body nor target — it cannot be invoked`, + Boolean((a as { body?: unknown }).body) || Boolean((a as { target?: unknown }).target) || declaredWrite, + `script action '${a.name}' has no body, no target and no declared write — it cannot be invoked`, ).toBe(true); } }); - it('the runtime produces a handler for Mark Done (regression: #2169)', () => { + it('the runtime produces a handler for every body action (regression: #2169)', () => { + expect(bodyActions.length).toBeGreaterThan(0); const factory = actionBodyRunnerFactory(runner, { ql: {}, appId: 'showcase' }); - const handler = factory(MarkDoneAction as never); - expect(typeof handler).toBe('function'); + for (const a of bodyActions) { + expect(typeof factory(a as never), `no handler for '${a.name}'`).toBe('function'); + } }); - it('Mark Done flips `done` + `progress` via the sandboxed body', async () => { - // Capture what the action writes through the proxied ObjectQL engine. - let written: { object: string; data: Record } | undefined; - const ql = { - object: (object: string) => ({ - update: async (data: Record) => { - written = { object, data }; - return { id: data.id }; - }, - }), - }; - - const factory = actionBodyRunnerFactory(runner, { ql, appId: 'showcase' }); - const handler = factory(MarkDoneAction as never); - expect(typeof handler).toBe('function'); - - const result = await handler!({ - recordId: 'task_1', - record: { id: 'task_1', status: 'in_progress', progress: 40, done: false }, - params: {}, - user: { id: 'u1' }, - }); + it('Mark Done declares the completion write: `done` + `progress`, never `status`', () => { + // The route writes exactly this patch to the current record. It + // deliberately does NOT touch `status` (the state-machine only permits + // in_review -> done). + expect(MarkDoneAction.operation).toBe('update'); + expect(MarkDoneAction.patch).toEqual({ done: true, progress: 100 }); + expect(MarkDoneAction).not.toHaveProperty('body'); + expect(MarkDoneAction.execution).toBe('perRecord'); + }); - // It updates the right object with the completion fields — and deliberately - // does NOT touch `status` (the state-machine only permits in_review -> done). - expect(written?.object).toBe('showcase_task'); - expect(written?.data).toMatchObject({ id: 'task_1', done: true, progress: 100 }); - expect(written?.data).not.toHaveProperty('status'); - expect(result).toEqual({ ok: true, id: 'task_1' }); + it('no action body writes without a capability gate', () => { + // A body's `ctx.api` runs system-elevated, outside the caller's RLS and + // FLS, so a body that may write is an elevation for every caller who can + // reach the action, unless `requiredPermissions` names who may run it + // (ADR-0066 D4). This app's record writes are declared writes, performed as + // the caller; the second half keeps a writing body from coming back ungated. + expect(scriptActions.filter(isDeclaredWrite).map((a) => a.name).sort()).toEqual([ + 'showcase_mark_done', + 'showcase_reopen_task', + 'showcase_submit_signoff', + ]); + const ungated = bodyActions + .filter((a) => ((a as { body?: { capabilities?: string[] } }).body?.capabilities ?? []).includes('api.write')) + .filter((a) => ((a as { requiredPermissions?: string[] }).requiredPermissions ?? []).length === 0) + .map((a) => a.name); + expect(ungated, 'script bodies that may write, with no requiredPermissions').toEqual([]); }); it('a body-less `script` action yields no handler (the #2169 failure mode)', () => { diff --git a/examples/app-showcase/test/task-reopen-hook-refusal.test.ts b/examples/app-showcase/test/task-reopen-hook-refusal.test.ts index 88a351b8c5a..76e5a1e4ce0 100644 --- a/examples/app-showcase/test/task-reopen-hook-refusal.test.ts +++ b/examples/app-showcase/test/task-reopen-hook-refusal.test.ts @@ -3,7 +3,7 @@ /** * The showcase's hook-REFUSAL fixture: `showcase_guard_task_reopen` refuses the * write that reopens a finished task, with a sentence addressed to the user, - * and `showcase_reopen_task` is the script action whose write reaches it. + * and `showcase_reopen_task` is the action whose declared write reaches it. * * Platform checklist item `records-forms.script-action-hook-refusal-toast` * drives this pair in the console (4xx on the action route, exactly one error @@ -14,12 +14,14 @@ * 1. on the real engine with the app's real hooks, the reopening write is * refused with the sentence and the stored row is unchanged — while an * edit of the same finished task that leaves `done` alone still lands; - * 2. the action's body writes exactly the reopening shape (`done: false` on - * its own record), so a click reaches the hook's condition. + * 2. the action declares exactly the reopening write (`done: false` on its + * own record, `operation: 'update'`), so a click reaches the hook's + * condition through the write the platform action route performs as the + * caller. * - * The action route's own 4xx for a nested sandboxed refusal is pinned in - * `packages/runtime/src/sandbox/nested-hook-refusal-is-a-rejection.test.ts`; - * it is not restated here. + * The action route's answer to that refusal, and to a caller who may not edit + * the task at all, is pinned over real HTTP in the dogfood suite + * (`showcase-record-write-actions.dogfood.test.ts`); it is not restated here. * * Harness: the production one `hook-body-persisted-writes.test.ts` uses — real * `ObjectQL`, real `SqlDriver` (better-sqlite3), real `QuickJSScriptRunner` @@ -29,11 +31,7 @@ import { describe, it, expect, afterEach } from 'vitest'; import { ObjectQL } from '@objectstack/objectql'; import { SqlDriver } from '@objectstack/driver-sql'; -import { - QuickJSScriptRunner, - actionBodyRunnerFactory, - hookBodyRunnerFactory, -} from '@objectstack/runtime'; +import { QuickJSScriptRunner, hookBodyRunnerFactory } from '@objectstack/runtime'; import { Account, Project, Task } from '../src/data/objects/index.js'; import { allHooks, TASK_REOPEN_REFUSAL } from '../src/data/hooks/index.js'; @@ -150,31 +148,11 @@ describe('showcase_guard_task_reopen — the hook refuses reopening a finished t }, 30000); }); -describe('showcase_reopen_task — the script action writes the shape the hook refuses', () => { - it("the body updates its own record with done: false and nothing else", async () => { - let written: { object: string; data: Record } | undefined; - const ql = { - object: (object: string) => ({ - update: async (data: Record) => { - written = { object, data }; - return { id: data.id }; - }, - }), - }; - - const handler = actionBodyRunnerFactory(new QuickJSScriptRunner(), { ql, appId: 'showcase' })( - ReopenTaskAction as never, - ); - expect(typeof handler).toBe('function'); - - await handler!({ - recordId: 'task_1', - record: { id: 'task_1', done: true, progress: 100 }, - params: {}, - user: { id: 'u1' }, - }); - - expect(written).toEqual({ object: 'showcase_task', data: { id: 'task_1', done: false } }); +describe('showcase_reopen_task — the declared write is the shape the hook refuses', () => { + it('declares an update of its own record with done: false and nothing else', () => { + expect(ReopenTaskAction.operation).toBe('update'); + expect(ReopenTaskAction.patch).toEqual({ done: false }); + expect(ReopenTaskAction).not.toHaveProperty('body'); }); it('is offered only on finished tasks', () => { From 630bfff701755ae60dbc89f108e8084ff1c71d74 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 19:02:13 +0000 Subject: [PATCH 2/4] test(dogfood): pin the showcase record-write actions to the caller's own write verdict Claude-Session: https://claude.ai/code/session_01SGzB5Np4fydLKpGjZm1dNr Co-authored-by: Claude --- ...wcase-record-write-actions.dogfood.test.ts | 232 ++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 packages/qa/dogfood/test/showcase-record-write-actions.dogfood.test.ts diff --git a/packages/qa/dogfood/test/showcase-record-write-actions.dogfood.test.ts b/packages/qa/dogfood/test/showcase-record-write-actions.dogfood.test.ts new file mode 100644 index 00000000000..48fea71c807 --- /dev/null +++ b/packages/qa/dogfood/test/showcase-record-write-actions.dogfood.test.ts @@ -0,0 +1,232 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [#25468] The showcase's record-write actions write AS THE CALLER, over real HTTP. +// +// Mark Done, Reopen and Submit for Sign-off each set fields on their own +// record and nothing else, so each declares the write (`operation: 'update'` + +// `patch`) instead of performing it from a script body. The difference is the +// whole point: a body's `ctx.api` runs with the system identity +// (`buildActionExecutionContext` stamps `isSystem`), so a body that writes is +// reachable by anyone who can see the button, while the platform action route +// performs a declared write with the CALLER's own envelope — object CRUD, RLS, +// FLS, hooks and validation all apply, exactly as for a PATCH of the same row. +// +// So every refusal below is paired with the data plane's own answer for the +// same caller and the same row: the action route must say what `PATCH +// /data/...` says. And every refusal is paired with an ALLOW for a caller who +// may edit, because a pin that only asserts denials stays green when the +// actions stop working for everyone. +// +// Personas are fresh sign-ups holding exactly one set (or none), granted the +// way `showcase-crud-persona-matrix.dogfood.test.ts` grants them: +// • member — the everyone baseline only: task read + create, no edit; +// • contributor — `showcase_contributor`, which edits tasks assigned to them; +// • auditor — `showcase_auditor`: View-All on invoices, no write bit anywhere. +// +// What this file does NOT cover: the console. The button is still OFFERED to +// a caller who may not edit (hiding it by edit permission is not something +// `visible` can express); the click's refusal toast is the console's, pinned in +// objectui (`ActionRunner.updateOperation.test.ts`). + +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { type VerifyStack } from '@objectstack/verify'; +import { bootShowcase } from './showcase-boot.js'; +import { showcaseAppDefaultSecurity } from './showcase-security.js'; +import { catalogPermissionSet } from './catalog-permission-set.js'; +// The refusal sentence, from the hook that throws it — a source import: the +// showcase package exports no hooks entry, and the oracle must be the shipped +// string, never a copy of it. +import { TASK_REOPEN_REFUSAL } from '../../../../examples/app-showcase/src/data/hooks/index.js'; + +const SYS = { isSystem: true } as const; +const ADMIN_EMAIL = 'admin@objectos.ai'; + +const idOf = (b: any) => b?.id ?? b?.record?.id ?? b?.data?.id; + +describe('showcase: record-write actions write as the caller (#25468)', () => { + let stack: VerifyStack; + let ql: any; + let adminTok: string; + const tok = { member: '', contributor: '', auditor: '' }; + const email = { + member: 'rwa-member@verify.test', + contributor: 'rwa-contributor@verify.test', + auditor: 'rwa-auditor@verify.test', + }; + let projectId = ''; + let accountId = ''; + + const text = async (r: Response) => { + try { + return await r.text(); + } catch { + return ''; + } + }; + const readTask = async (id: string) => + (await ql.findOne('showcase_task', { where: { id }, context: SYS })) as any; + const readInvoice = async (id: string) => + (await ql.findOne('showcase_invoice', { where: { id }, context: SYS })) as any; + + /** An open task created by the admin over HTTP, optionally assigned. */ + async function openTask(title: string, assignee?: string): Promise { + const r = await stack.apiAs(adminTok, 'POST', '/data/showcase_task', { + title, + project: projectId, + status: 'todo', + ...(assignee ? { assignee } : {}), + }); + const body = await text(r); + expect(r.status, `admin creates the task fixture — got ${body}`).toBeLessThan(300); + const id = String(idOf(JSON.parse(body))); + expect(id).toBeTruthy(); + const stored = await readTask(id); + expect(stored.done, 'the fixture starts open').toBeFalsy(); + return id; + } + + /** A finished task: created open, then finished by the admin's own edit. */ + async function finishedTask(title: string): Promise { + const id = await openTask(title); + const r = await stack.apiAs(adminTok, 'PATCH', `/data/showcase_task/${id}`, { done: true, progress: 100 }); + expect(r.status, `admin finishes the task fixture — got ${await text(r)}`).toBeLessThan(300); + expect((await readTask(id)).done).toBeTruthy(); + return id; + } + + /** + * A draft invoice created by the admin. `issued_on` is set because the + * invoice requires it once `status` is `sent` — the submit write must be + * judged on permission, never on a missing field. + */ + async function draftInvoice(name: string): Promise { + const r = await stack.apiAs(adminTok, 'POST', '/data/showcase_invoice', { + name, + account: accountId, + status: 'draft', + owner: ADMIN_EMAIL, + issued_on: '2026-10-01', + }); + const body = await text(r); + expect(r.status, `admin creates the invoice fixture — got ${body}`).toBeLessThan(300); + const id = String(idOf(JSON.parse(body))); + expect((await readInvoice(id)).status).toBe('draft'); + return id; + } + + const run = (token: string, object: string, action: string, id: string) => + stack.apiAs(token, 'POST', `/actions/${object}/${action}/${id}`, {}); + + beforeAll(async () => { + stack = await bootShowcase({ security: showcaseAppDefaultSecurity() }); + adminTok = await stack.signIn(); + ql = await stack.kernel.getServiceAsync('objectql'); + + projectId = String((await ql.find('showcase_project', { limit: 1, context: SYS }))?.[0]?.id ?? ''); + // An invoice may not be issued against a churned account (#18682). + accountId = String( + (await ql.find('showcase_account', { where: { status: { $ne: 'churned' } }, limit: 1, context: SYS }))?.[0]?.id ?? '', + ); + expect(projectId && accountId, 'the showcase seed provides a project and an open account').toBeTruthy(); + + tok.member = await stack.signUp(email.member); + for (const [who, set] of [['contributor', 'showcase_contributor'], ['auditor', 'showcase_auditor']] as const) { + tok[who] = await stack.signUp(email[who]); + const ps = await catalogPermissionSet(ql, set); + expect(ps, `permission set ${set} served by the security catalog`).toBeTruthy(); + const uid = (await ql.findOne('sys_user', { where: { email: email[who] }, context: SYS }))?.id; + expect(uid, `persona ${email[who]} provisioned`).toBeTruthy(); + await ql.insert('sys_user_permission_set', { user_id: uid, permission_set: ps.name }, { context: SYS }); + } + }, 300_000); + + afterAll(async () => { + await stack?.stop?.(); + }); + + describe('Mark Done', () => { + it('a member who may read but not edit the task is refused 403, as a PATCH is, and the task is unchanged', async () => { + const id = await openTask('RWA mark-done member'); + // The member CAN read the row: the refusal is the edit verdict, not a miss. + const read = await stack.apiAs(tok.member, 'GET', `/data/showcase_task/${id}`); + expect(read.status, await text(read)).toBe(200); + + const patch = await stack.apiAs(tok.member, 'PATCH', `/data/showcase_task/${id}`, { done: true, progress: 100 }); + expect(patch.status, `the data plane's own answer — ${await text(patch)}`).toBe(403); + + const res = await run(tok.member, 'showcase_task', 'showcase_mark_done', id); + expect(res.status, `the action route answers as the data plane does — ${await text(res)}`).toBe(403); + + const stored = await readTask(id); + expect(stored.done).toBeFalsy(); + expect(stored.progress ?? 0).not.toBe(100); + }, 60_000); + + it('a contributor may finish a task assigned to them: done and progress land', async () => { + const id = await openTask('RWA mark-done contributor', email.contributor); + + const res = await run(tok.contributor, 'showcase_task', 'showcase_mark_done', id); + expect(res.status, await text(res)).toBe(200); + + const stored = await readTask(id); + expect(stored.done).toBeTruthy(); + expect(stored.progress).toBe(100); + }, 60_000); + + it('the admin may finish any task', async () => { + const id = await openTask('RWA mark-done admin'); + + const res = await run(adminTok, 'showcase_task', 'showcase_mark_done', id); + expect(res.status, await text(res)).toBe(200); + expect((await readTask(id)).done).toBeTruthy(); + }, 60_000); + }); + + describe('Reopen', () => { + it('a member who may not edit the task is refused 403 before the guard hook is reached', async () => { + const id = await finishedTask('RWA reopen member'); + + const res = await run(tok.member, 'showcase_task', 'showcase_reopen_task', id); + const body = await text(res); + expect(res.status, body).toBe(403); + // The permission verdict, not the hook's: a 4xx carrying the hook's + // sentence here would mean the write ran far enough to meet the hook. + expect(body).not.toContain(TASK_REOPEN_REFUSAL); + expect((await readTask(id)).done).toBeTruthy(); + }, 60_000); + + it('a caller who may edit meets the guard hook: 4xx carrying its sentence, and the task stays finished', async () => { + const id = await finishedTask('RWA reopen admin'); + + const res = await run(adminTok, 'showcase_task', 'showcase_reopen_task', id); + const body = await text(res); + expect(res.status, body).toBeGreaterThanOrEqual(400); + expect(res.status, body).toBeLessThan(500); + expect(body).toContain(TASK_REOPEN_REFUSAL); + expect((await readTask(id)).done).toBeTruthy(); + }, 60_000); + }); + + describe('Submit for Sign-off', () => { + it('the auditor, who reads every invoice but edits none, is refused 403, as a PATCH is, and the status is unchanged', async () => { + const id = await draftInvoice('RWA submit auditor'); + const read = await stack.apiAs(tok.auditor, 'GET', `/data/showcase_invoice/${id}`); + expect(read.status, await text(read)).toBe(200); + + const patch = await stack.apiAs(tok.auditor, 'PATCH', `/data/showcase_invoice/${id}`, { status: 'sent' }); + expect(patch.status, `the data plane's own answer — ${await text(patch)}`).toBe(403); + + const res = await run(tok.auditor, 'showcase_invoice', 'showcase_submit_signoff', id); + expect(res.status, `the action route answers as the data plane does — ${await text(res)}`).toBe(403); + expect((await readInvoice(id)).status).toBe('draft'); + }, 60_000); + + it('the admin may submit: the invoice is sent', async () => { + const id = await draftInvoice('RWA submit admin'); + + const res = await run(adminTok, 'showcase_invoice', 'showcase_submit_signoff', id); + expect(res.status, await text(res)).toBe(200); + expect((await readInvoice(id)).status).toBe('sent'); + }, 60_000); + }); +}); From e7515fed8475a5ff5f7ece4760d8653562205e64 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 19:08:10 +0000 Subject: [PATCH 3/4] docs(qa): respell the two checklist items whose showcase fixture now declares its write Claude-Session: https://claude.ai/code/session_01SGzB5Np4fydLKpGjZm1dNr Co-authored-by: Claude --- .../qa/platform-checklist/areas/api-backend.json | 12 +++++++++--- .../platform-checklist/areas/records-forms.json | 16 +++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/qa/platform-checklist/areas/api-backend.json b/docs/qa/platform-checklist/areas/api-backend.json index 15978652008..c7b94bff1f5 100644 --- a/docs/qa/platform-checklist/areas/api-backend.json +++ b/docs/qa/platform-checklist/areas/api-backend.json @@ -1607,7 +1607,7 @@ "title": "A disabled packaged action is refused 409 ACTION_DISABLED at BOTH dispatch doors — after the capability gate (a 403 is never an oracle for the switch), before the param contract and the record load, durable across restart", "since": "v17", "status": "active", - "revision": 6, + "revision": 7, "priority": "P0", "surface": "api", "personas": [ @@ -1617,7 +1617,7 @@ "fixtures": { "app": "showcase", "requires": [ - "showcase_mark_done on showcase_task (ui/actions/index.ts — script action, registered body, NO declared params, no requiredPermissions): the clean 409 probe", + "showcase_mark_done on showcase_task (ui/actions/index.ts — a declared record write: operation 'update' with patch { done: true, progress: 100 } and no body, which the action route performs as the caller; NO declared params, no requiredPermissions): the clean 409 probe", "showcase_action_param_gallery on showcase_field_zoo (ui/actions/index.ts — script action with a required param p_text): the param-ordering discriminator — the ONLY stock action whose param contract can produce a contrasting 400, because enforceActionParams (action-execution.ts) returns null outright for an action with no declared params", "showcase_zoo_perm_missing on showcase_field_zoo (predicate-matrix.action.ts — requiredPermissions: ['showcase.restricted_ops'], granted to nobody): the 403-oracle probe", "showcase_portfolio_snapshot (ui/actions/index.ts — object-less/global, and the ONLY stock action with ai.exposed: true): the live MCP-door probe; its activation flip spells the object segment `global` (/actions/_activation/global/showcase_portfolio_snapshot)" @@ -1639,7 +1639,7 @@ ], "acceptance": [ { - "clause": "the REST door refuses a disabled packaged action 409 ACTION_DISABLED and dispatches NOTHING: status 409, code ACTION_DISABLED (registered in the ADR-0112 ledger, error-code-ledger.zod.ts), message = the engine's own describeDisabledAction sentence naming the ledger — and no side effect lands (the mark_done body's done/progress write never ran)", + "clause": "the REST door refuses a disabled packaged action 409 ACTION_DISABLED and dispatches NOTHING: status 409, code ACTION_DISABLED (registered in the ADR-0112 ledger, error-code-ledger.zod.ts), message = the engine's own describeDisabledAction sentence naming the ledger — and no side effect lands (mark_done's declared done/progress write never ran)", "oracle": "api", "verify": "step-3 trace: 409 + code ACTION_DISABLED + the disabled-action sentence; follow-up reads show no task mutated", "evidence": "the trace + the control re-reads" @@ -1748,6 +1748,12 @@ "date": "2026-10-20", "change": "steps[0] respelled: 'boot showcase isolated on ' → 'boot the showcase on its own port and DB, on '. Round 12's out-of-scope finding (landing record 6287983829 on wave anchor #24579): the phrase 'showcase isolated' named the dogfood §0 own-port boot, and a runner read it as the `isolated` tenancy posture (OS_TENANCY_POSTURE=isolated). The new spelling names that boot by what it is, in RUNNER.md's own words for it (the trap table's counter: own port/DB, skill §0), and names no posture. Read at base e4d604efd3. No clause changed", "ref": "#25003" + }, + { + "revision": 7, + "date": "2026-10-23", + "change": "fixtures.requires[0] and acceptance[0] respelled for #25468: showcase_mark_done is no longer a script action with a registered body; it declares its write (operation 'update', patch { done: true, progress: 100 }), which the action route performs as the caller. Its type stays 'script', the schema default, and it still declares no params and no requiredPermissions, so it is still the clean 409 probe: the activation consult runs ahead of the declarative branch in packages/runtime/src/domains/actions.ts (read at base aa2dbab7b; measured on a dogfood boot of the change: disabled with a nonexistent recordId answers 409 ACTION_DISABLED). No clause changed", + "ref": "#25468" } ] }, diff --git a/docs/qa/platform-checklist/areas/records-forms.json b/docs/qa/platform-checklist/areas/records-forms.json index 8f6653f6ba3..62271227127 100644 --- a/docs/qa/platform-checklist/areas/records-forms.json +++ b/docs/qa/platform-checklist/areas/records-forms.json @@ -5053,7 +5053,7 @@ "title": "A script action whose server-side hook refuses the write with a user-facing sentence answers a 4xx, the console shows exactly one error toast carrying that sentence, and the record is left unchanged", "since": "v17.5", "status": "active", - "revision": 2, + "revision": 3, "priority": "P2", "surface": "browser", "personas": [ @@ -5062,7 +5062,7 @@ "fixtures": { "app": "showcase", "requires": [ - "the refusal pair on showcase_task: the hook showcase_guard_task_reopen (examples/app-showcase/src/data/hooks/index.ts — beforeUpdate, condition previous.done == true && record.done != true, sandboxed body throws new Error(TASK_REOPEN_REFUSAL), onError:'abort') and the script action showcase_reopen_task (examples/app-showcase/src/ui/actions/index.ts — body writes { id, done: false } through ctx.api, execution perRecord, visible 'has(record.done) && record.done == true', locations list_item only — the Task Detail page is kind:'full' and renders no record_header bar)", + "the refusal pair on showcase_task: the hook showcase_guard_task_reopen (examples/app-showcase/src/data/hooks/index.ts — beforeUpdate, condition previous.done == true && record.done != true, sandboxed body throws new Error(TASK_REOPEN_REFUSAL), onError:'abort') and the action showcase_reopen_task (examples/app-showcase/src/ui/actions/index.ts — a declared record write: operation 'update' with patch { done: false } and no body, which the action route performs as the caller, execution perRecord, visible 'has(record.done) && record.done == true', locations list_item only — the Task Detail page is kind:'full' and renders no record_header bar)", "the refusal sentence, verbatim: 'A finished task cannot be reopened. Create a follow-up task instead.' (TASK_REOPEN_REFUSAL in the hooks file — re-read it there before the run, never from this line)", "a seeded FINISHED task (done: true) — 'Audit current IA' or 'App wireframes' (examples/app-showcase/src/data/seed/index.ts) — which is the only kind of record the action is offered on", "a console built at this repo's .objectui-sha (pnpm objectui:build), served by the same boot the run drives", @@ -5123,10 +5123,10 @@ ], "source": [ "examples/app-showcase/src/data/hooks/index.ts#GuardTaskReopenHook (the refusing beforeUpdate hook; the sentence is TASK_REOPEN_REFUSAL in the same file)", - "examples/app-showcase/src/ui/actions/index.ts#ReopenTaskAction (the script action whose ctx.api write the hook refuses)", + "examples/app-showcase/src/ui/actions/index.ts#ReopenTaskAction (the action whose declared write, performed by the action route as the caller, the hook refuses)", "examples/app-showcase/test/task-reopen-hook-refusal.test.ts (pins the fixture: the hook refuses with the sentence and leaves the row unchanged on the real engine, and the action writes the refused shape)", - "packages/runtime/src/sandbox/quickjs-runner.ts#sandboxRefusalMessage (a nested sandboxed hook refusal keeps its business message across the action VM hop, so the action route answers 4xx — #17265 / PR #17679)", - "packages/runtime/src/sandbox/nested-hook-refusal-is-a-rejection.test.ts (the wire half: 400 VALIDATION_ERROR with the sentence, unit-level)", + "packages/runtime/src/domains/actions.ts (the declarative-update branch runs inside the route's one catch, which serves a data-plane refusal with its own status and code: the hook's refusal arrives as 400 VALIDATION_ERROR carrying the sentence, the answer /data gives the same write since #11588)", + "packages/qa/dogfood/test/showcase-record-write-actions.dogfood.test.ts (the wire half over real HTTP on the stock showcase: a caller who may edit the task gets a 4xx carrying the sentence and the task stays finished; a caller who may not edit it is refused 403 before the hook is reached)", "objectui packages/app-shell/src/utils/__tests__/consoleServerAction.errorToast.test.ts (objectui#9252 — the console failure chain characterized end to end with the transport stubbed)", "objectui packages/app-shell/src/chrome/ConsoleToaster.tsx (sonner Toaster: richColors, duration 4000, toast nodes carry data-sonner-toast and data-type)", "objectui#9151 (the zero-toast symptom this item re-observes on a current build); #21596 (this item)" @@ -5143,6 +5143,12 @@ "date": "2026-10-20", "change": "steps[0] respelled: 'boot the showcase isolated (RUNNER canonical boot line: own port, own file DB, --seed-admin)' → 'boot the showcase with RUNNER's canonical checklist boot (own port, own file DB, --seed-admin)'. Round 12's out-of-scope finding (landing record 6287983829 on wave anchor #24579): the phrase 'showcase isolated' named the dogfood §0 own-port boot, and a runner read it as the `isolated` tenancy posture (OS_TENANCY_POSTURE=isolated). The new spelling names that boot by what it is, in RUNNER.md's own words for it (the trap table's counter: own port/DB, skill §0), and names no posture. Read at base e4d604efd3. No clause changed", "ref": "#25003" + }, + { + "revision": 3, + "date": "2026-10-23", + "change": "fixtures.requires[0] and source respelled for #25468: showcase_reopen_task no longer writes from a script body through ctx.api (an elevated write); it declares its write (operation 'update', patch { done: false }), which the action route performs as the caller, so the hook now refuses the caller's own update and the nested action-VM hop is gone from this path. Its type stays 'script', the schema default. The answer is unchanged: measured on a dogfood boot of the change, the seeded admin's Reopen on a finished task answers 400 VALIDATION_ERROR whose error.message is TASK_REOPEN_REFUSAL, and the console dispatches an operation 'update' action through the same registered script handler (objectui ActionRunner.executeUpdateOperation at the .objectui-sha pin 6fb31dc), so the toast chain knownGaps[0] cites is the one this item observes. The two source rows for the nested action-VM hop (quickjs-runner.ts#sandboxRefusalMessage and the unit pin nested-hook-refusal-is-a-rejection.test.ts) no longer describe this path and leave source; the route's catch in domains/actions.ts and the dogfood pin showcase-record-write-actions.dogfood.test.ts replace them. No clause changed", + "ref": "#25468" } ] }, From 3027e0a3934db2c01b7e49cdf1252fa3ba01376e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 19:11:22 +0000 Subject: [PATCH 4/4] docs(qa): the enabled control on a nonexistent record id answers 404, so the disabled-dispatch item no longer says it cannot Claude-Session: https://claude.ai/code/session_01SGzB5Np4fydLKpGjZm1dNr Co-authored-by: Claude --- docs/qa/platform-checklist/areas/api-backend.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/qa/platform-checklist/areas/api-backend.json b/docs/qa/platform-checklist/areas/api-backend.json index c7b94bff1f5..f0094375910 100644 --- a/docs/qa/platform-checklist/areas/api-backend.json +++ b/docs/qa/platform-checklist/areas/api-backend.json @@ -1624,7 +1624,7 @@ ], "knownGaps": [ "The MCP door cannot be driven live with showcase_mark_done: the bridge's AI-exposure gate (actionAiExposureError, fail-closed on ai.exposed !== true) sits AHEAD of the activation consult, so a non-exposed action answers the exposure refusal regardless of its switch. showcase_portfolio_snapshot is the only stock ai.exposed action. The MCP transport IS drivable live on a stock boot: the boot banner prints `MCP: http://localhost:/api/v1/mcp`, and QA run #21056 drove POST /api/v1/mcp tools/call run_action against showcase_portfolio_snapshot (disabled → isError carrying code ACTION_DISABLED, status 409; re-enabled → ok). Score the MCP clause live. Where the endpoint is not mounted, record acceptance[4] blocked(environment), with the unit pin cited beside it: action-activation-dispatch.test.ts 'door 2' calls invokeBusinessAction in-process over a stubbed engine and metadata service, with no MCP transport and no HTTP, so it is evidence of that layer only, never the clause's pass (RUNNER rule 6, a pin scores only the layer it drives).", - "The record-load half of the ordering proof has NO contrasting refusal: the REST door's record load is best-effort (try/catch in domains/actions.ts — a missing record passes an empty record for new-record actions), so a nonexistent recordId never 404s on its own, enabled or disabled. The record leg is proven by code order plus the absence of any read/side effect, never by expecting a 404 from the enabled control." + "The record-load half of the ordering proof is scored from the DISABLED traces: code order plus the absence of any read/side effect. An enabled control on the same nonexistent recordId answers 404 RECORD_NOT_FOUND, because every door refuses a subject the caller-scope load did not deliver (refuseDeniedSubjectLoad, packages/runtime/src/action-execution.ts — the script/body door, the flow door and the declarative branch Mark Done now takes all call it; measured on a dogfood boot of #25468: enabled 404, disabled 409, same id). That 404 corroborates the order but is not the leg's evidence. The load itself is still caught (loadActionSubjectRecord), so a new-record or object-less action, which attempts no load, never 404s." ] }, "steps": [ @@ -1651,9 +1651,9 @@ "evidence": "both traces side by side" }, { - "clause": "the consult also precedes the record load, proven by absence not by a contrasting refusal: the 409 arrives with a nonexistent recordId in play and no record read occurs — the enabled control CANNOT 404 on the bad id because the load is best-effort by design (domains/actions.ts catches and passes an empty record), so do not score this leg by expecting one", + "clause": "the consult also precedes the record load, proven by absence: the 409 arrives with a nonexistent recordId in play and no record read occurs. The enabled control on the same id answers 404 RECORD_NOT_FOUND (the caller-scope load's refusal, fixtures.knownGaps[1]), which corroborates the order but does not score this leg", "oracle": "api", - "verify": "the step-3/4 disabled traces are 409 with the bogus recordId present; the run record notes the enabled-control caveat rather than a fabricated 404 expectation", + "verify": "the step-3/4 disabled traces are 409 with the bogus recordId present; an enabled-control 404, when captured, is recorded beside them as corroboration, never as the verdict", "evidence": "traces + run-record note" }, { @@ -1752,7 +1752,7 @@ { "revision": 7, "date": "2026-10-23", - "change": "fixtures.requires[0] and acceptance[0] respelled for #25468: showcase_mark_done is no longer a script action with a registered body; it declares its write (operation 'update', patch { done: true, progress: 100 }), which the action route performs as the caller. Its type stays 'script', the schema default, and it still declares no params and no requiredPermissions, so it is still the clean 409 probe: the activation consult runs ahead of the declarative branch in packages/runtime/src/domains/actions.ts (read at base aa2dbab7b; measured on a dogfood boot of the change: disabled with a nonexistent recordId answers 409 ACTION_DISABLED). No clause changed", + "change": "fixtures.requires[0] and acceptance[0] respelled for #25468: showcase_mark_done is no longer a script action with a registered body; it declares its write (operation 'update', patch { done: true, progress: 100 }), which the action route performs as the caller. Its type stays 'script', the schema default, and it still declares no params and no requiredPermissions, so it is still the clean 409 probe: the activation consult runs ahead of the declarative branch in packages/runtime/src/domains/actions.ts (read at base aa2dbab7b; measured on a dogfood boot of the change: disabled with a nonexistent recordId answers 409 ACTION_DISABLED). The same boot answered the ENABLED control on that id 404 RECORD_NOT_FOUND, which falsified fixtures.knownGaps[1] and acceptance[2]'s 'the enabled control CANNOT 404': every door now consumes the caller-scope load's verdict through refuseDeniedSubjectLoad (action-execution.ts), the script/body door included, so the text was already stale for a script body and stays false for the declared write. Both are respelled; acceptance[2] still scores from the disabled traces alone, and the enabled 404 is corroboration only. acceptance[2]'s clause text changed, its verdict basis did not", "ref": "#25468" } ]