Skip to content

Commit 91f6845

Browse files
HugoXKBirfy
andauthored
fix(workflow): key an edge's fact the way the node lists are keyed (#2530)
Fixes #2425 Owner: Dev-4 Reviewer: Birfy Written-by: Dev-4 Base: 90a5944 Risk tier: T3 ## What changed `validateWorkflow` compared the edge's canonical artifact (`splitEndpoint` returns `formatArtifactSpec`) against the node's raw `inputs`/`outputs` arrays with `Array.prototype.includes`. Every other producer/consumer rule in `core/src/shared/workflow.js` (`producersOf`, `consumersOf`, `dependencyEdges`, `input/without-producer`, `output/without-consumer`, and the declared `inputs`/`deliverables` sets) reads those lists through `canonicalSpec`, so a definition the engine can run was refused as `edge/misaligned` when one fact was spelled with a space on a node and without one on its edge — and `workflow-store.js` turns the first problem into `workflow/invalid`, so the user cannot save it. After: both lists are keyed the way the rest of the engine keys them, so `text: draft` on a node and `text:draft` on its edge are one fact. A fact the consumer genuinely does not take in is still refused — that direction is asserted as a control. ## Verification at the tip Tip SHA: d25ccfc Ran: - red first on a clean `90a594471b5886737b433e116f6397aa8ca2b6f2` tree carrying only `core/test/workflow-edge-canonical-spec.test.js`: `# tests 4 / # pass 2 / # fail 2` — both `edge/misaligned`, one for a space on the producer (`outputs: ['text: draft']`) and one for a space on the consumer (`inputs: ['text: draft']`); the two controls (an edge-side space, and a fact the consumer does not take in) passed on the base by design. - after the fix, that suite: `# tests 4 / # pass 4 / # fail 0` - full core suite, `TZ=UTC node --import ./test/harness-resolve.mjs --test "test/*.test.js"`: `# tests 2931 / # pass 2931 / # fail 0` - `node scripts/build-client.mjs --check`: exit 0 (the module is not in the client bundle, so `client.js` is untouched) - `node scripts/ds-bot-patches.mjs check`: `ok ds-bot/ = Fei2411/DeepSeek-Bot@2b10c70 (tree 5834c00, v0.1.5)`, `ok 10 patches apply cleanly in order`, `ok core/ equals ds-bot/ + patches/ds-bot/` - `node scripts/ds-bot-patches.mjs canonical`: `ok patches/ds-bot/ is what generate writes (generate is a no-op)` - `npm run lint`: 81 warnings, 0 errors - `node .github/scripts/changelog.mjs check`: `36 fragment(s) in changelog.d/ are well formed` - `ARCH_DOCS_BASE=90a59447 node scripts/check-arch-docs.mjs`: `OK (5 changed file(s))` `patches/ds-bot/files/src/shared/workflow.js` and `patches/ds-bot/files/test/workflow-edge-canonical-spec.test.js` are whole-file mirrors written by `generate` (the file is new in FlyBot and has no `.patch` header); nothing here was edited by hand. Not run: the smoke test (no `index.js` or `src/host` behaviour change) and CI itself. Docs-not-needed: no owned path, module or contract changes; the check now agrees with the rule the module already documents (#1291 debt). ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 2530, "claim": "Dev-4", "issue": 2425, "summary": "The edge alignment check compared the edge's canonical artifact against the raw node inputs/outputs with includes, so a definition the engine runs was refused as edge/misaligned when one fact was spelled with a space on a node and without one on its edge. Both lists are now keyed through canonicalSpec, the way producersOf, consumersOf and dependencyEdges already read them. Red first at 90a5944: 2 of 4 new tests failed, one for each side carrying the space; the two controls passed on the base.", "files": [ "core/src/shared/workflow.js", "core/test/workflow-edge-canonical-spec.test.js", "patches/ds-bot/files/src/shared/workflow.js", "patches/ds-bot/files/test/workflow-edge-canonical-spec.test.js", "changelog.d/2425-workflow-edge-canonical-spec.fixed.md" ], "checks": { "ran": "TZ=UTC node --import ./test/harness-resolve.mjs --test \"test/*.test.js\"; node scripts/build-client.mjs --check; node scripts/ds-bot-patches.mjs check; node scripts/ds-bot-patches.mjs canonical; npm run lint", "result": "green", "at": "d25ccfc4021452ffa13b8c012ea1fcf199467cff" }, "next": "ready for the Verdict at d25ccfc" } ``` <!-- /flybot:checkpoint --> Co-authored-by: Danyang Chen <birfychen@gmail.com>
1 parent f665272 commit 91f6845

