Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/33838-connector-extras-run-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/i18n': patch
'@object-ui/app-shell': patch
'@object-ui/console': patch
---

fix(app-shell): the Studio connector action Input repeater follows the run's declared-keys rule

Clause-②: yes (widening) — `@object-ui/i18n` gains the studio pack key `engine.inspector.flowNode.kv.undeclaredKey` (en, zh). Nothing is removed or narrowed.
Metadata-protocol: none

- **The repeater offers extras only where the run accepts them.** A `connector_action` step refuses, at run time, an input key the action's input schema does not declare. Studio now reads the schema the same way: an action whose schema lists `properties` (every shipped connector) is closed, and one that carries `additionalProperties` or `unevaluatedProperties` other than `false`, a `$ref`, `allOf` / `anyOf` / `oneOf`, `patternProperties` or another key-admitting keyword, or no `properties` at all, is open. An open action keeps the key/value repeater beside its typed fields, as before. A closed action keeps it only for a key it declares that no typed field can edit, such as an OpenAPI operation's `$ref` or schemaless request `body`, or Slack's `blocks`, and suggests those keys in the key cell. When every declared key has a typed field, the repeater is gone.
- **Keys the run refuses are marked, not dropped.** On a closed action, a stored input key the schema does not declare (one left behind by an older flow or an action switch) stays in the repeater with a line under it saying that the run refuses it and how to fix it. A key typed into the repeater that the action does not declare gets the same line. Studio never removes such a key on its own; the author removes it.
- An OpenAPI operation whose only input is a schemaless body now gets the judged repeater too, where it used to get the generic one.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ export interface FlowKeyValueFieldProps {
* {@link valueEnvelope}.
*/
valueRefusal?: (value: unknown) => string[] | null;
/**
* objectstack#33838: the judge of one KEY — what the cell says under a row
* whose key the consumer refuses (a connector input key the action does not
* declare), or `null` when the key is accepted. The row stays as it is: a
* refused key is marked, never dropped. Omitted, no key is judged.
*/
keyRefusal?: (key: string) => string | null;
}

/**
Expand Down Expand Up @@ -308,6 +315,7 @@ export function FlowKeyValueField({
keysByLabel,
valueMode,
valueRefusal = valueEnvelopeRefusal,
keyRefusal,
}: FlowKeyValueFieldProps) {
const keyListId = React.useId();
const suggestsKeys = !!keyOptions && keyOptions.length > 0;
Expand Down Expand Up @@ -406,6 +414,7 @@ export function FlowKeyValueField({
const shownRefusal = refusal
? [...new Set(refusal.map((m) => (blankText && isBlankExpressionRefusal(m) ? blankText : m)))]
: null;
const keyRefused = keyRefusal && row.key.trim() !== '' ? keyRefusal(row.key.trim()) : null;
return (
<div key={row.id} className="space-y-1">
{/*
Expand Down Expand Up @@ -454,6 +463,11 @@ export function FlowKeyValueField({
<X className="h-3.5 w-3.5" />
</Button>
</div>
{keyRefused && (
<p className="text-[11px] leading-snug text-destructive" role="alert" data-testid="flow-kv-key-refusal">
{keyRefused}
</p>
)}
<div className="flex items-center gap-1.5" data-testid="flow-kv-value-line">
<VariableTextInput
mode={hole ? 'hole' : 'expression'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,25 @@ export interface FlowNodeConfigFieldProps {
requiredColumns?: ReadonlySet<string>;
}

/**
* objectstack#33838 — the key-cell props of a `keyValue` map judged against a
* closed key set ({@link FlowConfigField.acceptedKeys}): a key outside it is
* marked as refused, and the accepted keys no sibling field owns (`omitKeys`)
* are suggested. The key stays free text, so a marked key is still editable.
*/
function acceptedKeyProps(
acceptedKeys: readonly string[],
omitKeys: readonly string[] | undefined,
locale: string | undefined,
): Pick<FlowKeyValueFieldProps, 'keyRefusal' | 'keyOptions'> {
const accepted = new Set(acceptedKeys);
const offered = acceptedKeys.filter((k) => !omitKeys?.includes(k));
return {
keyRefusal: (key) => (accepted.has(key) ? null : t('engine.inspector.flowNode.kv.undeclaredKey', locale)),
...(offered.length > 0 ? { keyOptions: offered.map((k) => ({ value: k, label: k })) } : {}),
};
}

