@xenonbyte/da-vinci-workflow 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,24 @@
1
1
  const path = require("path");
2
- const { STATUS } = require("./workflow-contract");
3
2
  const {
4
3
  unique,
5
4
  resolveImplementationLanding,
6
- resolveChangeDir,
7
5
  parseBindingsArtifact,
8
6
  readChangeArtifacts,
9
7
  readArtifactTexts
10
8
  } = require("./planning-parsers");
9
+ const { buildGateEnvelope, finalizeGateEnvelope } = require("./gate-utils");
10
+ const {
11
+ buildBasePlanningResultEnvelope,
12
+ finalizePlanningResult,
13
+ resolveChangeWithFindings
14
+ } = require("./planning-quality-utils");
11
15
 
12
16
  function buildEnvelope(projectRoot, strict) {
13
17
  return {
14
- status: STATUS.PASS,
15
- failures: [],
16
- warnings: [],
17
- notes: [],
18
- projectRoot,
19
- changeId: null,
20
- strict,
18
+ ...buildBasePlanningResultEnvelope(projectRoot, strict),
19
+ gates: {
20
+ bindingsHealth: null
21
+ },
21
22
  summary: {
22
23
  mappings: 0,
23
24
  malformed: 0
@@ -29,13 +30,19 @@ function finalize(result) {
29
30
  result.failures = unique(result.failures);
30
31
  result.warnings = unique(result.warnings);
31
32
  result.notes = unique(result.notes);
32
- const hasFindings = result.failures.length > 0 || result.warnings.length > 0;
33
- if (!hasFindings) {
34
- result.status = STATUS.PASS;
35
- return result;
33
+ return finalizePlanningResult(result);
34
+ }
35
+
36
+ function attachBindingsGateFindings(result, gate) {
37
+ for (const message of gate.blocking || []) {
38
+ result.failures.push(`[gate:bindingsHealth] ${message}`);
39
+ }
40
+ for (const message of gate.advisory || []) {
41
+ result.warnings.push(`[gate:bindingsHealth] ${message}`);
42
+ }
43
+ for (const message of gate.compatibility || []) {
44
+ result.notes.push(`[gate:bindingsHealth] ${message}`);
36
45
  }
37
- result.status = result.strict ? STATUS.BLOCK : STATUS.WARN;
38
- return result;
39
46
  }
40
47
 
41
48
  function lintBindings(projectPathInput, options = {}) {
@@ -43,20 +50,22 @@ function lintBindings(projectPathInput, options = {}) {
43
50
  const strict = options.strict === true;
44
51
  const requestedChangeId = options.changeId ? String(options.changeId).trim() : "";
45
52
  const result = buildEnvelope(projectRoot, strict);
53
+ const bindingsGate = buildGateEnvelope("bindingsHealth");
46
54
 
47
- const resolved = resolveChangeDir(projectRoot, requestedChangeId);
48
- result.failures.push(...resolved.failures);
49
- result.notes.push(...resolved.notes);
50
- if (!resolved.changeDir) {
55
+ const changeDir = resolveChangeWithFindings(projectRoot, requestedChangeId, result.failures, result.notes);
56
+ if (!changeDir) {
57
+ result.gates.bindingsHealth = finalizeGateEnvelope(bindingsGate, { strict });
51
58
  result.notes.push("lint-bindings defaults to advisory mode; pass `--strict` to block on findings.");
52
59
  return finalize(result);
53
60
  }
54
- result.changeId = resolved.changeId;
61
+ result.changeId = path.basename(changeDir);
55
62
 
56
- const artifactPaths = readChangeArtifacts(projectRoot, resolved.changeId);
63
+ const artifactPaths = readChangeArtifacts(projectRoot, result.changeId);
57
64
  const artifacts = readArtifactTexts(artifactPaths);
58
65
  if (!artifacts.bindings) {
59
- result.failures.push("Missing `pencil-bindings.md` for lint-bindings.");
66
+ bindingsGate.blocking.push("Missing `pencil-bindings.md` for lint-bindings.");
67
+ result.gates.bindingsHealth = finalizeGateEnvelope(bindingsGate, { strict });
68
+ attachBindingsGateFindings(result, result.gates.bindingsHealth);
60
69
  result.notes.push("lint-bindings defaults to advisory mode; pass `--strict` to block on findings.");
61
70
  return finalize(result);
62
71
  }
@@ -66,17 +75,19 @@ function lintBindings(projectPathInput, options = {}) {
66
75
  result.summary.malformed = parsed.malformed.length;
67
76
 
68
77
  if (parsed.mappings.length === 0) {
69
- result.failures.push("No implementation-to-Pencil mappings were parsed from `pencil-bindings.md`.");
78
+ bindingsGate.blocking.push(
79
+ "No implementation-to-Pencil mappings were parsed from `pencil-bindings.md`."
80
+ );
70
81
  }
71
82
  if (parsed.malformed.length > 0) {
72
83
  for (const malformed of parsed.malformed) {
73
- result.warnings.push(`Malformed binding mapping entry: "${malformed}".`);
84
+ bindingsGate.advisory.push(`Malformed binding mapping entry: "${malformed}".`);
74
85
  }
75
86
  }
76
87
 
77
88
  for (const mapping of parsed.mappings) {
78
89
  if (!mapping.implementation || !mapping.designPage) {
79
- result.warnings.push(`Malformed binding mapping entry: "${mapping.raw}".`);
90
+ bindingsGate.advisory.push(`Malformed binding mapping entry: "${mapping.raw}".`);
80
91
  continue;
81
92
  }
82
93
 
@@ -86,21 +97,23 @@ function lintBindings(projectPathInput, options = {}) {
86
97
  /missing|todo|gap|pending|temporary/i.test(note)
87
98
  );
88
99
  if (noteContainsIntentionalGap) {
89
- result.warnings.push(
100
+ bindingsGate.compatibility.push(
90
101
  `Unresolved implementation landing for "${mapping.implementation}" (allowed by explicit notes).`
91
102
  );
92
103
  } else {
93
- result.warnings.push(`Unresolved implementation landing for "${mapping.implementation}".`);
104
+ bindingsGate.advisory.push(`Unresolved implementation landing for "${mapping.implementation}".`);
94
105
  }
95
106
  }
96
107
 
97
108
  if (mapping.designSource && !String(mapping.designSource).includes(".pen")) {
98
- result.warnings.push(
109
+ bindingsGate.advisory.push(
99
110
  `Binding source for "${mapping.implementation}" does not look like a .pen path: "${mapping.designSource}".`
100
111
  );
101
112
  }
102
113
  }
103
114
 
115
+ result.gates.bindingsHealth = finalizeGateEnvelope(bindingsGate, { strict });
116
+ attachBindingsGateFindings(result, result.gates.bindingsHealth);
104
117
  result.notes.push("lint-bindings defaults to advisory mode; pass `--strict` to block on findings.");
105
118
  return finalize(result);
106
119
  }