From ee53786b52ae178bf9ea949a16c838f220a7550f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 11:52:40 +0000 Subject: [PATCH 1/6] fix(lint)!: ten publish-time checks for flows that save and do not run Seven errors refuse the publish of a flow that the engine never starts, starts on the wrong rows, or fails on every write; three warnings name a missing cron timezone, an unknown subflow target and a create/update pair written as two flows. Registers the upgrade-guide entry publish-refuses-flows-that-save-and-do-not-run, and the CLI transcripts in the docs count 77 author-time rules. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbYLajSVuBY258yrEFn --- .../35143-flow-publish-checks-second-batch.md | 41 ++ content/docs/deployment/cli.mdx | 2 +- .../docs/deployment/validating-metadata.mdx | 2 +- .../build-with-claude-code.mdx | 2 +- content/docs/ui/react-pages.mdx | 2 +- .../flows/exchange-rate-sync.flow.ts | 2 +- examples/app-todo/src/flows/task.flow.ts | 4 +- packages/lint/src/authoring-rules.ts | 16 + .../flow-publish-checks-second-batch.test.ts | 436 ++++++++++++++++++ packages/lint/src/flow-select-options.ts | 126 +++++ packages/lint/src/index.ts | 12 + packages/lint/src/lint-flow-patterns.ts | 80 ++++ packages/lint/src/rule-explanations.ts | 140 ++++++ .../lint/src/validate-flow-node-writes.ts | 115 ++++- .../validate-flow-trigger-readiness.test.ts | 8 +- .../src/validate-flow-trigger-readiness.ts | 272 ++++++++++- ...-refuses-flows-that-save-and-do-not-run.ts | 38 ++ 17 files changed, 1284 insertions(+), 14 deletions(-) create mode 100644 .changeset/35143-flow-publish-checks-second-batch.md create mode 100644 packages/lint/src/flow-publish-checks-second-batch.test.ts create mode 100644 packages/lint/src/flow-select-options.ts create mode 100644 packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts diff --git a/.changeset/35143-flow-publish-checks-second-batch.md b/.changeset/35143-flow-publish-checks-second-batch.md new file mode 100644 index 00000000000..122f4500133 --- /dev/null +++ b/.changeset/35143-flow-publish-checks-second-batch.md @@ -0,0 +1,41 @@ +--- +'@objectstack/lint': patch +'@objectstack/spec': patch +--- + +fix(lint)!: ten publish-time checks for flows that save and do not run — seven refuse the publish, three warn + +Clause-②: yes (narrowing) +Metadata-protocol: none +Skills-docs: follow-up owed — skills/objectstack-automation/SKILL.md, skills/objectstack-automation/references/examples-flows.md + + + +**BREAKING** for the publish of a flow that carries one of the seven errors below: it was accepted before and is refused now, with the fix named in the finding. The schema is unchanged and stored flows are not rewritten or refused at boot; the refusal comes at the next publish, and from `os validate` / `lint` / `compile` / `build`. + +Seven errors, run by the runtime publish gate and the CLI: + +- `flow-trigger-object-missing`: a record-triggered flow with no `objectName` registers its hook with no object, so it fires on writes to every object. +- `flow-condition-option-label`: a start condition compares a select field with one of its option labels (`record.stage == 'Closed Lost'`) where the row holds the option value (`closed_lost`), so it is never true. Judged only when the field's options are inline in this stack. +- `flow-time-relative-shadowed`: a `timeRelative` block under a record `triggerType` never sweeps, because a record trigger wins. +- `flow-time-relative-key-misplaced`: `filter` or `maxRecords` written beside `timeRelative` is ignored; the sweep reads them only inside the block. +- `flow-time-relative-date-field-invalid`: a `timeRelative.dateField` the swept object does not have, or that is not a `date` / `datetime` field, matches no record. Judged only when the stack declares the object; `created_at` / `updated_at` count as datetime fields. +- `flow-node-write-unknown-option`: a create / update node writes a select field a literal no option carries; the record validator refuses it `invalid_option` on every run. When the literal is an option's label, the finding names its value. +- `flow-node-write-date-helper-text`: a create / update node writes a date field the text of a helper call (`'today()'`); the validator refuses it `invalid_date`. The fix is a CEL value envelope, `{ dialect: 'cel', source: 'isoDate(today())' }`. + +Three warnings, which refuse nothing and make `os validate --strict` exit 1 as any warning does: + +- `flow-schedule-timezone-missing`: a schedule or time-relative cron with no `timezone` runs in UTC. +- `flow-subflow-unknown` (CLI only, new rule `validateFlowSubflowTargets`): a `subflow` / `map` node names a flow this stack and its packages do not carry. The publish gate sees one flow at a time, and another package may ship the called flow, so it is not judged there. +- `flow-create-update-pair`: an after-create flow and an after-update flow on the same object with the same nodes; one flow on `triggerType: 'record-after-write'` does both (on the create run `previous` is null). Judged on the CLI, where the stack holds both flows. + +## FROM → TO + +- a start node `{ triggerType: 'record-after-update' }` with no `objectName` → `{ triggerType: 'record-after-update', objectName: 'deal' }`. +- `record.stage == 'Closed Lost'` → `record.stage == 'closed_lost'`. +- `triggerType: 'record-after-update'` plus `timeRelative` → keep the one the flow means. +- `{ timeRelative: {...}, filter, maxRecords }` → `{ timeRelative: { ..., filter, maxRecords } }`. +- `fields: { stage: 'Closed Lost' }` → `fields: { stage: 'closed_lost' }`. +- `fields: { due_on: 'today()' }` → `fields: { due_on: { dialect: 'cel', source: 'isoDate(today())' } }`. + +New exports from `@objectstack/lint`: `validateFlowSubflowTargets` and the rule ids `FLOW_TRIGGER_OBJECT_MISSING`, `FLOW_CONDITION_OPTION_LABEL`, `FLOW_TIME_RELATIVE_SHADOWED`, `FLOW_TIME_RELATIVE_KEY_MISPLACED`, `FLOW_TIME_RELATIVE_DATE_FIELD_INVALID`, `FLOW_SCHEDULE_TIMEZONE_MISSING`, `FLOW_SUBFLOW_UNKNOWN`, `FLOW_NODE_WRITE_UNKNOWN_OPTION`, `FLOW_NODE_WRITE_DATE_HELPER_TEXT`, `FLOW_CREATE_UPDATE_PAIR`. `@objectstack/spec` adds only the upgrade-guide entry `publish-refuses-flows-that-save-and-do-not-run`. diff --git a/content/docs/deployment/cli.mdx b/content/docs/deployment/cli.mdx index 725c766cf02..43cd68c17fe 100644 --- a/content/docs/deployment/cli.mdx +++ b/content/docs/deployment/cli.mdx @@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines → Normalizing stack definition... → Lowering inline handlers... → Validating protocol compliance... - → Running author-time rules (76)... + → Running author-time rules (77)... → Checking that every required capability has a provider installable in this edition... → Collecting package docs (ADR-0046)... 0 collected → Writing artifact... diff --git a/content/docs/deployment/validating-metadata.mdx b/content/docs/deployment/validating-metadata.mdx index 69a62a824b8..b4e6b0a4fd5 100644 --- a/content/docs/deployment/validating-metadata.mdx +++ b/content/docs/deployment/validating-metadata.mdx @@ -867,7 +867,7 @@ A clean run walks the registry and reports timing: Config: /path/to/support-desk/objectstack.config.ts Load time: 21ms → Validating against ObjectStack Protocol... - → Running author-time rules (76)... + → Running author-time rules (77)... → Checking that every required capability has a provider installable in this edition... → Checking package docs (ADR-0046)... diff --git a/content/docs/getting-started/build-with-claude-code.mdx b/content/docs/getting-started/build-with-claude-code.mdx index 593d23bfb29..5a253f68c8b 100644 --- a/content/docs/getting-started/build-with-claude-code.mdx +++ b/content/docs/getting-started/build-with-claude-code.mdx @@ -311,7 +311,7 @@ visible: 'status != "resolved"' ◆ Validate ──────────────────────────────────────── → Validating against ObjectStack Protocol... - → Running author-time rules (76)... + → Running author-time rules (77)... ✗ Author-time rules failed (1 issue) • stack · action 'resolve_ticket' visible: bare reference `status` — a diff --git a/content/docs/ui/react-pages.mdx b/content/docs/ui/react-pages.mdx index 0204769b764..52418ebaf38 100644 --- a/content/docs/ui/react-pages.mdx +++ b/content/docs/ui/react-pages.mdx @@ -404,7 +404,7 @@ objectstack validate ──────────────────────────────────────── → Loading configuration... → Validating against ObjectStack Protocol... - → Running author-time rules (76)... + → Running author-time rules (77)... → Checking that every required capability has a provider installable in this edition... → Checking package docs (ADR-0046)... diff --git a/examples/app-showcase/src/automation/flows/exchange-rate-sync.flow.ts b/examples/app-showcase/src/automation/flows/exchange-rate-sync.flow.ts index 2995c7fcb6f..fc3612540f5 100644 --- a/examples/app-showcase/src/automation/flows/exchange-rate-sync.flow.ts +++ b/examples/app-showcase/src/automation/flows/exchange-rate-sync.flow.ts @@ -87,7 +87,7 @@ export const ExchangeRateSyncFlow = defineFlow({ type: 'start', label: 'Daily at 06:00', config: { - schedule: { type: 'cron', expression: '0 6 * * *' }, + schedule: { type: 'cron', expression: '0 6 * * *', timezone: 'UTC' }, }, }, { diff --git a/examples/app-todo/src/flows/task.flow.ts b/examples/app-todo/src/flows/task.flow.ts index 34e6b34c508..1f352744e61 100644 --- a/examples/app-todo/src/flows/task.flow.ts +++ b/examples/app-todo/src/flows/task.flow.ts @@ -54,7 +54,7 @@ export const TaskReminderFlow: Flow = { // `objectName` into the record-change binding only), so the key would be // stored and never read. The sweep names its object where it reads, on the // `get_record` step below. - { id: 'start', type: 'start', label: 'Start (Daily 8 AM)', config: { schedule: '0 8 * * *' } }, + { id: 'start', type: 'start', label: 'Start (Daily 8 AM)', config: { schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' } } }, { id: 'get_upcoming_tasks', type: 'get_record', label: 'Get Tasks Due Tomorrow', // `limit > 1` is the declared way to make this a LIST read (`find`, not @@ -164,7 +164,7 @@ export const OverdueEscalationFlow: Flow = { nodes: [ // No `objectName` here either: see `todo_task_reminder`'s start node. - { id: 'start', type: 'start', label: 'Start (Daily 9 AM)', config: { schedule: '0 9 * * *' } }, + { id: 'start', type: 'start', label: 'Start (Daily 9 AM)', config: { schedule: { type: 'cron', expression: '0 9 * * *', timezone: 'UTC' } } }, { id: 'get_overdue_tasks', type: 'get_record', label: 'Get Severely Overdue Tasks', // `limit > 1` = LIST read; the undeclared `getAll` was never read (#4277). diff --git a/packages/lint/src/authoring-rules.ts b/packages/lint/src/authoring-rules.ts index 47d69056a25..beb779db540 100644 --- a/packages/lint/src/authoring-rules.ts +++ b/packages/lint/src/authoring-rules.ts @@ -123,6 +123,7 @@ import { validatePageSourceStyling } from './validate-page-source-styling.js'; import { validateCapabilityReferences } from './validate-capability-references.js'; import { validateFlowApiTriggerSecret, + validateFlowSubflowTargets, validateFlowTriggerReadiness, } from './validate-flow-trigger-readiness.js'; import { validateApprovalApprovers } from './validate-approval-approvers.js'; @@ -1658,6 +1659,21 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [ // GET → edit → PUT passes, and a secretless `api` flow is refused at `/meta` // with this id instead of being stored for the engine to refuse at // registration. + // #35143 — a `subflow` / `map` node calling a flow this stack does not + // define. CLI only: the runtime gate's flow snapshot holds just the written + // flow, so every call to another stored flow would read as unknown there. + // Advisory, with the sibling unknown-object hedge: another installed package + // may ship the called flow. + { + name: 'validateFlowSubflowTargets', + tier: 'advisory', + input: 'normalized', + commands: ALL, + source: 'packages/lint/src/validate-flow-trigger-readiness.ts', + surfaces: CLI_ONLY, + surfaceReason: RUNTIME_NEEDS_FULL_SNAPSHOT, + run: (stack) => validateFlowSubflowTargets(stack), + }, { name: 'validateFlowApiTriggerSecret', tier: 'gating', diff --git a/packages/lint/src/flow-publish-checks-second-batch.test.ts b/packages/lint/src/flow-publish-checks-second-batch.test.ts new file mode 100644 index 00000000000..0bbefaec6d0 --- /dev/null +++ b/packages/lint/src/flow-publish-checks-second-batch.test.ts @@ -0,0 +1,436 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * #35143 — the second batch of publish-time flow checks: the flow family of + * the hosted build checks the framework did not have. Each rule has a pin + * that fires, a pin that stays silent, and (for the rules the runtime publish + * gate runs) the gate's own verdict on a `flow` write. + */ + +import { describe, expect, it } from 'vitest'; +import { runAuthoringRules } from './authoring-rules.js'; +import { runRuntimeAuthoringRules } from './runtime-gate.js'; +import { FLOW_CREATE_UPDATE_PAIR, lintFlowPatterns } from './lint-flow-patterns.js'; +import { + FLOW_NODE_WRITE_DATE_HELPER_TEXT, + FLOW_NODE_WRITE_UNKNOWN_OPTION, + validateFlowNodeWrites, +} from './validate-flow-node-writes.js'; +import { + FLOW_CONDITION_OPTION_LABEL, + FLOW_SCHEDULE_TIMEZONE_MISSING, + FLOW_SUBFLOW_UNKNOWN, + FLOW_TIME_RELATIVE_DATE_FIELD_INVALID, + FLOW_TIME_RELATIVE_KEY_MISPLACED, + FLOW_TIME_RELATIVE_SHADOWED, + FLOW_TRIGGER_OBJECT_MISSING, + validateFlowSubflowTargets, + validateFlowTriggerReadiness, +} from './validate-flow-trigger-readiness.js'; +import { explainRule } from './rule-explanations.js'; + +type AnyRec = Record; + +const DEAL = { + name: 'deal', + label: 'Deal', + fields: { + name: { type: 'text', label: 'Name' }, + stage: { + type: 'select', + label: 'Stage', + options: [ + { value: 'open', label: 'Open' }, + { value: 'closed_lost', label: 'Closed Lost' }, + ], + }, + tags: { + type: 'multiselect', + label: 'Tags', + options: [ + { value: 'hot', label: 'Hot' }, + { value: 'cold', label: 'Cold' }, + ], + }, + region: { type: 'select', label: 'Region', picklist: 'regions' }, + locked_stage: { + type: 'select', + label: 'Locked stage', + readonly: true, + options: [{ value: 'a', label: 'A' }], + }, + due_on: { type: 'date', label: 'Due on' }, + amount: { type: 'number', label: 'Amount' }, + }, +}; + +const startNode = (config: AnyRec) => ({ id: 'start', type: 'start', label: 'Start', config }); + +const flow = (name: string, config: AnyRec, nodes: AnyRec[] = [], extra: AnyRec = {}): AnyRec => ({ + name, + label: name, + type: 'autolaunched', + status: 'active', + nodes: [startNode(config), ...nodes], + edges: nodes.map((n, i) => ({ id: `e${i}`, source: i === 0 ? 'start' : nodes[i - 1].id, target: n.id })), + ...extra, +}); + +const stack = (...flows: AnyRec[]): AnyRec => ({ objects: [DEAL], flows }); + +const rulesOf = (findings: readonly { rule: string }[]) => findings.map((f) => f.rule); + +const SWEEP = { object: 'deal', dateField: 'due_on', withinDays: 7 }; + +describe('flow-trigger-object-missing', () => { + it('refuses a record-change start that names no object', () => { + const findings = validateFlowTriggerReadiness(stack(flow('notify', { triggerType: 'record-after-update' }))); + const hit = findings.filter((f) => f.rule === FLOW_TRIGGER_OBJECT_MISSING); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[0].config.objectName' }); + expect(hit[0].message).toMatch(/every object/); + }); + + it('refuses a blank object name the same way', () => { + const findings = validateFlowTriggerReadiness( + stack(flow('notify', { triggerType: 'record-after-create', objectName: ' ' })), + ); + expect(rulesOf(findings)).toContain(FLOW_TRIGGER_OBJECT_MISSING); + }); + + it('is silent on a record-change start that names its object, and on a flow with no record trigger', () => { + const findings = validateFlowTriggerReadiness( + stack( + flow('notify', { triggerType: 'record-after-update', objectName: 'deal' }), + flow('manual', {}), + ), + ); + expect(rulesOf(findings)).not.toContain(FLOW_TRIGGER_OBJECT_MISSING); + }); + + it('the runtime publish gate refuses the flow write', () => { + const verdict = runRuntimeAuthoringRules({ + type: 'flow', + item: flow('notify', { triggerType: 'record-after-update' }), + context: { objects: [DEAL] }, + }); + expect(rulesOf(verdict.errors)).toContain(FLOW_TRIGGER_OBJECT_MISSING); + }); +}); + +describe('flow-condition-option-label', () => { + const withCondition = (condition: unknown) => + stack(flow('lost', { triggerType: 'record-after-update', objectName: 'deal', condition })); + + it('refuses a start condition comparing a select field with an option label', () => { + const findings = validateFlowTriggerReadiness(withCondition("record.stage == 'Closed Lost'")); + const hit = findings.filter((f) => f.rule === FLOW_CONDITION_OPTION_LABEL); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[0].config.condition' }); + expect(hit[0].hint).toContain("'closed_lost'"); + }); + + it('reads a CEL envelope and double quotes too', () => { + const findings = validateFlowTriggerReadiness( + withCondition({ dialect: 'cel', source: 'previous.stage != "Closed Lost"' }), + ); + expect(rulesOf(findings)).toContain(FLOW_CONDITION_OPTION_LABEL); + }); + + it('is silent when the condition compares the value, or names the value as well', () => { + for (const condition of [ + "record.stage == 'closed_lost'", + "record.stage == 'closed_lost' || record.name == 'Closed Lost'", + ]) { + expect(rulesOf(validateFlowTriggerReadiness(withCondition(condition)))).not.toContain( + FLOW_CONDITION_OPTION_LABEL, + ); + } + }); + + it('is silent when no select field is read, and for an object the stack does not declare', () => { + expect( + rulesOf(validateFlowTriggerReadiness(withCondition("record.name == 'Closed Lost'"))), + ).not.toContain(FLOW_CONDITION_OPTION_LABEL); + const foreign = { objects: [], flows: [flow('lost', { triggerType: 'record-after-update', objectName: 'deal', condition: "record.stage == 'Closed Lost'" })] }; + expect(rulesOf(validateFlowTriggerReadiness(foreign))).not.toContain(FLOW_CONDITION_OPTION_LABEL); + }); + + it('the runtime publish gate refuses the flow write', () => { + const verdict = runRuntimeAuthoringRules({ + type: 'flow', + item: flow('lost', { triggerType: 'record-after-update', objectName: 'deal', condition: "record.stage == 'Closed Lost'" }), + context: { objects: [DEAL] }, + }); + expect(rulesOf(verdict.errors)).toContain(FLOW_CONDITION_OPTION_LABEL); + }); +}); + +describe('flow-time-relative-shadowed', () => { + it('refuses a record-* token beside a sweep descriptor', () => { + const findings = validateFlowTriggerReadiness( + stack(flow('remind', { triggerType: 'record-after-update', objectName: 'deal', timeRelative: SWEEP })), + ); + const hit = findings.filter((f) => f.rule === FLOW_TIME_RELATIVE_SHADOWED); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[0].config.triggerType' }); + }); + + it('is silent on a sweep with no record token', () => { + const findings = validateFlowTriggerReadiness(stack(flow('remind', { timeRelative: SWEEP }, [], { runAs: 'system' }))); + expect(rulesOf(findings)).not.toContain(FLOW_TIME_RELATIVE_SHADOWED); + }); +}); + +describe('flow-time-relative-key-misplaced', () => { + it('refuses filter and maxRecords written beside the descriptor', () => { + const findings = validateFlowTriggerReadiness( + stack(flow('remind', { timeRelative: SWEEP, filter: { stage: 'open' }, maxRecords: 50 })), + ); + const hits = findings.filter((f) => f.rule === FLOW_TIME_RELATIVE_KEY_MISPLACED); + expect(hits.map((f) => f.path)).toEqual([ + 'flows[0].nodes[0].config.filter', + 'flows[0].nodes[0].config.maxRecords', + ]); + expect(hits.every((f) => f.severity === 'error')).toBe(true); + }); + + it('is silent when the keys sit inside the descriptor', () => { + const findings = validateFlowTriggerReadiness( + stack(flow('remind', { timeRelative: { ...SWEEP, filter: { stage: 'open' }, maxRecords: 50 } })), + ); + expect(rulesOf(findings)).not.toContain(FLOW_TIME_RELATIVE_KEY_MISPLACED); + }); + + it('is silent on a start with no descriptor', () => { + const findings = validateFlowTriggerReadiness( + stack(flow('notify', { triggerType: 'record-after-update', objectName: 'deal', filter: { stage: 'open' } })), + ); + expect(rulesOf(findings)).not.toContain(FLOW_TIME_RELATIVE_KEY_MISPLACED); + }); +}); + +describe('flow-time-relative-date-field-invalid', () => { + const sweeping = (dateField: string) => + validateFlowTriggerReadiness(stack(flow('remind', { timeRelative: { ...SWEEP, dateField } }))); + + it('refuses a swept field that is not a date', () => { + const hit = sweeping('amount').filter((f) => f.rule === FLOW_TIME_RELATIVE_DATE_FIELD_INVALID); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[0].config.timeRelative.dateField' }); + expect(hit[0].message).toContain("'number'"); + expect(hit[0].hint).toContain('due_on'); + }); + + it('refuses a swept field the object does not have', () => { + const hit = sweeping('due_date').filter((f) => f.rule === FLOW_TIME_RELATIVE_DATE_FIELD_INVALID); + expect(hit).toHaveLength(1); + expect(hit[0].message).toContain("no field 'due_date'"); + }); + + it('is silent on a date field, on a platform timestamp column, and on an object the stack does not declare', () => { + expect(rulesOf(sweeping('due_on'))).not.toContain(FLOW_TIME_RELATIVE_DATE_FIELD_INVALID); + expect(rulesOf(sweeping('created_at'))).not.toContain(FLOW_TIME_RELATIVE_DATE_FIELD_INVALID); + const foreign = validateFlowTriggerReadiness({ + objects: [], + flows: [flow('remind', { timeRelative: { ...SWEEP, object: 'invoice', dateField: 'amount' } })], + }); + expect(rulesOf(foreign)).not.toContain(FLOW_TIME_RELATIVE_DATE_FIELD_INVALID); + }); +}); + +describe('flow-schedule-timezone-missing', () => { + const scheduled = (schedule: unknown, extra: AnyRec = {}) => + validateFlowTriggerReadiness(stack(flow('digest', { schedule, ...extra }, [], { type: 'schedule' }))); + + it('advises on a cron with no zone, in both spellings', () => { + for (const schedule of ['0 9 * * *', { type: 'cron', expression: '0 9 * * *' }]) { + const hit = scheduled(schedule).filter((f) => f.rule === FLOW_SCHEDULE_TIMEZONE_MISSING); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'warning', path: 'flows[0].nodes[0].config.schedule' }); + } + }); + + it("advises on a sweep's cadence too", () => { + const findings = validateFlowTriggerReadiness( + stack(flow('remind', { timeRelative: SWEEP, schedule: { type: 'cron', expression: '0 9 * * *' } })), + ); + expect(rulesOf(findings)).toContain(FLOW_SCHEDULE_TIMEZONE_MISSING); + }); + + it('is silent on a cron that names its zone, on an interval, and on a record-change flow', () => { + expect( + rulesOf(scheduled({ type: 'cron', expression: '0 9 * * *', timezone: 'Asia/Shanghai' })), + ).not.toContain(FLOW_SCHEDULE_TIMEZONE_MISSING); + expect(rulesOf(scheduled({ type: 'interval', intervalMs: 60000 }))).not.toContain(FLOW_SCHEDULE_TIMEZONE_MISSING); + const recordFlow = validateFlowTriggerReadiness( + stack(flow('notify', { triggerType: 'record-after-update', objectName: 'deal', schedule: '0 9 * * *' })), + ); + expect(rulesOf(recordFlow)).not.toContain(FLOW_SCHEDULE_TIMEZONE_MISSING); + }); +}); + +describe('flow-subflow-unknown', () => { + const calling = (flowName: string) => + flow('parent', {}, [{ id: 'call', type: 'subflow', label: 'Call', config: { flowName } }]); + + it('advises on a subflow step calling a flow the stack does not define', () => { + const findings = validateFlowSubflowTargets(stack(calling('missing_child'))); + expect(findings).toHaveLength(1); + expect(findings[0]).toMatchObject({ + rule: FLOW_SUBFLOW_UNKNOWN, + severity: 'warning', + path: 'flows[0].nodes[1].config.flowName', + }); + }); + + it('is silent when the called flow is in the stack or in a carried package', () => { + expect(validateFlowSubflowTargets(stack(calling('child'), flow('child', {})))).toEqual([]); + expect( + validateFlowSubflowTargets({ ...stack(calling('child')), packages: [{ manifest: { id: 'dep' }, flows: [{ name: 'child' }] }] }), + ).toEqual([]); + }); + + it('runs on the CLI commands and not on the runtime publish gate', () => { + const cli = runAuthoringRules('validate', { normalized: stack(calling('missing_child')) } as never); + expect(rulesOf(cli)).toContain(FLOW_SUBFLOW_UNKNOWN); + const verdict = runRuntimeAuthoringRules({ type: 'flow', item: calling('missing_child'), context: { objects: [DEAL] } }); + expect(rulesOf([...verdict.errors, ...verdict.advisories])).not.toContain(FLOW_SUBFLOW_UNKNOWN); + }); +}); + +describe('flow-node-write-unknown-option', () => { + const writing = (fields: AnyRec) => + stack( + flow('close', { triggerType: 'record-after-update', objectName: 'deal' }, [ + { id: 'set_stage', type: 'update_record', label: 'Set stage', config: { objectName: 'deal', filter: { id: 'x' }, fields } }, + ]), + ); + + it("refuses an option's label written where its value belongs, naming the value", () => { + const hit = validateFlowNodeWrites(writing({ stage: 'Closed Lost' })).filter((f) => f.rule === FLOW_NODE_WRITE_UNKNOWN_OPTION); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[1].config.fields.stage' }); + expect(hit[0].hint).toBe("Write the option's value: 'closed_lost'"); + }); + + it('refuses a literal no option carries, and each bad member of a multi-value write', () => { + expect(rulesOf(validateFlowNodeWrites(writing({ stage: 'won' })))).toContain(FLOW_NODE_WRITE_UNKNOWN_OPTION); + const multi = validateFlowNodeWrites(writing({ tags: ['hot', 'Cold'] })).filter((f) => f.rule === FLOW_NODE_WRITE_UNKNOWN_OPTION); + expect(multi).toHaveLength(1); + expect(multi[0].hint).toContain("'cold'"); + }); + + it('is silent on a value, a CEL envelope, a picklist field, a readonly field and an empty write', () => { + for (const fields of [ + { stage: 'closed_lost' }, + { stage: { dialect: 'cel', source: "'closed_lost'" } }, + { region: 'Anywhere' }, + { locked_stage: 'zzz' }, + { stage: '' }, + { tags: ['hot', 'cold'] }, + ]) { + expect(rulesOf(validateFlowNodeWrites(writing(fields))), JSON.stringify(fields)).not.toContain( + FLOW_NODE_WRITE_UNKNOWN_OPTION, + ); + } + }); + + it('the runtime publish gate refuses the flow write', () => { + const item = writing({ stage: 'Closed Lost' }).flows[0]; + const verdict = runRuntimeAuthoringRules({ type: 'flow', item, context: { objects: [DEAL] } }); + expect(rulesOf(verdict.errors)).toContain(FLOW_NODE_WRITE_UNKNOWN_OPTION); + }); +}); + +describe('flow-node-write-date-helper-text', () => { + const writing = (fields: AnyRec) => + stack( + flow('create_followup', { triggerType: 'record-after-create', objectName: 'deal' }, [ + { id: 'make', type: 'create_record', label: 'Make', config: { objectName: 'deal', fields: { name: 'x', ...fields } } }, + ]), + ); + + it('refuses a date helper inside a plain string written to a date field', () => { + for (const text of ['today()', 'isoDate(daysFromNow(7))']) { + const hit = validateFlowNodeWrites(writing({ due_on: text })).filter((f) => f.rule === FLOW_NODE_WRITE_DATE_HELPER_TEXT); + expect(hit, text).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[1].config.fields.due_on' }); + } + }); + + it('is silent on a CEL envelope, a literal day, and helper text in a text field', () => { + for (const fields of [ + { due_on: { dialect: 'cel', source: 'isoDate(today())' } }, + { due_on: '2026-01-15' }, + { name: 'call back today()' }, + ]) { + expect(rulesOf(validateFlowNodeWrites(writing(fields))), JSON.stringify(fields)).not.toContain( + FLOW_NODE_WRITE_DATE_HELPER_TEXT, + ); + } + }); + + it('the runtime publish gate refuses the flow write', () => { + const item = writing({ due_on: 'today()' }).flows[0]; + const verdict = runRuntimeAuthoringRules({ type: 'flow', item, context: { objects: [DEAL] } }); + expect(rulesOf(verdict.errors)).toContain(FLOW_NODE_WRITE_DATE_HELPER_TEXT); + }); +}); + +describe('flow-create-update-pair', () => { + const notifyNode = { id: 'tell', type: 'notify', label: 'Tell', config: { recipients: ['owner'], title: 'Changed' } }; + const onEvent = (name: string, triggerType: string, objectName = 'deal', node: AnyRec = notifyNode) => + flow(name, { triggerType, objectName }, [node]); + + it('advises on an after-create and an after-update flow running the same steps', () => { + const findings = lintFlowPatterns( + stack(onEvent('on_create', 'record-after-create'), onEvent('on_update', 'record-after-update')), + ).filter((f) => f.rule === FLOW_CREATE_UPDATE_PAIR); + expect(findings).toHaveLength(1); + expect(findings[0].severity).toBe('warning'); + expect(findings[0].message).toContain("'on_create'"); + expect(findings[0].message).toContain("'on_update'"); + }); + + it('is silent when the steps differ, when the objects differ, and for one flow alone', () => { + const other = { ...notifyNode, config: { ...notifyNode.config, title: 'Other' } }; + // Two connector steps whose work rides on `connectorConfig`, not `config`. + const connector = (connectorId: string) => ({ + id: 'call', + type: 'connector_action', + label: 'Call', + connectorConfig: { connectorId, actionId: 'request', input: {} }, + }); + for (const flows of [ + [ + onEvent('on_create', 'record-after-create', 'deal', connector('status_api')), + onEvent('on_update', 'record-after-update', 'deal', connector('slack')), + ], + [onEvent('on_create', 'record-after-create'), onEvent('on_update', 'record-after-update', 'deal', other)], + [onEvent('on_create', 'record-after-create'), onEvent('on_update', 'record-after-update', 'lead')], + [onEvent('on_create', 'record-after-create')], + ]) { + expect(rulesOf(lintFlowPatterns(stack(...flows)))).not.toContain(FLOW_CREATE_UPDATE_PAIR); + } + }); +}); + +describe('every new rule has its explanation', () => { + it('os explain answers each id', () => { + for (const rule of [ + FLOW_TRIGGER_OBJECT_MISSING, + FLOW_CONDITION_OPTION_LABEL, + FLOW_TIME_RELATIVE_SHADOWED, + FLOW_TIME_RELATIVE_KEY_MISPLACED, + FLOW_TIME_RELATIVE_DATE_FIELD_INVALID, + FLOW_SCHEDULE_TIMEZONE_MISSING, + FLOW_SUBFLOW_UNKNOWN, + FLOW_NODE_WRITE_UNKNOWN_OPTION, + FLOW_NODE_WRITE_DATE_HELPER_TEXT, + FLOW_CREATE_UPDATE_PAIR, + ]) { + expect(explainRule(rule)?.rule, rule).toBe(rule); + } + }); +}); diff --git a/packages/lint/src/flow-select-options.ts b/packages/lint/src/flow-select-options.ts new file mode 100644 index 00000000000..f739edb2b4a --- /dev/null +++ b/packages/lint/src/flow-select-options.ts @@ -0,0 +1,126 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * #35143 — what a select field's options are, read the way the record + * validator judges a write (`objectql/src/validation/record-validator.ts`, + * `optionValues`): the stored code is each option's `value` (a bare string + * option is its own value and label), and a write of anything else is refused + * `invalid_option`. + * + * Two rules read it: `flow-condition-option-label` + * (`validate-flow-trigger-readiness.ts`, a start condition comparing an + * option's label) and `flow-node-write-unknown-option` + * (`validate-flow-node-writes.ts`, a CRUD write of a literal no option + * carries). One reading, so the two cannot disagree about what an option is. + * + * A field is judged only when its options are in hand: an inline, non-empty + * `options` array, no shared `picklist` (the registry folds that list in at + * registration, so the stack does not hold it), and not a field two object + * extensions tie on (which definition wins is registration order). + */ + +import { isMultiValueField } from '@objectstack/spec/data'; +import { objectsAsServed, objectsWithoutTiedFields, recordsOf } from './object-graph.js'; + +type AnyRec = Record; + +const isRec = (v: unknown): v is AnyRec => !!v && typeof v === 'object' && !Array.isArray(v); + +/** Field types whose value is one or more option codes. */ +const OPTION_FIELD_TYPES: ReadonlySet = new Set(['select', 'radio', 'multiselect', 'checkboxes']); + +/** One judgeable field's options. */ +export interface SelectOptions { + /** Every stored code, as text (the validator compares `String(value)`). */ + readonly values: ReadonlySet; + /** label → value, for options whose label is not also a value. */ + readonly labels: ReadonlyMap; + /** Whether the stored value is a list of codes. */ + readonly multiple: boolean; + /** `readonly: true` — the validator judges such a value by shape only. */ + readonly readonly: boolean; +} + +/** The options of one field definition, or `undefined` when they are not in hand. */ +export function selectOptionsOf(def: unknown): SelectOptions | undefined { + if (!isRec(def) || typeof def.type !== 'string' || !OPTION_FIELD_TYPES.has(def.type)) return undefined; + if (typeof def.picklist === 'string' && def.picklist.length > 0) return undefined; + if (!Array.isArray(def.options) || def.options.length === 0) return undefined; + const values = new Set(); + const pairs: Array<[string, string]> = []; + for (const option of def.options) { + if (typeof option === 'string') { + values.add(option); + continue; + } + if (!isRec(option) || option.value === undefined || option.value === null) continue; + const value = String(option.value); + values.add(value); + if (typeof option.label === 'string') pairs.push([option.label, value]); + } + if (values.size === 0) return undefined; + const labels = new Map(); + for (const [label, value] of pairs) { + if (label !== value && !values.has(label) && !labels.has(label)) labels.set(label, value); + } + return { + values, + labels, + multiple: isMultiValueField(def as { type: string; multiple?: boolean }), + readonly: def.readonly === true, + }; +} + +/** object name → field name → its options, for every judgeable field of the stack's served objects. */ +export function indexSelectOptions(stack: unknown): ReadonlyMap> { + const out = new Map>(); + for (const obj of objectsWithoutTiedFields(objectsAsServed(stack))) { + if (typeof obj.name !== 'string' || !obj.name) continue; + const byField = new Map(); + for (const field of recordsOf(obj.fields)) { + if (typeof field.name !== 'string' || !field.name) continue; + const options = selectOptionsOf(field); + if (options) byField.set(field.name, options); + } + out.set(obj.name, byField); + } + return out; +} + +/** One label compared where the value was meant. */ +export interface OptionLabelComparison { + readonly field: string; + readonly label: string; + readonly value: string; +} + +/** Is `literal` written in `src` as a quoted string, either quote? */ +function hasQuotedLiteral(src: string, literal: string): boolean { + return src.includes(`'${literal}'`) || src.includes(`"${literal}"`); +} + +/** Is `field` read in `src` (`record.F`, `previous.F`, or bare `F`)? */ +function readsField(src: string, field: string): boolean { + const escaped = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + return new RegExp(`(?:^|[^\\w.])(?:(?:record|previous)\\.)?${escaped}(?![\\w])`).test(src); +} + +/** + * The option labels a CEL source compares where the row holds values: a + * select field of the object is read, one of its option labels is written as + * a quoted literal, and that option's value is not. A label that is also some + * option's value is never reported (the literal may be that value). + */ +export function optionLabelComparisons( + src: string, + options: ReadonlyMap, +): OptionLabelComparison[] { + const out: OptionLabelComparison[] = []; + for (const [field, opts] of options) { + if (opts.labels.size === 0 || !readsField(src, field)) continue; + for (const [label, value] of opts.labels) { + if (hasQuotedLiteral(src, label) && !hasQuotedLiteral(src, value)) out.push({ field, label, value }); + } + } + return out; +} diff --git a/packages/lint/src/index.ts b/packages/lint/src/index.ts index 9f7f2367129..bea7a5e858c 100644 --- a/packages/lint/src/index.ts +++ b/packages/lint/src/index.ts @@ -173,6 +173,15 @@ export { FLOW_TRIGGER_UNROUTABLE, FLOW_API_TRIGGER_SECRET_MISSING, FLOW_API_TRIGGER_SIGNATURE_UNUSABLE, + // #35143 — the second batch of publish-time flow checks. + validateFlowSubflowTargets, + FLOW_TRIGGER_OBJECT_MISSING, + FLOW_CONDITION_OPTION_LABEL, + FLOW_TIME_RELATIVE_SHADOWED, + FLOW_TIME_RELATIVE_KEY_MISPLACED, + FLOW_TIME_RELATIVE_DATE_FIELD_INVALID, + FLOW_SCHEDULE_TIMEZONE_MISSING, + FLOW_SUBFLOW_UNKNOWN, } from './validate-flow-trigger-readiness.js'; export type { FlowTriggerReadinessFinding, @@ -1099,6 +1108,8 @@ export { validateFlowNodeWrites, FLOW_NODE_WRITE_UNKNOWN_FIELD, FLOW_NODE_WRITE_UNPROVISIONED_ANCHOR, + FLOW_NODE_WRITE_UNKNOWN_OPTION, + FLOW_NODE_WRITE_DATE_HELPER_TEXT, FLOW_WRITE_NODE_TYPES, FLOW_WRITE_NODE_TYPES_DEFERRED, } from './validate-flow-node-writes.js'; @@ -1173,6 +1184,7 @@ export { FLOW_DECISION_INCLUSIVE_OVERLAP, FLOW_APPROVAL_DECISION_UNROUTED, FLOW_HTTP_TIMEOUT_MISSING, + FLOW_CREATE_UPDATE_PAIR, } from './lint-flow-patterns.js'; // A credential typed as a literal into a served flow position — the advisory, diff --git a/packages/lint/src/lint-flow-patterns.ts b/packages/lint/src/lint-flow-patterns.ts index 6f3919da016..eda0f0d5c7a 100644 --- a/packages/lint/src/lint-flow-patterns.ts +++ b/packages/lint/src/lint-flow-patterns.ts @@ -390,6 +390,8 @@ export const FLOW_APPROVAL_DECISION_UNROUTED = 'flow-approval-decision-unrouted' * {@link scanHttpTimeouts}. */ export const FLOW_HTTP_TIMEOUT_MISSING = 'flow-http-timeout-missing'; +/** #35143 — an after-create and an after-update flow on one object running the same steps (advisory). */ +export const FLOW_CREATE_UPDATE_PAIR = 'flow-create-update-pair'; /** * Node types that ship in the box. `config.condition` is only ever READ on the @@ -2771,5 +2773,83 @@ export function lintFlowPatterns(stack: AnyRec): FlowLintFinding[] { scanTryCatchWithoutCatch(at, graphNodes, findings); } } + scanCreateUpdatePairs(recordsOf(stack.flows), findings); return findings; } + +/** + * JSON with object keys sorted at every depth, so two configs that differ only + * in key order fingerprint alike. + */ +function stableJson(v: unknown): string { + if (Array.isArray(v)) return `[${v.map(stableJson).join(',')}]`; + if (v && typeof v === 'object') { + const r = v as AnyRec; + return `{${Object.keys(r) + .sort() + .map((k) => `${JSON.stringify(k)}:${stableJson(r[k])}`) + .join(',')}}`; + } + return JSON.stringify(v ?? null); +} + +/** Node keys that name or place a node and change nothing it does. */ +const COSMETIC_NODE_KEYS: ReadonlySet = new Set(['id', 'label', 'description', 'position']); + +/** + * What a flow DOES: each non-start, non-end node whole (its `config`, and + * every other key a node carries its work in, such as `connectorConfig`), + * order insensitive, with the keys that only name or place it left out. + * `undefined` for a flow with no such node. + */ +function flowActionSignature(nodes: AnyRec[]): string | undefined { + const actions = nodes.filter((n) => n.type !== 'start' && n.type !== 'end'); + if (actions.length === 0) return undefined; + return actions + .map((n) => stableJson(Object.fromEntries(Object.entries(n).filter(([k]) => !COSMETIC_NODE_KEYS.has(k))))) + .sort() + .join('|'); +} + +/** + * #35143 — two record-change flows on one object, one started after create + * and one after update, that run the same steps. That is one rule written + * twice: `record-after-write` binds both events in one flow, and two copies + * drift the first time one is edited and the other is not. Advisory: both + * copies run as written. The runtime publish gate judges one flow per write, + * so this speaks on the CLI, where the stack holds both. + */ +function scanCreateUpdatePairs(flows: AnyRec[], findings: FlowLintFinding[]): void { + const legOf = (t: unknown): 'create' | 'update' | undefined => + t === 'record-after-create' || t === 'record-after-insert' ? 'create' + : t === 'record-after-update' ? 'update' + : undefined; + const pairs = new Map(); + for (const flow of flows) { + if (typeof flow.name !== 'string' || !flow.name) continue; + const nodes = recordsOf(flow.nodes); + const cfg = (nodes.find((n) => n.type === 'start')?.config ?? {}) as AnyRec; + const leg = legOf(cfg.triggerType); + const object = typeof cfg.objectName === 'string' && cfg.objectName ? cfg.objectName : undefined; + const signature = flowActionSignature(nodes); + if (!leg || !object || !signature) continue; + const key = `${object}\u0000${signature}`; + const entry = pairs.get(key) ?? { object }; + entry[leg] ??= flow.name; + pairs.set(key, entry); + } + for (const { object, create, update } of pairs.values()) { + if (!create || !update) continue; + findings.push({ + severity: 'warning', + where: `flow '${create}' · flow '${update}'`, + message: + `flows '${create}' (after create) and '${update}' (after update) both watch '${object}' and run the ` + + `same steps: one rule written twice, and the copies drift the first time only one of them is edited.`, + hint: + `Merge them into one flow with config.triggerType 'record-after-write' and delete the other; on the ` + + `create run \`previous\` is null, so write the condition to allow it.`, + rule: FLOW_CREATE_UPDATE_PAIR, + }); + } +} diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 056351737f4..676a3ebac5d 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -6527,6 +6527,136 @@ const FLOW_APPROVAL_DECISION_UNROUTED_EXPLANATION: RuleExplanation = { ], }; +// #35143 — the second batch of publish-time flow checks. + +const FLOW_TRIGGER_OBJECT_MISSING_EXPLANATION: RuleExplanation = { + rule: 'flow-trigger-object-missing', + covers: 'what a record-change start with no object watches', + paragraphs: [ + 'A record-change start (`triggerType: \'record-…\'`) names the object it watches in `config.objectName`. ' + + 'With none, the trigger registers its hook with no object target, and the data engine reads an absent ' + + 'target as every object. So the flow is not idle: it starts on a write to any object, with that row as ' + + '`record`, and its conditions and steps read fields that row usually does not have.', + 'An error: the start node alone settles it. Name the object whose records should start the flow.', + ], +}; + +const FLOW_CONDITION_OPTION_LABEL_EXPLANATION: RuleExplanation = { + rule: 'flow-condition-option-label', + covers: 'why a start condition compares option values', + paragraphs: [ + 'A select field stores the option\'s `value`, never its `label`. A record-change start condition that ' + + 'reads the field and compares it with a quoted label (`record.stage == \'Closed Lost\'` where the option ' + + 'is `{ value: \'closed_lost\', label: \'Closed Lost\' }`) is false on every record, or true on every ' + + 'record for `!=`, so the condition never tells one record from another.', + 'Reported when the condition reads the field, writes a label as a quoted literal and does not write that ' + + 'option\'s value. A label that is also some option\'s value is never reported. Fields whose options come ' + + 'from a shared picklist are not judged: the stack does not hold that list.', + ], +}; + +const FLOW_TIME_RELATIVE_SHADOWED_EXPLANATION: RuleExplanation = { + rule: 'flow-time-relative-shadowed', + covers: 'which trigger wins on a start with both', + paragraphs: [ + 'The engine picks one trigger per flow, in a fixed order: a `record-*` `triggerType` first, then a ' + + '`config.timeRelative` descriptor, then a schedule. A start node carrying both a `record-*` token and a ' + + 'descriptor is therefore a record-change flow: the date sweep is never installed, and the flow runs only ' + + 'when someone writes a record.', + 'Keep the one you mean: remove `triggerType` for the date sweep, or remove `timeRelative` for the ' + + 'record-change trigger.', + ], +}; + +const FLOW_TIME_RELATIVE_KEY_MISPLACED_EXPLANATION: RuleExplanation = { + rule: 'flow-time-relative-key-misplaced', + covers: 'where a sweep reads its filter and cap', + paragraphs: [ + 'A time-relative sweep reads `filter` and `maxRecords` from inside its descriptor ' + + '(`config.timeRelative.filter`, `config.timeRelative.maxRecords`). The start node\'s own `config` ' + + 'hands the sweep only its `schedule` and `condition`, so a `filter` written beside the descriptor ' + + 'narrows nothing (the flow runs for every record in the window, including those the filter meant to ' + + 'skip), and a `maxRecords` there caps nothing.', + 'Reported only when the descriptor does not carry the same key itself. Move the key inside the descriptor.', + ], +}; + +const FLOW_TIME_RELATIVE_DATE_FIELD_INVALID_EXPLANATION: RuleExplanation = { + rule: 'flow-time-relative-date-field-invalid', + covers: 'what field a sweep can run on', + paragraphs: [ + 'A sweep selects the records whose `dateField` falls in a window of days, as a range query on that ' + + 'column. A field the swept object does not have, or one that is not a `date` or `datetime` field, ' + + 'matches no record, so the flow never runs.', + 'Judged only when this stack declares the swept object; an object it does not declare is ' + + '`flow-trigger-unknown-object`\'s. The platform\'s own timestamp columns (`created_at`, `updated_at`) ' + + 'count as datetime fields.', + ], +}; + +const FLOW_SCHEDULE_TIMEZONE_MISSING_EXPLANATION: RuleExplanation = { + rule: 'flow-schedule-timezone-missing', + covers: 'which zone a cron hour runs in', + paragraphs: [ + 'A cron schedule fires at its hour in the zone `timezone` names, and with none it fires in UTC. An ' + + 'author who wants "every day at 9" for a team in another zone, and writes `0 9 * * *` with no zone, gets ' + + '09:00 UTC; one who converts the hour to UTC by hand records the conversion nowhere, so the next reader ' + + 'takes the converted hour for the intended one.', + 'A warning: UTC may be the intent. Name the zone the hour is meant in, ' + + '`{ type: \'cron\', expression: \'0 9 * * *\', timezone: \'Asia/Shanghai\' }`, or write `timezone: \'UTC\'` ' + + 'to say so. Read on schedule flows and on a time-relative sweep\'s cadence.', + ], +}; + +const FLOW_SUBFLOW_UNKNOWN_EXPLANATION: RuleExplanation = { + rule: 'flow-subflow-unknown', + covers: 'how a subflow step finds the flow it calls', + paragraphs: [ + 'A `subflow` or `map` step runs another flow by the name in `config.flowName`. When no flow has that ' + + 'name, the step fails on every run, and every run of the calling flow fails with it.', + 'A warning, and on the CLI only. Another installed package may ship the called flow, which this stack ' + + 'cannot see. And the runtime publish gate judges one flow per write, so a call to another stored flow ' + + 'could not be told from a call to a missing one there.', + ], +}; + +const FLOW_NODE_WRITE_UNKNOWN_OPTION_EXPLANATION: RuleExplanation = { + rule: 'flow-node-write-unknown-option', + covers: 'what a flow may write to a select field', + paragraphs: [ + 'A select field stores one of its options\' values. The record validator refuses a write of anything ' + + 'else (`invalid_option`), and a flow\'s create or update step hands its `fields` to that validator like ' + + 'any caller, so the step fails the run. The usual cause is the option\'s label written where its value ' + + 'belongs (`stage: \'Closed Lost\'` for `closed_lost`).', + 'Only literal values are judged; a CEL value envelope is evaluated at run time. Fields whose options come ' + + 'from a shared picklist, and `readonly` fields, are not judged.', + ], +}; + +const FLOW_NODE_WRITE_DATE_HELPER_TEXT_EXPLANATION: RuleExplanation = { + rule: 'flow-node-write-date-helper-text', + covers: 'how a flow computes a date it writes', + paragraphs: [ + 'A plain string in a flow\'s `fields` is written as the text it spells. `due: \'today()\'` writes the ' + + 'seven characters `today()` to a date field, which the record validator refuses (`invalid_date`), so the ' + + 'step fails the run. A date helper is evaluated only inside a CEL value envelope: ' + + '`{ dialect: \'cel\', source: \'isoDate(today())\' }` for a date, `isoDatetime(now())` for a datetime, ' + + '`isoDate(daysFromNow(7))` for a day offset.', + ], +}; + +const FLOW_CREATE_UPDATE_PAIR_EXPLANATION: RuleExplanation = { + rule: 'flow-create-update-pair', + covers: 'one rule written as two flows', + paragraphs: [ + 'Two record-change flows on the same object, one started after create and one after update, that run ' + + 'the same steps are one rule written twice. The copies drift the first time only one of them is edited. ' + + 'One flow with `triggerType: \'record-after-write\'` runs on both events; on the create run `previous` ' + + 'is null, so its condition must allow that.', + 'A warning: both copies run as written. Judged on the CLI, where the stack holds both flows.', + ], +}; + const FLOW_HTTP_TIMEOUT_MISSING_EXPLANATION: RuleExplanation = { rule: 'flow-http-timeout-missing', covers: 'why an http node needs a timeout', @@ -6821,6 +6951,16 @@ export const RULE_EXPLANATIONS: Readonly> = Obje [FLOW_NODE_TYPE_NO_EXECUTOR_EXPLANATION.rule]: FLOW_NODE_TYPE_NO_EXECUTOR_EXPLANATION, [FLOW_APPROVAL_DECISION_UNROUTED_EXPLANATION.rule]: FLOW_APPROVAL_DECISION_UNROUTED_EXPLANATION, [FLOW_HTTP_TIMEOUT_MISSING_EXPLANATION.rule]: FLOW_HTTP_TIMEOUT_MISSING_EXPLANATION, + [FLOW_TRIGGER_OBJECT_MISSING_EXPLANATION.rule]: FLOW_TRIGGER_OBJECT_MISSING_EXPLANATION, + [FLOW_CONDITION_OPTION_LABEL_EXPLANATION.rule]: FLOW_CONDITION_OPTION_LABEL_EXPLANATION, + [FLOW_TIME_RELATIVE_SHADOWED_EXPLANATION.rule]: FLOW_TIME_RELATIVE_SHADOWED_EXPLANATION, + [FLOW_TIME_RELATIVE_KEY_MISPLACED_EXPLANATION.rule]: FLOW_TIME_RELATIVE_KEY_MISPLACED_EXPLANATION, + [FLOW_TIME_RELATIVE_DATE_FIELD_INVALID_EXPLANATION.rule]: FLOW_TIME_RELATIVE_DATE_FIELD_INVALID_EXPLANATION, + [FLOW_SCHEDULE_TIMEZONE_MISSING_EXPLANATION.rule]: FLOW_SCHEDULE_TIMEZONE_MISSING_EXPLANATION, + [FLOW_SUBFLOW_UNKNOWN_EXPLANATION.rule]: FLOW_SUBFLOW_UNKNOWN_EXPLANATION, + [FLOW_NODE_WRITE_UNKNOWN_OPTION_EXPLANATION.rule]: FLOW_NODE_WRITE_UNKNOWN_OPTION_EXPLANATION, + [FLOW_NODE_WRITE_DATE_HELPER_TEXT_EXPLANATION.rule]: FLOW_NODE_WRITE_DATE_HELPER_TEXT_EXPLANATION, + [FLOW_CREATE_UPDATE_PAIR_EXPLANATION.rule]: FLOW_CREATE_UPDATE_PAIR_EXPLANATION, [STATE_MACHINE_NO_INITIAL_STATES_EXPLANATION.rule]: STATE_MACHINE_NO_INITIAL_STATES_EXPLANATION, [ACTION_NO_OBJECT_BINDING_EXPLANATION.rule]: ACTION_NO_OBJECT_BINDING_EXPLANATION, }); diff --git a/packages/lint/src/validate-flow-node-writes.ts b/packages/lint/src/validate-flow-node-writes.ts index e7a80d82fae..0c3bfc6ca44 100644 --- a/packages/lint/src/validate-flow-node-writes.ts +++ b/packages/lint/src/validate-flow-node-writes.ts @@ -97,7 +97,8 @@ import { } from './validate-hook-body-writes.js'; import { indexUnprovisionedAnchors, unprovisionedAnchorFix } from './system-fields.js'; import { walkFlowNodes, flowNodeLabel } from './flow-walk.js'; -import { recordsOf } from './object-graph.js'; +import { indexServedObjectGraph, recordsOf, type ObjectGraph } from './object-graph.js'; +import { indexSelectOptions, type SelectOptions } from './flow-select-options.js'; import type { UserTextParams } from './finding-user-text.js'; /** @@ -145,6 +146,30 @@ export const FLOW_NODE_WRITE_UNKNOWN_FIELD = 'flow-node-write-unknown-field'; */ export const FLOW_NODE_WRITE_UNPROVISIONED_ANCHOR = 'flow-node-write-unprovisioned-anchor'; +/** + * #35143 — a literal written to a select field that is not one of its option + * values, most often the option's LABEL (`stage: 'Closed Lost'` where the + * option stores `closed_lost`). The record validator judges the write's + * option membership and refuses it `invalid_option`, so the step fails the + * run. `error`, at the certainty the unknown-field verdict gates on: a + * literal value against the literal options of a literal object. The options + * read is `flow-select-options.ts`'s, shared with the start-condition rule. + */ +export const FLOW_NODE_WRITE_UNKNOWN_OPTION = 'flow-node-write-unknown-option'; + +/** + * #35143 — a date helper written inside a plain string (`due: 'today()'`, + * `'daysFromNow(7)'`) into a `date` / `datetime` field. A bare string in a + * value slot is the literal it spells (`FlowRecordFieldValueSchema`), so the + * helper is never evaluated, the record validator refuses the text + * `invalid_date`, and the step fails the run. The CEL value envelope is the + * spelling that evaluates it. + */ +export const FLOW_NODE_WRITE_DATE_HELPER_TEXT = 'flow-node-write-date-helper-text'; + +/** [#35143] A call to a clock or date helper, as it appears inside a plain string. */ +const DATE_HELPER_CALL = /\b(?:today|now|daysFromNow|daysAgo|isoDate|isoDatetime|addDays|addMonths|date|datetime)\s*\(/; + // ─── The covered-node ledger ──────────────────────────────────────────────── // // Which flow node types have their `config.fields` write map resolved against @@ -219,6 +244,9 @@ export function validateFlowNodeWrites(stack: AnyRec): FlowNodeWriteFinding[] { let objectFields: Map> | null = null; // [commit 192213f66] Non-empty only for a stack carrying an ADR-0015 `external` object. let anchors: ReadonlyMap> | null = null; + // [#35143] The value verdicts' two indexes, also built on first use. + let selectOptions: ReadonlyMap> | null = null; + let graph: ObjectGraph | null = null; flows.forEach((flow, flowIndex) => { const flowName = typeof flow.name === 'string' && flow.name ? flow.name : `#${flowIndex}`; @@ -260,7 +288,24 @@ export function validateFlowNodeWrites(stack: AnyRec): FlowNodeWriteFinding[] { for (const fieldName of written) { // An author-DECLARED column wins outright — on a federated object it // maps a remote column the author vouches for (#7859's direction). - if (known.has(fieldName)) continue; + if (known.has(fieldName)) { + // [#35143] Then the VALUE, where a literal value settles it. + selectOptions ??= indexSelectOptions(stack); + graph ??= indexServedObjectGraph(stack); + findings.push( + ...writtenValueFindings({ + value: fields[fieldName], + options: selectOptions.get(objectName)?.get(fieldName), + type: graph.get(objectName)?.fields.get(fieldName)?.type, + nodeType: node.type, + objectName, + fieldName, + where: `flow "${flowName}" › ${nodeWhere}`, + path: `${nodePath}.config.fields.${fieldName}`, + }), + ); + continue; + } if (IMPLICIT_FIELDS.has(fieldName)) { // [commit 192213f66] Implicitly writable SOMEWHERE is not provisioned HERE. if (!anchors.get(objectName)?.has(fieldName)) continue; @@ -308,6 +353,72 @@ export function validateFlowNodeWrites(stack: AnyRec): FlowNodeWriteFinding[] { return findings; } +/** + * [#35143] The two verdicts on a declared field's written VALUE: a select + * literal that is no option value, and a date helper inside a plain string + * written to a date field. A CEL or text envelope is evaluated at run time + * and judged by `validate-expressions`, so only literals are read here. + */ +function writtenValueFindings(at: { + value: unknown; + options: SelectOptions | undefined; + type: string | undefined; + nodeType: string; + objectName: string; + fieldName: string; + where: string; + path: string; +}): FlowNodeWriteFinding[] { + const out: FlowNodeWriteFinding[] = []; + const { value, options, objectName, fieldName } = at; + if (options && !options.readonly) { + const literals = Array.isArray(value) && options.multiple ? value : [value]; + for (const literal of literals) { + if (typeof literal !== 'string' && typeof literal !== 'number' && typeof literal !== 'boolean') continue; + const written = String(literal); + if (written === '' || options.values.has(written)) continue; + const meant = options.labels.get(written); + out.push({ + severity: 'error', + rule: FLOW_NODE_WRITE_UNKNOWN_OPTION, + where: at.where, + path: at.path, + message: + `${at.nodeType} writes '${written}' to '${objectName}.${fieldName}', ` + + (meant !== undefined ? `which is an option's label, not its value; ` : `which is not one of its options; `) + + `the record validator refuses the write (invalid_option) and the step fails the run`, + hint: + meant !== undefined + ? `Write the option's value: '${meant}'` + : `Write one of the option values of '${fieldName}': ${[...options.values].map((v) => `'${v}'`).join(', ')}`, + }); + } + } + if ( + (at.type === 'date' || at.type === 'datetime') && + typeof value === 'string' && + DATE_HELPER_CALL.test(value) + ) { + const source = value.trim(); + out.push({ + severity: 'error', + rule: FLOW_NODE_WRITE_DATE_HELPER_TEXT, + where: at.where, + path: at.path, + message: + `${at.nodeType} writes the text '${source}' to the ${at.type} field '${objectName}.${fieldName}'; a plain ` + + `string is written as it is, so the helper is never evaluated, the write is refused (invalid_date) and ` + + `the step fails the run`, + hint: + at.type === 'date' + ? `Write a CEL value envelope: { dialect: 'cel', source: 'isoDate(today())' } (a day offset is ` + + `'isoDate(daysFromNow(7))')` + : `Write a CEL value envelope: { dialect: 'cel', source: 'isoDatetime(now())' }`, + }); + } + return out; +} + /** Did-you-mean (declared + system columns as candidates) plus the fix. */ function fixHint(field: string, declared: string[]): string { const suggestion = formatSuggestion(findClosestMatches(field, [...declared, ...IMPLICIT_FIELDS])); diff --git a/packages/lint/src/validate-flow-trigger-readiness.test.ts b/packages/lint/src/validate-flow-trigger-readiness.test.ts index 2cc3d8b5565..38a5b41cb87 100644 --- a/packages/lint/src/validate-flow-trigger-readiness.test.ts +++ b/packages/lint/src/validate-flow-trigger-readiness.test.ts @@ -721,7 +721,7 @@ describe('validateFlowTriggerReadiness', () => { const withSchedule = scalarOnlyStack('daily'); ( (withSchedule.flows[0] as Record).nodes as Array> - )[0].config = { timeRelative: 'daily', schedule: { type: 'cron', expression: '0 8 * * *' } }; + )[0].config = { timeRelative: 'daily', schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' } }; const [f] = validateFlowTriggerReadiness(withSchedule); expect(f.rule).toBe(FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE); expect(f.message).toContain('config.schedule'); @@ -1853,7 +1853,7 @@ describe('validateFlowTriggerReadiness', () => { it('reports NOTHING for a `schedule` flow that declares no organization', () => { expect( - validateFlowTriggerReadiness(timeTriggered({ schedule: { type: 'cron', expression: '0 1 * * *' } })), + validateFlowTriggerReadiness(timeTriggered({ schedule: { type: 'cron', expression: '0 1 * * *', timezone: 'UTC' } })), 'the deleted rule fired here; under the single posture with the switch on this flow is correct', ).toEqual([]); }); @@ -1873,7 +1873,7 @@ describe('validateFlowTriggerReadiness', () => { // layer that knows neither. expect( validateFlowTriggerReadiness( - timeTriggered({ schedule: { type: 'cron', expression: '0 1 * * *' }, organizationId: 'org_x' }), + timeTriggered({ schedule: { type: 'cron', expression: '0 1 * * *', timezone: 'UTC' }, organizationId: 'org_x' }), ), ).toEqual([]); }); @@ -1881,7 +1881,7 @@ describe('validateFlowTriggerReadiness', () => { it('reports NOTHING for a present-but-unusable organization value', () => { for (const bad of ['', 123, { id: 'org_x' }, null]) { expect( - validateFlowTriggerReadiness(timeTriggered({ schedule: '0 1 * * *', organization: bad })), + validateFlowTriggerReadiness(timeTriggered({ schedule: { type: 'cron', expression: '0 1 * * *', timezone: 'UTC' }, organization: bad })), `organization: ${JSON.stringify(bad)} is the trigger's judgement to make, not lint's`, ).toEqual([]); } diff --git a/packages/lint/src/validate-flow-trigger-readiness.ts b/packages/lint/src/validate-flow-trigger-readiness.ts index 89cc72686ac..75ed8d4d1cc 100644 --- a/packages/lint/src/validate-flow-trigger-readiness.ts +++ b/packages/lint/src/validate-flow-trigger-readiness.ts @@ -219,7 +219,15 @@ import { } from '@objectstack/spec/automation'; import { resolvePackageClosure } from '@objectstack/metadata-core'; import { walkFlowNodes } from './flow-walk.js'; -import { closureDependencyRemedy, packagesOf, recordsOf, suggestName } from './object-graph.js'; +import { + closureDependencyRemedy, + indexServedObjectGraph, + packagesOf, + recordsOf, + suggestName, + type ObjectGraph, +} from './object-graph.js'; +import { indexSelectOptions, optionLabelComparisons, type SelectOptions } from './flow-select-options.js'; import type { UserTextParams } from './finding-user-text.js'; export type FlowTriggerReadinessSeverity = 'error' | 'warning'; @@ -389,6 +397,52 @@ export const FLOW_API_TRIGGER_SECRET_MISSING = 'flow-api-trigger-secret-missing' * restates none of the declaration's grammar. */ export const FLOW_API_TRIGGER_SIGNATURE_UNUSABLE = 'flow-api-trigger-signature-unusable'; +/** + * #35143 — a record-change start (`triggerType: 'record-…'`) that names no + * `config.objectName`. The binding hands the record-change trigger + * `object: undefined`, and a hook registered with no object target runs on + * EVERY object's write (ObjectQL `registerHook`: an absent target is the + * whole collection). So the flow does not sit idle: it starts on a write to + * any object, with that row as `record`. `error`: the start node alone + * settles it, and no installed package changes the answer. + */ +export const FLOW_TRIGGER_OBJECT_MISSING = 'flow-trigger-object-missing'; +/** + * #35143 — a record-change start condition that compares a select field of + * the trigger object with an option's LABEL (`record.stage == 'Closed Lost'`) + * where the field stores the option's VALUE (`closed_lost`). The row holds + * the value, so the comparison is always false (or always true for `!=`) and + * the condition never tells one record from another. + */ +export const FLOW_CONDITION_OPTION_LABEL = 'flow-condition-option-label'; +/** + * #35143 — a start node carrying BOTH a `record-*` `triggerType` and a + * `config.timeRelative` descriptor. The engine's binding resolver + * (`resolveFlowTriggerKind`) answers `record_change` first, so the sweep is + * never installed: the flow runs on record writes and never on the date. + */ +export const FLOW_TIME_RELATIVE_SHADOWED = 'flow-time-relative-shadowed'; +/** + * #35143 — `filter` or `maxRecords` written beside `config.timeRelative` + * instead of inside it. The sweep reads both from the descriptor only; the + * binding forwards `schedule` and `condition` from the start config and + * nothing else, so a sibling `filter` narrows nothing and a sibling cap caps + * nothing. + */ +export const FLOW_TIME_RELATIVE_KEY_MISPLACED = 'flow-time-relative-key-misplaced'; +/** + * #35143 — `config.timeRelative.dateField` names a field the swept object + * does not have, or one that is not a `date` / `datetime` field. The sweep + * builds its window as a range on that column, so it matches no record. + */ +export const FLOW_TIME_RELATIVE_DATE_FIELD_INVALID = 'flow-time-relative-date-field-invalid'; +/** + * #35143 — a schedule (or a time-relative sweep's cadence) written as a cron + * with no `timezone`. The trigger reads the cron in UTC + * (`schedule.timezone ?? 'UTC'`), so the hour fires at UTC, not at the hour + * of the zone the author had in mind. Advisory: a UTC hour may be the intent. + */ +export const FLOW_SCHEDULE_TIMEZONE_MISSING = 'flow-schedule-timezone-missing'; type AnyRec = Record; @@ -624,6 +678,33 @@ function nonEmptyString(value: unknown): string | undefined { } /** The start node of a flow definition, if any. */ +/** [#35143] The field types a time-relative sweep's window can fall on. */ +const DATE_FIELD_TYPES: ReadonlySet = new Set(['date', 'datetime']); + +/** A start condition's CEL source: the bare string, or an envelope's `source`. */ +function conditionSourceOf(raw: unknown): string { + if (typeof raw === 'string') return raw; + if (raw && typeof raw === 'object' && typeof (raw as AnyRec).source === 'string') return (raw as AnyRec).source as string; + return ''; +} + +/** + * [#35143] The cron expression of a `config.schedule` that names no + * `timezone`, read in the shapes the schedule trigger's `normalizeSchedule` + * reads: a bare cron string, or `{ type: 'cron', expression }` (`cron` is the + * older spelling of `expression`). Any other shape is no cron here. + */ +function cronWithoutZone(raw: unknown): string | undefined { + if (typeof raw === 'string') return raw.trim() || undefined; + if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return undefined; + const s = raw as AnyRec; + const isCron = s.type === 'cron' || (s.type === undefined && (typeof s.cron === 'string' || typeof s.expression === 'string')); + if (!isCron) return undefined; + const expression = (typeof s.expression === 'string' && s.expression) || (typeof s.cron === 'string' && s.cron) || ''; + if (!expression.trim()) return undefined; + return typeof s.timezone === 'string' && s.timezone.trim() ? undefined : expression.trim(); +} + function startNodeOf(flow: AnyRec): { node: AnyRec; index: number } | undefined { const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : []; const index = nodes.findIndex((n) => n?.type === 'start'); @@ -708,6 +789,10 @@ export function validateFlowTriggerReadiness( }; }; + // [#35143] Built on first use: most stacks' flows never reach these reads. + let selectOptions: ReadonlyMap> | undefined; + let servedGraph: ObjectGraph | undefined; + flows.forEach((flow, flowIndex) => { const flowName = typeof flow.name === 'string' ? flow.name : `#${flowIndex}`; const start = startNodeOf(flow); @@ -756,6 +841,41 @@ export function validateFlowTriggerReadiness( ), ); } + // 1-ii. #35143 — no object at all. Not "binds to nothing": the trigger + // registers its hook with no object target, which ObjectQL reads as + // every object, so the flow starts on a write to any of them. + if (objectName === undefined || objectName.trim() === '') { + findings.push({ + severity: 'error', + rule: FLOW_TRIGGER_OBJECT_MISSING, + where: `flow "${flowName}" › start node`, + path: `flows[${flowIndex}].nodes[${start.index}].config.objectName`, + message: + `is a record-change flow ('${triggerType}') with no config.objectName, so its trigger watches every ` + + `object: it starts on a write to any object, with that row as \`record\``, + hint: `Set config.objectName to the object whose records should start this flow`, + }); + } else { + // 1-iii. #35143 — the start condition compares a select field with an + // option's label where the row holds the option's value. + selectOptions ??= indexSelectOptions(stack); + const options = selectOptions.get(objectName); + const src = conditionSourceOf(config.condition); + if (options && src) { + for (const hit of optionLabelComparisons(src, options)) { + findings.push({ + severity: 'error', + rule: FLOW_CONDITION_OPTION_LABEL, + where: `flow "${flowName}" › start node`, + path: `flows[${flowIndex}].nodes[${start.index}].config.condition`, + message: + `compares '${objectName}.${hit.field}' with '${hit.label}', which is that option's label; the ` + + `field stores the value '${hit.value}', so the comparison never matches a record`, + hint: `Compare with the option's value: write '${hit.value}' in place of '${hit.label}'`, + }); + } + } + } } // 1b. Two facts about the same `config.timeRelative` descriptor, from the two @@ -890,6 +1010,98 @@ export function validateFlowTriggerReadiness( `checked against the record each run holds`, }); } + + // 1b-iv. #35143 — a `record-*` token beside the descriptor. The resolver + // answers `record_change` first, so the sweep is never installed. + if (isRecordTriggered) { + findings.push({ + severity: 'error', + rule: FLOW_TIME_RELATIVE_SHADOWED, + where: `flow "${flowName}" › start node`, + path: `flows[${flowIndex}].nodes[${start.index}].config.triggerType`, + message: + `declares both config.triggerType '${triggerType}' and config.timeRelative; the record-change ` + + `trigger takes precedence, so the sweep is never installed and the flow never runs on the date`, + hint: + `Remove config.triggerType to keep the date sweep, or remove config.timeRelative to keep the ` + + `record-change trigger`, + }); + } + + // 1b-v. #35143 — `filter` / `maxRecords` beside the descriptor. The sweep + // reads both from inside it only. + for (const key of ['filter', 'maxRecords'] as const) { + if (config[key] === undefined || tr[key] !== undefined) continue; + findings.push({ + severity: 'error', + rule: FLOW_TIME_RELATIVE_KEY_MISPLACED, + where: `flow "${flowName}" › start node`, + path: `flows[${flowIndex}].nodes[${start.index}].config.${key}`, + message: + key === 'filter' + ? `sets config.filter beside config.timeRelative; the sweep reads its filter only from ` + + `config.timeRelative.filter, so this one is ignored and the flow runs for every record in the window` + : `sets config.maxRecords beside config.timeRelative; the sweep reads its cap only from ` + + `config.timeRelative.maxRecords, so this one is ignored and the default cap applies`, + hint: `Move it inside the descriptor: config.timeRelative.${key}`, + }); + } + + // 1b-vi. #35143 — the swept date field, against the swept object when + // this stack declares it (an object it does not declare is 1b-i's). + const dateField = typeof tr.dateField === 'string' ? tr.dateField : undefined; + if (sweptObject && dateField) { + servedGraph ??= indexServedObjectGraph(stack); + const graphObject = servedGraph.get(sweptObject); + if (graphObject) { + const slice = graphObject.fields.get(dateField) ?? graphObject.injected.get(dateField); + const known = graphObject.names.has(dateField) || graphObject.injected.has(dateField); + const type = slice?.type; + if (!known || (type !== undefined && !DATE_FIELD_TYPES.has(type))) { + const dateFields = [...graphObject.fields, ...graphObject.injected] + .filter(([, f]) => f.type !== undefined && DATE_FIELD_TYPES.has(f.type)) + .map(([n]) => n); + findings.push({ + severity: 'error', + rule: FLOW_TIME_RELATIVE_DATE_FIELD_INVALID, + where: `flow "${flowName}" › start node`, + path: `flows[${flowIndex}].nodes[${start.index}].config.timeRelative.dateField`, + message: !known + ? `sweeps '${sweptObject}.${dateField}', and object '${sweptObject}' has no field '${dateField}', ` + + `so the sweep's date window matches no record and the flow never runs` + + suggestName(dateField, dateFields) + : `sweeps '${sweptObject}.${dateField}', a '${type}' field; the sweep's window is a date range, ` + + `which a '${type}' field never falls in, so the flow never runs`, + hint: + dateFields.length > 0 + ? `Set config.timeRelative.dateField to a date or datetime field of '${sweptObject}' ` + + `(${dateFields.join(', ')})` + : `Add a date or datetime field to '${sweptObject}' and set config.timeRelative.dateField to it`, + }); + } + } + } + } + + // 1b-vii. #35143 — a cron cadence with no zone, on a flow the clock starts + // (a schedule flow, or a sweep's cadence). The trigger reads it in UTC. + const clockKind = resolveFlowTriggerKind(flow); + if (start && (clockKind === 'schedule' || clockKind === 'time_relative')) { + const cron = cronWithoutZone(config.schedule); + if (cron !== undefined) { + findings.push({ + severity: 'warning', + rule: FLOW_SCHEDULE_TIMEZONE_MISSING, + where: `flow "${flowName}" › start node`, + path: `flows[${flowIndex}].nodes[${start.index}].config.schedule`, + message: + `sets the cron '${cron}' with no timezone, so it fires at that hour in UTC, not in the zone ` + + `the hour was meant in`, + hint: + `Write the schedule as { type: 'cron', expression: '${cron}', timezone: 'Area/City' } with the zone ` + + `the hour is meant in, or set timezone: 'UTC' if UTC is the intent`, + }); + } } // 1c. A `record-`-prefixed triggerType the trigger cannot map to any hook — @@ -1455,3 +1667,61 @@ function signatureUnusableFinding( `x-objectstack-signature`, }; } + +/** + * #35143 — a `subflow` or `map` node whose `config.flowName` names no flow + * of this stack (nor of a package it carries in `packages[]`). The node asks + * the engine to run that flow by name, and the engine finds none, so the step + * fails every run (`subflow 'X' failed`). + * + * Its OWN exported rule, run on the CLI only, for the reason + * `flow-trigger-unknown-object` carries a hedge plus one more: the runtime + * publish gate judges a flow write over a snapshot whose `flows` holds only + * the written item, so a call to any other stored flow would read as unknown + * there. On the CLI the stack is one app; a flow another installed package + * ships is a legitimate target, so the finding is advisory, as that sibling's + * is without a stated closure. + */ +export const FLOW_SUBFLOW_UNKNOWN = 'flow-subflow-unknown'; + +export function validateFlowSubflowTargets(stack: AnyRec): FlowTriggerReadinessFinding[] { + const findings: FlowTriggerReadinessFinding[] = []; + const flows = recordsOf(stack.flows); + if (flows.length === 0) return findings; + const known = new Set(); + for (const flow of flows) { + const name = nonEmptyString(flow.name); + if (name) known.add(name); + } + for (const entry of packagesOf(stack)) { + for (const flow of recordsOf(entry.flows)) { + const name = nonEmptyString(flow.name); + if (name) known.add(name); + } + } + flows.forEach((flow, flowIndex) => { + const flowName = nonEmptyString(flow.name) ?? `#${flowIndex}`; + for (const { node, path, regionTrail } of walkFlowNodes(flow, `flows[${flowIndex}]`)) { + if (node.type !== 'subflow' && node.type !== 'map') continue; + const config = node.config && typeof node.config === 'object' ? (node.config as AnyRec) : {}; + const called = nonEmptyString(config.flowName)?.trim(); + if (!called || known.has(called)) continue; + const nodeId = nonEmptyString(node.id) ?? String(node.type); + const nodeWhere = regionTrail ? `${regionTrail} › node "${nodeId}"` : `node "${nodeId}"`; + findings.push({ + severity: 'warning', + rule: FLOW_SUBFLOW_UNKNOWN, + where: `flow "${flowName}" › ${nodeWhere}`, + path: `${path}.config.flowName`, + message: + `${String(node.type)} node '${nodeId}' calls flow '${called}', which this stack does not define; if ` + + `the name is wrong, the step fails on every run` + + suggestName(called, known), + hint: + `Set config.flowName to the exact name of a flow this app defines, or ignore this if another ` + + `installed package ships '${called}'`, + }); + } + }); + return findings; +} diff --git a/packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts b/packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts new file mode 100644 index 00000000000..17c5c57eab6 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts @@ -0,0 +1,38 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// The upgrade-guide entry of the second batch of author-time flow rules (#35143) +// that refuse, at publish and in `os validate` / `build`, a flow the schema still +// accepts but the engine never starts, starts on the wrong rows, or fails on +// every write. Notice only: no key is removed and no D2 conversion exists, +// because each fix is a choice only the author can make (which object a +// trigger watches, which option a condition means). +export const entry: SemanticMigration = { + id: 'publish-refuses-flows-that-save-and-do-not-run', + surface: + 'Seven author-time flow errors, run by the runtime publish gate and by `os validate` / `lint` / `compile` / `build`: ' + + 'a record-triggered flow with no `objectName` (`flow-trigger-object-missing`); a start condition that compares a ' + + 'select field with one of its option labels where the row holds the option value (`flow-condition-option-label`); ' + + 'a `timeRelative` block under a record `triggerType`, which wins (`flow-time-relative-shadowed`); `filter` or ' + + '`maxRecords` beside `timeRelative` instead of inside it (`flow-time-relative-key-misplaced`); a `timeRelative.dateField` ' + + 'that is not a `date` / `datetime` field of the object (`flow-time-relative-date-field-invalid`); a create / update ' + + 'node that writes a select field a literal no option carries (`flow-node-write-unknown-option`); a create / update ' + + 'node that writes a date field the text of a date helper call such as `today()` (`flow-node-write-date-helper-text`)', + replacement: + 'Set the trigger\'s `objectName`; compare the option value, not its label; drop the record `triggerType` or the ' + + '`timeRelative` block, whichever the flow does not mean; move `filter` / `maxRecords` inside `timeRelative`; point ' + + '`dateField` at a `date` or `datetime` field; write an option value the field lists; write a date as a CEL value ' + + 'envelope (`{ dialect: \'cel\', source: \'isoDate(today())\' }`) instead of the helper call as text', + reason: + 'Each flow parses and publishes, then misbehaves on every run: a record trigger with no object fires on writes to ' + + 'every object; a label comparison is never true, because the row stores the value; a record trigger shadows the ' + + 'time-relative schedule, so the sweep never runs; a misplaced `filter` / `maxRecords` is ignored, so the sweep reads ' + + 'every row; a sweep over a field that is not a date matches no record; a write of an unknown option is refused ' + + '`invalid_option` and a write of helper text is refused `invalid_date`, so the node fails on every run. Stored ' + + 'flows are not rewritten or refused at boot. The next publish of a flow that carries one of the seven errors is ' + + 'refused with the fix named. Three warnings join them (`flow-schedule-timezone-missing`, `flow-subflow-unknown`, ' + + '`flow-create-update-pair`), which refuse nothing and make `os validate --strict` exit 1 as any warning does.', + acceptanceCriteria: + 'os validate reports none of the seven errors; a publish of every flow the package carries succeeds.', +}; From 72fe0c0764df3ae49d06ded9b5da20f286a64134 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 12:07:25 +0000 Subject: [PATCH 2/6] fix(lint): judge an option label only as its field's comparand; declare the narrowing flow-condition-option-label reported a label quoted anywhere in a condition that read the field; it now reports only F == 'L', 'L' == F, != and F in [...]. A blank objectName gets its own message: the flow is never bound. Metadata-protocol narrowed, @objectstack/lint minor. The spec and docs cron examples state their timezone. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbYLajSVuBY258yrEFn --- .../35143-flow-publish-checks-second-batch.md | 10 ++-- content/docs/automation/flows.mdx | 4 +- .../automation/schedule-organization.mdx | 2 +- .../automation/time-relative-trigger.mdx | 2 +- .../flow-publish-checks-second-batch.test.ts | 44 ++++++++++++++- packages/lint/src/flow-select-options.ts | 56 ++++++++++++++----- packages/lint/src/rule-explanations.ts | 10 +++- .../src/validate-flow-trigger-readiness.ts | 7 ++- .../automation/schedule-organization.zod.ts | 2 +- .../automation/time-relative-trigger.zod.ts | 2 +- 10 files changed, 107 insertions(+), 32 deletions(-) diff --git a/.changeset/35143-flow-publish-checks-second-batch.md b/.changeset/35143-flow-publish-checks-second-batch.md index 122f4500133..8841cd86e15 100644 --- a/.changeset/35143-flow-publish-checks-second-batch.md +++ b/.changeset/35143-flow-publish-checks-second-batch.md @@ -1,13 +1,13 @@ --- -'@objectstack/lint': patch +'@objectstack/lint': minor '@objectstack/spec': patch --- fix(lint)!: ten publish-time checks for flows that save and do not run — seven refuse the publish, three warn Clause-②: yes (narrowing) -Metadata-protocol: none -Skills-docs: follow-up owed — skills/objectstack-automation/SKILL.md, skills/objectstack-automation/references/examples-flows.md +Metadata-protocol: narrowed +Skills-docs: follow-up owed — skills/objectstack-automation/SKILL.md, skills/objectstack-automation/references/examples-flows.md, skills/objectstack-automation/references/integration-recipes.md @@ -15,8 +15,8 @@ Skills-docs: follow-up owed — skills/objectstack-automation/SKILL.md, skills/o Seven errors, run by the runtime publish gate and the CLI: -- `flow-trigger-object-missing`: a record-triggered flow with no `objectName` registers its hook with no object, so it fires on writes to every object. -- `flow-condition-option-label`: a start condition compares a select field with one of its option labels (`record.stage == 'Closed Lost'`) where the row holds the option value (`closed_lost`), so it is never true. Judged only when the field's options are inline in this stack. +- `flow-trigger-object-missing`: a record-triggered flow with no `objectName` registers its hook with no object, so it fires on writes to every object; a blank `objectName` is refused too, because the engine will not register a hook on an empty name and the flow never starts. +- `flow-condition-option-label`: a start condition compares a select field with one of its option labels (`record.stage == 'Closed Lost'`) where the row holds the option value (`closed_lost`), so it is never true. Reported only when the label is that field's own comparand (`F == 'L'`, `F != 'L'`, `'L' == F`, or a member of `F in [...]`); judged only when the field's options are inline in this stack. - `flow-time-relative-shadowed`: a `timeRelative` block under a record `triggerType` never sweeps, because a record trigger wins. - `flow-time-relative-key-misplaced`: `filter` or `maxRecords` written beside `timeRelative` is ignored; the sweep reads them only inside the block. - `flow-time-relative-date-field-invalid`: a `timeRelative.dateField` the swept object does not have, or that is not a `date` / `datetime` field, matches no record. Judged only when the stack declares the object; `created_at` / `updated_at` count as datetime fields. diff --git a/content/docs/automation/flows.mdx b/content/docs/automation/flows.mdx index 8ac220e6d4d..8b24cc5fff7 100644 --- a/content/docs/automation/flows.mdx +++ b/content/docs/automation/flows.mdx @@ -3029,7 +3029,7 @@ export const renewalReminder: Flow = { // run acts as its own record's organization) and not read under // `single`. See "The acting organization" below. organization: '', - // schedule: { type: 'cron', expression: '0 8 * * *' } // optional; defaults to daily 08:00 UTC + // schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' } // optional; defaults to daily 08:00 UTC }, }, { id: 'notify_owner', type: 'notify', label: 'Notify Owner' }, @@ -3094,7 +3094,7 @@ it runs as**, on the start node's `config`, beside the cadence it scopes: ```typescript config: { - schedule: { type: 'cron', expression: '0 8 * * *' }, + schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }, organization: 'org_msokm9oaz0cal87q', // a sys_organization.id } ``` diff --git a/content/docs/references/automation/schedule-organization.mdx b/content/docs/references/automation/schedule-organization.mdx index 66a1c588db7..eeef21c06f1 100644 --- a/content/docs/references/automation/schedule-organization.mdx +++ b/content/docs/references/automation/schedule-organization.mdx @@ -122,7 +122,7 @@ On the flow's START node `config`, beside the cadence it scopes: ```ts config: { - schedule: { type: 'cron', expression: '0 8 * * *' }, + schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }, organization: 'org_msokm9oaz0cal87q', } ``` diff --git a/content/docs/references/automation/time-relative-trigger.mdx b/content/docs/references/automation/time-relative-trigger.mdx index 538305cdbf3..95cfe6fa477 100644 --- a/content/docs/references/automation/time-relative-trigger.mdx +++ b/content/docs/references/automation/time-relative-trigger.mdx @@ -42,7 +42,7 @@ config: { filter: { status: 'active' }, }, // optional sweep cadence — defaults to daily at 08:00 UTC - schedule: { type: 'cron', expression: '0 8 * * *' }, + schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }, } ``` diff --git a/packages/lint/src/flow-publish-checks-second-batch.test.ts b/packages/lint/src/flow-publish-checks-second-batch.test.ts index 0bbefaec6d0..3e330f03131 100644 --- a/packages/lint/src/flow-publish-checks-second-batch.test.ts +++ b/packages/lint/src/flow-publish-checks-second-batch.test.ts @@ -91,11 +91,14 @@ describe('flow-trigger-object-missing', () => { expect(hit[0].message).toMatch(/every object/); }); - it('refuses a blank object name the same way', () => { + it('refuses a blank object name, saying the flow is never bound (not that it watches every object)', () => { const findings = validateFlowTriggerReadiness( stack(flow('notify', { triggerType: 'record-after-create', objectName: ' ' })), ); - expect(rulesOf(findings)).toContain(FLOW_TRIGGER_OBJECT_MISSING); + const hit = findings.filter((f) => f.rule === FLOW_TRIGGER_OBJECT_MISSING); + expect(hit).toHaveLength(1); + expect(hit[0].message).toMatch(/never bound/); + expect(hit[0].message).not.toMatch(/every object/); }); it('is silent on a record-change start that names its object, and on a flow with no record trigger', () => { @@ -148,6 +151,43 @@ describe('flow-condition-option-label', () => { } }); + it('reads the literal-first spelling and each member of an `in` list', () => { + for (const condition of ["'Closed Lost' == record.stage", "stage in ['open', 'Closed Lost']"]) { + const hit = validateFlowTriggerReadiness(withCondition(condition)).filter( + (f) => f.rule === FLOW_CONDITION_OPTION_LABEL, + ); + expect(hit, condition).toHaveLength(1); + expect(hit[0].hint).toContain("'closed_lost'"); + } + }); + + it('is silent when the label is the comparand of another field, not of the select field', () => { + expect( + rulesOf(validateFlowTriggerReadiness(withCondition("record.stage == 'open' && record.name == 'Closed Lost'"))), + ).not.toContain(FLOW_CONDITION_OPTION_LABEL); + + // One select field's label is the other's value: comparing `severity` with 'High' is right. + const TICKET = { + name: 'ticket', + label: 'Ticket', + fields: { + priority: { type: 'select', label: 'Priority', options: [{ value: 'high', label: 'High' }, { value: 'low', label: 'Low' }] }, + severity: { type: 'select', label: 'Severity', options: ['High', 'Low'] }, + }, + }; + const ticketStack = (condition: string) => ({ + objects: [TICKET], + flows: [flow('triage', { triggerType: 'record-after-update', objectName: 'ticket', condition })], + }); + expect( + rulesOf(validateFlowTriggerReadiness(ticketStack("record.severity == 'High' && record.priority != null"))), + ).not.toContain(FLOW_CONDITION_OPTION_LABEL); + // …while comparing `priority` with its own label still is reported. + expect(rulesOf(validateFlowTriggerReadiness(ticketStack("record.priority == 'High'")))).toContain( + FLOW_CONDITION_OPTION_LABEL, + ); + }); + it('is silent when no select field is read, and for an object the stack does not declare', () => { expect( rulesOf(validateFlowTriggerReadiness(withCondition("record.name == 'Closed Lost'"))), diff --git a/packages/lint/src/flow-select-options.ts b/packages/lint/src/flow-select-options.ts index f739edb2b4a..b32710a3bdf 100644 --- a/packages/lint/src/flow-select-options.ts +++ b/packages/lint/src/flow-select-options.ts @@ -94,22 +94,46 @@ export interface OptionLabelComparison { readonly value: string; } -/** Is `literal` written in `src` as a quoted string, either quote? */ -function hasQuotedLiteral(src: string, literal: string): boolean { - return src.includes(`'${literal}'`) || src.includes(`"${literal}"`); -} +/** One quoted literal, either quote (no escapes: a label with a quote in it is not judged). */ +const QUOTED = String.raw`(?:'([^'\\]*)'|"([^"\\]*)")`; -/** Is `field` read in `src` (`record.F`, `previous.F`, or bare `F`)? */ -function readsField(src: string, field: string): boolean { +/** A read of `field`: `record.F`, `previous.F` or bare `F`, not a member of something else. */ +function readOf(field: string): string { const escaped = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - return new RegExp(`(?:^|[^\\w.])(?:(?:record|previous)\\.)?${escaped}(?![\\w])`).test(src); + return String.raw`(?:(?:record|previous)\.)?${escaped}(?![\w.])`; +} + +/** + * The quoted literals `src` compares with `field` itself: `F == 'L'`, `F != 'L'`, + * `'L' == F`, `'L' != F`, and each member of `F in [...]`. A literal that sits + * elsewhere in the source (the comparand of another field) is not one. + */ +function comparandsOf(src: string, field: string): string[] { + const read = readOf(field); + const lead = String.raw`(?:^|[^\w.])`; + const out: string[] = []; + const pick = (m: RegExpExecArray, at: number) => { + const v = m[at] ?? m[at + 1]; + if (v !== undefined) out.push(v); + }; + const fieldFirst = new RegExp(String.raw`${lead}${read}\s*(?:==|!=)\s*${QUOTED}`, 'g'); + for (let m = fieldFirst.exec(src); m; m = fieldFirst.exec(src)) pick(m, 1); + const literalFirst = new RegExp(String.raw`${QUOTED}\s*(?:==|!=)\s*${read}`, 'g'); + for (let m = literalFirst.exec(src); m; m = literalFirst.exec(src)) pick(m, 1); + const inList = new RegExp(String.raw`${lead}${read}\s+in\s*\[([^\]]*)\]`, 'g'); + for (let m = inList.exec(src); m; m = inList.exec(src)) { + const members = new RegExp(QUOTED, 'g'); + for (let k = members.exec(m[1]); k; k = members.exec(m[1])) pick(k, 1); + } + return out; } /** - * The option labels a CEL source compares where the row holds values: a - * select field of the object is read, one of its option labels is written as - * a quoted literal, and that option's value is not. A label that is also some - * option's value is never reported (the literal may be that value). + * The option labels a CEL source compares a select field with, where the row + * holds that option's value: the label must be the comparand of that field + * (`F == 'L'`, `'L' != F`, `F in ['L', ...]`), not merely quoted somewhere in + * the source. A label that is also some option's value is never reported + * (the literal may be that value). */ export function optionLabelComparisons( src: string, @@ -117,9 +141,13 @@ export function optionLabelComparisons( ): OptionLabelComparison[] { const out: OptionLabelComparison[] = []; for (const [field, opts] of options) { - if (opts.labels.size === 0 || !readsField(src, field)) continue; - for (const [label, value] of opts.labels) { - if (hasQuotedLiteral(src, label) && !hasQuotedLiteral(src, value)) out.push({ field, label, value }); + if (opts.labels.size === 0) continue; + const seen = new Set(); + for (const literal of comparandsOf(src, field)) { + const value = opts.labels.get(literal); + if (value === undefined || seen.has(literal)) continue; + seen.add(literal); + out.push({ field, label: literal, value }); } } return out; diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 676a3ebac5d..fd7cbc91aa2 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -6537,6 +6537,8 @@ const FLOW_TRIGGER_OBJECT_MISSING_EXPLANATION: RuleExplanation = { 'With none, the trigger registers its hook with no object target, and the data engine reads an absent ' + 'target as every object. So the flow is not idle: it starts on a write to any object, with that row as ' + '`record`, and its conditions and steps read fields that row usually does not have.', + 'A blank name (`\'\'` or spaces) is refused too, for the opposite reason: the data engine refuses to ' + + 'register a hook on an empty object name, so the trigger is never bound and the flow never starts.', 'An error: the start node alone settles it. Name the object whose records should start the flow.', ], }; @@ -6549,9 +6551,11 @@ const FLOW_CONDITION_OPTION_LABEL_EXPLANATION: RuleExplanation = { 'reads the field and compares it with a quoted label (`record.stage == \'Closed Lost\'` where the option ' + 'is `{ value: \'closed_lost\', label: \'Closed Lost\' }`) is false on every record, or true on every ' + 'record for `!=`, so the condition never tells one record from another.', - 'Reported when the condition reads the field, writes a label as a quoted literal and does not write that ' + - 'option\'s value. A label that is also some option\'s value is never reported. Fields whose options come ' + - 'from a shared picklist are not judged: the stack does not hold that list.', + 'Reported only when the label is the comparand of that field: `F == \'L\'`, `F != \'L\'`, `\'L\' == F`, or ' + + 'a member of `F in [...]`, with `F` read bare or as `record.F` / `previous.F`. A label quoted elsewhere ' + + 'in the condition, such as the comparand of another field, is not. A label that is also some option\'s ' + + 'value is never reported. Fields whose options come from a shared picklist are not judged: the stack ' + + 'does not hold that list.', ], }; diff --git a/packages/lint/src/validate-flow-trigger-readiness.ts b/packages/lint/src/validate-flow-trigger-readiness.ts index 75ed8d4d1cc..39ac4cadd7e 100644 --- a/packages/lint/src/validate-flow-trigger-readiness.ts +++ b/packages/lint/src/validate-flow-trigger-readiness.ts @@ -851,8 +851,11 @@ export function validateFlowTriggerReadiness( where: `flow "${flowName}" › start node`, path: `flows[${flowIndex}].nodes[${start.index}].config.objectName`, message: - `is a record-change flow ('${triggerType}') with no config.objectName, so its trigger watches every ` + - `object: it starts on a write to any object, with that row as \`record\``, + objectName === undefined + ? `is a record-change flow ('${triggerType}') with no config.objectName, so its trigger watches every ` + + `object: it starts on a write to any object, with that row as \`record\`` + : `is a record-change flow ('${triggerType}') whose config.objectName is blank; the engine refuses to ` + + `register a hook on an empty object name, so the trigger is never bound and the flow never starts`, hint: `Set config.objectName to the object whose records should start this flow`, }); } else { diff --git a/packages/spec/src/automation/schedule-organization.zod.ts b/packages/spec/src/automation/schedule-organization.zod.ts index 8d2972ea602..18990c5bd7a 100644 --- a/packages/spec/src/automation/schedule-organization.zod.ts +++ b/packages/spec/src/automation/schedule-organization.zod.ts @@ -119,7 +119,7 @@ import { z } from 'zod'; * * ```ts * config: { - * schedule: { type: 'cron', expression: '0 8 * * *' }, + * schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }, * organization: 'org_msokm9oaz0cal87q', * } * ``` diff --git a/packages/spec/src/automation/time-relative-trigger.zod.ts b/packages/spec/src/automation/time-relative-trigger.zod.ts index c32412ae88e..b1849b437c2 100644 --- a/packages/spec/src/automation/time-relative-trigger.zod.ts +++ b/packages/spec/src/automation/time-relative-trigger.zod.ts @@ -41,7 +41,7 @@ import { strictObject } from '../shared/strict-object'; * filter: { status: 'active' }, * }, * // optional sweep cadence — defaults to daily at 08:00 UTC - * schedule: { type: 'cron', expression: '0 8 * * *' }, + * schedule: { type: 'cron', expression: '0 8 * * *', timezone: 'UTC' }, * } * ``` * From 7bc8e8a6e703650e839b245317ae38304d1393d9 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 12:11:46 +0000 Subject: [PATCH 3/6] test(metadata-protocol): the package-closure sweep fixture sweeps a datetime column The fixture swept the text field 'title', which the new flow-time-relative-date-field-invalid rule refuses at the publish gate; the test is about the package closure, so it now sweeps created_at. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbYLajSVuBY258yrEFn --- .../metadata-protocol/src/protocol.package-closure-gate.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts b/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts index 374db6770f4..f1ed4559364 100644 --- a/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts +++ b/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts @@ -84,7 +84,7 @@ const sweepOf = (name: string, object: string) => ({ id: 'start', type: 'start', label: 'Daily sweep', - config: { timeRelative: { object, dateField: 'title', withinDays: 7 } }, + config: { timeRelative: { object, dateField: 'created_at', withinDays: 7 } }, }, { id: 'end', type: 'end', label: 'End' }, ], From 4466c0cc8b649939618bc6634ac946d5bccb74c8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 12:22:19 +0000 Subject: [PATCH 4/6] test(metadata-protocol): pay the lint load at collection in the package-closure gate test Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbYLajSVuBY258yrEFn --- .../src/protocol.package-closure-gate.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts b/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts index f1ed4559364..c7b3879999e 100644 --- a/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts +++ b/packages/metadata-protocol/src/protocol.package-closure-gate.test.ts @@ -44,6 +44,11 @@ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'; // `@objectstack/objectql` — that import would close a cycle turbo rejects. import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFindOnePredicate } from '@objectstack/metadata-core'; import { ObjectStackProtocolImplementation } from './protocol.js'; +// `@objectstack/lint` loads lazily, behind the source's own dynamic `import()` +// (`metadata-diagnostics.ts`). Paid here, at collection, so no case's +// `testTimeout` window pays that first load +// (`scripts/check-test-source-alias.mjs`, "The source reach"). +import '@objectstack/lint'; const OWN = 'com.acme.crm'; const DEP = 'com.acme.core'; From b28dc726fb6d9adc45b5ea33a772052d9142ff9b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 13:57:27 +0000 Subject: [PATCH 5/6] chore(changeset): the Skills-docs follow-up is #36718 Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbYLajSVuBY258yrEFn --- .changeset/35143-flow-publish-checks-second-batch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/35143-flow-publish-checks-second-batch.md b/.changeset/35143-flow-publish-checks-second-batch.md index 8841cd86e15..54621979a70 100644 --- a/.changeset/35143-flow-publish-checks-second-batch.md +++ b/.changeset/35143-flow-publish-checks-second-batch.md @@ -7,7 +7,7 @@ fix(lint)!: ten publish-time checks for flows that save and do not run — seven Clause-②: yes (narrowing) Metadata-protocol: narrowed -Skills-docs: follow-up owed — skills/objectstack-automation/SKILL.md, skills/objectstack-automation/references/examples-flows.md, skills/objectstack-automation/references/integration-recipes.md +Skills-docs: follow-up #36718 From 05bdad81607e398374b0b5c55a84a0b71d3ac62b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 14:43:46 +0000 Subject: [PATCH 6/6] docs: CLI transcripts count 78 author-time rules after merging main Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JQwxbYLajSVuBY258yrEFn --- content/docs/deployment/cli.mdx | 2 +- content/docs/deployment/validating-metadata.mdx | 2 +- content/docs/getting-started/build-with-claude-code.mdx | 2 +- content/docs/ui/react-pages.mdx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/content/docs/deployment/cli.mdx b/content/docs/deployment/cli.mdx index 43cd68c17fe..61d9a6a49f1 100644 --- a/content/docs/deployment/cli.mdx +++ b/content/docs/deployment/cli.mdx @@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines → Normalizing stack definition... → Lowering inline handlers... → Validating protocol compliance... - → Running author-time rules (77)... + → Running author-time rules (78)... → Checking that every required capability has a provider installable in this edition... → Collecting package docs (ADR-0046)... 0 collected → Writing artifact... diff --git a/content/docs/deployment/validating-metadata.mdx b/content/docs/deployment/validating-metadata.mdx index b4e6b0a4fd5..00b994a5208 100644 --- a/content/docs/deployment/validating-metadata.mdx +++ b/content/docs/deployment/validating-metadata.mdx @@ -867,7 +867,7 @@ A clean run walks the registry and reports timing: Config: /path/to/support-desk/objectstack.config.ts Load time: 21ms → Validating against ObjectStack Protocol... - → Running author-time rules (77)... + → Running author-time rules (78)... → Checking that every required capability has a provider installable in this edition... → Checking package docs (ADR-0046)... diff --git a/content/docs/getting-started/build-with-claude-code.mdx b/content/docs/getting-started/build-with-claude-code.mdx index 5a253f68c8b..dd243eecf3d 100644 --- a/content/docs/getting-started/build-with-claude-code.mdx +++ b/content/docs/getting-started/build-with-claude-code.mdx @@ -311,7 +311,7 @@ visible: 'status != "resolved"' ◆ Validate ──────────────────────────────────────── → Validating against ObjectStack Protocol... - → Running author-time rules (77)... + → Running author-time rules (78)... ✗ Author-time rules failed (1 issue) • stack · action 'resolve_ticket' visible: bare reference `status` — a diff --git a/content/docs/ui/react-pages.mdx b/content/docs/ui/react-pages.mdx index 52418ebaf38..91055f88ff1 100644 --- a/content/docs/ui/react-pages.mdx +++ b/content/docs/ui/react-pages.mdx @@ -404,7 +404,7 @@ objectstack validate ──────────────────────────────────────── → Loading configuration... → Validating against ObjectStack Protocol... - → Running author-time rules (77)... + → Running author-time rules (78)... → Checking that every required capability has a provider installable in this edition... → Checking package docs (ADR-0046)...