export function FlowNodeConfigField({ field, value, onCommit, disabled, locale, context, scopeGroups, approvalScopeGroups, triggerScope, inactiveRetained, onClearInactive, required, requiredColumns }: FlowNodeConfigFieldProps) {
// A text / textarea field with no override is a literal (no picker spelling).
const refMode: 'expression' | 'hole' | undefined =
Expand Down Expand Up @@ -777,6 +796,11 @@ export function FlowNodeConfigField({ field, value, onCommit, disabled, locale,
// `headers`) renders `{{ }}` holes in each value cell.
valueMode: field.refMode === 'hole' ? 'hole' : undefined,
valueRefusal: isFilterOperandSlot(context?.node?.type, field.path) ? filterOperandRefusal : undefined,
// objectstack#33838 — a map the run judges against a closed key set
// (a connector action's declared inputs): each other key is marked
// as refused, and the declared keys no sibling field types are
// suggested in the key cell.
...(field.acceptedKeys ? acceptedKeyProps(field.acceptedKeys, field.omitKeys, locale) : {}),
};
// objectui#11788 — a record node's field-value map: its keys are fields
// of the node's own target object, so the key cell lists them. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* undeclared extras and their order all survive).
*/

// The source loads this lazily; pay that load at collection, not inside a
// case's clocked window.
import '@objectstack/lint';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react';

Expand Down Expand Up @@ -48,6 +51,12 @@ const SLACK_POST_MESSAGE = {
},
};

/** The slack schema without `blocks` (which no field can type) — CLOSED, every declared key typed. */
const SLACK_TYPED_ONLY = {
...SLACK_POST_MESSAGE,
properties: Object.fromEntries(Object.entries(SLACK_POST_MESSAGE.properties).filter(([k]) => k !== 'blocks')),
};

function mockRegistry(actions: unknown[]) {
vi.stubGlobal(
'fetch',
Expand Down Expand Up @@ -168,7 +177,7 @@ describe('#4305 — the Input section derives typed fields from the descriptor i
expect(patchedInput(onPatch)).toEqual({ channel: 'C123', legacy_note: 'keep me', text: 'hello' });
});

it('an undeclared stored key stays editable in the extras repeater (schema is OPEN)', async () => {
it('an undeclared stored key stays editable in the extras repeater (never hidden or dropped)', async () => {
mockRegistry([{ key: 'chat.postMessage', label: 'Post Message', inputSchema: SLACK_POST_MESSAGE }]);
renderInspector(makeDraft());

Expand Down Expand Up @@ -199,12 +208,12 @@ describe('#4305 — the Input section derives typed fields from the descriptor i
expect(patchedInput(onPatch)).toEqual({ channel: 'C123', legacy_note: 'edited' });
});

it('a CLOSED schema (additionalProperties:false) drops the repeater', async () => {
it('a CLOSED schema whose every declared key is typed drops the repeater', async () => {
mockRegistry([
{
key: 'chat.postMessage',
label: 'Post Message',
inputSchema: { ...SLACK_POST_MESSAGE, additionalProperties: false },
inputSchema: SLACK_TYPED_ONLY,
},
]);
renderInspector(makeDraft({ channel: 'C123' }));
Expand Down Expand Up @@ -233,6 +242,50 @@ describe('#4305 — the Input section derives typed fields from the descriptor i
});
});

describe('objectstack#33838 — the extras repeater follows the run\'s declared-keys rule', () => {
it('a stored key a CLOSED schema does not declare is shown and marked as refused by the run', async () => {
mockRegistry([{ key: 'chat.postMessage', label: 'Post Message', inputSchema: SLACK_TYPED_ONLY }]);
const { onPatch } = renderInspector(makeDraft());

await screen.findByText('Channel');
await waitFor(() => expect(screen.queryByDisplayValue('channel')).toBeNull());
expect(screen.getByDisplayValue('legacy_note')).toBeTruthy();
const marks = screen.getAllByTestId('flow-kv-key-refusal');
expect(marks).toHaveLength(1);
expect(marks[0].getAttribute('role')).toBe('alert');
// Marked, not dropped: rendering alone writes nothing.
expect(onPatch).not.toHaveBeenCalled();
});

it('an OPEN schema (a key-admitting `allOf`) keeps the repeater and marks no key', async () => {
mockRegistry([
{ key: 'chat.postMessage', label: 'Post Message', inputSchema: { ...SLACK_TYPED_ONLY, allOf: [{ type: 'object' }] } },
]);
renderInspector(makeDraft());

await screen.findByText('Channel');
await waitFor(() => expect(screen.queryByDisplayValue('channel')).toBeNull());
expect(screen.getByDisplayValue('legacy_note')).toBeTruthy();
expect(screen.queryByTestId('flow-kv-key-refusal')).toBeNull();
});

it('a declared key no field types (an openapi `body: {}`) is offered by the repeater and not marked', async () => {
mockRegistry([
{
key: 'chat.postMessage',
label: 'Post Message',
inputSchema: { type: 'object', properties: { channel: { type: 'string' }, body: {} } },
},
]);
renderInspector(makeDraft({ channel: 'C123', body: '{"a":1}' }));

await screen.findByText('Channel');
await waitFor(() => expect(screen.queryByDisplayValue('channel')).toBeNull());
expect(screen.getByDisplayValue('body')).toBeTruthy();
expect(screen.queryByTestId('flow-kv-key-refusal')).toBeNull();
});
});

describe('#4305 — pins that must NOT move', () => {
it('a descriptor with NO inputSchema keeps the generic repeater, showing every key', async () => {
mockRegistry([{ key: 'plain', label: 'Plain' }]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { describe, it, expect } from 'vitest';
import {
CONNECTOR_INPUT_PATH,
connectorActionInputSchema,
connectorInputContractKeys,
connectorInputFields,
connectorInputExtras,
mergeConnectorInputExtras,
Expand All @@ -36,6 +37,12 @@ const SLACK_POST_MESSAGE = {
},
};

/** The slack schema without `blocks` — every key it declares gets a typed field. */
const SLACK_TYPED_ONLY = {
...SLACK_POST_MESSAGE,
properties: Object.fromEntries(Object.entries(SLACK_POST_MESSAGE.properties).filter(([k]) => k !== 'blocks')),
};

/** A registry payload shaped like the dispatcher's `{ data: { connectors } }`. */
const CONNECTORS = [
{
Expand Down Expand Up @@ -183,20 +190,46 @@ describe('connectorInputFields — re-rooting onto connectorConfig.input', () =>
});
});

describe('connectorInputFields — measured additionalProperties semantics', () => {
it('treats an ABSENT additionalProperties as OPEN (every shipped connector omits it)', () => {
expect(connectorInputFields(SLACK_POST_MESSAGE)!.open).toBe(true);
/**
* objectstack#33838 — the run's rule, mirrored. Since objectstack#33614 the
* `connector_action` node refuses an input key the action's schema does not
* declare (`service-automation` `connector-input-schema.ts` `declaredKeysOf`),
* reading `properties` as the contract rather than JSON Schema's open default.
*/
describe('connectorInputContractKeys — the run\'s declared-keys rule', () => {
it('a schema listing `properties` (every shipped connector, no `additionalProperties`) is CLOSED', () => {
expect(connectorInputContractKeys(SLACK_POST_MESSAGE)).toEqual(['channel', 'text', 'thread_ts', 'blocks']);
expect(connectorInputFields(SLACK_POST_MESSAGE)!.open).toBe(false);
});

it('declares the `required` names too, even ones `properties` does not list', () => {
expect(connectorInputContractKeys({ type: 'object', properties: { a: { type: 'string' } }, required: ['a', 'b'] }))
.toEqual(['a', 'b']);
});

it('treats `additionalProperties: false` as CLOSED', () => {
expect(connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: false })!.open).toBe(false);
it('`additionalProperties: false` is CLOSED, and with no `properties` declares none', () => {
expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, additionalProperties: false }))
.toEqual(['channel', 'text', 'thread_ts', 'blocks']);
expect(connectorInputContractKeys({ type: 'object', additionalProperties: false })).toEqual([]);
});

it('treats `additionalProperties: true` / a value schema as OPEN', () => {
it('`additionalProperties` / `unevaluatedProperties` set to `true` or a schema is OPEN', () => {
expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, additionalProperties: true })).toBeNull();
expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, additionalProperties: { type: 'string' } })).toBeNull();
expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, unevaluatedProperties: true })).toBeNull();
expect(connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: true })!.open).toBe(true);
expect(
connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: { type: 'string' } })!.open,
).toBe(true);
});

it('a key-admitting keyword (`$ref`, `allOf`, `patternProperties`, …) is OPEN', () => {
for (const k of ['$ref', 'allOf', 'anyOf', 'oneOf', 'patternProperties', 'if', 'dependentSchemas']) {
expect(connectorInputContractKeys({ ...SLACK_POST_MESSAGE, [k]: k === '$ref' ? '#/x' : [] })).toBeNull();
}
});

it('a schema listing no `properties` (and not closed) is OPEN; a non-object is not judged', () => {
expect(connectorInputContractKeys({ type: 'object' })).toBeNull();
expect(connectorInputContractKeys(undefined)).toBeNull();
expect(connectorInputContractKeys([])).toBeNull();
});
});

