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
15 changes: 15 additions & 0 deletions .changeset/36400-flow-label-every-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/lint': patch
'@objectstack/cli': patch
---

fix(lint): the translation coverage check asks every named flow for its label, not only a flow with a screen or an approval step

Clause-②: no
Metadata-protocol: none

`flows.FLOW_NAME.label` is now demanded for every flow a stack declares with a `name`. Until now it was demanded only for a flow with a `screen` or `approval` node, the two readers the key used to have (the screen-flow runner and the approvals inbox). The docs viewer's `type: flow` embed titles its card by the same key for whichever flow a page names, record-triggered, scheduled and API flows included, and the check already asks every flow's drawn steps for their `nodes` labels. So a zh-CN reader saw an English flow name above translated step names, and `os lint` and `os i18n check` did not report it.

What you see after upgrading: `os lint` reports one more `i18n/missing-flow` finding per untranslated locale for each flow that has neither a screen nor an approval step, and `os i18n extract` scaffolds its `label`. Translate it under `flows.FLOW_NAME.label` in each locale bundle, the key the runner and the approvals inbox already read. A flow with no `name` is not asked: no bundle entry can address it.

The repository's own coverage ratchet rises by those labels: `examples/app-showcase` 425 to 449 (24 flows, one untranslated locale each) and `examples/app-todo` 130 to 136 (3 flows in two locales). The other twelve configs, including the ten bundle packages, are unchanged.
2 changes: 1 addition & 1 deletion packages/cli/src/utils/i18n-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ const COVERAGE_SOURCE: Record<ExpectedEntry['source'], CoverageIssue['source']>
// it, so it keeps its own bucket and reports as `i18n/missing-picklist`.
picklist: 'picklist',
page: 'page',
// Screen-flow copy (`flows.<f>.label`, `flows.<f>.screens.<n>.title` /
// Flow copy (every flow's `flows.<f>.label`, `flows.<f>.screens.<n>.title` /
// `.description` (#22507), and the per-field `label` / `placeholder` /
// option labels), the terminal
// toasts (`flows.<f>.successMessage` / `.errorMessage`, #22507) and a refused
Expand Down
16 changes: 9 additions & 7 deletions packages/cli/test/i18n-flow-approval-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
// approval step at all, so `os lint` and `os i18n check` never listed an
// approval flow as untranslated: HotCRM's six approval flows rendered English
// in zh-CN / ja-JP / es-ES under a green coverage run. These pins are the CLI
// half: the walker scaffolds both keys, the coverage gate demands them, and a
// flow no reader names (no screen, no approval) still owes no label.
// half: the walker scaffolds both keys and the coverage gate demands them. The
// flow label is now asked of every named flow (the docs flow embed titles any
// flow by it), pinned in `i18n-flow-screen-coverage.test.ts`; a scheduled flow
// still owes no approval or screen key.
//
// The ledger mock is `i18n-flow-screen-coverage.test.ts`'s, for its reason:
// these pins measure the bucket itself, whatever the shipped ledger says next.
Expand Down Expand Up @@ -61,7 +63,7 @@ const quickNote = {
edges: [],
};

