@buaa_smat/hometrans 26.0.4 → 26.0.5

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.
Files changed (102) hide show
  1. package/agents/code-reviewer.md +2 -0
  2. package/agents/model-render-worker.md +1 -1
  3. package/i18n/agents/code-reviewer.md +2 -0
  4. package/i18n/agents/model-render-worker.md +1 -1
  5. package/i18n/skills/a2h-app-migrate/SKILL.md +51 -3
  6. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +140 -32
  7. package/i18n/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
  8. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
  9. package/i18n/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
  10. package/i18n/skills/a2h-app-migrate/test/test_image_probe.mjs +3 -3
  11. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
  12. package/i18n/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
  13. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
  14. package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
  15. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
  16. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
  17. package/i18n/skills/a2h-batch-ui-align/SKILL.md +1 -1
  18. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
  19. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
  20. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
  21. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
  22. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
  23. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
  24. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
  25. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
  26. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
  27. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
  28. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
  29. package/i18n/skills/a2h-page-specgen/references/spec-example.md +35 -5
  30. package/i18n/skills/a2h-page-specgen/references/spec-template.md +4 -4
  31. package/i18n/skills/a2h-spec-generate/SKILL.md +3 -1
  32. package/i18n/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
  33. package/i18n/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  34. package/i18n/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
  35. package/i18n/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
  36. package/i18n/skills/a2h-spec-generate/references/spec-samples.md +5 -1
  37. package/i18n/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
  38. package/i18n/skills/a2h-spec-generate/references/worker-rules.md +25 -2
  39. package/i18n/skills/a2h-spec-generate/scripts/check_spec.ts +121 -6
  40. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +2 -1
  41. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
  42. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
  43. package/i18n/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +11 -2
  44. package/i18n/skills/a2h-spec-generate/test/check-spec.test.ts +35 -0
  45. package/package.json +1 -1
  46. package/skills/a2h-app-migrate/SKILL.md +53 -5
  47. package/skills/a2h-app-migrate/references/workflow.yaml +140 -32
  48. package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +226 -0
  49. package/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
  50. package/skills/a2h-app-migrate/scripts/dag_process_executor.mjs +199 -0
  51. package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +897 -0
  52. package/skills/a2h-app-migrate/scripts/dag_runner.mjs +1767 -0
  53. package/skills/a2h-app-migrate/scripts/ledger.mjs +15 -2
  54. package/skills/a2h-app-migrate/scripts/lib-yaml-lite.mjs +8 -2
  55. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -8
  56. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
  57. package/skills/a2h-app-migrate/test/test_dag_complete.mjs +222 -0
  58. package/skills/a2h-app-migrate/test/test_dag_production.mjs +670 -0
  59. package/skills/a2h-app-migrate/test/test_dag_runner.mjs +423 -0
  60. package/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
  61. package/skills/a2h-app-migrate/test/test_image_probe.mjs +1 -1
  62. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +16 -1
  63. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
  64. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
  65. package/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
  66. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
  67. package/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
  68. package/skills/a2h-batch-ui-align/SKILL.md +1 -1
  69. package/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
  70. package/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
  71. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
  72. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
  73. package/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
  74. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +49 -3
  75. package/skills/a2h-batch-ui-align/scripts/static_check/core/android.ts +36 -0
  76. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
  77. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +8 -0
  78. package/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
  79. package/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
  80. package/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
  81. package/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
  82. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_coolmall_ds1123.test.mjs +433 -0
  83. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_overlay_in_linear.test.mjs +288 -0
  84. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +46 -0
  85. package/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
  86. package/skills/a2h-page-specgen/references/spec-example.md +35 -5
  87. package/skills/a2h-page-specgen/references/spec-template.md +4 -4
  88. package/skills/a2h-spec-generate/SKILL.md +3 -1
  89. package/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
  90. package/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  91. package/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
  92. package/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
  93. package/skills/a2h-spec-generate/references/spec-samples.md +5 -1
  94. package/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
  95. package/skills/a2h-spec-generate/references/worker-rules.md +25 -2
  96. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +3 -1
  97. package/skills/a2h-spec-generate/scripts/check_spec.ts +262 -6
  98. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +12 -2
  99. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
  100. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
  101. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +54 -3
  102. package/skills/a2h-spec-generate/test/check-spec.test.ts +247 -0
