Skip to content

Commit f10d535

Browse files
committed
feat(automation,app-shell): the resume refuses a value under a record_link screen field; the flow dialog shows the record's name as a link
Claude-Session: https://claude.ai/code/session_0115tbh4XfgivQD2RpHHwdMz Co-authored-by: Claude <noreply@anthropic.com>
1 parent f24b991 commit f10d535

7 files changed

Lines changed: 587 additions & 10 deletions

File tree

‎content/docs/automation/flows.mdx‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,40 @@ wizard can collect everything first and write once, after its last screen:
818818
The target `file` field's own `accept` / `maxSize` still apply at the write
819819
that claims the file.
820820

821+
#### A read-only record link
822+
823+
`type: 'record_link'` shows a record the run already holds the id of, so a
824+
screen flow can end on a result screen that links the records it created:
825+
826+
```typescript
827+
{ id: 'create_account', type: 'create_record', config: { objectName: 'crm_account',
828+
fields: { name: { dialect: 'cel', source: 'company' } }, outputVariable: 'account' } },
829+
{ id: 'create_contact', type: 'create_record', config: { objectName: 'crm_contact',
830+
fields: { last_name: { dialect: 'cel', source: 'last_name' } }, outputVariable: 'contact' } },
831+
{ id: 'done', type: 'screen', config: { title: 'Lead converted', fields: [
832+
{ name: 'account_link', label: 'Account', type: 'record_link',
833+
reference: 'crm_account', defaultValue: { dialect: 'cel', source: 'account.id' } },
834+
{ name: 'contact_link', label: 'Contact', type: 'record_link',
835+
reference: 'crm_contact', defaultValue: { dialect: 'cel', source: 'contact.id' } },
836+
] } },
837+
```
838+
839+
- **The console shows the record's name as a link.** The flow dialog fetches the
840+
record and shows its display name (the object's `nameField`), as a link to the
841+
record's page. An empty id shows "—". `visibleWhen` works as on any field.
842+
- **`reference` and `defaultValue` are required.** `reference` names the
843+
record's object. `defaultValue` is a value slot that evaluates to the record's
844+
id when the screen is served, usually a CEL envelope over a flow variable.
845+
- **It takes no input.** `required`, `options`, `placeholder`, `min` and `max`
846+
are refused on it at publish. The console posts nothing for it, and a resume
847+
that carries any value under its name is refused with `invalid_value` inside
848+
the run's `INVALID_SCREEN_INPUT`. The value is never bound to a flow variable.
849+
- **The screen still ends with Submit.** A result screen is an ordinary screen:
850+
the run completes when the user submits it. A user who follows a link first
851+
leaves the run paused, as closing the dialog does.
852+
- **Why not `record`?** That name is already an object field type (a name-keyed
853+
map of sub-objects), and a screen field's `type` uses the same vocabulary.
854+
821855
**Screen (object form):**
822856

823857
Set `config.objectName`
@@ -1255,11 +1289,14 @@ POST /api/v1/automation/{flow}/runs/{runId}/resume
12551289
— declared fields: 'kind', 'escalation_reason'
12561290
```
12571291

1258-
Two conditions are refused, both reported at once and both with
1259-
`code: 'INVALID_SCREEN_INPUT'`:
1292+
These conditions are refused, all reported at once and all with
1293+
`code: 'INVALID_SCREEN_INPUT'` (the value shapes of `type: 'number'` and
1294+
`type: 'file'`, and the `min` / `max` bounds, are described with those fields
1295+
above):
12601296

12611297
- a **`required` field the caller was actually asked for** is missing (an empty
12621298
or blank string counts as missing);
1299+
- a value was sent under a **`type: 'record_link'` field**, which takes none;
12631300
- a key the screen **never declared** was sent.
12641301

12651302
`visibleWhen` is evaluated against the **submitted values** first, so a hidden

‎packages/services/service-automation/src/builtin/screen-nodes.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ import { judgeHeadlessScreen } from '../screen-input-contract.js';
6868
*/
6969
const LOOKUP_TARGET_COLUMN = {
7070
type: 'string',
71-
title: 'Lookup object',
71+
title: 'Target object',
7272
xRef: { kind: 'object' },
73-
description: "Object whose records a `lookup` field picks from. Required on a `lookup` field — a picker with no target object resolves nothing.",
73+
description: "Object whose records a `lookup` field picks from, or that a `record_link` field's record belongs to. Required on both — a picker with no target object resolves nothing, and a link with none cannot name its record.",
7474
};
7575

7676
/** How a refusal names a value that is not a record id — `null`, a number (`42`), a map. */
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* A screen flow ends on a result screen that links the records it created
5+
* (ruling B on the screen-flow result screen).
6+
*
7+
* The flow writes two records, then pauses on a screen of two
8+
* `type: 'record_link'` fields whose `defaultValue` envelopes read the created
9+
* records' ids. Pinned here, at the engine:
10+
* - the paused screen carries each field typed `record_link`, with its
11+
* `reference` and its `defaultValue` already evaluated to the id;
12+
* - a resume carrying a value under a link field's name is refused with
13+
* `INVALID_SCREEN_INPUT`, nothing after the screen runs, and the pause
14+
* survives;
15+
* - the resume that leaves the links out completes, and the flow variable the
16+
* id came from is the record the run created — the account link is named
17+
* after that very variable (`account`), so a bound refused value would have
18+
* replaced the record with a string and the audit write after the screen
19+
* would not read the created id.
20+
*/
21+
22+
import { describe, it, expect } from 'vitest';
23+
import { AutomationEngine } from '../engine.js';
24+
import { installBuiltinNodes } from './index.js';
25+
26+
function silentLogger(): any {
27+
const l: any = { info() {}, warn() {}, error() {}, debug() {} };
28+
l.child = () => l;
29+
return l;
30+
}
31+
32+
/** A data engine that mints `<object>_<n>` ids and records every insert. */
33+
function fakeData() {
34+
const inserts: Array<{ obj: string; fields: Record<string, unknown> }> = [];
35+
const data: any = {
36+
async insert(obj: string, fields: Record<string, unknown>) {
37+
inserts.push({ obj, fields });
38+
return { id: `${obj}_${inserts.length}`, ...fields };
39+
},
40+
};
41+
return { data, inserts };
42+
}
43+
44+
const CEL = (source: string) => ({ dialect: 'cel', source });
45+
46+
/** start → create account → create contact → result screen (two links) → audit write → end. */
47+
function convertFlow() {
48+
return {
49+
name: 'convert_with_result',
50+
label: 'Convert with result screen',
51+
type: 'screen',
52+
status: 'active',
53+
runAs: 'system',
54+
nodes: [
55+
{ id: 'start', type: 'start', label: 'Start' },
56+
{ id: 'acc', type: 'create_record', label: 'Account', config: { objectName: 'crm_account', fields: { name: 'Acme' }, outputVariable: 'account' } },
57+
{ id: 'con', type: 'create_record', label: 'Contact', config: { objectName: 'crm_contact', fields: { name: 'Ada' }, outputVariable: 'contact' } },
58+
{
59+
id: 'result', type: 'screen', label: 'Created',
60+
config: {
61+
fields: [
62+
{ name: 'account', label: 'Account', type: 'record_link', reference: 'crm_account', defaultValue: CEL('account.id') },
63+
{ name: 'contact_link', label: 'Contact', type: 'record_link', reference: 'crm_contact', defaultValue: CEL('contact.id') },
64+
],
65+
},
66+
},
67+
{ id: 'audit', type: 'create_record', label: 'Audit', config: { objectName: 'audit', fields: { account: CEL('account.id') } } },
68+
{ id: 'end', type: 'end', label: 'End' },
69+
],
70+
edges: [
71+
{ id: 'e1', source: 'start', target: 'acc' },
72+
{ id: 'e2', source: 'acc', target: 'con' },
73+
{ id: 'e3', source: 'con', target: 'result' },
74+
{ id: 'e4', source: 'result', target: 'audit' },
75+
{ id: 'e5', source: 'audit', target: 'end' },
76+
],
77+
};
78+
}
79+
80+
function makeEngine() {
81+
const { data, inserts } = fakeData();
82+
const engine = new AutomationEngine(silentLogger());
83+
installBuiltinNodes(engine, { logger: silentLogger(), getService: (n: string) => (n === 'data' ? data : undefined) } as any);
84+
engine.registerFlow('convert_with_result', convertFlow() as any);
85+
return { engine, inserts };
86+
}
87+
88+
describe('a screen flow ends on a screen that links the records it created', () => {
89+
it('pauses with both fields typed `record_link`, each carrying its object and the created id', async () => {
90+
const { engine, inserts } = makeEngine();
91+
const started = await engine.execute('convert_with_result', {} as any);
92+
expect(started.status).toBe('paused');
93+
expect(started.screen?.fields).toEqual([
94+
expect.objectContaining({ name: 'account', type: 'record_link', reference: 'crm_account', defaultValue: 'crm_account_1' }),
95+
expect.objectContaining({ name: 'contact_link', type: 'record_link', reference: 'crm_contact', defaultValue: 'crm_contact_2' }),
96+
]);
97+
expect(started.screen?.fields.every((f) => f.required === false)).toBe(true);
98+
expect(inserts.map((i) => i.obj)).toEqual(['crm_account', 'crm_contact']);
99+
});
100+
101+
it('refuses a resume carrying a link field\'s value, runs nothing after the screen, and keeps the pause', async () => {
102+
const { engine, inserts } = makeEngine();
103+
const { runId } = await engine.execute('convert_with_result', {} as any);
104+
105+
const refused = await engine.resume(runId!, { variables: { account: 'crm_account_999' } });
106+
expect(refused.success).toBe(false);
107+
expect(refused.code).toBe('INVALID_SCREEN_INPUT');
108+
expect(refused.error).toContain('Screen field "account" shows a record and takes no value');
109+
expect(inserts.map((i) => i.obj)).toEqual(['crm_account', 'crm_contact']);
110+
111+
// The refusal consumed nothing, and bound nothing: the clean resume
112+
// completes and the next node reads `account.id` — the record the run
113+
// created, not the string the refused resume sent under the same name.
114+
const resumed = await engine.resume(runId!, { variables: {} });
115+
expect(resumed.success, resumed.error).toBe(true);
116+
expect(inserts[2]).toEqual({ obj: 'audit', fields: { account: 'crm_account_1' } });
117+
});
118+
});

‎packages/services/service-automation/src/screen-input-contract.ts‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { isDeepStrictEqual } from 'node:util';
2525

2626
import type { ScreenFieldSpec, ScreenSpec } from '@objectstack/spec/contracts';
2727
import type { FieldErrorCode } from '@objectstack/spec/api';
28+
import { SCREEN_FIELD_RECORD_LINK_TYPE } from '@objectstack/spec/automation';
2829
import { isFileIdToken } from '@objectstack/spec/data';
2930

3031
/** One violation of a screen's declared field contract. */
@@ -33,8 +34,8 @@ export interface ScreenInputIssue {
3334
field: string;
3435
/**
3536
* Which constraint the bag violated, from the field-level catalog
36-
* (ADR-0114 D2) — `required`, `invalid_type`, `min_value`, `max_value` and
37-
* `unknown_field`. Typed as `FieldErrorCode` rather than a local literal
37+
* (ADR-0114 D2) — `required`, `invalid_type`, `invalid_value`, `min_value`,
38+
* `max_value` and `unknown_field`. Typed as `FieldErrorCode` rather than a local literal
3839
* union for the reason `ActionParamIssue` gives: a screen field, an action
3940
* param and a record column must not drift into three vocabularies for the
4041
* same conditions. ⛔ Every member here is one the catalog ALREADY declares —
@@ -73,6 +74,15 @@ const SCREEN_FIELD_VALUE_DOMAINS: ReadonlyMap<string, { admits: (value: unknown)
7374
['file', { admits: isFileIdToken, expected: 'the id of an uploaded file' }],
7475
]);
7576

77+
/**
78+
* Whether a screen field is the read-only record link (`type: 'record_link'`):
79+
* it SHOWS a record by the id its `defaultValue` was served with, and takes no
80+
* value. Matched exactly, as the value domains are.
81+
*/
82+
function isRecordLinkField(field: { type?: string }): boolean {
83+
return field.type === SCREEN_FIELD_RECORD_LINK_TYPE;
84+
}
85+
7686
/**
7787
* Whether a screen surfaces a field contract worth enforcing.
7888
*
@@ -104,6 +114,7 @@ export function screenDeclaresInputContract(screen: ScreenSpec | undefined): boo
104114
* - the VALUE SHAPE of a `type: 'number'` field (#17306) and of a
105115
* `type: 'file'` field (#25801);
106116
* - the declared numeric bound pair `min` / `max` (#17306);
117+
* - no value at all under a `type: 'record_link'` field;
107118
* - undeclared keys.
108119
*
109120
* `visibleWhen` is resolved FIRST, by the caller-supplied {@link visibility}
@@ -158,6 +169,17 @@ export function screenDeclaresInputContract(screen: ScreenSpec | undefined): boo
158169
*
159170
* No other widget hint is read as a value domain: the set is
160171
* {@link SCREEN_FIELD_VALUE_DOMAINS}, and a member joins it by ruling.
172+
*
173+
* `'record_link'` is the one member that takes NO value (ruling B on the
174+
* screen-flow result screen). The field shows a record — the id its
175+
* `defaultValue` was served with — as a link, and nothing the user does on the
176+
* screen changes it. So a resume that carries ANY value under its name, `null`
177+
* included, is refused with `invalid_value` (the catalog's member for a value
178+
* refused for a reason no other member names; ADR-0114 D2, no new code), ⛔
179+
* never dropped and ⛔ never bound: binding it would let a caller who skips the
180+
* console overwrite the flow variable the id came from, and dropping it would
181+
* answer a wrong request with success. Visibility does not matter here — a
182+
* hidden display field takes no value either.
161183
*/
162184
export function validateScreenInputs(
163185
fields: readonly ScreenFieldSpec[],
@@ -208,6 +230,18 @@ export function validateScreenInputs(
208230
});
209231
}
210232

233+
// A read-only record link takes no value, visible or not — the key itself is
234+
// the error, so presence is judged on the key, not on `isPresent`.
235+
for (const field of declared.values()) {
236+
if (!isRecordLinkField(field)) continue;
237+
if (!Object.prototype.hasOwnProperty.call(bag, field.name)) continue;
238+
issues.push({
239+
field: field.name,
240+
code: 'invalid_value',
241+
message: `Screen field "${field.name}" shows a record and takes no value — leave it out of the resume`,
242+
});
243+
}
244+
211245
// Bound pair (#17306). Separate pass from `required` on purpose: a bound
212246
// constrains a value that IS present, so an absent one is the `required`
213247
// question and never this one — an optional bounded field left empty is
@@ -265,6 +299,8 @@ export function declaredScreenFieldNames(fields: readonly ScreenFieldSpec[]): st
265299
*/
266300
export interface ScreenFieldContract {
267301
name: string;
302+
/** Read for one member only: a `'record_link'` field is never answered by a caller. */
303+
type?: string;
268304
required?: boolean;
269305
visibleWhen?: string;
270306
}
@@ -482,6 +518,9 @@ export function judgeHeadlessScreen(
482518
const supplied: string[] = [];
483519
const bag: Record<string, unknown> = {};
484520
for (const field of declared) {
521+
// A read-only record link takes no value, so no caller can answer it: a
522+
// param that happens to share its name does not drive this screen.
523+
if (isRecordLinkField(field)) continue;
485524
if (!callerSupplied(field.name, context)) continue;
486525
supplied.push(field.name);
487526
bag[field.name] = variables.get(field.name);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* A `type: 'record_link'` screen field takes NO value on resume (ruling B on
5+
* the screen-flow result screen).
6+
*
7+
* The field shows a record — the id its `defaultValue` was served with — as a
8+
* link to the record's page. Nothing on the screen changes it, so a resume that
9+
* carries any value under its name is refused with `invalid_value`, ⛔ never
10+
* dropped and ⛔ never bound. And because no caller can answer a display field,
11+
* the headless verdict never counts one as supplied.
12+
*/
13+
14+
import { describe, expect, it } from 'vitest';
15+
16+
import type { ScreenFieldSpec } from '@objectstack/spec/contracts';
17+
18+
import { judgeHeadlessScreen, validateScreenInputs } from './screen-input-contract.js';
19+
20+
const ALWAYS_VISIBLE = () => true;
21+
22+
const link: ScreenFieldSpec = { name: 'created_account', label: 'Account', type: 'record_link', reference: 'crm_account', defaultValue: 'acc_1' };
23+
const note: ScreenFieldSpec = { name: 'note', label: 'Note', type: 'text' };
24+
25+
describe("validateScreenInputs — a `type: 'record_link'` field takes no value", () => {
26+
it('passes a resume that leaves the field out', () => {
27+
expect(validateScreenInputs([link, note], { note: 'done' }, ALWAYS_VISIBLE)).toEqual([]);
28+
expect(validateScreenInputs([link], {}, ALWAYS_VISIBLE)).toEqual([]);
29+
});
30+
31+
it('refuses ANY value under its name with `invalid_value` — the id it shows, another id, empty and null alike', () => {
32+
for (const value of ['acc_1', 'acc_2', '', null, { id: 'acc_1' }, 0, false]) {
33+
const issues = validateScreenInputs([link, note], { created_account: value, note: 'x' }, ALWAYS_VISIBLE);
34+
expect(issues, JSON.stringify(value)).toEqual([{
35+
field: 'created_account',
36+
code: 'invalid_value',
37+
message: 'Screen field "created_account" shows a record and takes no value — leave it out of the resume',
38+
}]);
39+
}
40+
});
41+
42+
it('refuses it hidden too — visibility decides what a user was asked for, and this field asks nothing', () => {
43+
const hidden: ScreenFieldSpec = { ...link, visibleWhen: 'false' };
44+
for (const visibility of [() => false, () => undefined]) {
45+
const issues = validateScreenInputs([hidden], { created_account: 'acc_1' }, visibility);
46+
expect(issues.map((i) => i.code)).toEqual(['invalid_value']);
47+
}
48+
});
49+
50+
it('reads the member exactly, as the value domains are read — another type with the same value is untouched', () => {
51+
for (const type of ['text', 'lookup', 'record', 'Record_Link']) {
52+
const field: ScreenFieldSpec = { ...link, type };
53+
expect(validateScreenInputs([field], { created_account: 'acc_1' }, ALWAYS_VISIBLE), type).toEqual([]);
54+
}
55+
});
56+
});
57+
58+
describe("judgeHeadlessScreen — a caller cannot answer a `type: 'record_link'` field", () => {
59+
it('does not count a param that shares the field\'s name as supplied, so the screen still pauses', () => {
60+
const verdict = judgeHeadlessScreen(
61+
[link],
62+
new Map<string, unknown>([['created_account', 'acc_1']]),
63+
{ params: { created_account: 'acc_1' }, callerParamKeys: ['created_account'] },
64+
);
65+
expect(verdict).toEqual({ satisfied: false, supplied: [], missing: [] });
66+
});
67+
68+
it('positive control: the same param under an input field\'s name is supplied', () => {
69+
const asText: ScreenFieldSpec = { ...link, type: 'text', defaultValue: undefined };
70+
const verdict = judgeHeadlessScreen(
71+
[asText],
72+
new Map<string, unknown>([['created_account', 'acc_1']]),
73+
{ params: { created_account: 'acc_1' }, callerParamKeys: ['created_account'] },
74+
);
75+
expect(verdict).toEqual({ satisfied: true, supplied: ['created_account'], missing: [] });
76+
});
77+
});

0 commit comments

Comments
 (0)