/** A scheduled flow with no screen and no approval: no reader names it. */
/** A scheduled flow with no screen and no approval: only its label is read (the docs flow embed's title). */
const nightlyDigest = {
name: 'nightly_digest',
label: 'Nightly Digest',
Expand Down Expand Up @@ -96,8 +98,8 @@ describe('what the walker harvests from an approval flow (#24916)', () => {
expect(flowKeys({ flows: [flow] })).toEqual(['flows.expense_approval.label']);
});

it('still emits no label for a flow with neither a screen nor an approval node', () => {
expect(flowKeys({ flows: [nightlyDigest] })).toEqual([]);
it('emits only the flow label for a flow with neither a screen nor an approval node', () => {
expect(flowKeys({ flows: [nightlyDigest] })).toEqual(['flows.nightly_digest.label']);
});
});

Expand Down Expand Up @@ -139,14 +141,14 @@ describe('the coverage gate demands the approval flow and its steps (#24916)', (
expect(keys.filter((k) => k.startsWith('flows.expense_approval.'))).toEqual([]);
});

it('keeps the screen flow\'s demand exactly as it was, and asks nothing of the scheduled flow', () => {
it('keeps the screen flow\'s demand exactly as it was, and asks only the scheduled flow\'s label', () => {
const keys = zhFlowIssues(tree()).map((i) => i.key);
expect(keys.filter((k) => k.startsWith('flows.quick_note.'))).toEqual([
'flows.quick_note.label',
'flows.quick_note.screens.ask.title',
'flows.quick_note.screens.ask.fields.note.label',
]);
expect(keys.filter((k) => k.startsWith('flows.nightly_digest.'))).toEqual([]);
expect(keys.filter((k) => k.startsWith('flows.nightly_digest.'))).toEqual(['flows.nightly_digest.label']);
});

it('accepts the translated pack the way the translation contract declares it', () => {
Expand Down
65 changes: 38 additions & 27 deletions packages/cli/test/i18n-flow-screen-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,10 @@ describe('a screen inside an ADR-0031 region (#17511)', () => {
},
],
};
// Not even the flow's own label: the payload object is not a screen node,
// so the flow has none and the runner can never open on it.
expect(flowKeys({ flows: [callout] })).toEqual([]);
// Only the flow's own label, which every named flow owes (the docs flow
// embed titles any flow by it): the payload object is not a screen node,
// so no screen key comes out of it.
expect(flowKeys({ flows: [callout] })).toEqual(['flows.callout.label']);
// The lit control for that empty answer: the same flow with one real
// screen node is walked, and the payload object still is not.
const confirmed = { ...callout, nodes: [...callout.nodes, { id: 'confirm', type: 'screen', config: { title: 'Confirm' } }] };
Expand Down Expand Up @@ -614,17 +615,16 @@ describe('a screen inside an ADR-0031 region (#17511)', () => {
});
});

// ── The flow's own label is demanded only for a flow the runner can open ────
// ── The flow's own label is demanded for every named flow ───────────────────
//
// The console's `FlowRunner` reads `flows.<flow>.label`: it names the flow in
// its header and its completion toast, and it opens only on a run paused at a
// screen node. So the walker emits the label entry for a flow with a screen
// node somewhere in the node universe the screens walk reads, at any depth.
// Both sides are pinned: a flow with no screen node owes no label, and a flow
// whose only screen sits inside a region still owes it. The approvals door is
// the key's other reader, so a flow with an `approval` node owes it too
// (#24916, pinned in `i18n-flow-approval-coverage.test.ts`); the scheduled
// flow below has neither.
// `flows.<flow>.label` has three readers: the console's `FlowRunner` (header
// and completion toast, on a run paused at a screen), the approvals door
// (#24916) and the docs viewer's `type: flow` embed, which titles its card by
// it for whichever flow a page names, whatever its nodes. The third draws a
// scheduled flow with no screen and no approval too, so the walker asks every
// named flow for its label; a flow with no `name` has no key to ask for. The
// scheduled flow below has neither a screen nor an approval and owes the label
// all the same.

/** A scheduled flow whose nodes include a region, and no screen at any depth. */
const nightlyDigest = {
Expand Down Expand Up @@ -711,9 +711,16 @@ describe('a screen\'s body text is a key where the screen authors one (#22507)',
});
});

