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
20 changes: 20 additions & 0 deletions .changeset/34818-flow-checks-before-publish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/spec': minor
'@objectstack/lint': patch
'@objectstack/metadata-protocol': patch
'@objectstack/rest': patch
'@objectstack/runtime': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(flow designer): the publish checks show in the Problems tab and the publish drawer before the publish, worded for the builder

Clause-②: yes (widening: optional userTextLocales on GetMetaItemRequestSchema)
Metadata-protocol: added

Before, a flow's publish checks were seen only after the publish, as a toast that listed rule ids, machine names and English prose, and then disappeared.

- **The draft read carries what the publish would still report.** A flow draft read (`state: 'draft'`) now adds the publish gate's advisory findings to `_diagnostics.warnings`, next to the refusals it already carried. Each warning has the finding's user sentence in the reader's language. The REST door and the runtime dispatcher pass the request's locales, through a new optional `userTextLocales` on `GetMetaItemRequestSchema`. With no locales the sentence is English. `valid` does not change, and the drafts of other types read as before.
- **The sentences name what the builder sees.** `flow-decision-unconditional-branch` has user text in all 11 platform locales. It names the flow, the branch step and the paths by their labels, and says what the shape does to a run and how to fix it. The `approval-approvers-*` sentences now name the flow and the approval step by their labels instead of the flow's machine name and the node id. A step or flow with no label falls back to its id or name. The findings' `message`, `where`, rules and severities do not change.
- **The console shows them before the publish.** The designer's Problems tab already lists a draft's warnings, so the checks now appear there after each save, and clicking one selects its step. The pending-changes drawer lists each flow draft's checks under the flow's label, above Publish. A publish from the drawer or the designer, made after the checks were listed, ends with the toast's title line only. A publish the author did not review, such as one an AI surface performs, keeps the full toast.
8 changes: 8 additions & 0 deletions content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,14 @@ refusal to a loud log for a migration window, so rows written before the gate
existed stay re-savable; it converts refusals, and never promotes them into
`advisories`.

A flow draft can be read before it is published. That read (`GET /api/v1/meta/flow/:name?state=draft`)
runs the publish's own judgement, so its `_diagnostics` say what the publish would answer. A refusal is
listed in `errors`. Each advisory is listed in `warnings`, at the flow-relative path of the step it is
about (`nodes.1`), as the finding's sentence for the builder in the language the request states
(`Accept-Language`, else the workspace default, else English). `valid` is not changed by an advisory.
The flow designer's Problems tab and the pending-changes drawer read these warnings, so an author sees
the publish checks before pressing Publish. A draft of any other type carries no advisories in its read.

