Skip to content

Commit 96f4483

Browse files
committed
fix(lint): flow-region-shape-invalid skips a non-record flows[] entry like every registry reader
Claude-Session: https://claude.ai/code/session_01ADHkmQjqkXDjc5jhjFfHt3 Co-authored-by: Claude <noreply@anthropic.com>
1 parent a0e211a commit 96f4483

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎packages/lint/src/validate-flow-region-shape.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ describe('[#29049] flow-region-shape-invalid', () => {
8181
expect(finding!.message).toContain('nodes');
8282
});
8383

84+
it('a non-record entry is no flow and draws nothing; the flow after it keeps its own index', () => {
85+
const bad = flow('rgn_lead_time', guard(fanOut(false)));
86+
const findings = validateFlowRegionShape({ flows: [null, 'x', bad] });
87+
expect(findings.map(({ path }) => path)).toEqual(['flows[2]']);
88+
});
89+
8490
it('a body with no string name is named by its path', () => {
8591
const [finding] = validateFlowRegionShape({ flows: [unparseable()] });
8692
expect(finding).toMatchObject({ where: "flow 'flows[0]'", path: 'flows[0]' });

‎packages/lint/src/validate-flow-region-shape.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
* register it too. Either way the finding says the flow could not be judged
3333
* and carries the schema's issues.
3434
*
35+
* An entry that is not a record at all (an empty YAML list item, a string) is
36+
* skipped, as every registry reader skips it (`non-record-object-entry.test.ts`):
37+
* no author wrote a flow there, and `os validate` refuses the collection with
38+
* the stack schema's own sentence. Its index is kept, so the paths of the
39+
* flows around it stay the author's.
40+
*
3541
* ## Not judged here
3642
*
3743
* A cycle in the flow's TOP-LEVEL graph. The engine refuses it with
@@ -43,6 +49,8 @@ import { FlowSchema, validateControlFlow } from '@objectstack/spec/automation';
4349

4450
type AnyRec = Record<string, unknown>;
4551

52+
const isRec = (v: unknown): v is AnyRec => !!v && typeof v === 'object' && !Array.isArray(v);
53+
4654
/** The rule id every finding of this rule carries. */
4755
export const FLOW_REGION_SHAPE_INVALID = 'flow-region-shape-invalid';
4856

@@ -77,10 +85,11 @@ export function validateFlowRegionShape(stack: AnyRec): FlowRegionShapeFinding[]
7785
if (!Array.isArray(flows)) return [];
7886
const findings: FlowRegionShapeFinding[] = [];
7987
flows.forEach((raw, i) => {
88+
if (!isRec(raw)) return;
8089
const path = `flows[${i}]`;
8190
const result = FlowSchema.safeParse(raw);
8291
if (!result.success) {
83-
const declared = (raw as { name?: unknown } | null)?.name;
92+
const declared = raw.name;
8493
const name = typeof declared === 'string' && declared !== '' ? declared : path;
8594
const issues = result.error.issues
8695
.map((issue) => `${issue.path.length > 0 ? issue.path.join('.') : '(root)'}: ${issue.message}`)

0 commit comments

Comments
 (0)