5 files changed

Lines changed: 127 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A workflow whose node spells a fact with a space while the edge carries the canonical spelling no longer fails to save: the edge alignment check keys the node lists the same way the rest of the engine does, so `text: draft` on a node and `text:draft` on its edge are one fact.

‎core/src/shared/workflow.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,10 @@ export function validateWorkflow(raw, options = {}) {
634634
}
635635
const fromNode = nodeById(def, from.node)
636636
const toNode = nodeById(def, to.node)
637-
if (!fromNode.outputs.includes(from.artifact) || !toNode.inputs.includes(to.artifact)) {
637+
// The edge's artifact is canonical and the node lists are not (#2425): key them the way
638+
// `producersOf` and `consumersOf` do, or a spelling difference refuses a definition the rest
639+
// of the engine can run.
640+
if (!canonicalList(fromNode.outputs).includes(from.artifact) || !canonicalList(toNode.inputs).includes(to.artifact)) {
638641
problems.push(
639642
message(
640643
'edge/misaligned',
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// One fact has one key (#1291 debt): `text: draft` and `text:draft` are the same fact, and every
2+
// consumer/producer rule in the engine reads the node lists through `canonicalSpec`. The edge
3+
// alignment check was the one place that compared the edge's canonical artifact against the raw
4+
// lists, so a definition the engine can run was still refused (#2425).
5+
import assert from 'node:assert/strict'
6+
import { test } from 'node:test'
7+
import { artifact } from '../src/shared/artifact.js'
8+
import { dependencyEdges, enterNode, validateWorkflow } from '../src/shared/workflow.js'
9+
10+
const definition = (producerSpec, edgeFrom, edgeTo, consumerSpec) => ({
11+
id: 'draft-publish',
12+
name: 'Draft and publish',
13+
version: 1,
14+
inputs: [],
15+
deliverables: ['link:published'],
16+
nodes: [
17+
{ id: 'draft', name: 'Draft', role: 'Writer', outputs: [producerSpec] },
18+
{ id: 'publish', name: 'Publish', role: 'Publisher', inputs: [consumerSpec], outputs: ['link:published'] },
19+
],
20+
edges: [{ from: edgeFrom, to: edgeTo }],
21+
loops: [],
22+
})
23+
24+
test('a space on the node and none on its edge is still one fact', () => {
25+
const def = definition('text: draft', 'draft.text:draft', 'publish.text:draft', 'text:draft')
26+
const result = validateWorkflow(def)
27+
assert.deepEqual(result.problems, [])
28+
assert.equal(result.ok, true)
29+
assert.deepEqual(dependencyEdges(def), [{ from: 'draft', to: 'publish' }])
30+
const taken = enterNode(def, 'publish', {
31+
present: { 'text:draft': artifact('text:draft', 'abc1234') },
32+
current: { 'text:draft': 'abc1234' },
33+
})
34+
assert.equal(taken.ok, true, taken.refusal)
35+
})
36+
37+
test('a space on the consumer and none on the edge is still one fact', () => {
38+
const def = definition('text:draft', 'draft.text:draft', 'publish.text:draft', 'text: draft')
39+
const result = validateWorkflow(def)
40+
assert.deepEqual(result.problems, [])
41+
assert.equal(result.ok, true)
42+
})
43+
44+
test('the same fact with the space moved to the edge is one fact too', () => {
45+
const def = definition('text:draft', 'draft.text: draft', 'publish.text:draft', 'text:draft')
46+
const result = validateWorkflow(def)
47+
assert.deepEqual(result.problems, [])
48+
assert.equal(result.ok, true)
49+
})
50+
51+
test('an edge that carries a fact the consumer does not take in is still refused (control)', () => {
52+
const def = definition('text:draft', 'draft.text:draft', 'publish.text:other', 'text:draft')
53+
const result = validateWorkflow(def)
54+
assert.equal(result.ok, false)
55+
assert.ok(
56+
result.problems.some((problem) => problem.code === 'edge/misaligned' || problem.code === 'edge/unknown-end'),
57+
JSON.stringify(result.problems),
58+
)
59+
})

‎patches/ds-bot/files/src/shared/workflow.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,10 @@ export function validateWorkflow(raw, options = {}) {
634634
}
635635
const fromNode = nodeById(def, from.node)
636636
const toNode = nodeById(def, to.node)
637-
if (!fromNode.outputs.includes(from.artifact) || !toNode.inputs.includes(to.artifact)) {
637+
// The edge's artifact is canonical and the node lists are not (#2425): key them the way
638+
// `producersOf` and `consumersOf` do, or a spelling difference refuses a definition the rest
639+
// of the engine can run.
640+
if (!canonicalList(fromNode.outputs).includes(from.artifact) || !canonicalList(toNode.inputs).includes(to.artifact)) {
638641
problems.push(
639642
message(
640643
'edge/misaligned',
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// One fact has one key (#1291 debt): `text: draft` and `text:draft` are the same fact, and every
2+
// consumer/producer rule in the engine reads the node lists through `canonicalSpec`. The edge
3+
// alignment check was the one place that compared the edge's canonical artifact against the raw
4+
// lists, so a definition the engine can run was still refused (#2425).
5+
import assert from 'node:assert/strict'
6+
import { test } from 'node:test'
7+
import { artifact } from '../src/shared/artifact.js'
8+
import { dependencyEdges, enterNode, validateWorkflow } from '../src/shared/workflow.js'
9+
10+
const definition = (producerSpec, edgeFrom, edgeTo, consumerSpec) => ({
11+
id: 'draft-publish',
12+
name: 'Draft and publish',
13+
version: 1,
14+
inputs: [],
15+
deliverables: ['link:published'],
16+
nodes: [
17+
{ id: 'draft', name: 'Draft', role: 'Writer', outputs: [producerSpec] },
18+
{ id: 'publish', name: 'Publish', role: 'Publisher', inputs: [consumerSpec], outputs: ['link:published'] },
19+
],
20+
edges: [{ from: edgeFrom, to: edgeTo }],
21+
loops: [],
22+
})
23+
24+
test('a space on the node and none on its edge is still one fact', () => {
25+
const def = definition('text: draft', 'draft.text:draft', 'publish.text:draft', 'text:draft')
26+
const result = validateWorkflow(def)
27+
assert.deepEqual(result.problems, [])
28+
assert.equal(result.ok, true)
29+
assert.deepEqual(dependencyEdges(def), [{ from: 'draft', to: 'publish' }])
30+
const taken = enterNode(def, 'publish', {
31+
present: { 'text:draft': artifact('text:draft', 'abc1234') },
32+
current: { 'text:draft': 'abc1234' },
33+
})
34+
assert.equal(taken.ok, true, taken.refusal)
35+
})
36+
37+
test('a space on the consumer and none on the edge is still one fact', () => {
38+
const def = definition('text:draft', 'draft.text:draft', 'publish.text:draft', 'text: draft')
39+
const result = validateWorkflow(def)
40+
assert.deepEqual(result.problems, [])
41+
assert.equal(result.ok, true)
42+
})
43+
44+
test('the same fact with the space moved to the edge is one fact too', () => {
45+
const def = definition('text:draft', 'draft.text: draft', 'publish.text:draft', 'text:draft')
46+
const result = validateWorkflow(def)
47+
assert.deepEqual(result.problems, [])
48+
assert.equal(result.ok, true)
49+
})
50+
51+
test('an edge that carries a fact the consumer does not take in is still refused (control)', () => {
52+
const def = definition('text:draft', 'draft.text:draft', 'publish.text:other', 'text:draft')
53+
const result = validateWorkflow(def)
54+
assert.equal(result.ok, false)
55+
assert.ok(
56+
result.problems.some((problem) => problem.code === 'edge/misaligned' || problem.code === 'edge/unknown-end'),
57+
JSON.stringify(result.problems),
58+
)
59+
})

0 commit comments

Comments
 (0)