So `os validate` is the fast inner-loop check (no artifact), `os build` is what
you run when you need the deployable artifact, and `os lint` adds its own style
rubric on top. **Any rule that can fail a build runs on all three**, so a green
Expand Down
1 change: 1 addition & 0 deletions content/docs/references/api/protocol.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@ This schema accepts one of the following structures:
| **member** | `string` | optional | Bundle member selector, for a metadata type whose identity is a pair (today only `email_template`, identified by `(name, locale)`): the member this request addresses, spelled as its discriminator value (`zh-CN`). Absent, the canonical member (`en-US` for `email_template`), which is what a bare-name read answers; naming the canonical value is the same request. It is not the response translation locale, which `?locale=` and `Accept-Language` choose. Refused with 400 `VALIDATION_ERROR` on a type that has no members, and for a blank value or one longer than a stored member can be (100 characters). A well-formed member with nothing stored or shipped answers as that door answers an absent item. |
| **state** | `Enum<'active' \| 'draft'>` | optional | Draft-visibility switch — which lifecycle row to read (strict mode): `'draft'` opens the pending draft buffer (Studio's editor read) and fails when no draft exists; absent or `'active'` reads the live published row. Distinct from `previewDrafts`, which FALLS BACK to the active row when no draft exists. Declaration ≠ authorization: this member only selects which stored row is read — ADR-0106 masking is unaffected, and draft access is gated upstream, not by this schema. |
| **previewDrafts** | `boolean` | optional | Draft-visibility switch (ADR-0033 draft-overlay preview, non-strict): when true and `state` is not `'draft'`, a pending draft row is preferred if one exists, else the read falls back to the active row — the render path degrades to the published value instead of erroring. A served draft is tagged `_draft: true` so UIs can badge it. Declaration ≠ authorization: this member only switches which row is read, and ADR-0106 masking is unaffected — draft preview is admin-gated upstream, not by this schema. |
| **userTextLocales** | `string[]` | optional | The locales the user-facing sentences of a served DRAFT's check findings are composed in, in ladder order: the locale the request names, then the workspace default — the save request's member of the same name, read the same way (each value against the platform locale table, whole and then one subtag shorter at a time; a value that names no table language is passed over; `en` is the last rung). Read only by the `state: 'draft'` read, which folds what publishing the draft would say into its `_diagnostics`: an advisory finding that carries a user sentence becomes a `_diagnostics.warnings[]` entry in that sentence. Stated by the door that holds the request (the REST door and the dispatcher state `[ExecutionContext.locale, ExecutionContext.workspaceLocale]`), never read from a query string. ABSENT ⇒ the sentences are composed in `en`. It selects a language only: which row is read, and what the verdict is, do not depend on it. |


---
Expand Down
8 changes: 7 additions & 1 deletion packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2059,9 +2059,15 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
severity: f.severity ?? 'warning',
rule: f.rule,
where: f.where,
path: f.where,
// [#34818] A finding placed on a node carries its document path, so a
// draft's `_diagnostics` entry resolves onto that node; the rest keep
// `where` as before.
path: f.path ?? f.where,
message: f.message,
hint: f.hint,
// The user sentence's names ride through the re-map, so the doors can
// render this finding in the request's language.
...(f.userTextParams !== undefined ? { userTextParams: f.userTextParams } : {}),
})),
},
// A credential typed as a LITERAL into a flow position every flow reader is
Expand Down
98 changes: 96 additions & 2 deletions packages/lint/src/finding-user-text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import { FLOW_UPDATE_READONLY_WHEN_FIELD, validateReadonlyFlowWrites } from './v
import { READONLY_FLOW_WRITES_USER_TEXT } from './validate-readonly-flow-writes.user-text.js';
import { FLOW_CREDENTIAL_LITERAL, lintFlowCredentialLiterals } from './lint-flow-credential-literals.js';
import { FLOW_CREDENTIAL_LITERALS_USER_TEXT } from './lint-flow-credential-literals.user-text.js';
import { FLOW_DECISION_UNCONDITIONAL_BRANCH, lintFlowPatterns } from './lint-flow-patterns.js';
import { FLOW_PATTERNS_USER_TEXT } from './lint-flow-patterns.user-text.js';