@@ -17,7 +17,9 @@
17
17
  * With --work, a ui.batch / enrich.spec_gen / logic.spec_pipeline terminal record also writes its resume summary
18
18
  * (write_resume_summary.mjs) in the same call, so the summary no longer depends on a second command being remembered.
19
19
  * node ledger.mjs --ledger <LEDGER> --failures
20
- * Read-only: nodes with status=failed in this run (after the last run_start), as one JSON array line on stdout (used by logic.finalize).
20
+ * Read-only: nodes whose *last* node record in this run (after the last run_start) is failed, as one JSON array
21
+ * line on stdout (used by logic.finalize). A failure superseded by a later record (rewind / new generation) is not
22
+ * listed, matching assert_dag_complete and run_end.failed_nodes.
21
23
  *
22
24
  * Old-format lines ({node, status, reason} without an event field) are read as node records.
23
25
  * A failed record whose reason blames the context / tokens / session length is refused (exit 2, policy.context_budget).
@@ -86,6 +88,17 @@ export function startedFields(records, node, startedAt, now = new Date()) {
86
88
 
87
89
  export const SUMMARY_NODES = ["ui.batch", "enrich.spec_gen", "logic.spec_pipeline"];
88
90
 
91
+ /** Nodes whose last node record in the current run is failed (later generations supersede earlier ones). */
92
+ export function currentFailures(records) {
93
+ const latest = new Map();
94
+ for (const record of currentRun(records)) {
95
+ if (record.event !== "node") continue;
96
+ latest.delete(record.node);
97
+ latest.set(record.node, record);
98
+ }
99
+ return [...latest.values()].filter((record) => record.status === "failed");
100
+ }
101
+
89
102
  /** Records after the last run_start (no run_start -> all of them). */
90
103
  export function currentRun(records) {
91
104
  let i = records.length - 1;
@@ -100,7 +113,7 @@ function main() {
100
113
  flags: ["start", "failures", "begin"],
101
114
  });
102
115
  if (args.failures) {
103
- const failed = currentRun(readLedger(args.ledger)).filter((r) => r.event === "node" && r.status === "failed");
116
+ const failed = currentFailures(readLedger(args.ledger));
104
117
  process.stdout.write(JSON.stringify(failed.map(({ node, reason }) => ({ node, reason: reason || "" }))) + "\n");
105
118
  return 0;
106
119
  }
@@ -48,6 +48,12 @@ function stripInlineComment(line) {
48
48
  return line;
49
49
  }
50
50
 
51
+ function isEscaped(text, index) {
52
+ let slashes = 0;
53
+ for (let i = index - 1; i >= 0 && text[i] === "\\"; i--) slashes++;
54
+ return slashes % 2 === 1;
55
+ }
56
+
51
57
  function parseFlow(text, start) {
52
58
  const open = text[start];
53
59
  const close = open === "{" ? "}" : "]";
@@ -72,7 +78,7 @@ function parseFlow(text, start) {
72
78
  for (let k = 0; k < t.length; k++) {
73
79
  const c = t[k];
74
80
  if (c === "'" && !d) s = !s;
75
- else if (c === '"' && !s) d = !d;
81
+ else if (c === '"' && !s && !isEscaped(t, k)) d = !d;
76
82
  else if (!s && !d) {
77
83
  if (c === "{" || c === "[") ds++;
78
84
  else if (c === "}" || c === "]") ds--;
@@ -98,7 +104,7 @@ function parseFlow(text, start) {
98
104
  i++;
99
105
  continue;
100
106
  }
101
- if (c === '"' && !inSingle) {
107
+ if (c === '"' && !inSingle && !isEscaped(text, i)) {
102
108
  inDouble = !inDouble;
103
109
  buf += c;
104
110
  i++;
@@ -35,6 +35,7 @@ import path from "node:path";
35
35
  import { fileURLToPath } from "node:url";
36
36
 
37
37
  import yaml from "./lib-yaml-lite.mjs";
38
+ import { profileSkipped } from "./dag_graph.mjs";
38
39
  import { readLedger } from "./ledger.mjs";
39
40
  import { parseArgs } from "./paths_preflight.mjs";
40
41
  import { DEFAULT_SPEC_ENGINE, LEGACY_SPEC_ENGINE, SPEC_ENGINES, normalizeEngine } from "./run_dir.mjs";
@@ -91,6 +92,8 @@ function graph(doc, { conditional = true } = {}) {
91
92
  return parents;
92
93
  }
93
94
 
95
+ export { profileSkipped } from "./dag_graph.mjs";
96
+
94
97
  function closure(start, edges) {
95
98
  const seen = new Set();
96
99
  const stack = [...(edges[start] || [])];
@@ -103,14 +106,6 @@ function closure(start, edges) {
103
106
  return seen;
104
107
  }
105
108
 
106
- /** Nodes cut by the profile: lane not in include_lanes, or named by force_skip (node id or lane id). */
107
- export function profileSkipped(doc, profile) {
108
- const conf = doc.profiles?.[profile] || {};
109
- const lanes = conf.include_lanes === "all" || !conf.include_lanes ? null : new Set(conf.include_lanes);
110
- const force = new Set(conf.force_skip || []);
111
- return new Set((doc.nodes || []).filter((n) => (lanes && !lanes.has(n.lane)) || force.has(n.id) || force.has(n.lane)).map((n) => n.id));
112
- }
113
-
114
109
  const truthy = (v) => ["true", "1", "yes", "on"].includes(String(v ?? "").trim().toLowerCase());
115
110
 
116
111
  export function planResume(doc, records, { fromNode, baseProfile = "", engine = "", engineGiven = false }) {
@@ -12,6 +12,7 @@ import path from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
 
14
14
  import yaml from "./lib-yaml-lite.mjs";
15
+ import { validateGraph } from "./dag_graph.mjs";
15
16
  import { parseArgs } from "./paths_preflight.mjs";
16
17
 
17
18
  const HERE = path.dirname(fileURLToPath(import.meta.url));
@@ -63,6 +64,75 @@ function hasPhrase(text, [zh, en], { ci = false } = {}) {
63
64
 
64
65
  const SEED = { ANDROID: "/A", HMOS: "/H", SKILLS_ROOT: "/S", APK_PATH: "/apk" };
65
66
 
67
+ const PRODUCTION_SERIAL_ORDER = [
68
+ "bootstrap",
69
+ "discover.android_index",
70
+ "boot.workspace",
71
+ "discover.arch",
72
+ "discover.utg_static",
73
+ "review.arch",
74
+ "discover.utg_snapshot",
75
+ "discover.feature_scope",
76
+ "ui.batch",
77
+ "review.ui_batch",
78
+ "enrich.spec_gen",
79
+ "review.spec_gen",
80
+ "enrich.module_docs",
81
+ "barrier.l2_enrich",
82
+ "adopt.signing",
83
+ "adopt.specs_json",
84
+ "logic.spec_pipeline",
85
+ "logic.finalize",
86
+ ];
87
+
88
+ // A node's own reuse lives only in runner.reuse_if. The one exception is a node whose sole consumer is reused
89
+ // this round: that is "nobody needs this output", a skip, not a reuse of this node's artifacts.
90
+ const CROSS_NODE_REUSE_IN_SKIP_IF = {
91
+ "discover.utg_static": ["REUSE_SPEC_GENERATE"],
92
+ };
93
+
94
+ const PRODUCTION_RUNNER_KINDS = {
95
+ bootstrap: "bootstrap",
96
+ "discover.android_index": "script",
97
+ "discover.arch": "skill",
98
+ "boot.workspace": "workspace",
99
+ "discover.utg_static": "skill",
100
+ "review.arch": "gate",
101
+ "discover.utg_snapshot": "snapshot",
102
+ "discover.feature_scope": "host_action",
103
+ "ui.batch": "skill",
104
+ "review.ui_batch": "gate",
105
+ "enrich.spec_gen": "skill",
106
+ "review.spec_gen": "gate",
107
+ "enrich.module_docs": "skill",
108
+ "barrier.l2_enrich": "barrier",
109
+ "adopt.signing": "host_action",
110
+ "adopt.specs_json": "adopt_specs",
111
+ "logic.spec_pipeline": "skill",
112
+ "logic.finalize": "host_action",
113
+ };
114
+
115
+ const PRODUCTION_GATES = {
116
+ "review.arch": {
117
+ gate: "arch",
118
+ checkpoint: "${CHECKPOINT_DIR}/arch-reviewed.ok",
119
+ rewind_to: "discover.arch",
120
+ rewind_clear_vars: ["REUSE_DISCOVER_ARCH"],
121
+ },
122
+ "review.spec_gen": {
123
+ gate: "spec_gen",
124
+ checkpoint: "${CHECKPOINT_DIR}/spec-gen-reviewed.ok",
125
+ rewind_to: "enrich.spec_gen",
126
+ rewind_clear_vars: ["REUSE_SPEC_GENERATE"],
127
+ },
128
+ "review.ui_batch": {
129
+ gate: "ui_batch",
130
+ checkpoint: "${CHECKPOINT_DIR}/ui-batch-reviewed.ok",
131
+ rewind_to: "ui.batch",
132
+ rewind_clear_vars: ["REUSE_UI_BATCH"],
133
+ },
134
+ };
135
+
66
136
  function expand(value, env, depth = 12) {
67
137
  let out = String(value);
68
138
  for (let i = 0; i < depth; i++) {
@@ -164,38 +234,78 @@ function main() {
164
234
  const ids = nodes.map((n) => n.id);
165
235
  const N = Object.fromEntries(nodes.map((n) => [n.id, n]));
166
236
  const env = buildEnv(doc);
167
- const errors = [];
237
+ const errors = validateGraph(doc);
168
238
 
169
- const dups = new Set(ids.filter((i) => ids.filter((x) => x === i).length > 1));
170
- if (dups.size) errors.push(`duplicate node ids: ${[...dups].sort()}`);
239
+ if (doc.id === "a2h-app-migrate") {
240
+ if (JSON.stringify(doc.serial_order || []) !== JSON.stringify(PRODUCTION_SERIAL_ORDER)) {
241
+ errors.push(`serial_order must exactly cover the production nodes in the approved fixed order: ${PRODUCTION_SERIAL_ORDER.join(", ")}`);
242
+ }
243
+ for (const n of nodes) {
244
+ const expectedKind = PRODUCTION_RUNNER_KINDS[n.id];
245
+ if (!expectedKind) {
246
+ errors.push(`${n.id}: unexpected node in the production workflow`);
247
+ continue;
248
+ }
249
+ if (n.runner?.action !== "production" || n.runner?.kind !== expectedKind) {
250
+ errors.push(`${n.id}: runner must be action=production kind=${expectedKind}`);
251
+ }
252
+ const allowedReuse = CROSS_NODE_REUSE_IN_SKIP_IF[n.id] || [];
253
+ const ownReuse = new Set(String(n.runner?.reuse_if || "").match(/\bREUSE_[A-Z0-9_]+\b/g) || []);
254
+ for (const v of new Set(String(n.skip_if || "").match(/\bREUSE_[A-Z0-9_]+\b/g) || [])) {
255
+ if (!allowedReuse.includes(v) || ownReuse.has(v)) {
256
+ errors.push(`${n.id}: skip_if must not contain ${v}; reuse belongs only in runner.reuse_if`);
257
+ }
258
+ }
259
+ }
260
+ for (const id of PRODUCTION_SERIAL_ORDER) {
261
+ if (!N[id]) errors.push(`production workflow is missing node ${id}`);
262
+ }
171
263
 
172
- for (const n of nodes) {
173
- for (const p of n.needs || []) {
174
- if (!(p in N)) errors.push(`${n.id}: needs points to a missing node \`${p}\``);
264
+ const summaryNodes = nodes.filter((n) => n.runner?.after_terminal != null);
265
+ const expectedSummaryNodes = ["ui.batch", "enrich.spec_gen", "logic.spec_pipeline"];
266
+ if (JSON.stringify(summaryNodes.map((n) => n.id).sort()) !== JSON.stringify([...expectedSummaryNodes].sort())) {
267
+ errors.push(`runner.after_terminal=resume_summary must be configured only on ${expectedSummaryNodes.join(", ")}`);
268
+ }
269
+ for (const n of summaryNodes) {
270
+ if (n.runner.after_terminal !== "resume_summary") errors.push(`${n.id}: unsupported runner.after_terminal ${n.runner.after_terminal}`);
271
+ }
272
+
273
+ for (const [id, expected] of Object.entries(PRODUCTION_GATES)) {
274
+ const runner = N[id]?.runner || {};
275
+ for (const [key, value] of Object.entries(expected)) {
276
+ if (JSON.stringify(runner[key]) !== JSON.stringify(value)) {
277
+ errors.push(`${id}: runner.${key} must be ${JSON.stringify(value)}`);
278
+ }
279
+ }
280
+ if (N[id]?.human_gate !== true) errors.push(`${id}: production review gate must keep human_gate: true`);
281
+ }
282
+
283
+ const finalize = N["logic.finalize"];
284
+ const finalizeSuccess = finalize?.success || [];
285
+ if (
286
+ finalizeSuccess.length !== 1
287
+ || finalizeSuccess[0]?.file_exists !== "${LOGIC_REPORT}"
288
+ ) {
289
+ errors.push("logic.finalize: success must only verify file_exists=${LOGIC_REPORT}; the Runner owns DAG certification");
175
290
  }
291
+ const finalizeBlob = JSON.stringify(finalize || {});
292
+ if (finalizeBlob.includes("--write-run-end") || /--node\s+logic\.finalize\s+--status/.test(finalizeBlob)) {
293
+ errors.push("logic.finalize: workflow must not append its own terminal record or run_end");
294
+ }
295
+ if (JSON.stringify(doc).includes("--write-run-end")) {
296
+ errors.push("workflow must not contain --write-run-end; only the Runner may certify a run");
297
+ }
298
+ }
299
+
300
+ for (const n of nodes) {
176
301
  for (const c of n.conditional_needs || []) {
177
302
  if (!String(c.when || "").trim()) errors.push(`${n.id}: conditional_needs entry is missing when`);
178
303
  if (!String(c.why || "").trim()) {
179
304
  errors.push(`${n.id}: conditional_needs entry is missing why (a conditional edge must state its reason)`);
180
305
  }
181
- for (const t of c.add || []) {
182
- if (!(t in N)) errors.push(`${n.id}: conditional_needs.add points to a missing node \`${t}\``);
183
- }
184
306
  }
185
307
  }
186
308
 
187
- const seen = new Set();
188
- let todo = [...nodes];
189
- while (todo.length) {
190
- const ready = todo.filter((n) => (n.needs || []).every((p) => seen.has(p)));
191
- if (!ready.length) {
192
- errors.push(`the DAG has a cycle involving: ${todo.map((n) => n.id)}`);
193
- break;
194
- }
195
- for (const n of ready) seen.add(n.id);
196
- todo = todo.filter((n) => !seen.has(n.id));
197
- }
198
-
199
309
  const fm = new Set(Object.keys(doc.fail_matrix || {}));
200
310
  for (const i of ids) {
201
311
  if (!fm.has(i)) errors.push(`fail_matrix is missing node \`${i}\` (no failure handling defined)`);
@@ -505,6 +615,9 @@ function main() {
505
615
  process.stdout.write("✅ ids unique / needs closed / no cycles\n");
506
616
  process.stdout.write("✅ fail_matrix and schedule_hint cover every node\n");
507
617
  process.stdout.write("✅ force_skip targets valid\n");
618
+ if (doc.id === "a2h-app-migrate") {
619
+ process.stdout.write("✅ all production nodes use the fixed Runner kinds/order; reuse, gates, summaries and finalize ownership are valid\n");
620
+ }
508
621
  process.stdout.write(
509
622
  `✅ no unregistered concurrent read/write races (${exempt.length} registered exemption(s), all still valid)\n`,
510
623
  );
@@ -0,0 +1,222 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import test from "node:test";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ import { evaluateDag } from "../scripts/assert_dag_complete.mjs";
10
+ import { readLedger } from "../scripts/ledger.mjs";
11
+ import yaml from "../scripts/lib-yaml-lite.mjs";
12
+ import { profileSkipped } from "../scripts/resume_plan.mjs";
13
+
14
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
15
+ const WORKFLOW = path.join(HERE, "..", "references", "workflow.yaml");
16
+ const SCRIPT = path.join(HERE, "..", "scripts", "assert_dag_complete.mjs");
17
+ const doc = yaml.load(fs.readFileSync(WORKFLOW, "utf8"));
18
+
19
+ const start = (profile = "full", at = "2026-11-22T00:00:00.000Z", extra = {}) => ({
20
+ event: "run_start",
21
+ profile,
22
+ from_node: "bootstrap",
23
+ resume: false,
24
+ at,
25
+ ...extra,
26
+ });
27
+ const node = (id, status = "done", reason = "") => ({ event: "node", node: id, status, ...(reason ? { reason } : {}) });
28
+
29
+ function completeRecords(profile = "full") {
30
+ const skipped = profileSkipped(doc, profile);
31
+ return [
32
+ start(profile),
33
+ ...doc.nodes.filter((n) => !skipped.has(n.id)).map((n) => node(n.id)),
34
+ ];
35
+ }
36
+
37
+ function fixture(profile = "full") {
38
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "dag-complete-"));
39
+ const work = path.join(root, "HMOS", ".hometrans", "app-migrate");
40
+ fs.mkdirSync(work, { recursive: true });
41
+ const ledger = path.join(work, "stage-ledger.jsonl");
42
+ const logicReport = path.join(work, "logic-convert-report.md");
43
+ const state = path.join(root, "HMOS", ".hometrans", "spec_pipeline_state.json");
44
+ fs.writeFileSync(logicReport, "# report\n");
45
+ fs.writeFileSync(state, JSON.stringify({
46
+ schema: "spec_pipeline_state/v2",
47
+ groups: [{ G: 1, status: "done", chunks: [] }],
48
+ specs: [{ status: "done" }],
49
+ finalization: { done: true, homecheck: "PASS", smoke: "PASS", final_build: "SUCCESS" },
50
+ }));
51
+ return { root, work, ledger, logicReport, state, profile };
52
+ }
53
+
54
+ function options(f) {
55
+ return { profile: f.profile, logicReport: f.logicReport, state: f.state };
56
+ }
57
+
58
+ function writeLedger(f, records) {
59
+ fs.writeFileSync(f.ledger, records.map((record) => JSON.stringify(record)).join("\n") + "\n");
60
+ }
61
+
62
+ function runCli(f, records, ...args) {
63
+ writeLedger(f, records);
64
+ return spawnSync(process.execPath, [SCRIPT, "--workflow", WORKFLOW, "--ledger", f.ledger, "--profile", f.profile, ...args], {
65
+ encoding: "utf8",
66
+ });
67
+ }
68
+
69
+ test("reproduces the early stop before F0: logic nodes are required and the next node is logic.spec_pipeline", () => {
70
+ const f = fixture();
71
+ const records = completeRecords().filter((record) => record.event === "run_start" || !["logic.spec_pipeline", "logic.finalize"].includes(record.node));
72
+ const r = evaluateDag(doc, records, options(f));
73
+ assert.equal(r.code, 1);
74
+ assert.equal(r.summary.complete, false);
75
+ assert.deepEqual(r.summary.missing, ["logic.spec_pipeline", "logic.finalize"]);
76
+ assert.deepEqual(r.summary.next_nodes, ["logic.spec_pipeline"]);
77
+ assert.equal(r.summary.can_final, false);
78
+ });
79
+
80
+ test("a fully terminal full DAG with valid logic evidence is complete", () => {
81
+ const f = fixture();
82
+ const r = evaluateDag(doc, completeRecords(), options(f));
83
+ assert.equal(r.code, 0, JSON.stringify(r.summary));
84
+ assert.equal(r.summary.status, "completed");
85
+ assert.equal(r.summary.success, true);
86
+ assert.equal(r.summary.can_final, true);
87
+ });
88
+
89
+ test("soft_continue failures produce completed_with_failures, not success", () => {
90
+ const f = fixture();
91
+ const records = completeRecords().map((record) => record.node === "ui.batch" ? node("ui.batch", "failed", "device lost") : record);
92
+ const r = evaluateDag(doc, records, options(f));
93
+ assert.equal(r.code, 0, JSON.stringify(r.summary));
94
+ assert.equal(r.summary.status, "completed_with_failures");
95
+ assert.equal(r.summary.success, false);
96
+ assert.deepEqual(r.summary.failed_soft, [{ node: "ui.batch", reason: "device lost" }]);
97
+ });
98
+
99
+ test("a hard_stop failure cannot be certified as a completed DAG", () => {
100
+ const f = fixture();
101
+ const records = completeRecords().map((record) => record.node === "discover.arch" ? node("discover.arch", "failed", "scaffold failed") : record);
102
+ const r = evaluateDag(doc, records, options(f));
103
+ assert.equal(r.code, 3);
104
+ assert.equal(r.summary.status, "failed");
105
+ assert.equal(r.summary.can_final, false);
106
+ assert.deepEqual(r.summary.failed_hard, [{ node: "discover.arch", reason: "scaffold failed" }]);
107
+ });
108
+
109
+ test("ui-only accepts profile-skipped logic nodes without demanding pipeline state", () => {
110
+ const f = fixture("ui-only");
111
+ fs.rmSync(f.state);
112
+ const r = evaluateDag(doc, completeRecords("ui-only"), options(f));
113
+ assert.equal(r.code, 0, JSON.stringify(r.summary));
114
+ assert.equal(r.summary.status, "completed");
115
+ });
116
+
117
+ test("background waiting may be inspected, but --require-complete still rejects it", () => {
118
+ const f = fixture();
119
+ const records = completeRecords().filter((record) => record.event === "run_start" || !["logic.spec_pipeline", "logic.finalize"].includes(record.node));
120
+ const diagnostic = runCli(f, records);
121
+ assert.equal(diagnostic.status, 0, diagnostic.stderr);
122
+ assert.equal(JSON.parse(diagnostic.stdout).complete, false);
123
+
124
+ const finalAttempt = runCli(f, records, "--require-complete");
125
+ assert.equal(finalAttempt.status, 1, finalAttempt.stderr);
126
+ assert.equal(JSON.parse(finalAttempt.stdout).code, undefined);
127
+ assert.deepEqual(JSON.parse(finalAttempt.stdout).next_nodes, ["logic.spec_pipeline"]);
128
+ assert.equal(readLedger(f.ledger).some((record) => record.event === "run_end"), false);
129
+ });
130
+
131
+ test("a previous run_end cannot certify a new run", () => {
132
+ const f = fixture();
133
+ const first = completeRecords();
134
+ first.push({ event: "run_end", run_id: first[0].at, status: "completed" });
135
+ const records = [...first, start("full", "2026-11-22T01:00:00.000Z", { from_node: "logic.spec_pipeline", resume: true })];
136
+ const r = evaluateDag(doc, records, options(f));
137
+ assert.equal(r.code, 1);
138
+ assert.equal(r.summary.run_id, "2026-11-22T01:00:00.000Z");
139
+ assert.equal(r.summary.complete, false);
140
+ });
141
+
142
+ test("records appended after run_end make that certificate stale", () => {
143
+ const f = fixture();
144
+ const records = completeRecords();
145
+ records.push({ event: "run_end", run_id: records[0].at, status: "completed" }, node("logic.finalize"));
146
+ const r = evaluateDag(doc, records, options(f));
147
+ assert.equal(r.code, 2);
148
+ assert.match(r.summary.error, /run_end is stale/);
149
+ });
150
+
151
+ test("a report file without valid ledger and artifact evidence cannot pass", () => {
152
+ const f = fixture();
153
+ fs.rmSync(f.logicReport);
154
+ const r = evaluateDag(doc, completeRecords(), options(f));
155
+ assert.equal(r.code, 2);
156
+ assert.match(r.summary.error, /report does not exist/);
157
+ });
158
+
159
+ test("an active node cannot invent skipped or reused status without a skip contract", () => {
160
+ const f = fixture();
161
+ const records = completeRecords().map((record) => record.node === "boot.workspace" ? node("boot.workspace", "skipped") : record);
162
+ const r = evaluateDag(doc, records, options(f));
163
+ assert.equal(r.code, 2);
164
+ assert.deepEqual(r.summary.invalid, [{ node: "boot.workspace", status: "skipped", reason: "node has no skip_if/reuse contract" }]);
165
+ });
166
+
167
+ test("failed status requires failure evidence", () => {
168
+ const f = fixture();
169
+ const records = completeRecords().map((record) => record.node === "ui.batch" ? node("ui.batch", "failed") : record);
170
+ const r = evaluateDag(doc, records, options(f));
171
+ assert.equal(r.code, 2);
172
+ assert.match(r.summary.invalid[0].reason, /requires failure evidence/);
173
+ });
174
+
175
+ test("done logic requires check_spec_pipeline_done evidence", () => {
176
+ const f = fixture();
177
+ fs.writeFileSync(f.state, JSON.stringify({
178
+ schema: "spec_pipeline_state/v2",
179
+ groups: [{ G: 1, status: "pending", chunks: [] }],
180
+ specs: [],
181
+ finalization: { done: false },
182
+ }));
183
+ const r = evaluateDag(doc, completeRecords(), options(f));
184
+ assert.equal(r.code, 2);
185
+ assert.match(r.summary.error, /state does not pass/);
186
+ assert.equal(r.summary.logic_pipeline_check.done, false);
187
+ });
188
+
189
+ test("logic.finalize integration rejects certification before its terminal record, then certifies exactly once", () => {
190
+ const f = fixture();
191
+ const beforeTerminal = completeRecords().filter((record) => record.node !== "logic.finalize");
192
+ const rejected = runCli(f, beforeTerminal, "--require-complete", "--write-run-end");
193
+ assert.equal(rejected.status, 1, rejected.stderr);
194
+ assert.deepEqual(JSON.parse(rejected.stdout).missing, ["logic.finalize"]);
195
+ assert.equal(readLedger(f.ledger).some((record) => record.event === "run_end"), false);
196
+
197
+ const terminalRecords = [...beforeTerminal, node("logic.finalize")];
198
+ const certified = runCli(f, terminalRecords, "--require-complete", "--write-run-end");
199
+ assert.equal(certified.status, 0, certified.stderr);
200
+ const ledger = readLedger(f.ledger);
201
+ assert.equal(ledger.filter((record) => record.event === "run_end").length, 1);
202
+ assert.equal(ledger[ledger.length - 1].event, "run_end");
203
+
204
+ const successRecheck = runCli(f, ledger, "--require-complete", "--write-run-end");
205
+ assert.equal(successRecheck.status, 0, successRecheck.stderr);
206
+ assert.equal(readLedger(f.ledger).filter((record) => record.event === "run_end").length, 1);
207
+ });
208
+
209
+ test("--write-run-end writes one certificate and is idempotent", () => {
210
+ const f = fixture();
211
+ const first = runCli(f, completeRecords(), "--write-run-end");
212
+ assert.equal(first.status, 0, first.stderr);
213
+ assert.equal(JSON.parse(first.stdout).status, "completed");
214
+ let ends = readLedger(f.ledger).filter((record) => record.event === "run_end");
215
+ assert.equal(ends.length, 1);
216
+ assert.equal(ends[0].run_id, "2026-11-22T00:00:00.000Z");
217
+
218
+ const second = runCli(f, readLedger(f.ledger), "--write-run-end");
219
+ assert.equal(second.status, 0, second.stderr);
220
+ ends = readLedger(f.ledger).filter((record) => record.event === "run_end");
221
+ assert.equal(ends.length, 1);
222
+ });