Skip to content

Commit 582dd2f

Browse files
committed
test(dogfood): a screen flow's result screen carries the two records it created as record links, and a resume carrying a link's value is refused
Claude-Session: https://claude.ai/code/session_0115tbh4XfgivQD2RpHHwdMz Co-authored-by: Claude <noreply@anthropic.com>
1 parent bfd427c commit 582dd2f

2 files changed

Lines changed: 247 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Flow screen record-link fixture (#25872, contract half #26304).
4+
//
5+
// The shape the ruling asks for: a screen flow that creates records ends on a
6+
// result screen that links them, instead of a toast that points at nothing.
7+
// The flow asks for a company and a contact, writes an account and a contact,
8+
// and pauses on a last screen of two read-only `type: 'record_link'` fields
9+
// whose `defaultValue` envelopes read the created records' ids.
10+
//
11+
// Both objects name their records by a field that is NOT `name`
12+
// (`company_name`, `full_name`, ADR-0079 `nameField`), so a client that showed
13+
// a `name` column or the raw id would show the wrong thing.
14+
15+
import { defineStack } from '@objectstack/spec';
16+
import { ObjectSchema, Field } from '@objectstack/spec/data';
17+
import type { Flow } from '@objectstack/spec/automation';
18+
19+
export const SrlAccount = ObjectSchema.create({
20+
name: 'srl_account',
21+
// [ADR-0090 D1] grandfather stamp: the gate under test is the result screen,
22+
// not owner-sharing.
23+
sharingModel: 'public_read_write',
24+
label: 'Account',
25+
pluralLabel: 'Accounts',
26+
nameField: 'company_name',
27+
fields: {
28+
company_name: Field.text({ label: 'Company', required: true }),
29+
},
30+
});
31+
32+
export const SrlContact = ObjectSchema.create({
33+
name: 'srl_contact',
34+
sharingModel: 'public_read_write',
35+
label: 'Contact',
36+
pluralLabel: 'Contacts',
37+
nameField: 'full_name',
38+
fields: {
39+
full_name: Field.text({ label: 'Full name', required: true }),
40+
account: Field.lookup('srl_account', { label: 'Account' }),
41+
},
42+
});
43+
44+
const CEL = (source: string) => ({ dialect: 'cel' as const, source });
45+
46+
/**
47+
* `srl_convert` — start → ask (company, contact) → create account → create
48+
* contact → result (two record links) → end.
49+
*/
50+
export const flowScreenRecordLink: Flow = {
51+
name: 'srl_convert',
52+
label: 'Convert with a result screen',
53+
type: 'screen',
54+
status: 'active',
55+
runAs: 'user',
56+
nodes: [
57+
{ id: 'start', type: 'start', label: 'Start' },
58+
{
59+
id: 'ask',
60+
type: 'screen',
61+
label: 'Convert',
62+
config: {
63+
title: 'Convert',
64+
fields: [
65+
{ name: 'company', label: 'Company', type: 'text', required: true },
66+
{ name: 'contact_name', label: 'Contact', type: 'text', required: true },
67+
],
68+
},
69+
},
70+
{
71+
id: 'create_account',
72+
type: 'create_record',
73+
label: 'Create account',
74+
config: { objectName: 'srl_account', fields: { company_name: CEL('company') }, outputVariable: 'account' },
75+
},
76+
{
77+
id: 'create_contact',
78+
type: 'create_record',
79+
label: 'Create contact',
80+
config: {
81+
objectName: 'srl_contact',
82+
fields: { full_name: CEL('contact_name'), account: CEL('account.id') },
83+
outputVariable: 'contact',
84+
},
85+
},
86+
{
87+
id: 'result',
88+
type: 'screen',
89+
label: 'Created',
90+
config: {
91+
title: 'Created',
92+
fields: [
93+
{ name: 'account_link', label: 'Account', type: 'record_link', reference: 'srl_account', defaultValue: CEL('account.id') },
94+
{ name: 'contact_link', label: 'Contact', type: 'record_link', reference: 'srl_contact', defaultValue: CEL('contact.id') },
95+
],
96+
},
97+
},
98+
{ id: 'end', type: 'end', label: 'End' },
99+
],
100+
edges: [
101+
{ id: 'e1', source: 'start', target: 'ask' },
102+
{ id: 'e2', source: 'ask', target: 'create_account' },
103+
{ id: 'e3', source: 'create_account', target: 'create_contact' },
104+
{ id: 'e4', source: 'create_contact', target: 'result' },
105+
{ id: 'e5', source: 'result', target: 'end' },
106+
],
107+
};
108+
109+
export const screenRecordLinkStack = defineStack({
110+
manifest: {
111+
id: 'com.dogfood.flow-screen-record-link',
112+
namespace: 'srl',
113+
version: '0.0.0',
114+
type: 'app',
115+
name: 'Flow Screen Record Link Fixture',
116+
description: 'A screen flow that creates two records and ends on a screen that links them.',
117+
},
118+
objects: [SrlAccount, SrlContact],
119+
flows: [flowScreenRecordLink],
120+
});
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// FLOW SCREEN RECORD LINK (#25872, contract half #26304) — a screen flow that
4+
// creates records ends on a result screen that links them. Driven end to end
5+
// through a REAL boot: the real trigger and resume doors, real writes, and the
6+
// record read back through the data door the console's record page reads.
7+
//
8+
// The chain, each link asserted where it lands rather than as "no error":
9+
//
10+
// • the run writes an account and a contact, then pauses on the result
11+
// screen. Each of its two fields arrives typed `record_link`, naming its
12+
// object (`reference`) and carrying the id of the record THIS run created
13+
// (`defaultValue`, evaluated before the screen went on the wire), with no
14+
// `required` to meet;
15+
// • each id is a record of that object, readable through the data door, and
16+
// its display name (the object's `nameField`, ADR-0079) is the name the
17+
// author typed — what the console draws as the link text, linking to that
18+
// object's record page;
19+
// • a resume carrying a value under a link field's name is refused 400
20+
// `INVALID_SCREEN_INPUT` naming the field, and the pause survives it;
21+
// • the resume that leaves the links out completes the run.
22+
23+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
24+
import { bootStack, type VerifyStack } from '@objectstack/verify';
25+
import { screenRecordLinkStack } from './fixtures/flow-screen-record-link-fixture.js';
26+
27+
const SYS = { isSystem: true } as const;
28+
const FLOW = 'srl_convert';
29+
30+
describe('objectstack verify FLOW SCREEN RECORD LINK (#25872): a result screen links the records the run created', () => {
31+
let stack: VerifyStack;
32+
let ql: any;
33+
let token: string;
34+
35+
/** Trigger the flow; returns the paused result. */
36+
async function start(): Promise<any> {
37+
const triggered = await stack.apiAs(token, 'POST', `/automation/${FLOW}/trigger`, { params: {} });
38+
expect(triggered.status, await triggered.clone().text()).toBeLessThan(300);
39+
const tj = (await triggered.json()) as any;
40+
const result = tj.result ?? tj.data ?? tj;
41+
expect(result.status).toBe('paused');
42+
expect(result.runId, 'no runId on the paused result').toBeTruthy();
43+
return result;
44+
}
45+
46+
const resume = (runId: string, inputs: Record<string, unknown>) =>
47+
stack.apiAs(token, 'POST', `/automation/${FLOW}/runs/${runId}/resume`, { inputs });
48+
49+
/** Answer the first screen and return the paused result screen. */
50+
async function convert(company: string, contactName: string): Promise<{ runId: string; screen: any }> {
51+
const { runId } = await start();
52+
const answered = await resume(runId, { company, contact_name: contactName });
53+
expect(answered.status, await answered.clone().text()).toBeLessThan(300);
54+
const aj = (await answered.json()) as any;
55+
const result = aj.result ?? aj.data ?? aj;
56+
expect(result.status, `the run did not pause on the result screen: ${JSON.stringify(result)}`).toBe('paused');
57+
expect(result.screen?.nodeId).toBe('result');
58+
return { runId: result.runId ?? runId, screen: result.screen };
59+
}
60+
61+
/** The record behind an id, read as the console's record page reads it. */
62+
async function readRecord(objectName: string, id: string): Promise<Record<string, unknown>> {
63+
const read = await stack.apiAs(token, 'GET', `/data/${objectName}/${id}`);
64+
expect(read.status, await read.clone().text()).toBe(200);
65+
const body = (await read.json()) as any;
66+
return body.record ?? body;
67+
}
68+
69+
beforeAll(async () => {
70+
stack = await bootStack(screenRecordLinkStack as never, { automation: true });
71+
token = await stack.signIn();
72+
ql = await stack.kernel.getServiceAsync('objectql');
73+
}, 120_000);
74+
75+
afterAll(async () => {
76+
await stack?.stop();
77+
});
78+
79+
it('pauses on a result screen whose two fields carry the created records, each named and linkable', async () => {
80+
const { screen } = await convert('Acme Corp', 'Ada Lovelace');
81+
const fields: any[] = screen.fields ?? [];
82+
expect(fields.map((f) => [f.name, f.type, f.reference])).toEqual([
83+
['account_link', 'record_link', 'srl_account'],
84+
['contact_link', 'record_link', 'srl_contact'],
85+
]);
86+
expect(fields.every((f) => f.required !== true), 'a record link asks nothing of the user').toBe(true);
87+
88+
// The ids are the records this run wrote — no other row could carry these names.
89+
const [accounts, contacts] = await Promise.all([
90+
ql.find('srl_account', { where: { company_name: 'Acme Corp' }, context: SYS }),
91+
ql.find('srl_contact', { where: { full_name: 'Ada Lovelace' }, context: SYS }),
92+
]);
93+
expect(accounts).toHaveLength(1);
94+
expect(contacts).toHaveLength(1);
95+
const [accountLink, contactLink] = fields;
96+
expect(String(accountLink.defaultValue)).toBe(String(accounts[0].id));
97+
expect(String(contactLink.defaultValue)).toBe(String(contacts[0].id));
98+
99+
// What the link shows: each record's `nameField` value, read through the
100+
// data door the record page it links to reads.
101+
const account = await readRecord('srl_account', String(accountLink.defaultValue));
102+
expect(account.company_name).toBe('Acme Corp');
103+
const contact = await readRecord('srl_contact', String(contactLink.defaultValue));
104+
expect(contact.full_name).toBe('Ada Lovelace');
105+
}, 60_000);
106+
107+
it('refuses a resume that carries a link field\'s value, keeps the pause, and completes on the clean resume', async () => {
108+
const { runId, screen } = await convert('Globex', 'Grace Hopper');
109+
const createdAccountId = String(screen.fields[0].defaultValue);
110+
111+
for (const inputs of [{ account_link: createdAccountId }, { contact_link: null }]) {
112+
const refused = await resume(runId, inputs);
113+
expect(refused.status, JSON.stringify(inputs)).toBe(400);
114+
const text = await refused.text();
115+
expect(text).toContain('INVALID_SCREEN_INPUT');
116+
expect(text).toContain(`Screen field "${Object.keys(inputs)[0]}" shows a record and takes no value`);
117+
}
118+
119+
// Refused, not consumed: the resume that leaves the links out finishes the run.
120+
const done = await resume(runId, {});
121+
expect(done.status, await done.clone().text()).toBeLessThan(300);
122+
const dj = (await done.json()) as any;
123+
const result = dj.result ?? dj.data ?? dj;
124+
expect(result.status ?? 'completed').toBe('completed');
125+
expect(await ql.find('srl_account', { where: { company_name: 'Globex' }, context: SYS })).toHaveLength(1);
126+
}, 60_000);
127+
});

0 commit comments

Comments
 (0)