From 0e115078621193f20e04aed07a32ed58822a1eb4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:25:58 +0000 Subject: [PATCH 1/5] fix(runtime): a declarative update action answers the warnings its write raised executeDeclarativeUpdateAction composed its answer from the written record and dropped the advisory validation-rule hits the data-plane update answered, so a button that performs the same write as a form save answered no warnings. Claude-Session: https://claude.ai/code/session_01L9qiby3dfNfCgpXwPkB2Hf Co-authored-by: Claude --- .../src/action-declarative-update.test.ts | 120 ++++++++++++++++++ packages/runtime/src/action-execution.ts | 29 ++++- 2 files changed, 148 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/action-declarative-update.test.ts b/packages/runtime/src/action-declarative-update.test.ts index 7196b7bbc67..ec4aac2d096 100644 --- a/packages/runtime/src/action-declarative-update.test.ts +++ b/packages/runtime/src/action-declarative-update.test.ts @@ -770,3 +770,123 @@ describe('#15079 reverse pin — a handler-less `type: script` action WITHOUT `o expect(rig.row.status).toBe('open'); }); }); + +// ─────────────────────────────────────────────────────────────────────────── +// [#37867] The write's advisory `warnings` ride the action's answer +// ─────────────────────────────────────────────────────────────────────────── + +/** + * A warning rule lets the write through and answers `warnings` + * (`protocol.updateData`, #22726). The button that performs the same write + * answers the same warnings, at both doors, or the rule warns only the people + * who edit the form. + * + * The rig above reaches the ObjectQL fallback of `callData`, which answers no + * warnings by construction, so this block puts a `protocol` slot in front of it: + * a double whose `updateData` writes through the rig's caller-honouring + * `ql.update` and answers the protocol's shape, `warnings` set only when the + * write tripped the stand-in rule (`status` set to `closed` while + * `priority` is `low`). + */ +describe('#37867 — a declarative update answers the `warnings` its data-plane write raised', () => { + const EARLY_CLOSE_WARNING = { + field: 'status', + code: 'rule_violation', + message: 'A low-priority case closed this early skips the review queue.', + rule: 'early_close_review', + severity: 'warning', + }; + + function protocolRig() { + const rig = makeRig(); + const protocol: any = { + updateData: vi.fn(async (req: any) => { + await rig.ql.update(req.object, { ...req.data, id: req.id }, { where: { id: req.id }, context: req.context }); + const trips = rig.row.status === 'closed' && rig.row.priority === 'low'; + return { + object: req.object, + id: req.id, + record: { ...rig.row }, + ...(trips ? { warnings: [{ ...EARLY_CLOSE_WARNING }] } : {}), + }; + }), + }; + return { rig, protocol }; + } + + async function restVia(userId: string, rig: Rig, protocol: any, path: string, body: any = {}) { + const metadata: any = { + load: vi.fn(async () => null), + loadDiagnosed: vi.fn(async () => ({ data: null, degraded: false, errors: [] })), + listObjects: vi.fn(async () => [OBJECT_DEF]), + getObject: vi.fn(async (n: string) => (n === OBJECT_DEF.name ? OBJECT_DEF : undefined)), + }; + const kernel: any = { + context: { + getService: (n: string) => + n === 'objectql' || n === 'data' ? rig.ql + : n === 'metadata' ? metadata + : n === 'protocol' ? protocol + : null, + }, + }; + const context: any = { request: {}, environmentId: 'platform', executionContext: ec(userId) }; + const res: any = await (new HttpDispatcher(kernel) as any).handleActions(path, 'POST', body, context); + return res.response; + } + + async function mcpVia(userId: string, rig: Rig, protocol: any, name: string, input: Record) { + const deps: any = { + resolveService: async (_ctx: unknown, n: string) => (n === 'protocol' ? protocol : undefined), + getObjectQL: async () => rig.ql, + }; + const requestContext: any = { request: {}, environmentId: 'platform' }; + return await invokeBusinessAction(deps, requestContext, name, input as any, { + driver: undefined, + envId: 'platform', + ec: ec(userId), + getMeta: () => ({ listObjects: async () => [OBJECT_DEF] }), + callData: (action, params, dataDriver, scopeId, execCtx) => + callData(deps, requestContext, action, params, dataDriver, scopeId, execCtx), + }); + } + + it('REST: the 200 answer carries the write\'s warnings, element for element, beside the written record', async () => { + const { rig, protocol } = protocolRig(); + const res = await restVia(OWNER, rig, protocol, `/${OBJECT}/close_case/${RECORD_ID}`); + + expect(res.status).toBe(200); + expect(res.body.success).toBe(true); + // The write went through the protocol, once, as the caller. + expect(protocol.updateData).toHaveBeenCalledTimes(1); + expect(protocol.updateData.mock.calls[0][0].context?.userId).toBe(OWNER); + expect(rig.row.status).toBe('closed'); + expect(res.body.data.warnings).toEqual([EARLY_CLOSE_WARNING]); + expect(res.body.data).toMatchObject({ operation: DECLARATIVE_UPDATE_OPERATION, object: OBJECT, id: RECORD_ID }); + expect(res.body.data.record).toMatchObject({ id: RECORD_ID, status: 'closed' }); + // The undo anchor still rides beside them. + expect(res.body.data.undo).toMatchObject({ undoData: { status: 'open' }, redoData: { status: 'closed' } }); + }); + + it('MCP `run_action`: the same write answers the same warnings', async () => { + const { rig, protocol } = protocolRig(); + const out: any = await mcpVia(OWNER, rig, protocol, 'close_case', { recordId: RECORD_ID }); + + expect(out.ok).toBe(true); + expect(protocol.updateData).toHaveBeenCalledTimes(1); + expect(out.result.warnings).toEqual([EARLY_CLOSE_WARNING]); + }); + + it('a write that trips no rule carries no `warnings` key at all', async () => { + // The same action through the same protocol, on a row the rule does not + // fire for. ABSENT, never `[]` — the data door's own shape; the firing + // positive control is the REST case above, same rig. + const { rig, protocol } = protocolRig(); + rig.row.priority = 'high'; + const res = await restVia(OWNER, rig, protocol, `/${OBJECT}/close_case/${RECORD_ID}`); + + expect(res.status).toBe(200); + expect(protocol.updateData).toHaveBeenCalledTimes(1); + expect('warnings' in res.body.data).toBe(false); + }); +}); diff --git a/packages/runtime/src/action-execution.ts b/packages/runtime/src/action-execution.ts index 2aa7db94e87..4d014c1e625 100644 --- a/packages/runtime/src/action-execution.ts +++ b/packages/runtime/src/action-execution.ts @@ -23,7 +23,7 @@ import { EngineQueryOptionsSchema, DATA_ACTION_TO_API_OPERATION } from '@objects 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'; -import { standardErrorCodeForHttpStatus, type MetadataProtocol } from '@objectstack/spec/api'; +import { standardErrorCodeForHttpStatus, type MetadataProtocol, type ValidateDataIssue } from '@objectstack/spec/api'; import { renderOperationMessage } from '@objectstack/spec/system'; // [#15942 / #16293] The confirmation member's SPELLING is the contract, so it // is imported, never hand-spelled: the door that refuses and the client that @@ -4985,6 +4985,26 @@ export interface DeclarativeUpdateResult { record: Record; /** Present only when the action declares `undoable: true`. */ undo?: DeclarativeUpdateUndo; + /** + * [#37867] The advisory validation-rule hits (`severity: 'warning' | 'info'`) + * of THIS write, exactly as the data-plane update answered them — the + * element is `ValidateDataIssue`, the data door's own `warnings` vocabulary. + * Present only when the write raised one: the same rule on the same write + * answers the same warnings whichever door the person used. + */ + warnings?: ValidateDataIssue[]; +} + +/** + * [#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. + */ +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; } /** @@ -5238,12 +5258,19 @@ export async function executeDeclarativeUpdateAction( }; } + // [#37867] The write's advisory rule hits ride the answer. A warning rule + // 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); + const result: DeclarativeUpdateResult = { operation: DECLARATIVE_UPDATE_OPERATION, object: objectName, id: recordId, record, ...(undo ? { undo } : {}), + ...(warnings ? { warnings } : {}), }; if (stale) throw withEarnedAnswer(stale, { ...result }); return result; From 4d3e6eacbacd40587406a69fb80a7bcfa3e93c8f Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:28:01 +0000 Subject: [PATCH 2/5] fix(console): an update action's success toast carries the warnings its write raised The runner reads the declarative-update answer's warnings and raises the success toast on its warning variant with the rule's words as its description; both console toast handlers learn the warning variant. Claude-Session: https://claude.ai/code/session_01L9qiby3dfNfCgpXwPkB2Hf Co-authored-by: Claude --- .../src/hooks/useConsoleActionRuntime.tsx | 13 +++ .../app-shell/src/views/RecordDetailView.tsx | 15 ++- ui/packages/core/src/actions/ActionRunner.ts | 48 ++++++++- .../ActionRunner.updateOperation.test.ts | 101 ++++++++++++++++++ 4 files changed, 175 insertions(+), 2 deletions(-) diff --git a/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx b/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx index 6e1a02cf701..2e56620a594 100644 --- a/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx +++ b/ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx @@ -404,6 +404,19 @@ export function useConsoleActionRuntime(opts: ConsoleActionRuntimeOptions): Cons const toastHandler = useCallback((message, options) => { if (options?.type === 'error') { toast.error(message); return; } + // objectstack#37867 — a write that went through with warnings: the + // runner's success toast on its warning variant, the warnings under the + // title, the Undo button kept (the same toast a record save raises). + if (options?.type === 'warning') { + toast.warning(message, { + duration: options.duration, + ...(options.description ? { description: options.description } : {}), + ...(options.undo + ? { action: { label: options.undo.label || 'Undo', onClick: () => { void undoCtl.undo(); } } } + : {}), + }); + return; + } if (options?.undo) { toast.success(message, { duration: options.duration, diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index 2528c3e2e0d..9aa7af7c274 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -1946,8 +1946,21 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri }, }); - const toastHandler = useCallback((message: string, options?: { type?: string; duration?: number; undo?: { label?: string } }) => { + const toastHandler = useCallback((message: string, options?: { type?: string; duration?: number; description?: string; undo?: { label?: string } }) => { if (options?.type === 'error') { toast.error(message); return; } + // objectstack#37867 — a write that went through with warnings: the + // runner's success toast on its warning variant, the warnings under the + // title, the Undo button kept (the same toast a record save raises). + if (options?.type === 'warning') { + toast.warning(message, { + duration: options.duration, + ...(options.description ? { description: options.description } : {}), + ...(options.undo + ? { action: { label: options.undo.label || 'Undo', onClick: () => { void undoCtl.undo(); } } } + : {}), + }); + return; + } if (options?.undo) { toast.success(message, { duration: options.duration, diff --git a/ui/packages/core/src/actions/ActionRunner.ts b/ui/packages/core/src/actions/ActionRunner.ts index 86b94ff37c6..353b2932db0 100644 --- a/ui/packages/core/src/actions/ActionRunner.ts +++ b/ui/packages/core/src/actions/ActionRunner.ts @@ -638,6 +638,10 @@ 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. */ + description?: string; /** When set, the toast offers an "Undo" affordance (the runner has already * pushed the operation onto the global UndoManager). */ undo?: { label?: string }; @@ -1286,6 +1290,32 @@ function isUpdateOperationAction(action: ActionDef): boolean { return action.operation === 'update'; } +/** + * The advisory warning messages the route answered for an `operation: + * 'update'` action's write, distinct, in answer order (objectstack#37867). + * + * The route's declarative-update answer carries `warnings` when the write + * tripped a `severity: 'warning'` (or `'info'`) validation rule, in the data + * door's own element shape (`{ field, code, message, rule?, severity? }`) — + * the write went through, and the person who clicked owes the rule's words, + * exactly as a record save shows them (`@object-ui/react`'s + * `answerWarningLines`, which this package sits below and cannot import). + * Asked of an update action only: no other action's answer declares the + * member, so a script's own `warnings` key is never read as one. + */ +function updateAnswerWarningLines(action: ActionDef, result: ActionResult): string[] { + if (!isUpdateOperationAction(action)) return []; + const payload = readActionPayload(result.data); + const wire = payload && typeof payload === 'object' ? (payload as { warnings?: unknown }).warnings : undefined; + if (!Array.isArray(wire)) return []; + const lines: string[] = []; + for (const entry of wire) { + const message = (entry as { message?: unknown } | null)?.message; + if (typeof message === 'string' && message.trim() !== '' && !lines.includes(message)) lines.push(message); + } + return lines; +} + /** * What a launch of an `ask_ai` action on a runner with no in-app assistant is * told. Not a locale-pack text: such an action is not drawn @@ -2319,6 +2349,10 @@ export class ActionRunner { if (this.toastHandler) { const showToast = action.toast ?? { showOnSuccess: true, showOnError: true }; const duration = action.toast?.duration; + // objectstack#37867 — the warnings the write raised. They ride the + // success toast, which then takes the warning variant: one toast, as a + // record save raises one. + const warnings = result.success ? updateAnswerWarningLines(action, result) : []; if (result.success && !hasResultDialog && !result.silent && showToast.showOnSuccess !== false) { // The server returns FACTS and the console writes the sentence @@ -2333,10 +2367,22 @@ export class ActionRunner { try { globalUndoManager.push(result.undo); } catch { /* non-fatal */ } } this.toastHandler(message, { - type: 'success', + type: warnings.length > 0 ? 'warning' : 'success', duration, + ...(warnings.length > 0 ? { description: warnings.join('\n') } : {}), undo: result.undo ? { label: this.runnerText(RUNNER_TEXT.undo) } : undefined, }); + } else if (warnings.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; + this.toastHandler(first, { + type: 'warning', + duration, + ...(rest.length > 0 ? { description: rest.join('\n') } : {}), + }); } if (!result.success && showToast.showOnError !== false && result.error) { 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 63693ec1e5a..8d327dcb17f 100644 --- a/ui/packages/core/src/actions/__tests__/ActionRunner.updateOperation.test.ts +++ b/ui/packages/core/src/actions/__tests__/ActionRunner.updateOperation.test.ts @@ -417,3 +417,104 @@ describe('reverse pin — a script action WITHOUT `operation` is untouched', () expect(navigated).toEqual(['/docs']); }); }); + +describe("operation: 'update' — the write's warnings reach the person (objectstack#37867)", () => { + /** The route's 200 answer for a write that tripped a `severity: 'warning'` rule. */ + function warnedFetch(warnings: unknown[]) { + return okFetch({ + success: true, + data: { + operation: 'update', + object: 'tasks', + id: 'rec_1', + record: { id: 'rec_1', status: 'done' }, + ...(warnings.length > 0 ? { warnings } : {}), + }, + }); + } + const OVER_QUOTA = { + field: 'contract', + code: 'rule_violation', + message: 'This order takes its framework contract over the Contract Value.', + rule: 'framework_quota_exceeded', + 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('one toast, on the warning variant: the success message as its title, the rule\'s words under it', async () => { + const { runner, toasts } = wireWithOptions(warnedFetch([OVER_QUOTA])); + const result = await runner.execute(updateAction({ + successMessage: 'Order confirmed.', + params: { recordId: 'rec_1' } as never, + })); + + expect(result.success).toBe(true); + expect(toasts).toHaveLength(1); + expect(toasts[0].message).toBe('Order confirmed.'); + expect(toasts[0].opts?.type).toBe('warning'); + expect(toasts[0].opts?.description).toBe(OVER_QUOTA.message); + }); + + it('repeated messages are said once, and every distinct one gets its own line', async () => { + const second = { ...OVER_QUOTA, rule: 'credit_hold', message: 'The account is on credit hold.' }; + const { runner, toasts } = wireWithOptions(warnedFetch([OVER_QUOTA, { ...OVER_QUOTA, field: 'total' }, second])); + await runner.execute(updateAction({ params: { recordId: 'rec_1' } as never })); + + expect(toasts).toHaveLength(1); + expect(toasts[0].opts?.description).toBe(`${OVER_QUOTA.message}\n${second.message}`); + }); + + it('keeps the Undo affordance on the warning toast of an undoable action', async () => { + const { runner, toasts } = wireWithOptions(warnedFetch([OVER_QUOTA])); + const result = await runner.execute(updateAction({ + undoable: true, + params: { recordId: 'rec_1', _rowRecord: { id: 'rec_1', status: 'todo' } } as never, + })); + + expect(result.undo?.undoData).toEqual({ status: 'todo' }); + expect(toasts).toHaveLength(1); + expect(toasts[0].opts?.type).toBe('warning'); + expect(toasts[0].opts?.undo).toBeDefined(); + }); + + it('control: a write with no warnings keeps the plain success toast, with no description', async () => { + const { runner, toasts } = wireWithOptions(warnedFetch([])); + 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('an author who turned the success toast off still has the person warned, in the rule\'s own words', async () => { + const { runner, toasts } = wireWithOptions(warnedFetch([OVER_QUOTA])); + await runner.execute(updateAction({ + toast: { showOnSuccess: false }, + params: { recordId: 'rec_1' } as never, + } as never)); + + expect(toasts).toEqual([{ message: OVER_QUOTA.message, opts: { type: 'warning', duration: undefined } }]); + }); + + it('reverse pin: a script action WITHOUT `operation` never reads its answer\'s `warnings` key', async () => { + const { runner, toasts } = wireWithOptions(warnedFetch([OVER_QUOTA])); + 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?.type).toBe('success'); + }); +}); From 99d4f58013959488fd89f41ba19be247b556154b Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:29:44 +0000 Subject: [PATCH 3/5] test(console): an update action's warnings reach the toast on the grid row and the record page; changeset Claude-Session: https://claude.ai/code/session_01L9qiby3dfNfCgpXwPkB2Hf Co-authored-by: Claude --- ...7867-declarative-update-action-warnings.md | 16 +++++ ...eActionRuntime.undoLookupId-11122.test.tsx | 59 ++++++++++++++++++- ...cordDetailView.undoLookupId-11122.test.tsx | 47 +++++++++++++-- 3 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 .changeset/37867-declarative-update-action-warnings.md diff --git a/.changeset/37867-declarative-update-action-warnings.md b/.changeset/37867-declarative-update-action-warnings.md new file mode 100644 index 00000000000..647afccee73 --- /dev/null +++ b/.changeset/37867-declarative-update-action-warnings.md @@ -0,0 +1,16 @@ +--- +'@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 about the validation warnings its write raised. +A `severity: 'warning'` rule lets the save through and answers `warnings`, and the edit form shows them; the +button that performs the same write answered only its success. The action's answer +(`POST /api/v1/actions/:object/:action`, and MCP `run_action`) now carries the write's `warnings`, in the data +door's own element shape, present only when the write raised one. The console's action runner raises the +success toast on its warning variant with the rule's words under the title, and keeps the Undo button; an action +whose success toast is turned off still shows the warning. `ToastHandler` options gain an optional `description`. 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 d94d4ffa135..102086ec91e 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 @@ -75,6 +75,9 @@ vi.mock('../../views/FlowRunner', () => ({ FlowRunner: () => null })); // stub is handed, standing in for the declaration the route resolves by name: // the request never carries it (objectui#12941). const routeWrites: Array> = []; +// What the route answers beside the write: by default the bare success, else +// the declarative-update answer a case sets (objectstack#37867's `warnings`). +let routeAnswerData: Record | undefined; vi.mock('../../utils/consoleServerAction', () => ({ createConsoleServerActionHandler: () => vi.fn(async (action: { params?: Record; @@ -82,7 +85,7 @@ vi.mock('../../utils/consoleServerAction', () => ({ }) => { const { _rowRecord: _row, recordId: _id, ...fields } = action.params ?? {}; routeWrites.push({ ...(action.patch ?? {}), ...fields }); - return { success: true }; + return routeAnswerData ? { success: true, data: routeAnswerData } : { success: true }; }), })); @@ -175,7 +178,9 @@ async function runOnGridRow(action: Record) { afterEach(() => { cleanup(); routeWrites.length = 0; + routeAnswerData = undefined; vi.mocked(toast.success).mockClear(); + vi.mocked(toast.warning).mockClear(); globalUndoManager.clear(); }); @@ -290,3 +295,55 @@ describe('console runtime — where the field definitions come from (objectui#11 expect(global.context).not.toHaveProperty('objectFields'); }); }); + +describe('grid row — an update whose write raised warnings warns, on one toast (objectstack#37867)', () => { + const WARNING = 'This deal takes its account over the credit limit.'; + + it('the runtime raises the warning toast: the success message, the warning under it, and Undo', async () => { + routeAnswerData = { + operation: 'update', + object: OBJECT, + id: 'o1', + record: { ...STORED, account: 'a2' }, + warnings: [{ field: 'account', code: 'rule_violation', message: WARNING, rule: 'credit_limit', severity: 'warning' }], + }; + 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')); + + await waitFor(() => expect(toast.warning).toHaveBeenCalledTimes(1)); + const [message, options] = vi.mocked(toast.warning).mock.calls[0] as [string, { description?: string; action?: { onClick: () => void } }]; + expect(message).toBe(MESSAGE); + expect(options.description).toBe(WARNING); + expect(options.action).toBeDefined(); + // One toast: the warning variant replaces the success one, never joins it. + expect(vi.mocked(toast.success).mock.calls.filter(([m]) => m === MESSAGE)).toHaveLength(0); + + // The kept Undo is the runtime's real one. + await act(async () => { options.action!.onClick(); }); + await waitFor(() => expect(dataSource.update).toHaveBeenLastCalledWith(OBJECT, 'o1', { account: 'a1' })); + }); +}); 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 82e05346e17..e64698fba0f 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 @@ -79,8 +79,12 @@ vi.mock('../hooks/useActionModal', () => ({ resolveModalTarget: vi.fn(async () => null), }), })); +// What the route answers: by default the bare success, else the +// declarative-update answer a case sets (objectstack#37867's `warnings`). +const route = vi.hoisted(() => ({ answerData: undefined as Record | undefined })); vi.mock('../utils/consoleServerAction', () => ({ - createConsoleServerActionHandler: () => vi.fn(async () => ({ success: true })), + createConsoleServerActionHandler: () => vi.fn(async () => + (route.answerData ? { success: true, data: route.answerData } : { success: true })), })); type ProviderProps = React.ComponentProps; @@ -206,7 +210,11 @@ function operationUpdate(patch: Record, row: Record, action: (loaded: Record) => ActionDef) { +async function runOnRecordPage( + record: Record, + action: (loaded: Record) => ActionDef, + variant: 'success' | 'warning' = 'success', +) { const dataSource = { find: vi.fn(async () => ({ data: [] })), findOne: vi.fn(async () => structuredClone(record)), @@ -245,20 +253,22 @@ async function runOnRecordPage(record: Record, action: (loaded: }); expect(result.success).toBe(true); - const call = vi.mocked(toast.success).mock.calls.find(([message]) => message === MESSAGE); + const call = vi.mocked(toast[variant]).mock.calls.find(([message]) => message === MESSAGE); expect(call).toBeTruthy(); - const options = call![1] as { action?: { label: string; onClick: () => void } } | undefined; + const options = call![1] as { description?: string; action?: { label: string; onClick: () => void } } | undefined; expect(options?.action).toBeDefined(); const undo = async () => { await act(async () => { options!.action!.onClick(); }); }; - return { dataSource, result, context: provider.context, undo }; + return { dataSource, result, context: provider.context, undo, description: options?.description }; } afterEach(() => { cleanup(); captured.length = 0; + route.answerData = undefined; vi.mocked(toast.success).mockClear(); + vi.mocked(toast.warning).mockClear(); globalUndoManager.clear(); }); @@ -307,3 +317,30 @@ describe('record page — Undo of a lookup update restores the stored id (object ); }); }); + +describe('record page — an update whose write raised warnings warns, on one toast (objectstack#37867)', () => { + it('the page raises the warning toast: the success message, the warning under it, and Undo', async () => { + const WARNING = 'This deal takes its account over the credit limit.'; + route.answerData = { + operation: 'update', + object: OBJECT_NAME, + id: RECORD_ID, + record: { id: RECORD_ID, account: 'a2' }, + warnings: [{ field: 'account', code: 'rule_violation', message: WARNING, rule: 'credit_limit', severity: 'warning' }], + }; + const { dataSource, description, undo } = await runOnRecordPage( + EXPANDED_RECORD, + (loaded) => operationUpdate({ account: 'a2' }, loaded), + 'warning', + ); + + expect(description).toBe(WARNING); + expect(toast.warning).toHaveBeenCalledTimes(1); + // One toast: the warning variant replaces the success one, never joins it. + expect(vi.mocked(toast.success).mock.calls.filter(([m]) => m === MESSAGE)).toHaveLength(0); + + // The kept Undo is the page's real one. + await undo(); + await waitFor(() => expect(dataSource.update).toHaveBeenLastCalledWith(OBJECT_NAME, RECORD_ID, { account: 'a1' })); + }); +}); From a3a483395ab4bf01944ee768e8028c9f9f8261ca Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:34:30 +0000 Subject: [PATCH 4/5] refactor(console): place the update-answer warnings reader clear of the ask_ai retirement's hunk Claude-Session: https://claude.ai/code/session_01L9qiby3dfNfCgpXwPkB2Hf Co-authored-by: Claude --- ui/packages/core/src/actions/ActionRunner.ts | 52 ++++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/ui/packages/core/src/actions/ActionRunner.ts b/ui/packages/core/src/actions/ActionRunner.ts index 353b2932db0..d36f6014164 100644 --- a/ui/packages/core/src/actions/ActionRunner.ts +++ b/ui/packages/core/src/actions/ActionRunner.ts @@ -1290,32 +1290,6 @@ function isUpdateOperationAction(action: ActionDef): boolean { return action.operation === 'update'; } -/** - * The advisory warning messages the route answered for an `operation: - * 'update'` action's write, distinct, in answer order (objectstack#37867). - * - * The route's declarative-update answer carries `warnings` when the write - * tripped a `severity: 'warning'` (or `'info'`) validation rule, in the data - * door's own element shape (`{ field, code, message, rule?, severity? }`) — - * the write went through, and the person who clicked owes the rule's words, - * exactly as a record save shows them (`@object-ui/react`'s - * `answerWarningLines`, which this package sits below and cannot import). - * Asked of an update action only: no other action's answer declares the - * member, so a script's own `warnings` key is never read as one. - */ -function updateAnswerWarningLines(action: ActionDef, result: ActionResult): string[] { - if (!isUpdateOperationAction(action)) return []; - const payload = readActionPayload(result.data); - const wire = payload && typeof payload === 'object' ? (payload as { warnings?: unknown }).warnings : undefined; - if (!Array.isArray(wire)) return []; - const lines: string[] = []; - for (const entry of wire) { - const message = (entry as { message?: unknown } | null)?.message; - if (typeof message === 'string' && message.trim() !== '' && !lines.includes(message)) lines.push(message); - } - return lines; -} - /** * What a launch of an `ask_ai` action on a runner with no in-app assistant is * told. Not a locale-pack text: such an action is not drawn @@ -1360,6 +1334,32 @@ function declaresSuccessMessage(action: ActionDef): boolean { return text !== undefined && text.trim() !== ''; } +/** + * The advisory warning messages the route answered for an `operation: + * 'update'` action's write, distinct, in answer order (objectstack#37867). + * + * The route's declarative-update answer carries `warnings` when the write + * tripped a `severity: 'warning'` (or `'info'`) validation rule, in the data + * door's own element shape (`{ field, code, message, rule?, severity? }`) — + * the write went through, and the person who clicked owes the rule's words, + * exactly as a record save shows them (`@object-ui/react`'s + * `answerWarningLines`, which this package sits below and cannot import). + * Asked of an update action only: no other action's answer declares the + * member, so a script's own `warnings` key is never read as one. + */ +function updateAnswerWarningLines(action: ActionDef, result: ActionResult): string[] { + if (!isUpdateOperationAction(action)) return []; + const payload = readActionPayload(result.data); + const wire = payload && typeof payload === 'object' ? (payload as { warnings?: unknown }).warnings : undefined; + if (!Array.isArray(wire)) return []; + const lines: string[] = []; + for (const entry of wire) { + const message = (entry as { message?: unknown } | null)?.message; + if (typeof message === 'string' && message.trim() !== '' && !lines.includes(message)) lines.push(message); + } + return lines; +} + /** * The fields an `operation: 'update'` action writes, and their prior values. * From 40c5c821495c1c02e2a7a4a96244fd1bc0ab1870 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 02:15:10 +0000 Subject: [PATCH 5/5] test(runtime): pay the dispatcher's lazy metadata load at collection in the declarative-update harness Claude-Session: https://claude.ai/code/session_01L9qiby3dfNfCgpXwPkB2Hf Co-authored-by: Claude --- packages/runtime/src/action-declarative-update.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/runtime/src/action-declarative-update.test.ts b/packages/runtime/src/action-declarative-update.test.ts index ec4aac2d096..9c96c7837e6 100644 --- a/packages/runtime/src/action-declarative-update.test.ts +++ b/packages/runtime/src/action-declarative-update.test.ts @@ -40,6 +40,9 @@ import { describe, it, expect, vi } from 'vitest'; import { assertEngineUpdateDispatch } from '@objectstack/metadata-core'; +// Paid at collection, not inside a case's clocked window: the dispatcher's reach +// loads it lazily (check:test-source-alias). +import '@objectstack/metadata'; import { HttpDispatcher } from './http-dispatcher.js'; import {