describe('finding user text · the locale ladder (request locale, then workspace default, then en)', () => {
/** A synthetic entry with two sentences: English and Simplified Chinese. */
Expand Down Expand Up @@ -479,12 +481,13 @@ interface AdvisoryCase {
}

/** Params that pick a sentence's arm rather than name something the sentence must show. */
const ARM_PARAMS: ReadonlySet<string> = new Set(['slate', 'locked', 'trigger', 'root', 'position']);
const ARM_PARAMS: ReadonlySet<string> = new Set(['slate', 'locked', 'trigger', 'root', 'position', 'shape']);

/** A list param carries one name per line; each name must show. */
const shownNamesOf = (params: Record<string, string>): string[] =>
Object.entries(params)
.filter(([key, value]) => !ARM_PARAMS.has(key) && value !== '')
.map(([, value]) => value);
.flatMap(([, value]) => value.split('\n'));

/** The catalog holds exactly `ids`, each in exactly the platform locales, and is the one the door renders from. */
function pinCatalog(name: string, catalog: UserTextCatalog, ids: readonly string[]): void {
Expand Down Expand Up @@ -1012,3 +1015,94 @@ describe('flow credential literals user text · never the value', () => {
expect(findingUserMessage(advisory, ['ja-JP'])).toContain('ヘッダー「Authorization」');
});
});

// ── lint-flow-patterns (#34818) ────────────────────────────────────────────
//
// The flow designer's Problems tab shows the draft's check findings before
// publish, so the sentence names the flow and its steps by the labels the
// builder sees, never `node_2` or the rule id.

/** A labelled decision flow; `edges` are the decision's out-edges. */
const decisionStack = (edges: Array<Record<string, unknown>>) => ({
flows: [{
name: 'meeting_reminder',
label: 'Meeting reminder',
nodes: [
{ id: 'start', type: 'start', label: 'Start', config: {} },
{ id: 'node_2', type: 'decision', label: 'Check date', config: {} },
{ id: 'node_3', type: 'end', label: 'Remind owner', config: {} },
{ id: 'node_4', type: 'end', label: 'Skip', config: {} },
],
edges: [{ id: 'e0', source: 'start', target: 'node_2' }, ...edges],
}],
});

const FLOW_PATTERN_CASES: readonly AdvisoryCase[] = [
{
label: 'a decision that gates on nothing',
rule: FLOW_DECISION_UNCONDITIONAL_BRANCH,
stack: decisionStack([
{ id: 'e1', source: 'node_2', target: 'node_3' },
{ id: 'e2', source: 'node_2', target: 'node_4' },
]),
params: { flow: 'Meeting reminder', node: 'Check date', shape: 'none', targets: 'Remind owner\nSkip' },
},
{
label: 'a decision with an ungated path beside a guarded one',
rule: FLOW_DECISION_UNCONDITIONAL_BRANCH,
stack: decisionStack([
{ id: 'e1', source: 'node_2', target: 'node_3', condition: 'record.amount > 10' },
{ id: 'e2', source: 'node_2', target: 'node_4' },
]),
params: { flow: 'Meeting reminder', node: 'Check date', shape: 'mixed', targets: 'Skip' },
},
];

pinCatalog('flow patterns', FLOW_PATTERNS_USER_TEXT, [FLOW_DECISION_UNCONDITIONAL_BRANCH]);
// The rule leaves `severity` unset for a warning, as the registry row reads it.
pinCases('flow patterns', (stack) => lintFlowPatterns(stack).map((f) => ({ ...f, severity: f.severity ?? 'warning' })), FLOW_PATTERN_CASES);

describe('flow patterns user text · what the builder reads (#34818)', () => {
it('places the finding on the decision node by its document path, so the draft verdict resolves onto it', () => {
for (const c of FLOW_PATTERN_CASES) {
const [finding] = lintFlowPatterns(c.stack).filter((f) => f.rule === c.rule);
expect(finding!.path, c.label).toBe('flows[0].nodes[1]');
const result = runRuntimeAuthoringRules({ type: 'flow', item: (c.stack.flows as unknown[])[0] });
expect(result.advisories.find((f) => f.rule === c.rule)!.path, c.label).toBe('flows[0].nodes[1]');
}
});

it('names no machine name and no rule id in any locale', () => {
for (const c of FLOW_PATTERN_CASES) {
const [finding] = lintFlowPatterns(c.stack).filter((f) => f.rule === c.rule);
for (const tag of PLATFORM_LOCALE_TAGS) {
const text = findingUserMessage(finding!, [tag])!;
expect(text, `${c.label} · ${tag}`).not.toMatch(/node_\d|meeting_reminder|flow-decision|config\./);
}
}
});

it('falls back to the machine names for a flow and nodes that declare no label', () => {
const stack = decisionStack([
{ id: 'e1', source: 'node_2', target: 'node_3' },
{ id: 'e2', source: 'node_2', target: 'node_4' },
]);
const flow = (stack.flows as Array<Record<string, unknown>>)[0]!;
delete flow.label;
for (const node of flow.nodes as Array<Record<string, unknown>>) delete node.label;
const [finding] = lintFlowPatterns(stack).filter((f) => f.rule === FLOW_DECISION_UNCONDITIONAL_BRANCH);
expect(finding!.userTextParams).toEqual({ flow: 'meeting_reminder', node: 'node_2', shape: 'none', targets: 'node_3\nnode_4' });
});

it('names an approval node and its flow by their labels too', () => {
const stack = approvalStack([{ type: 'position', value: 'finance_manager' }]);
const flow = (stack.flows as Array<Record<string, unknown>>)[0]!;
flow.label = 'Expense approval';
(flow.nodes as Array<Record<string, unknown>>)[1]!.label = 'Manager review';
const finding = validateApprovalApprovers(stack).find((f) => f.rule === APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY)!;
expect(finding.userTextParams).toEqual({ flow: 'Expense approval', node: 'Manager review', slate: 'group', locked: 'yes' });
expect(findingUserMessage(finding, ['zh-CN'])).toContain('流程“Expense approval”的审批节点“Manager review”');
// `where` keeps the machine names for `os validate` and logs.
expect(finding.where).toBe('flow "expense_approval" · node "manager_review"');
});
});
2 changes: 2 additions & 0 deletions packages/lint/src/finding-user-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { FLOW_TEMPLATE_PATHS_USER_TEXT } from './validate-flow-template-paths.us
import { FLOW_NODE_WRITES_USER_TEXT } from './validate-flow-node-writes.user-text.js';
import { READONLY_FLOW_WRITES_USER_TEXT } from './validate-readonly-flow-writes.user-text.js';
import { FLOW_CREDENTIAL_LITERALS_USER_TEXT } from './lint-flow-credential-literals.user-text.js';
import { FLOW_PATTERNS_USER_TEXT } from './lint-flow-patterns.user-text.js';
import { WIDGET_BINDINGS_USER_TEXT } from './validate-widget-bindings.user-text.js';
import { CHART_BINDINGS_USER_TEXT } from './validate-chart-bindings.user-text.js';
import { AUTONUMBER_FORMATS_USER_TEXT } from './lint-autonumber-formats.user-text.js';
Expand Down Expand Up @@ -180,6 +181,7 @@ export const FINDING_USER_TEXT_CATALOG: UserTextCatalog = mergeUserTextCatalogs(
FLOW_NODE_WRITES_USER_TEXT,
READONLY_FLOW_WRITES_USER_TEXT,
FLOW_CREDENTIAL_LITERALS_USER_TEXT,
FLOW_PATTERNS_USER_TEXT,
// The dashboard writes: widget and chart binding advisories.
WIDGET_BINDINGS_USER_TEXT,
CHART_BINDINGS_USER_TEXT,
Expand Down
10 changes: 10 additions & 0 deletions packages/lint/src/flow-walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ export function flowNodeLabel(node: AnyRec, index: number): string {
return strName(node.label) ?? strName(node.id) ?? `#${index}`;
}

/**
* A flow's name for a USER sentence (`userTextParams`): its `label`, then its
* machine `name`, then `(flow N)`. A builder reads a flow by the label Studio
* shows them; the machine name is the fallback for a flow that declares none,
* the way {@link flowNodeLabel} falls back to a node's `id`.
*/
export function flowDisplayLabel(flow: AnyRec, index: number): string {
return strName(flow.label) ?? strName(flow.name) ?? `(flow ${index})`;
}

const EMPTY_SLOTS: readonly string[] = [];

/** The region slots a node type owns — empty for every non-container type. */
Expand Down
Loading
Loading