Expand Down Expand Up @@ -265,21 +298,24 @@ describe('applyConnectorInputForm — splicing into the connector_action group',
'connectorConfig.input.channel',
'connectorConfig.input.text',
'connectorConfig.input.thread_ts',
'connectorConfig.input', // the extras repeater, still open-schema
'connectorConfig.input', // the repeater, kept for the declared `blocks` no field types
'timeoutMs',
]);
});

it('an OPEN schema keeps the repeater, carrying the declared keys as omitKeys', () => {
const form = connectorInputFields(SLACK_POST_MESSAGE)!;
it('an OPEN schema keeps the repeater, carrying the typed keys as omitKeys and judging no key', () => {
const form = connectorInputFields({ ...SLACK_POST_MESSAGE, allOf: [{ type: 'object' }] })!;
expect(form.open).toBe(true);
const repeater = applyConnectorInputForm(base(), form).find((f) => f.id === 'connectorConfig.input')!;
expect(repeater.kind).toBe('keyValue');
expect(repeater.omitKeys).toEqual(['channel', 'text', 'thread_ts']);
expect(repeater.acceptedKeys).toBeUndefined();
});

it('a CLOSED schema drops the repeater entirely', () => {
const form = connectorInputFields({ ...SLACK_POST_MESSAGE, additionalProperties: false })!;
const out = applyConnectorInputForm(base(), form);
it('a CLOSED schema whose every declared key is typed drops the repeater entirely', () => {
const form = connectorInputFields(SLACK_TYPED_ONLY)!;
expect(form.open).toBe(false);
const out = applyConnectorInputForm(base(), form, { channel: 'C123' });
expect(out.some((f) => f.id === 'connectorConfig.input')).toBe(false);
expect(out.map((f) => f.id)).toEqual([
'connectorConfig.connectorId',
Expand All @@ -291,6 +327,49 @@ describe('applyConnectorInputForm — splicing into the connector_action group',
]);
});

it('a CLOSED schema keeps the repeater for a declared key no field types (slack `blocks`), judging every key', () => {
const form = connectorInputFields(SLACK_POST_MESSAGE)!;
const repeater = applyConnectorInputForm(base(), form, { channel: 'C123' }).find((f) => f.id === 'connectorConfig.input')!;
expect(repeater.omitKeys).toEqual(['channel', 'text', 'thread_ts']);
expect(repeater.acceptedKeys).toEqual(['channel', 'text', 'thread_ts', 'blocks']);
});

it('an openapi operation whose `$ref` / schemaless body is declared as `body: {}` offers `body` in the repeater', () => {
// openapi-connector.ts `buildInputSchema`: an unresolved `$ref` request
// body (or content with no `schema`) is declared `body: {}` — any value.
// No field can type it, so the repeater is its only editor; the top level
// stays closed, so anything else typed there is judged.
const form = connectorInputFields({
type: 'object',
properties: {
path: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] },
body: {},
},
required: ['path'],
})!;
expect(form.open).toBe(false);
expect(form.declaredKeys).toEqual(['path']);
const repeater = applyConnectorInputForm(base(), form).find((f) => f.id === 'connectorConfig.input')!;
expect(repeater.omitKeys).toEqual(['path']);
expect(repeater.acceptedKeys).toEqual(['path', 'body']);
});

it('a body-only openapi operation still resolves: the closed schema keeps a judged repeater with no typed field', () => {
const form = connectorInputFields({ type: 'object', properties: { body: {} } })!;
expect(form).not.toBeNull();
expect(form.fields).toEqual([]);
const repeater = applyConnectorInputForm(base(), form).find((f) => f.id === 'connectorConfig.input')!;
expect(repeater.acceptedKeys).toEqual(['body']);
});

it('a stored key a CLOSED schema does not declare keeps the repeater, judged — never dropped', () => {
const form = connectorInputFields(SLACK_TYPED_ONLY)!;
const stored = { channel: 'C123', legacy_note: 'keep me' };
const repeater = applyConnectorInputForm(base(), form, stored).find((f) => f.id === 'connectorConfig.input')!;
expect(repeater.acceptedKeys).toEqual(['channel', 'text', 'thread_ts']);
expect(connectorInputExtras(stored, repeater.omitKeys!)).toEqual({ legacy_note: 'keep me' });
});

it('leaves a group that has no Input field untouched', () => {
const form = connectorInputFields(SLACK_POST_MESSAGE)!;
const httpFields = fieldsForNodeType('http');
Expand Down
Loading
Loading