Skip to content

Commit 27b9308

Browse files
committed
fix(app-shell): editing an action in Studio no longer stops the object from saving
The action inspector writes the spec's nested `ai` block instead of the flat `aiExposed` / `aiDescription` it refuses, clears the keys a Type switch makes refused, and edits Body Shape as Flat or Wrap(key). The Data pillar holds an action that is only unfinished, and places a refused one on the action, with "Show me" opening it on the Actions view. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jSHgVcT66bTgBM8Yq3
1 parent c8583f8 commit 27b9308

14 files changed

Lines changed: 1074 additions & 25 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(app-shell): editing an action in Studio no longer stops the object from saving
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Three edits in Studio's action editor (Data › an object › Actions) wrote an action the spec refuses, and from then on every save of the object was refused until a reload, with nothing on screen naming the action:
12+
13+
- **Expose to AI agents** wrote a flat `aiExposed` (and its description a flat `aiDescription`). It now writes the spec's nested block, `ai: { exposed, description }`, and reads it back; unticking leaves a draft the spec accepts. A draft that still carries the flat keys is cleaned by the control's next write. The action preview's AI pill reads the same block.
14+
- **Switching the Type** kept keys the new type refuses (a script `body` on an API action, `onSuccess`, `outcomeMessages`, `undoable: true`). The switch now clears exactly those, and keeps everything the new type accepts.
15+
- **Body Shape** was a free-text box, so the documented `{ "wrap": "payload" }` was written as a string the spec refuses. It is now a Flat / Wrap control with a key input; a stored `{ wrap }` reads back as Wrap with its key, and Wrap is written only once it has a key.
16+
17+
The Data pillar now holds an action that is only unfinished, as it already held a field with no options: after "Run a script" before a source is typed, a Type switch before its endpoint, address or target is filled, or "Expose to AI agents" before a long enough description, no save goes out, and a neutral line names the input on the action until it is filled. A save the server still refuses is shown at the action: the strip names it (and the input, when the editor has one for that key), and "Show me" opens it on the Actions view. The next accepted save clears the strip, with no reload.
18+
19+
New `studio` namespace strings (en, zh): the Body Shape control, and the refusal and held lines for an action.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26728 — "Expose to AI agents" writes the spec's nested `ai`
5+
* block, and unticking leaves a draft the spec accepts.
6+
*
7+
* The control used to write a flat `aiExposed` (and its description a flat
8+
* `aiDescription`). The spec's `ActionSchema` refuses both by name, so one tick
9+
* refused every later save of the object, and unticking wrote `aiExposed:
10+
* false`, still refused. The pins drive the real inspector inside a host that
11+
* merges each patch shallowly (as `ObjectActionsPanel` applies `onPatch`), send
12+
* the held draft through a JSON round trip (the body the save sends), and parse
13+
* it with the spec's own `ActionSchema`:
14+
*
15+
* - a tick writes `ai.exposed`, and the spec's only refusal is the
16+
* description it requires beside it — the input the inspector opens;
17+
* - a description of the spec's minimum length parses, and reads back;
18+
* - unticking parses, with or without a description typed;
19+
* - an older draft carrying the flat keys parses after the control's next
20+
* write, which clears them;
21+
* - the other `ai` keys (edited under "More fields") are kept.
22+
*
23+
* Parity: `AI_DESCRIPTION_MIN` is the spec's own minimum, measured both sides.
24+
*/
25+
26+
import '@testing-library/jest-dom/vitest';
27+
import * as React from 'react';
28+
import { describe, it, expect, vi, afterEach } from 'vitest';
29+
import { render, screen, cleanup, fireEvent } from '@testing-library/react';
30+
import { ActionSchema } from '@objectstack/spec/ui';
31+
32+
// objectui#4697: the inspector reads the shared client on mount; stub it so
33+
// nothing reaches the network, as the sibling inspector suites do.
34+
const state = vi.hoisted(() => ({
35+
metadataClient: { get: vi.fn(async () => undefined), list: vi.fn(async () => [] as unknown[]), withPreviewDrafts() { return this; } },
36+
}));
37+
vi.mock('../useMetadata', () => ({ useMetadataClient: () => state.metadataClient }));
38+
39+
import { ActionDefaultInspector, AI_DESCRIPTION_MIN } from './ActionDefaultInspector';
40+
41+
afterEach(cleanup);
42+
43+
type Draft = Record<string, unknown>;
44+
45+
const SCRIPT_ACTION: Draft = {
46+
name: 'invoice_send',
47+
label: 'Send',
48+
objectName: 'invoice',
49+
locations: ['record_more'],
50+
type: 'script',
51+
body: { language: 'expression', source: 'true' },
52+
};
53+
54+
const DESCRIPTION = 'Send the invoice to its customer once it has been approved by finance.';
55+
56+
function mountHost(initial: Draft) {
57+
const seen: { draft: Draft; writes: Draft[] } = { draft: initial, writes: [] };
58+
function Host() {
59+
const [draft, setDraft] = React.useState<Draft>(initial);
60+
seen.draft = draft;
61+
return (
62+
<ActionDefaultInspector
63+
type="action"
64+
name={String(initial.name)}
65+
locale={'en-US' as never}
66+
readOnly={false}
67+
draft={draft}
68+
onPatch={(patch) => {
69+
seen.writes.push(patch);
70+
setDraft((d) => ({ ...d, ...patch }));
71+
}}
72+
/>
73+
);
74+
}
75+
render(<Host />);
76+
return seen;
77+
}
78+
79+
const sent = (draft: Draft): Draft => JSON.parse(JSON.stringify(draft));
80+
81+
function refusals(draft: Draft): string[] {
82+
const parsed = ActionSchema.safeParse(sent(draft));
83+
return parsed.success ? [] : parsed.error.issues.map((i) => `${i.path.join('.')}:${i.code}`);
84+
}
85+
86+
const exposeBox = () => screen.getByRole('checkbox', { name: 'Expose to AI agents' });
87+
const typeDescription = (text: string) =>
88+
fireEvent.change(screen.getByPlaceholderText('When and why an agent should call this action…'), { target: { value: text } });
89+
90+
describe('aiBlockPin — "Expose to AI agents" writes the nested ai block (objectstack#26728)', () => {
91+
it('a tick writes ai.exposed, never a flat key; the only refusal is the description it requires', () => {
92+
const seen = mountHost(SCRIPT_ACTION);
93+
expect(refusals(seen.draft)).toEqual([]);
94+
95+
fireEvent.click(exposeBox());
96+
expect(seen.writes.at(-1)).toStrictEqual({ ai: { exposed: true } });
97+
expect(sent(seen.draft)).not.toHaveProperty('aiExposed');
98+
// Before the fix: `:unrecognized_keys` at the action, on every later save.
99+
expect(refusals(seen.draft)).toEqual(['ai.description:custom']);
100+
expect(exposeBox()).toBeChecked();
101+
});
102+
103+
it('a description of the spec minimum parses, and reads back into the box', () => {
104+
const seen = mountHost(SCRIPT_ACTION);
105+
fireEvent.click(exposeBox());
106+
typeDescription('short');
107+
expect(refusals(seen.draft)).toEqual(['ai.description:too_small']);
108+
109+
typeDescription(DESCRIPTION);
110+
expect(sent(seen.draft).ai).toStrictEqual({ exposed: true, description: DESCRIPTION });
111+
expect(refusals(seen.draft)).toEqual([]);
112+
expect(screen.getByPlaceholderText('When and why an agent should call this action…')).toHaveValue(DESCRIPTION);
113+
});
114+
115+
it('unticking parses: a finished description is kept, one the spec would refuse goes with the box', () => {
116+
const seen = mountHost(SCRIPT_ACTION);
117+
fireEvent.click(exposeBox());
118+
typeDescription(DESCRIPTION);
119+
fireEvent.click(exposeBox());
120+
expect(sent(seen.draft).ai).toStrictEqual({ exposed: false, description: DESCRIPTION });
121+
expect(refusals(seen.draft)).toEqual([]);
122+
123+
fireEvent.click(exposeBox());
124+
typeDescription('short');
125+
fireEvent.click(exposeBox());
126+
expect(sent(seen.draft).ai).toStrictEqual({ exposed: false });
127+
expect(refusals(seen.draft)).toEqual([]);
128+
});
129+
130+
it('an older draft carrying the flat keys parses after the control\'s next write', () => {
131+
// The shape the control wrote before this fix: refused at the action.
132+
const seen = mountHost({ ...SCRIPT_ACTION, aiExposed: true, aiDescription: 'x' });
133+
expect(refusals(seen.draft)).toEqual([':unrecognized_keys']);
134+
// The flat keys are never read: the box is unticked.
135+
expect(exposeBox()).not.toBeChecked();
136+
137+
fireEvent.click(exposeBox());
138+
fireEvent.click(exposeBox());
139+
expect(sent(seen.draft)).not.toHaveProperty('aiExposed');
140+
expect(sent(seen.draft)).not.toHaveProperty('aiDescription');
141+
expect(refusals(seen.draft)).toEqual([]);
142+
});
143+
144+
it('control: the other ai keys are kept through a tick and an untick', () => {
145+
const seen = mountHost({ ...SCRIPT_ACTION, ai: { category: 'data', requiresConfirmation: true } });
146+
fireEvent.click(exposeBox());
147+
typeDescription(DESCRIPTION);
148+
expect(sent(seen.draft).ai).toStrictEqual({ category: 'data', requiresConfirmation: true, exposed: true, description: DESCRIPTION });
149+
expect(refusals(seen.draft)).toEqual([]);
150+
});
151+
});
152+
153+
describe('aiBlockPin — AI_DESCRIPTION_MIN is the spec minimum (objectstack#26728)', () => {
154+
const withDescription = (length: number): Draft => ({ ...SCRIPT_ACTION, ai: { exposed: true, description: 'x'.repeat(length) } });
155+
156+
it('the spec accepts a description of that length and refuses one shorter', () => {
157+
expect(refusals(withDescription(AI_DESCRIPTION_MIN))).toEqual([]);
158+
expect(refusals(withDescription(AI_DESCRIPTION_MIN - 1))).toEqual(['ai.description:too_small']);
159+
});
160+
});

0 commit comments

Comments
 (0)