From 57db934e3c44e978d5a6e4a99737ca4f2469658c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:12:26 +0000 Subject: [PATCH 1/6] fix(runtime): a declarative update action answers its write's notice and droppedFields The data door answers the message a hook set for the person (notice) and the fields the engine did not store (droppedFields); the action executor now carries both onto its answer, at the REST and MCP doors alike, beside the warnings it already carried. Claude-Session: https://claude.ai/code/session_01L9qibwKycKW36n75AWgepd Co-authored-by: Claude --- .../src/action-declarative-update.test.ts | 157 ++++++++++++++++++ packages/runtime/src/action-execution.ts | 47 ++++-- 2 files changed, 193 insertions(+), 11 deletions(-) diff --git a/packages/runtime/src/action-declarative-update.test.ts b/packages/runtime/src/action-declarative-update.test.ts index f9bb3edccc8..e0b6ec025f3 100644 --- a/packages/runtime/src/action-declarative-update.test.ts +++ b/packages/runtime/src/action-declarative-update.test.ts @@ -46,6 +46,10 @@ import { assertEngineUpdateDispatch } from '@objectstack/metadata-core'; // loads it lazily (check:test-source-alias). import '@objectstack/metadata'; +import { ObjectQL } from '@objectstack/objectql'; +import { InMemoryDriver } from '@objectstack/driver-memory'; +import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; + import { HttpDispatcher } from './http-dispatcher.js'; import { callData, @@ -902,3 +906,156 @@ describe('#37867 — a declarative update answers the `warnings` its data-plane expect('warnings' in res.body.data).toBe(false); }); }); + +// ─────────────────────────────────────────────────────────────────────────── +// [#38103] The write's `notice` and `droppedFields` ride the action's answer +// ─────────────────────────────────────────────────────────────────────────── + +/** + * A hook on the write tells the person what it set in motion (`ctx.notice`), + * and the engine reports every field it did not store (`droppedFields`); the + * data door answers both (`protocol.updateData`). A button that performs the + * same write answers the same, at both doors — or the hook's message reaches + * only people who edit the form, and a field the engine stripped from the + * action's `patch` is answered as a plain success. + * + * Unlike the blocks above, nothing here is a double: a REAL `ObjectQL` engine + * on the REAL `InMemoryDriver`, the REAL `ObjectStackProtocolImplementation` + * as the `protocol` service, and an object whose `closed_reason` is + * `readonly: true` — the strip, the hook's message and the data door's answer + * are the producers' own. Each case compares the action's answer with the + * data door's answer to the SAME write on a fresh engine. + */ +describe('#38103 — a declarative update answers the `notice` and `droppedFields` of its data-plane write', () => { + const FB_OBJECT = 'fb_case'; + const FB_RECORD = 'fbc_1'; + const NOTICE = 'Closing this case notified the customer.'; + const CLOSE_WITH_REASON = { + name: 'close_with_reason', + label: 'Close', + operation: 'update', + // `closed_reason` is `readonly: true`: the engine strips it from the caller's write. + patch: { status: 'closed', closed_reason: 'resolved' }, + ai: { exposed: true, description: 'Close this support case and record why it was closed.' }, + }; + const SET_PRIORITY = { + name: 'set_priority', + label: 'Set priority', + operation: 'update', + patch: { priority: 'high' }, + ai: { exposed: true, description: 'Raise the priority of this support case to high.' }, + }; + const FB_OBJECT_DEF: any = { + name: FB_OBJECT, + fields: { + status: { type: 'text' }, + priority: { type: 'text' }, + closed_reason: { type: 'text', readonly: true }, + }, + actions: [CLOSE_WITH_REASON, SET_PRIORITY], + }; + const quiet = { info() {}, debug() {}, warn() {}, error() {} }; + + async function boot() { + const engine = new ObjectQL({ logger: quiet } as any); + engine.registerDriver(new InMemoryDriver() as any, true); + await engine.init(); + engine.registry.registerObject(FB_OBJECT_DEF as never, 'com.objectstack.test.38103'); + // The hook says what closing did, from the write it is handed. + engine.registerHook('beforeUpdate', async (ctx: any) => { + if (ctx.input?.data?.status === 'closed') ctx.notice(NOTICE); + }, { object: FB_OBJECT }); + await engine.insert(FB_OBJECT, { id: FB_RECORD, status: 'open', priority: 'low' }, { context: { isSystem: true } } as any); + const protocol = new ObjectStackProtocolImplementation(engine as never); + return { engine, protocol }; + } + + /** The data door's own answer to the write the action makes, on a fresh engine. */ + async function dataDoorAnswer(patch: Record) { + const { protocol } = await boot(); + return await protocol.updateData({ object: FB_OBJECT, id: FB_RECORD, data: patch, context: ec(OWNER) } as any) as any; + } + + async function restOn(path: string) { + const { engine, protocol } = await boot(); + const metadata: any = { + load: vi.fn(async () => null), + loadDiagnosed: vi.fn(async () => ({ data: null, degraded: false, errors: [] })), + listObjects: vi.fn(async () => [FB_OBJECT_DEF]), + getObject: vi.fn(async (n: string) => (n === FB_OBJECT ? FB_OBJECT_DEF : undefined)), + }; + const kernel: any = { + context: { + getService: (n: string) => + n === 'objectql' || n === 'data' ? engine + : n === 'metadata' ? metadata + : n === 'protocol' ? protocol + : null, + }, + }; + const context: any = { request: {}, environmentId: 'platform', executionContext: ec(OWNER) }; + const res: any = await (new HttpDispatcher(kernel) as any).handleActions(path, 'POST', {}, context); + const stored: any = await engine.findOne(FB_OBJECT, { where: { id: FB_RECORD }, context: { isSystem: true } } as any); + return { response: res.response, stored }; + } + + async function mcpOn(name: string) { + const { engine, protocol } = await boot(); + const deps: any = { + resolveService: async (_ctx: unknown, n: string) => (n === 'protocol' ? protocol : undefined), + getObjectQL: async () => engine, + }; + const requestContext: any = { request: {}, environmentId: 'platform' }; + return await invokeBusinessAction(deps, requestContext, name, { recordId: FB_RECORD } as any, { + driver: undefined, + envId: 'platform', + ec: ec(OWNER), + getMeta: () => ({ listObjects: async () => [FB_OBJECT_DEF] }), + callData: (action, params, dataDriver, scopeId, execCtx) => + callData(deps, requestContext, action, params, dataDriver, scopeId, execCtx), + }) as any; + } + + it('control: the data door answers the hook\'s notice and the stripped field for this write', async () => { + const answer = await dataDoorAnswer(CLOSE_WITH_REASON.patch); + expect(answer.notice).toBe(NOTICE); + expect(answer.droppedFields).toEqual([{ object: FB_OBJECT, fields: ['closed_reason'], reason: 'readonly' }]); + }); + + it('REST: the 200 answer carries the same `notice` and `droppedFields` as the data door', async () => { + const door = await dataDoorAnswer(CLOSE_WITH_REASON.patch); + const { response, stored } = await restOn(`/${FB_OBJECT}/close_with_reason/${FB_RECORD}`); + + expect(response.status).toBe(200); + expect(response.body.success).toBe(true); + expect(response.body.data).toMatchObject({ operation: DECLARATIVE_UPDATE_OPERATION, object: FB_OBJECT, id: FB_RECORD }); + expect(response.body.data.notice).toBe(door.notice); + expect(response.body.data.droppedFields).toEqual(door.droppedFields); + // The strip is real: the row took `status` and not `closed_reason`. + expect(stored.status).toBe('closed'); + expect(stored.closed_reason ?? null).toBeNull(); + }); + + it('MCP `run_action`: the same write answers the same `notice` and `droppedFields`', async () => { + const door = await dataDoorAnswer(CLOSE_WITH_REASON.patch); + const out = await mcpOn('close_with_reason'); + + expect(out.ok).toBe(true); + expect(out.result.notice).toBe(door.notice); + expect(out.result.droppedFields).toEqual(door.droppedFields); + }); + + it('a write no hook spoke on and nothing was stripped from carries neither key', async () => { + // ABSENT, never `''` or `[]` — the data door's own shape; the firing + // positive control is the REST case above, same engine and object. + const door = await dataDoorAnswer(SET_PRIORITY.patch); + expect('notice' in door).toBe(false); + expect('droppedFields' in door).toBe(false); + + const { response, stored } = await restOn(`/${FB_OBJECT}/set_priority/${FB_RECORD}`); + expect(response.status).toBe(200); + expect(stored.priority).toBe('high'); + expect('notice' in response.body.data).toBe(false); + expect('droppedFields' in response.body.data).toBe(false); + }); +}); diff --git a/packages/runtime/src/action-execution.ts b/packages/runtime/src/action-execution.ts index 00d16746167..ef9dd6cb740 100644 --- a/packages/runtime/src/action-execution.ts +++ b/packages/runtime/src/action-execution.ts @@ -19,7 +19,7 @@ import { ACTION_PARAM_BUILTIN_KEYS, validateActionParams, resolveI18nLabel, type import { templateSlotSource } from '@objectstack/spec/automation'; // [#15124] The facade's `find` judges its own parameter against the SAME // declaration its type names, so the refusal and the type cannot drift apart. -import { EngineQueryOptionsSchema, DATA_ACTION_TO_API_OPERATION } from '@objectstack/spec/data'; +import { EngineQueryOptionsSchema, DATA_ACTION_TO_API_OPERATION, type DroppedFieldsEvent } from '@objectstack/spec/data'; import type { ExecutionContext } from '@objectstack/spec/kernel'; import { isStoredMetadataBodyObject } from '@objectstack/spec/kernel'; import type { IHttpServer, IObjectQLEngine, InternalFieldEvaluationQuery, QueryEvaluationGate, ServiceSlotContract, ServiceSlotContracts } from '@objectstack/spec/contracts'; @@ -5030,18 +5030,40 @@ export interface DeclarativeUpdateResult { * answers the same warnings whichever door the person used. */ warnings?: ValidateDataIssue[]; + /** + * [#38103] The one message a hook on THIS write set for the person who made + * it (`ctx.notice`), exactly as the data-plane update answered it. Present + * only when a hook set one: the same hook on the same write tells the + * person the same thing whichever door they used. + */ + notice?: string; + /** + * [#38103] The fields the engine did NOT store from this write (a static + * `readonly`, a true `readonlyWhen`, …), exactly as the data-plane update + * answered them — the element is the engine's own `DroppedFieldsEvent`. + * Present only when a field was dropped: without it the answer reads as a + * success that wrote everything the action declared. + */ + droppedFields?: DroppedFieldsEvent[]; } /** - * [#37867] The `warnings` a data-plane write answer carries, or `undefined` - * when it carries none. The protocol's `updateData` sets the member only when - * the write raised an advisory rule hit, so an empty or absent member answers - * the same: no warnings. Only the protocol arm of `callData` produces it; the - * ObjectQL fallback arm answers none, and this reads none from it. + * [#37867, #38103] What a data-plane write answer tells the person beyond the + * written row: its advisory `warnings`, the `notice` a hook set and the + * `droppedFields` the engine stripped — each only when the answer carries it. + * The protocol's `updateData` sets every one of these members only when there + * is something to say, so an empty or absent member answers the same: nothing. + * Only the protocol arm of `callData` produces them; the ObjectQL fallback arm + * answers none, and this reads none from it. */ -function writeAnswerWarnings(written: unknown): ValidateDataIssue[] | undefined { - const warnings = (written as { warnings?: unknown } | null | undefined)?.warnings; - return Array.isArray(warnings) && warnings.length > 0 ? (warnings as ValidateDataIssue[]) : undefined; +function writeAnswerFeedback(written: unknown): Pick { + const answer = (written ?? undefined) as { warnings?: unknown; notice?: unknown; droppedFields?: unknown } | undefined; + const { warnings, notice, droppedFields } = answer && typeof answer === 'object' ? answer : {}; + return { + ...(Array.isArray(warnings) && warnings.length > 0 ? { warnings: warnings as ValidateDataIssue[] } : {}), + ...(typeof notice === 'string' && notice.trim() !== '' ? { notice } : {}), + ...(Array.isArray(droppedFields) && droppedFields.length > 0 ? { droppedFields: droppedFields as DroppedFieldsEvent[] } : {}), + }; } /** @@ -5299,7 +5321,10 @@ export async function executeDeclarativeUpdateAction( // lets the save through and tells the person; the data door answers it as // `warnings`, and a button that performs the same write owes the same // answer, or the warning holds only for people who edit the form. - const warnings = writeAnswerWarnings(written); + // [#38103] So do the hook's `notice` and the engine's `droppedFields`: a + // field the engine stripped from the action's patch answered as a bare + // success is a silent field loss. + const feedback = writeAnswerFeedback(written); const result: DeclarativeUpdateResult = { operation: DECLARATIVE_UPDATE_OPERATION, @@ -5307,7 +5332,7 @@ export async function executeDeclarativeUpdateAction( id: recordId, record, ...(undo ? { undo } : {}), - ...(warnings ? { warnings } : {}), + ...feedback, }; if (stale) throw withEarnedAnswer(stale, { ...result }); return result; From c9f9891fb1b220c6f29efb899794ef49072f8e42 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:15:53 +0000 Subject: [PATCH 2/6] wip(ui): the action toast leads with the write's notice; stripped fields get the record save's toast Claude-Session: https://claude.ai/code/session_01L9qibwKycKW36n75AWgepd Co-authored-by: Claude --- .../src/hooks/useConsoleActionRuntime.tsx | 35 +++++++--- ui/packages/app-shell/src/utils/flowLaunch.ts | 68 +++++++++++++++++-- .../app-shell/src/views/RecordDetailView.tsx | 35 +++++++--- ui/packages/core/src/actions/ActionRunner.ts | 48 ++++++++++--- 4 files changed, 154 insertions(+), 32 deletions(-) diff --git a/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx b/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx index 65d898e5aaf..123ef756980 100644 --- a/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx +++ b/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx @@ -52,7 +52,7 @@ import { resolveActionParams, withKnownObjects } from '@object-ui/fields'; import { EnvironmentEntitlementDialog, type EntitlementDialogState } from '../environment/EnvironmentEntitlementDialog.js'; import { entitlementDialogFromError, type EntitlementDialogSpec } from '../environment/entitlements.js'; import { resolvePageVarTokens } from '../utils/resolvePageVarTokens.js'; -import { launchConsoleFlow } from '../utils/flowLaunch.js'; +import { launchConsoleFlow, withAnnouncedUpdateDroppedFields } from '../utils/flowLaunch.js'; import { useScreenFlowQueue } from './useScreenFlowQueue.js'; import type { TranslateFn } from '@object-ui/i18n'; import { apiActionRefusalResult } from '../utils/flowResponse.js'; @@ -412,14 +412,24 @@ export function useConsoleActionRuntime(opts: ConsoleActionRuntimeOptions): Cons }); return; } - if (options?.undo) { - toast.success(message, { + // objectstack#38103 — the notice a hook on the write set, alone, when the + // runner's success toast is off: the hook's words as an info toast. + if (options?.type === 'info') { + toast.info(message, { duration: options.duration, - action: { label: options.undo.label || 'Undo', onClick: () => { void undoCtl.undo(); } }, + ...(options.description ? { description: options.description } : {}), }); return; } - toast.success(message, { duration: options?.duration }); + // A success toast carries the write's notice under the title when a hook + // set one (objectstack#38103), and the Undo button when the action has one. + toast.success(message, { + duration: options?.duration, + ...(options?.description ? { description: options.description } : {}), + ...(options?.undo + ? { action: { label: options.undo.label || 'Undo', onClick: () => { void undoCtl.undo(); } } } + : {}), + }); }, [undoCtl]); // The app an in-place hop is hosted under (objectui#13379): the inbox's own @@ -864,10 +874,13 @@ export function useConsoleActionRuntime(opts: ConsoleActionRuntimeOptions): Cons // memoized once) while the config thunks read the latest object scope and // refresh callback — the factory's in-flight guard only spans invocations of // the same instance. - const serverActionEnvRef = useRef({ objApiName, refresh, t, navigate }); - serverActionEnvRef.current = { objApiName, refresh, t, navigate }; + const serverActionEnvRef = useRef({ objApiName, refresh, t, navigate, fieldLabel, dataSource }); + serverActionEnvRef.current = { objApiName, refresh, t, navigate, fieldLabel, dataSource }; + // objectstack#38103 — a declarative update action's stripped fields get the + // record save's own stripped-fields toast, beside the action's toast (see + // `withAnnouncedUpdateDroppedFields`), labelled through this host's data source. const serverActionHandler = useMemo( - () => createConsoleServerActionHandler({ + () => withAnnouncedUpdateDroppedFields(createConsoleServerActionHandler({ fetch: authFetch, baseUrl: () => import.meta.env.VITE_SERVER_URL || '', resolveObject: () => serverActionEnvRef.current.objApiName, @@ -881,7 +894,11 @@ export function useConsoleActionRuntime(opts: ConsoleActionRuntimeOptions): Cons // (objectui#3321). t: (key, englishDefault, values) => String(serverActionEnvRef.current.t(key, { defaultValue: englishDefault, ...values })), - }), + }), () => ({ + t: serverActionEnvRef.current.t as TranslateFn, + fieldLabel: serverActionEnvRef.current.fieldLabel, + dataSource: serverActionEnvRef.current.dataSource, + })), [authFetch], ); diff --git a/ui/packages/app-shell/src/utils/flowLaunch.ts b/ui/packages/app-shell/src/utils/flowLaunch.ts index 48bce93f237..78fe8f411c4 100644 --- a/ui/packages/app-shell/src/utils/flowLaunch.ts +++ b/ui/packages/app-shell/src/utils/flowLaunch.ts @@ -86,8 +86,8 @@ */ import { toast } from 'sonner'; -import { createServerActionHandler } from '@object-ui/core'; -import type { ActionDef, ActionResult, ServerActionFetch } from '@object-ui/core'; +import { createServerActionHandler, readActionPayload } from '@object-ui/core'; +import type { ActionContext, ActionDef, ActionResult, ServerActionFetch, ServerActionHandler } from '@object-ui/core'; import { asDroppedFieldsNotice, isWireDroppedFieldsEntry, @@ -166,7 +166,16 @@ export interface FlowDroppedFieldsContext { * in wire order; empty when the answer carries none. */ export function flowAnswerDroppedFields(json: unknown): DroppedFieldsNotice[] { - const wire = (json as { data?: { droppedFields?: unknown } } | null | undefined)?.data?.droppedFields; + return parseDroppedFields((json as { data?: { droppedFields?: unknown } } | null | undefined)?.data?.droppedFields); +} + +/** + * An answer's `droppedFields` member, parsed, in wire order; empty when it is + * absent or not an array. The ONE parse every answer reader here goes + * through: a flow run's (`AutomationResult.droppedFields`) and a declarative + * update action's (objectstack#38103), both the data engine's own events. + */ +function parseDroppedFields(wire: unknown): DroppedFieldsNotice[] { if (!Array.isArray(wire)) return []; return wire .filter(isWireDroppedFieldsEntry) @@ -190,9 +199,21 @@ export async function announceFlowDroppedFields( json: unknown, ctx: FlowDroppedFieldsContext, sink: WriteWarningSink = toast, +): Promise { + await announceDroppedFields(flowAnswerDroppedFields(json), ctx, sink); +} + +/** + * The reader both answer kinds speak through: one `emitWriteWarning` per + * object the notices name, nothing when there are none. Never throws. + */ +async function announceDroppedFields( + notices: readonly DroppedFieldsNotice[], + ctx: FlowDroppedFieldsContext, + sink: WriteWarningSink, ): Promise { const byObject = new Map(); - for (const notice of flowAnswerDroppedFields(json)) { + for (const notice of notices) { const object = notice.object ?? UNATTRIBUTED_FLOW_DROP; byObject.set(object, [...(byObject.get(object) ?? []), notice]); } @@ -215,6 +236,45 @@ export async function announceFlowDroppedFields( } } +/** + * A host's server-action handler that also warns about the fields a + * declarative update action's write did not store (objectstack#38103). + * + * An `operation: 'update'` action's answer carries the data write's + * `droppedFields` (the engine's own events, the member a record save's answer + * carries) when the engine stripped a field from the action's `patch`. The + * person who clicked is warned with the record save's own stripped-fields + * toast ("Saved — but some fields did not take effect"), beside the action's + * own toast and never folded into it — the same second toast a record save and + * a flow button raise, whatever the action's `toast` settings say, because the + * author's switch is about the success message, not about a value that was + * lost. Not on a failed dispatch, and not for any other action: only the + * update answer declares the member, so a script's own `droppedFields` key is + * never read as one. + * + * `ctx` is a thunk so the host's live translator, label convention and data + * source are read per dispatch while the handler instance stays stable. The + * handler's members (`refuseBeforeInput`) are kept. + */ +export function withAnnouncedUpdateDroppedFields( + handler: ServerActionHandler, + ctx: () => FlowDroppedFieldsContext, + sink: WriteWarningSink = toast, +): ServerActionHandler { + const wrapped = async (action: ActionDef, context?: ActionContext): Promise => { + const result = await handler(action, context); + if (result.success && action.operation === 'update') { + const payload = readActionPayload(result.data) as { droppedFields?: unknown } | null | undefined; + const notices = parseDroppedFields(payload && typeof payload === 'object' ? payload.droppedFields : undefined); + // Not awaited: the label lookup must not hold the click's outcome, and + // the reader never rejects. + if (notices.length > 0) void announceDroppedFields(notices, ctx(), sink); + } + return result; + }; + return Object.assign(wrapped, { refuseBeforeInput: handler.refuseBeforeInput }); +} + /** The door a flow click went through. */ export type ConsoleFlowLaunchDoor = 'action' | 'trigger'; diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index f3568785f25..675ed418789 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -81,7 +81,7 @@ import { DesignModeHeaderPins, useObjectPins } from '../layout/DesignModeHeaderP import { headerReadsPins } from '../layout/designModeHeaderPinsModel.js'; import { useDesignModeActive } from '../layout/designMode.js'; import { recycleBinRefusalLabelsOf, recycleBinRestoreOf } from '../utils/recycleBinRestore.js'; -import { launchConsoleFlow } from '../utils/flowLaunch.js'; +import { launchConsoleFlow, withAnnouncedUpdateDroppedFields } from '../utils/flowLaunch.js'; import type { TranslateFn } from '@object-ui/i18n'; import { apiActionRefusalResult } from '../utils/flowResponse.js'; import { invitationVerifyEmailPromptPath, isAcceptNeedsVerifiedEmail } from '../console/organizations/orgErrorMessage.js'; @@ -1961,14 +1961,24 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri }); return; } - if (options?.undo) { - toast.success(message, { + // objectstack#38103 — the notice a hook on the write set, alone, when the + // runner's success toast is off: the hook's words as an info toast. + if (options?.type === 'info') { + toast.info(message, { duration: options.duration, - action: { label: options.undo.label || 'Undo', onClick: () => { void undoCtl.undo(); } }, + ...(options.description ? { description: options.description } : {}), }); return; } - toast.success(message, { duration: options?.duration }); + // A success toast carries the write's notice under the title when a hook + // set one (objectstack#38103), and the Undo button when the action has one. + toast.success(message, { + duration: options?.duration, + ...(options?.description ? { description: options.description } : {}), + ...(options?.undo + ? { action: { label: options.undo.label || 'Undo', onClick: () => { void undoCtl.undo(); } } } + : {}), + }); }, [undoCtl]); // The app an in-place hop from this page is hosted under (objectui#13396). @@ -2392,10 +2402,13 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri // `action.recordId`; header/more actions carry none and use this page's id. // The env ref keeps the handler instance stable across renders (authFetch is // memoized once) while the thunks read the live record/object. - const serverActionEnvRef = useRef({ objectName, pureRecordId, notifyViewChanged, t, navigate }); - serverActionEnvRef.current = { objectName, pureRecordId, notifyViewChanged, t, navigate }; + const serverActionEnvRef = useRef({ objectName, pureRecordId, notifyViewChanged, t, navigate, fieldLabel, dataSource }); + serverActionEnvRef.current = { objectName, pureRecordId, notifyViewChanged, t, navigate, fieldLabel, dataSource }; + // objectstack#38103 — a declarative update action's stripped fields get the + // record save's own stripped-fields toast, beside the action's toast (see + // `withAnnouncedUpdateDroppedFields`), labelled through this host's data source. const serverActionHandler = useMemo( - () => createConsoleServerActionHandler({ + () => withAnnouncedUpdateDroppedFields(createConsoleServerActionHandler({ fetch: authFetch, baseUrl: () => import.meta.env.VITE_SERVER_URL || '', resolveObject: () => serverActionEnvRef.current.objectName, @@ -2411,7 +2424,11 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri // (objectui#3321). t: (key, englishDefault, values) => String(serverActionEnvRef.current.t(key, { defaultValue: englishDefault, ...values })), - }), + }), () => ({ + t: serverActionEnvRef.current.t as TranslateFn, + fieldLabel: serverActionEnvRef.current.fieldLabel, + dataSource: serverActionEnvRef.current.dataSource, + })), [authFetch], ); diff --git a/ui/packages/core/src/actions/ActionRunner.ts b/ui/packages/core/src/actions/ActionRunner.ts index 712ed73688b..5c9e9ab0170 100644 --- a/ui/packages/core/src/actions/ActionRunner.ts +++ b/ui/packages/core/src/actions/ActionRunner.ts @@ -638,9 +638,11 @@ export type ConfirmationHandler = (message: string, options?: { export type ToastHandler = (message: string, options?: { type?: 'success' | 'error' | 'info' | 'warning'; duration?: number; - /** A second line under `message`, one entry per line (`\n`-joined). Set on - * a `warning` toast to carry the warnings of the write the action made - * (objectstack#37867), as a record save's toast carries them. */ + /** A second line under `message`, one entry per line (`\n`-joined). Carries + * what the write the action made told the person beyond "done": the + * `notice` a hook set (objectstack#38103), then the write's warnings + * (objectstack#37867), as a record save's toast carries them. A toast with + * warnings is a `warning` one; a notice alone keeps it a `success`. */ description?: string; /** When set, the toast offers an "Undo" affordance (the runner has already * pushed the operation onto the global UndoManager). */ @@ -1312,6 +1314,24 @@ function updateAnswerWarningLines(action: ActionDef, result: ActionResult): stri return lines; } +/** + * The message a hook on an `operation: 'update'` action's write set for the + * person who clicked (`ctx.notice` on the server, objectstack#38103), or + * `undefined` when it set none. + * + * The route's declarative-update answer carries it as `notice` exactly as the + * data door answers a record save, and a record save's one toast leads with it + * (`@object-ui/react`'s `toastRecordSave`, which this package sits below and + * cannot import): it reports an outcome, never a problem. Asked of an update + * action only, for the same reason as {@link updateAnswerWarningLines}. + */ +function updateAnswerNotice(action: ActionDef, result: ActionResult): string | undefined { + if (!isUpdateOperationAction(action)) return undefined; + const payload = readActionPayload(result.data); + const notice = payload && typeof payload === 'object' ? (payload as { notice?: unknown }).notice : undefined; + return typeof notice === 'string' && notice.trim() !== '' ? notice : undefined; +} + /** * The fields an `operation: 'update'` action writes, and their prior values. * @@ -2259,6 +2279,12 @@ export class ActionRunner { // success toast, which then takes the warning variant: one toast, as a // record save raises one. const warnings = result.success ? updateAnswerWarningLines(action, result) : []; + // objectstack#38103 — the notice a hook on the write set leads the same + // toast's lines; alone it keeps the toast a success (`toastRecordSave`'s + // rule). The write's stripped fields are not this toast's: the host + // raises the record save's own stripped-fields toast beside it. + const notice = result.success ? updateAnswerNotice(action, result) : undefined; + const lines = notice !== undefined ? [notice, ...warnings] : warnings; if (result.success && !hasResultDialog && !result.silent && showToast.showOnSuccess !== false) { // The server returns FACTS and the console writes the sentence @@ -2275,17 +2301,19 @@ export class ActionRunner { this.toastHandler(message, { type: warnings.length > 0 ? 'warning' : 'success', duration, - ...(warnings.length > 0 ? { description: warnings.join('\n') } : {}), + ...(lines.length > 0 ? { description: lines.join('\n') } : {}), undo: result.undo ? { label: this.runnerText(RUNNER_TEXT.undo) } : undefined, }); - } else if (warnings.length > 0 && !result.silent) { + } else if (lines.length > 0 && !result.silent) { // The success toast is not shown (the author turned it off, or a - // result dialog replaces it), but a warning is not a success message: - // the rule's author asked for the person to be told. The rule's own - // words are the whole toast, so no runner text is needed for it. - const [first, ...rest] = warnings; + // result dialog replaces it), but a warning or a hook's notice is not + // a success message: the rule's or the hook's author asked for the + // person to be told. Their own words are the whole toast, so no runner + // text is needed for it — a notice alone is an `info` toast, as a + // record save's unclaimed notice is. + const [first, ...rest] = lines; this.toastHandler(first, { - type: 'warning', + type: warnings.length > 0 ? 'warning' : 'info', duration, ...(rest.length > 0 ? { description: rest.join('\n') } : {}), }); From 988eb2c4e2fb6a5812f6f8c33a125b0a0ad08da4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:17:22 +0000 Subject: [PATCH 3/6] test(ui): pin the update action's notice and stripped-fields toasts; changeset Claude-Session: https://claude.ai/code/session_01L9qibwKycKW36n75AWgepd Co-authored-by: Claude --- ...ive-update-action-notice-dropped-fields.md | 17 +++ ...eActionRuntime.undoLookupId-11122.test.tsx | 80 ++++++++++++++ ...cordDetailView.undoLookupId-11122.test.tsx | 29 +++++ .../ActionRunner.updateOperation.test.ts | 101 ++++++++++++++++++ 4 files changed, 227 insertions(+) create mode 100644 .changeset/38103-declarative-update-action-notice-dropped-fields.md diff --git a/.changeset/38103-declarative-update-action-notice-dropped-fields.md b/.changeset/38103-declarative-update-action-notice-dropped-fields.md new file mode 100644 index 00000000000..f7f64676a8d --- /dev/null +++ b/.changeset/38103-declarative-update-action-notice-dropped-fields.md @@ -0,0 +1,17 @@ +--- +'@objectstack/runtime': patch +'@object-ui/core': patch +'@object-ui/app-shell': patch +--- + +Clause-②: yes (widening) +Metadata-protocol: none + +A declarative `operation: 'update'` action now tells the person what its write told a record save: the message a +hook set (`ctx.notice`) and the fields the engine did not store. Before, a field the engine stripped from the +action's `patch` (a `readonly` field, a true `readonlyWhen`) was answered as a plain success, and the hook's message +was lost. The action's answer (`POST /api/v1/actions/:object/:action`, and MCP `run_action`) now carries the write's +`notice` and `droppedFields`, in the data door's own shapes, each present only when the write produced it. The +console's action runner puts the notice under the toast's title (a notice alone keeps the success toast; with the +success toast turned off it is an info toast of its own), and the console raises the record save's own +"Saved — but some fields did not take effect" toast for the stripped fields, with their labels. diff --git a/ui/packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.undoLookupId-11122.test.tsx b/ui/packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.undoLookupId-11122.test.tsx index 6484e5d460e..20ce52cbb17 100644 --- a/ui/packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.undoLookupId-11122.test.tsx +++ b/ui/packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.undoLookupId-11122.test.tsx @@ -347,3 +347,83 @@ describe('grid row — an update whose write raised warnings warns, on one toast await waitFor(() => expect(dataSource.update).toHaveBeenLastCalledWith(OBJECT, 'o1', { account: 'a1' })); }); }); + +describe('grid row — an update\'s notice and stripped fields reach the person (objectstack#38103)', () => { + const NOTICE = 'Reassigning this deal notified the new account owner.'; + const STRIPPED_TITLE = 'Saved — but some fields did not take effect'; + + async function runSetAccount() { + const dataSource = makeDataSource(); + render( + + + + + + + + + , + ); + await waitFor(() => expect(screen.getByText('Deal')).toBeInTheDocument()); + await userEvent.click(await screen.findByTestId('row-action-trigger')); + await userEvent.click(await screen.findByTestId('row-action-set_account')); + return dataSource; + } + + it('the success toast carries the hook\'s notice and Undo; the stripped field gets the record save\'s own toast, labelled', async () => { + routeAnswerData = { + operation: 'update', + object: OBJECT, + id: 'o1', + record: { ...STORED, account: 'a2' }, + notice: NOTICE, + droppedFields: [{ object: OBJECT, fields: ['config'], reason: 'readonly' }], + }; + const dataSource = await runSetAccount(); + + const call = await waitFor(() => { + const found = vi.mocked(toast.success).mock.calls.find(([m]) => m === MESSAGE); + expect(found).toBeTruthy(); + return found!; + }); + const options = call[1] as { description?: string; action?: { onClick: () => void } }; + expect(options.description).toBe(NOTICE); + expect(options.action).toBeDefined(); + + // The stripped field: one warning toast, the record save's title, the field by its label. + await waitFor(() => expect(toast.warning).toHaveBeenCalledTimes(1)); + const [title, stripped] = vi.mocked(toast.warning).mock.calls[0] as [string, { description?: string }]; + expect(title).toBe(STRIPPED_TITLE); + expect(stripped.description).toContain('Config'); + expect(dataSource.getObjectSchema).toHaveBeenCalledWith(OBJECT); + + // The kept Undo is the runtime's real one. + await act(async () => { options.action!.onClick(); }); + await waitFor(() => expect(dataSource.update).toHaveBeenLastCalledWith(OBJECT, 'o1', expect.objectContaining({ account: 'a1' }))); + }); + + it('control: an answer with neither raises the plain success toast and no stripped-fields toast', async () => { + routeAnswerData = { operation: 'update', object: OBJECT, id: 'o1', record: { ...STORED, account: 'a2' } }; + await runSetAccount(); + + const call = await waitFor(() => { + const found = vi.mocked(toast.success).mock.calls.find(([m]) => m === MESSAGE); + expect(found).toBeTruthy(); + return found!; + }); + expect((call[1] as { description?: string }).description).toBeUndefined(); + expect(toast.warning).not.toHaveBeenCalled(); + }); +}); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.undoLookupId-11122.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.undoLookupId-11122.test.tsx index e64698fba0f..3188c30dfec 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.undoLookupId-11122.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.undoLookupId-11122.test.tsx @@ -344,3 +344,32 @@ describe('record page — an update whose write raised warnings warns, on one to await waitFor(() => expect(dataSource.update).toHaveBeenLastCalledWith(OBJECT_NAME, RECORD_ID, { account: 'a1' })); }); }); + +describe('record page — an update\'s notice and stripped fields reach the person (objectstack#38103)', () => { + it('the success toast carries the hook\'s notice and Undo; the stripped field gets the record save\'s own toast', async () => { + const NOTICE = 'Reassigning this deal notified the new account owner.'; + route.answerData = { + operation: 'update', + object: OBJECT_NAME, + id: RECORD_ID, + record: { id: RECORD_ID, account: 'a2' }, + notice: NOTICE, + droppedFields: [{ object: OBJECT_NAME, fields: ['config'], reason: 'readonly' }], + }; + const { dataSource, description, undo } = await runOnRecordPage( + EXPANDED_RECORD, + (loaded) => operationUpdate({ account: 'a2', config: { mode: 'loose' } }, loaded), + ); + + expect(description).toBe(NOTICE); + // The stripped field: one warning toast, the record save's own title. + await waitFor(() => expect(toast.warning).toHaveBeenCalledTimes(1)); + const [title, stripped] = vi.mocked(toast.warning).mock.calls[0] as [string, { description?: string }]; + expect(title).toBe('Saved — but some fields did not take effect'); + expect(stripped.description).toMatch(/config/i); + + // The kept Undo is the page's real one. + await undo(); + await waitFor(() => expect(dataSource.update).toHaveBeenLastCalledWith(OBJECT_NAME, RECORD_ID, expect.objectContaining({ account: 'a1' }))); + }); +}); diff --git a/ui/packages/core/src/actions/__tests__/ActionRunner.updateOperation.test.ts b/ui/packages/core/src/actions/__tests__/ActionRunner.updateOperation.test.ts index 8d327dcb17f..c76b14e8dfb 100644 --- a/ui/packages/core/src/actions/__tests__/ActionRunner.updateOperation.test.ts +++ b/ui/packages/core/src/actions/__tests__/ActionRunner.updateOperation.test.ts @@ -518,3 +518,104 @@ describe("operation: 'update' — the write's warnings reach the person (objects expect(toasts[0].opts?.type).toBe('success'); }); }); + +describe("operation: 'update' — the notice a hook set on the write reaches the person (objectstack#38103)", () => { + /** The route's 200 answer, with the data write's `notice` / `warnings` / `droppedFields` when given. */ + function answeredFetch(extra: { notice?: string; warnings?: unknown[]; droppedFields?: unknown[] }) { + return okFetch({ + success: true, + data: { + operation: 'update', + object: 'tasks', + id: 'rec_1', + record: { id: 'rec_1', status: 'done' }, + ...extra, + }, + }); + } + const NOTICE = 'Marking this done notified the requester.'; + const LATE = { + field: 'status', + code: 'rule_violation', + message: 'This task was closed after its due date.', + rule: 'closed_late', + severity: 'warning', + }; + + function wireWithOptions(fetch: ReturnType) { + const runner = new ActionRunner({}); + const toasts: Array<{ message: string; opts?: Parameters[0]>[1] }> = []; + runner.setToastHandler((message, opts) => { toasts.push({ message, opts }); }); + runner.registerHandler('script', createServerActionHandler({ fetch: fetch as unknown as ServerActionFetch })); + return { runner, toasts }; + } + + it('a notice alone rides the success toast as its line, and the toast stays a success', async () => { + const { runner, toasts } = wireWithOptions(answeredFetch({ notice: NOTICE })); + await runner.execute(updateAction({ successMessage: 'Task done.', params: { recordId: 'rec_1' } as never })); + + expect(toasts).toHaveLength(1); + expect(toasts[0].message).toBe('Task done.'); + expect(toasts[0].opts?.type).toBe('success'); + expect(toasts[0].opts?.description).toBe(NOTICE); + }); + + it('with warnings too, the notice leads the lines of the one warning toast', async () => { + const { runner, toasts } = wireWithOptions(answeredFetch({ notice: NOTICE, warnings: [LATE] })); + await runner.execute(updateAction({ params: { recordId: 'rec_1' } as never })); + + expect(toasts).toHaveLength(1); + expect(toasts[0].opts?.type).toBe('warning'); + expect(toasts[0].opts?.description).toBe(`${NOTICE}\n${LATE.message}`); + }); + + it('keeps the Undo affordance on the success toast that carries the notice', async () => { + const { runner, toasts } = wireWithOptions(answeredFetch({ notice: NOTICE })); + await runner.execute(updateAction({ + undoable: true, + params: { recordId: 'rec_1', _rowRecord: { id: 'rec_1', status: 'todo' } } as never, + })); + + expect(toasts).toHaveLength(1); + expect(toasts[0].opts?.description).toBe(NOTICE); + expect(toasts[0].opts?.undo).toBeDefined(); + }); + + it('an author who turned the success toast off still has the hook\'s words shown, as an info toast', async () => { + const { runner, toasts } = wireWithOptions(answeredFetch({ notice: NOTICE })); + await runner.execute(updateAction({ + toast: { showOnSuccess: false }, + params: { recordId: 'rec_1' } as never, + } as never)); + + expect(toasts).toEqual([{ message: NOTICE, opts: { type: 'info', duration: undefined } }]); + }); + + it('the stripped fields are not this toast\'s: a `droppedFields` answer alone is a plain success here', async () => { + // The host announces them on the record save's own stripped-fields toast + // (app-shell `withAnnouncedUpdateDroppedFields`), never folded into this one. + const { runner, toasts } = wireWithOptions(answeredFetch({ + droppedFields: [{ object: 'tasks', fields: ['closed_on'], reason: 'readonly' }], + })); + await runner.execute(updateAction({ params: { recordId: 'rec_1' } as never })); + + expect(toasts).toHaveLength(1); + expect(toasts[0].opts?.type).toBe('success'); + expect(toasts[0].opts && 'description' in toasts[0].opts).toBe(false); + }); + + it('reverse pin: a script action WITHOUT `operation` never reads its answer\'s `notice` key', async () => { + const { runner, toasts } = wireWithOptions(answeredFetch({ notice: NOTICE })); + await runner.execute({ + type: 'script', + name: 'recalc', + label: 'Recalc', + objectName: 'tasks', + target: 'recalc', + successMessage: 'Done.', + } as ActionDef); + + expect(toasts).toHaveLength(1); + expect(toasts[0].opts && 'description' in toasts[0].opts).toBe(false); + }); +}); From 000383d7b6103efbe1e5db45bd538d36f7e84523 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 10:28:33 +0000 Subject: [PATCH 4/6] test(ui): pin the server-action wrapper that announces an update's stripped fields Claude-Session: https://claude.ai/code/session_01L9qibwKycKW36n75AWgepd Co-authored-by: Claude --- .../flowLaunch.droppedFields-33009.test.ts | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/ui/packages/app-shell/src/utils/__tests__/flowLaunch.droppedFields-33009.test.ts b/ui/packages/app-shell/src/utils/__tests__/flowLaunch.droppedFields-33009.test.ts index b271912b9d3..165f7795ec7 100644 --- a/ui/packages/app-shell/src/utils/__tests__/flowLaunch.droppedFields-33009.test.ts +++ b/ui/packages/app-shell/src/utils/__tests__/flowLaunch.droppedFields-33009.test.ts @@ -24,7 +24,7 @@ import { UNRECOGNIZED_DROP_REASON } from '@object-ui/data-objectstack'; const toasts = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn(), warning: vi.fn(), info: vi.fn() })); vi.mock('sonner', () => ({ toast: toasts })); -import { announceFlowDroppedFields, flowAnswerDroppedFields, launchConsoleFlow } from '../flowLaunch'; +import { announceFlowDroppedFields, flowAnswerDroppedFields, launchConsoleFlow, withAnnouncedUpdateDroppedFields } from '../flowLaunch'; const SCHEMAS: Record }> = { expense_report: { fields: { status: { label: 'Approval status' } } }, @@ -135,3 +135,54 @@ describe('launchConsoleFlow — a failed run says only that it failed', () => { expect(toasts.warning).not.toHaveBeenCalled(); }); }); + +describe('withAnnouncedUpdateDroppedFields — a declarative update action\'s stripped fields (objectstack#38103)', () => { + const UPDATE = { type: 'script', name: 'submit', objectName: 'expense_report', operation: 'update', patch: { status: 'submitted' } } as never; + const STRIPPED = [{ object: 'expense_report', fields: ['status'], reason: 'readonly' }]; + /** A server-action handler answering `data`, with the member core's factory sets. */ + function handlerAnswering(result: unknown) { + const refuseBeforeInput = vi.fn(() => undefined); + return Object.assign(vi.fn(async () => result as never), { refuseBeforeInput }); + } + /** The announcement is not awaited by the wrapper: let its label lookup settle. */ + const settle = () => new Promise((r) => setTimeout(r, 0)); + + it('warns with the record save\'s own stripped-fields toast, labelled, and hands the result back unchanged', async () => { + const result = { success: true, data: { operation: 'update', object: 'expense_report', id: 'r1', record: {}, droppedFields: STRIPPED } }; + const s = sink(); + const wrapped = withAnnouncedUpdateDroppedFields(handlerAnswering(result), () => ctx, s); + + expect(await wrapped(UPDATE)).toBe(result); + await settle(); + expect(s.warning).toHaveBeenCalledTimes(1); + expect(s.warning.mock.calls[0][0]).toBe('Saved — but some fields did not take effect'); + expect(s.warning.mock.calls[0][1].description).toBe('Read-only, so it did not take effect: Approval status'); + }); + + it('keeps the handler\'s `refuseBeforeInput` member', () => { + const inner = handlerAnswering({ success: true }); + expect(withAnnouncedUpdateDroppedFields(inner, () => ctx, sink()).refuseBeforeInput).toBe(inner.refuseBeforeInput); + }); + + it('control: an update answer without the member warns about nothing', async () => { + const s = sink(); + await withAnnouncedUpdateDroppedFields(handlerAnswering({ success: true, data: { operation: 'update', record: {} } }), () => ctx, s)(UPDATE); + await settle(); + expect(s.warning).not.toHaveBeenCalled(); + }); + + it('a failed dispatch is not told "saved, but"', async () => { + const s = sink(); + await withAnnouncedUpdateDroppedFields(handlerAnswering({ success: false, error: 'Refused', data: { droppedFields: STRIPPED } }), () => ctx, s)(UPDATE); + await settle(); + expect(s.warning).not.toHaveBeenCalled(); + }); + + it('reverse pin: an action WITHOUT `operation: \'update\'` never has its answer\'s `droppedFields` key read', async () => { + const s = sink(); + const script = { type: 'script', name: 'recalc', objectName: 'expense_report', target: 'recalc' } as never; + await withAnnouncedUpdateDroppedFields(handlerAnswering({ success: true, data: { droppedFields: STRIPPED } }), () => ctx, s)(script); + await settle(); + expect(s.warning).not.toHaveBeenCalled(); + }); +}); From 7bb423769f4ea57acae1d401ef044bdd304f34d4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 11:24:56 +0000 Subject: [PATCH 5/6] test(runtime): run the notice / droppedFields pins on the SQL driver, not the frozen memory driver Claude-Session: https://claude.ai/code/session_01L9qibwKycKW36n75AWgepd Co-authored-by: Claude --- .../src/action-declarative-update.test.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/runtime/src/action-declarative-update.test.ts b/packages/runtime/src/action-declarative-update.test.ts index e0b6ec025f3..e1312e401ef 100644 --- a/packages/runtime/src/action-declarative-update.test.ts +++ b/packages/runtime/src/action-declarative-update.test.ts @@ -37,7 +37,7 @@ * collapse or the not-found envelope is mocked away. */ -import { describe, it, expect, vi } from 'vitest'; +import { describe, it, expect, vi, afterEach } from 'vitest'; // Paid at collection, not inside a case's clock (check:test-source-alias). import '@objectstack/metadata'; @@ -47,10 +47,11 @@ import { assertEngineUpdateDispatch } from '@objectstack/metadata-core'; import '@objectstack/metadata'; import { ObjectQL } from '@objectstack/objectql'; -import { InMemoryDriver } from '@objectstack/driver-memory'; +import { SqlDriver } from '@objectstack/driver-sql'; import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; import { HttpDispatcher } from './http-dispatcher.js'; +import { installDefaultOrganization } from './default-organization.testkit.js'; import { callData, invokeBusinessAction, @@ -920,7 +921,7 @@ describe('#37867 — a declarative update answers the `warnings` its data-plane * action's `patch` is answered as a plain success. * * Unlike the blocks above, nothing here is a double: a REAL `ObjectQL` engine - * on the REAL `InMemoryDriver`, the REAL `ObjectStackProtocolImplementation` + * on the REAL `SqlDriver` (better-sqlite3, `:memory:`), the REAL `ObjectStackProtocolImplementation` * as the `protocol` service, and an object whose `closed_reason` is * `readonly: true` — the strip, the hook's message and the data door's answer * are the producers' own. Each case compares the action's answer with the @@ -955,12 +956,21 @@ describe('#38103 — a declarative update answers the `notice` and `droppedField actions: [CLOSE_WITH_REASON, SET_PRIORITY], }; const quiet = { info() {}, debug() {}, warn() {}, error() {} }; + const booted: ObjectQL[] = []; + afterEach(async () => { + for (const engine of booted.splice(0)) { + try { await engine.destroy(); } catch { /* noop */ } + } + }); async function boot() { const engine = new ObjectQL({ logger: quiet } as any); - engine.registerDriver(new InMemoryDriver() as any, true); + booted.push(engine); + engine.registerDriver(new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true }) as any, true); await engine.init(); engine.registry.registerObject(FB_OBJECT_DEF as never, 'com.objectstack.test.38103'); + await engine.syncSchemas(); + await installDefaultOrganization(engine); // The hook says what closing did, from the write it is handed. engine.registerHook('beforeUpdate', async (ctx: any) => { if (ctx.input?.data?.status === 'closed') ctx.notice(NOTICE); From 3ac5fe29202d593aa05d1f7bd4ae5386e1caec35 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 11:36:16 +0000 Subject: [PATCH 6/6] test(runtime): type the notice pins' system-context reads instead of casting them Claude-Session: https://claude.ai/code/session_01L9qibwKycKW36n75AWgepd Co-authored-by: Claude --- packages/runtime/src/action-declarative-update.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/runtime/src/action-declarative-update.test.ts b/packages/runtime/src/action-declarative-update.test.ts index e1312e401ef..10d7b84fbd6 100644 --- a/packages/runtime/src/action-declarative-update.test.ts +++ b/packages/runtime/src/action-declarative-update.test.ts @@ -975,7 +975,7 @@ describe('#38103 — a declarative update answers the `notice` and `droppedField engine.registerHook('beforeUpdate', async (ctx: any) => { if (ctx.input?.data?.status === 'closed') ctx.notice(NOTICE); }, { object: FB_OBJECT }); - await engine.insert(FB_OBJECT, { id: FB_RECORD, status: 'open', priority: 'low' }, { context: { isSystem: true } } as any); + await engine.insert(FB_OBJECT, { id: FB_RECORD, status: 'open', priority: 'low' }, { context: { isSystem: true } }); const protocol = new ObjectStackProtocolImplementation(engine as never); return { engine, protocol }; } @@ -1005,7 +1005,7 @@ describe('#38103 — a declarative update answers the `notice` and `droppedField }; const context: any = { request: {}, environmentId: 'platform', executionContext: ec(OWNER) }; const res: any = await (new HttpDispatcher(kernel) as any).handleActions(path, 'POST', {}, context); - const stored: any = await engine.findOne(FB_OBJECT, { where: { id: FB_RECORD }, context: { isSystem: true } } as any); + const stored: any = await engine.findOne(FB_OBJECT, { where: { id: FB_RECORD }, context: { isSystem: true } }); return { response: res.response, stored }; }