describe('the flow label is demanded only for a flow the runner can open', () => {
it('emits no `flows.<flow>.label` entry for a flow with no screen node', () => {
expect(flowKeys({ flows: [nightlyDigest] })).toEqual([]);
describe('the flow label is demanded for every named flow', () => {
it('emits the `flows.<flow>.label` entry for a flow with no screen node, seeded with its label', () => {
expect(flowKeys({ flows: [nightlyDigest] })).toEqual(['flows.nightly_digest.label']);
const entry = collectExpectedEntries({ flows: [nightlyDigest] }).find((e) => e.path.join('.') === 'flows.nightly_digest.label');
expect(entry).toMatchObject({ sourceValue: 'Nightly Digest' });
});

it('asks nothing of a flow with no name, which no bundle entry can address', () => {
expect(flowKeys({ flows: [{ ...nightlyDigest, name: undefined }] })).toEqual([]);
expect(flowKeys({ flows: [{ ...nightlyDigest, name: '' }] })).toEqual([]);
});

it('still emits it for a flow whose only screen node is region-nested', () => {
Expand All @@ -723,16 +730,20 @@ describe('the flow label is demanded only for a flow the runner can open', () =>
]);
});

it('asks the coverage gate for the screen flow\'s label and not the other\'s, in one tree', () => {
const report = computeI18nCoverage({
i18n: { defaultLocale: 'en', supportedLocales: ['en', 'zh-CN'] },
flows: [nightlyDigest, guardedCapture],
translations: [{ 'zh-CN': {} }],
});
const labels = userIssues(report)
.map((i) => i.key)
.filter((k) => k.endsWith('.label') && k.split('.').length === 3)
.sort();
expect(labels).toEqual(['flows.guarded_capture.label']);
it('asks the coverage gate for both flows\' labels in one tree, and goes quiet once translated', () => {
const flowLabelIssues = (zh: Record<string, unknown>) =>
userIssues(
computeI18nCoverage({
i18n: { defaultLocale: 'en', supportedLocales: ['en', 'zh-CN'] },
flows: [nightlyDigest, guardedCapture],
translations: [{ 'zh-CN': zh }],
}),
)
.filter((i) => i.source === 'flow')
.map((i) => i.key)
.filter((k) => k.endsWith('.label') && k.split('.').length === 3)
.sort();
expect(flowLabelIssues({})).toEqual(['flows.guarded_capture.label', 'flows.nightly_digest.label']);
expect(flowLabelIssues({ flows: { nightly_digest: { label: '每日摘要' } } })).toEqual(['flows.guarded_capture.label']);
});
});
37 changes: 19 additions & 18 deletions packages/lint/src/i18n-walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2443,30 +2443,31 @@ function walkScreenFlows(config: any, out: ExpectedEntry[]): void {
// by the schema, so this is authored text in practice; `pushOptional`
// keeps a label-less flow from seeding an empty string anyway.
//
// Demanded for a flow with a `screen` node or an `approval` node, at any
// depth of the same node universe the walks below read. The predicate
// mirrors the two readers of the key, and nothing wider:
// Demanded for EVERY named flow. The key has three readers, and the
// third draws any flow, whatever its nodes:
//
// - the console's `FlowRunner` names the flow by it, in its header and its
// completion toast, and the runner opens only on a run paused at a screen;
// completion toast (a run paused at a screen);
// - [#24916] the approvals door names a request's flow by it in the
// reader's locale (`plugin-approvals` `reader-locale-labels.ts`, the
// inbox, the record's approval panel and the request page), and a request
// exists only where an `approval` node opened one.
// inbox, the record's approval panel and the request page);
// - the docs viewer's `type: flow` embed titles its card by it
// (`metadata-viewer.tsx` `FlowView`, `useFlowLabelTranslations`), for
// whichever flow a page names, record-triggered, scheduled and API flows
// included. That is the reader the `nodes` demand below already asks
// every flow's drawn steps for, and a card whose steps are asked for
// and whose title is not draws an English heading over translated
// steps.
//
// A flow with neither (record-triggered, scheduled or an API flow that
// only does work) has no surface that shows its translated label: the
// console's launch hosts toast the action's copy or the flow's own
// `successMessage` / `errorMessage`, never its label. Demanding one would
// ask an author for a string that is stored and never read, so `Flow.label`
// being required by the schema is not the test. When a reader of such a
// flow's label lands, this predicate widens in the same change as that
// reader.
const hasScreen = nodes.some((node) => node && typeof node === 'object' && node.type === SCREEN_NODE_TYPE);
// Until that embed read the key, a flow with neither a screen nor an
// approval had no surface showing its translated label, and this
// predicate was narrower; it widens with that reader, as the walk's rule
// says: a string nobody reads is not demanded, and this one is read. A
// flow with no `name` has no key and is skipped above, the one flow no
// reader can draw by a bundle entry.
const approvalNodes = nodes.filter((node) => node && typeof node === 'object' && node.type === APPROVAL_NODE_TYPE);
if (hasScreen || approvalNodes.length > 0) {
pushOptional(out, ['flows', flowName, 'label'], flow.label, 'flow', scope);
}
const hasScreen = nodes.some((node) => node && typeof node === 'object' && node.type === SCREEN_NODE_TYPE);
pushOptional(out, ['flows', flowName, 'label'], flow.label, 'flow', scope);

// `flows.<flow>.successMessage` / `.errorMessage` (#22507) — the terminal
// toasts, seeded from the flow's own text and emitted ONLY where the flow
Expand Down
4 changes: 2 additions & 2 deletions scripts/i18n-coverage-baseline.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"examples/app-crm/objectstack.config.ts": 0,
"examples/app-multi-package/objectstack.config.ts": 0,
"examples/app-showcase/objectstack.config.ts": 425,
"examples/app-todo/objectstack.config.ts": 130,
"examples/app-showcase/objectstack.config.ts": 449,
"examples/app-todo/objectstack.config.ts": 136,
"packages/platform-objects/scripts/i18n-extract.config.ts": 0,
"packages/plugins/plugin-approvals/scripts/i18n-extract.config.ts": 0,
"packages/plugins/plugin-audit/scripts/i18n-extract.config.ts": 0,
Expand Down
Loading