@principles/pd-cli 1.152.12 → 1.152.14

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 (305) hide show
  1. package/dist/commands/candidate.d.ts.map +1 -1
  2. package/dist/commands/candidate.js +34 -7
  3. package/dist/commands/candidate.js.map +1 -1
  4. package/dist/commands/diagnose.d.ts.map +1 -1
  5. package/dist/commands/diagnose.js +23 -7
  6. package/dist/commands/diagnose.js.map +1 -1
  7. package/dist/commands/pain-retry.d.ts.map +1 -1
  8. package/dist/commands/pain-retry.js +21 -7
  9. package/dist/commands/pain-retry.js.map +1 -1
  10. package/package.json +13 -7
  11. package/CHANGELOG.md +0 -23
  12. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  13. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  14. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  15. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  16. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  17. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  18. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  19. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  20. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  21. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  22. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  23. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  24. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  25. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  26. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  27. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  28. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  29. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  30. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  31. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  32. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  33. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  34. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  35. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  36. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  37. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  38. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  39. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  40. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  41. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  42. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  43. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  44. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  45. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  46. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  47. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  48. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  49. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  50. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  51. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  52. package/dist/commands/__tests__/version.test.d.ts +0 -2
  53. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  54. package/dist/commands/__tests__/version.test.js +0 -238
  55. package/dist/commands/__tests__/version.test.js.map +0 -1
  56. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  57. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  58. package/dist/commands/runtime-uat.guard.test.js +0 -153
  59. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  60. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  61. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  62. package/dist/services/__tests__/cli-output.test.js +0 -103
  63. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  64. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  65. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  66. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  67. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  68. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  69. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  70. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  71. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  72. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  73. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  74. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  75. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  76. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  77. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  78. package/dist/utils/production-workspace-guard.test.js +0 -137
  79. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  80. package/scripts/llm-dogfood.ts +0 -456
  81. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  82. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  83. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  84. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  85. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  86. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  87. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  88. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  89. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  90. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  91. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  92. package/src/commands/__tests__/version.test.ts +0 -251
  93. package/src/commands/admission-gate.ts +0 -30
  94. package/src/commands/artifact.ts +0 -82
  95. package/src/commands/build-trajectory-evidence.ts +0 -298
  96. package/src/commands/candidate.ts +0 -1250
  97. package/src/commands/codex-ingest-catchup.ts +0 -114
  98. package/src/commands/codex-ingest-quarantine.ts +0 -127
  99. package/src/commands/codex-reconcile.ts +0 -84
  100. package/src/commands/codex-setup.ts +0 -476
  101. package/src/commands/codex-worker.ts +0 -185
  102. package/src/commands/command-helpers.ts +0 -24
  103. package/src/commands/config-doctor.ts +0 -193
  104. package/src/commands/console.ts +0 -797
  105. package/src/commands/context.ts +0 -72
  106. package/src/commands/demo-story-a.ts +0 -241
  107. package/src/commands/diagnose.ts +0 -756
  108. package/src/commands/errors-list.ts +0 -441
  109. package/src/commands/evolution-tasks-list.ts +0 -48
  110. package/src/commands/evolution-tasks-show.ts +0 -62
  111. package/src/commands/flow.ts +0 -60
  112. package/src/commands/health-codex.ts +0 -576
  113. package/src/commands/health.ts +0 -315
  114. package/src/commands/history.ts +0 -63
  115. package/src/commands/intent.ts +0 -457
  116. package/src/commands/legacy-cleanup.ts +0 -531
  117. package/src/commands/legacy-import.ts +0 -104
  118. package/src/commands/mvp-smoke.ts +0 -160
  119. package/src/commands/pain-evidence.ts +0 -226
  120. package/src/commands/pain-list.ts +0 -239
  121. package/src/commands/pain-record.ts +0 -612
  122. package/src/commands/pain-retry.ts +0 -916
  123. package/src/commands/principles-stats.ts +0 -700
  124. package/src/commands/proven-channel-baseline.ts +0 -115
  125. package/src/commands/quality-scorecard.ts +0 -272
  126. package/src/commands/remediation-output.ts +0 -66
  127. package/src/commands/rulecode.ts +0 -465
  128. package/src/commands/run.ts +0 -89
  129. package/src/commands/runtime-activation.ts +0 -1629
  130. package/src/commands/runtime-artifact-repair.ts +0 -524
  131. package/src/commands/runtime-canary.ts +0 -395
  132. package/src/commands/runtime-compatibility-scan.ts +0 -105
  133. package/src/commands/runtime-diagnostics-export.ts +0 -229
  134. package/src/commands/runtime-features.ts +0 -153
  135. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  136. package/src/commands/runtime-health-snapshot.ts +0 -108
  137. package/src/commands/runtime-init.ts +0 -429
  138. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  139. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  140. package/src/commands/runtime-internalization-integrity.ts +0 -107
  141. package/src/commands/runtime-internalization-queue.ts +0 -135
  142. package/src/commands/runtime-internalization-retry.ts +0 -191
  143. package/src/commands/runtime-internalization-run-once.ts +0 -791
  144. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  145. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  146. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  147. package/src/commands/runtime-pruning.ts +0 -438
  148. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  149. package/src/commands/runtime-recovery.ts +0 -109
  150. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  151. package/src/commands/runtime-uat.guard.test.ts +0 -175
  152. package/src/commands/runtime-uat.ts +0 -380
  153. package/src/commands/runtime.ts +0 -473
  154. package/src/commands/samples-list.ts +0 -39
  155. package/src/commands/samples-review.ts +0 -36
  156. package/src/commands/task.ts +0 -271
  157. package/src/commands/telemetry.ts +0 -349
  158. package/src/commands/trace.ts +0 -174
  159. package/src/commands/trajectory-db-unavailable.ts +0 -19
  160. package/src/commands/trajectory.ts +0 -64
  161. package/src/commands/version.ts +0 -49
  162. package/src/config-reader.ts +0 -122
  163. package/src/index.ts +0 -1276
  164. package/src/legacy/legacy-import.ts +0 -179
  165. package/src/legacy/session-history-import.ts +0 -203
  166. package/src/resolve-workspace.ts +0 -106
  167. package/src/services/__tests__/cli-output.test.ts +0 -130
  168. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  169. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  170. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  171. package/src/services/cli-output.ts +0 -95
  172. package/src/services/config-doctor.ts +0 -697
  173. package/src/services/console-launcher.ts +0 -537
  174. package/src/services/demo-rule-compiler.ts +0 -40
  175. package/src/services/demo-story-a-runner.ts +0 -471
  176. package/src/services/mainline-snapshot-assembler.ts +0 -579
  177. package/src/services/pain-flood-simulation-runner.ts +0 -462
  178. package/src/services/pd-config-loader.ts +0 -433
  179. package/src/services/proven-channel-baseline-runner.ts +0 -157
  180. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  181. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  182. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  183. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  184. package/src/services/rulehost-pipeline-runner.ts +0 -1214
  185. package/src/services/rulehost-readiness.ts +0 -326
  186. package/src/services/runtime-adapter-resolver.ts +0 -364
  187. package/src/services/synthetic-baseline-runner.ts +0 -400
  188. package/src/services/version-report.ts +0 -253
  189. package/src/services/workspace-tool-semantics.ts +0 -26
  190. package/src/utils/path-security.ts +0 -96
  191. package/src/utils/production-workspace-guard.test.ts +0 -157
  192. package/src/utils/production-workspace-guard.ts +0 -210
  193. package/tests/bdd/cli-contract.steps.ts +0 -346
  194. package/tests/bdd/principles-stats.steps.ts +0 -211
  195. package/tests/bdd/support/gherkin-loader.ts +0 -147
  196. package/tests/bdd/support/repo-root.ts +0 -62
  197. package/tests/bdd/support/vitest-bdd.ts +0 -179
  198. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  199. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  200. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  201. package/tests/commands/candidate-intake.test.ts +0 -732
  202. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  203. package/tests/commands/candidate-internalize-lineage.test.ts +0 -628
  204. package/tests/commands/candidate-internalize.test.ts +0 -299
  205. package/tests/commands/candidate-route.test.ts +0 -329
  206. package/tests/commands/candidate-show.test.ts +0 -95
  207. package/tests/commands/cli-command-tree.test.ts +0 -144
  208. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  209. package/tests/commands/cli-skill-contract.test.ts +0 -121
  210. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  211. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  212. package/tests/commands/codex-setup.test.ts +0 -297
  213. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  214. package/tests/commands/codex-worker-registration.test.ts +0 -207
  215. package/tests/commands/config-doctor.test.ts +0 -336
  216. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  217. package/tests/commands/console-open.test.ts +0 -1381
  218. package/tests/commands/context.test.ts +0 -114
  219. package/tests/commands/demo-story-a.test.ts +0 -318
  220. package/tests/commands/diagnose.test.ts +0 -1803
  221. package/tests/commands/errors-list.test.ts +0 -679
  222. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  223. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  224. package/tests/commands/health-codex.test.ts +0 -349
  225. package/tests/commands/health-host-wiring.test.ts +0 -76
  226. package/tests/commands/health-reliability.test.ts +0 -99
  227. package/tests/commands/health.test.ts +0 -413
  228. package/tests/commands/intent.test.ts +0 -321
  229. package/tests/commands/legacy-cleanup.test.ts +0 -148
  230. package/tests/commands/pain-evidence.test.ts +0 -518
  231. package/tests/commands/pain-list.test.ts +0 -219
  232. package/tests/commands/pain-record-async.test.ts +0 -335
  233. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  234. package/tests/commands/pain-record.test.ts +0 -851
  235. package/tests/commands/pain-retry.test.ts +0 -1121
  236. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  237. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  238. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  239. package/tests/commands/principles-stats.test.ts +0 -274
  240. package/tests/commands/product-path-regression.test.ts +0 -86
  241. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  242. package/tests/commands/rulecode.test.ts +0 -177
  243. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  244. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  245. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  246. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  247. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  248. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  249. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  250. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  251. package/tests/commands/runtime-activation.test.ts +0 -2052
  252. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  253. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  254. package/tests/commands/runtime-canary.test.ts +0 -430
  255. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  256. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  257. package/tests/commands/runtime-features.test.ts +0 -249
  258. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  259. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  260. package/tests/commands/runtime-init.test.ts +0 -420
  261. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  262. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  263. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  264. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  265. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  266. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  267. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  268. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  269. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  270. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  271. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  272. package/tests/commands/runtime-internalization.test.ts +0 -53
  273. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  274. package/tests/commands/runtime-pruning.test.ts +0 -694
  275. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  276. package/tests/commands/runtime-recovery.test.ts +0 -120
  277. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  278. package/tests/commands/runtime-uat.test.ts +0 -397
  279. package/tests/commands/runtime.test.ts +0 -392
  280. package/tests/commands/samples-list.test.ts +0 -43
  281. package/tests/commands/samples-review.test.ts +0 -41
  282. package/tests/commands/task.test.ts +0 -153
  283. package/tests/commands/telemetry.test.ts +0 -190
  284. package/tests/commands/trace.test.ts +0 -316
  285. package/tests/config-reader.test.ts +0 -143
  286. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  287. package/tests/e2e/cli-full-flow.test.ts +0 -233
  288. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  289. package/tests/helpers/pd-cli-path.ts +0 -5
  290. package/tests/pd-cli-smoke.test.ts +0 -13
  291. package/tests/resolve-workspace.test.ts +0 -196
  292. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  293. package/tests/services/console-launcher.test.ts +0 -114
  294. package/tests/services/demo-rule-compiler.test.ts +0 -242
  295. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  296. package/tests/services/pd-config-loader.test.ts +0 -505
  297. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  298. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  299. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  300. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  301. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1242
  302. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  303. package/tests/utils/path-security.test.ts +0 -180
  304. package/tsconfig.json +0 -26
  305. package/vitest.config.ts +0 -10
@@ -1,782 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { Command } from 'commander';
3
-
4
- const mockListTasks = vi.hoisted(() => vi.fn());
5
- const mockGetTask = vi.hoisted(() => vi.fn());
6
- const mockCommitNextTaskProposal = vi.hoisted(() => vi.fn());
7
- const mockProposeNextTask = vi.hoisted(() => vi.fn());
8
- const mockClose = vi.hoisted(() => vi.fn().mockResolvedValue(undefined));
9
- const mockInitialize = vi.hoisted(() => vi.fn().mockResolvedValue(undefined));
10
- const mockRuntimeStateManagerOpts = vi.hoisted(() => vi.fn());
11
-
12
- vi.mock('../../src/resolve-workspace.js', () => ({
13
- resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
14
- }));
15
-
16
- // PRI-612: spread the real barrel exports so pure constants consumed by the
17
- // command (PD_TASK_STATUSES) stay authentic; only the stateful classes are
18
- // mocked. Previously a bare factory mock left new barrel exports undefined
19
- // at runtime (ERR-083 vi.mock variant — 19 tests failed on CI).
20
- vi.mock('@principles/core/runtime-v2', async (importOriginal) => ({
21
- ...(await importOriginal<typeof import('@principles/core/runtime-v2')>()),
22
- RuntimeStateManager: vi.fn().mockImplementation(function (opts: Record<string, unknown>) {
23
- mockRuntimeStateManagerOpts(opts);
24
- return {
25
- initialize: mockInitialize,
26
- close: mockClose,
27
- listTasks: mockListTasks,
28
- getTask: mockGetTask,
29
- };
30
- }),
31
- InternalizationOrchestrator: vi.fn().mockImplementation(function () {
32
- return {
33
- commitNextTaskProposal: mockCommitNextTaskProposal,
34
- proposeNextTask: mockProposeNextTask,
35
- };
36
- }),
37
- isPeerRunnerKind: vi.fn().mockImplementation((k: string) =>
38
- ['dreamer', 'philosopher', 'scribe', 'artificer', 'evaluator', 'rollout_reviewer'].includes(k),
39
- ),
40
- hydratePITaskRecord: vi.fn().mockImplementation((task: Record<string, unknown>) => {
41
- if (typeof task.diagnosticJson !== 'string' || task.diagnosticJson.length === 0) return null;
42
- try {
43
- const meta = JSON.parse(task.diagnosticJson);
44
- if (typeof meta !== 'object' || meta === null || Array.isArray(meta)) return null;
45
- return {
46
- taskId: task.taskId,
47
- taskKind: task.taskKind,
48
- status: task.status,
49
- attemptCount: task.attemptCount ?? 0,
50
- dependencyTaskIds: meta.dependencyTaskIds ?? [],
51
- channel: meta.channel ?? 'prompt',
52
- timeoutMs: meta.timeoutMs ?? 300_000,
53
- inputArtifactRefs: meta.inputArtifactRefs ?? [],
54
- outputArtifactRefs: meta.outputArtifactRefs ?? [],
55
- parentTaskId: meta.parentTaskId ?? null,
56
- correlationId: meta.correlationId ?? null,
57
- };
58
- } catch {
59
- return null;
60
- }
61
- }),
62
- resolveOutputLanguage: vi.fn().mockReturnValue({ outputLanguage: 'zh-CN' }),
63
- }));
64
-
65
- import { handleRuntimeInternalizationEnqueueSuccessors } from '../../src/commands/runtime-internalization-enqueue-successors.js';
66
-
67
- const WS = '/fake/workspace';
68
-
69
- function mockDryRunListTasks(succeededTasks: ReturnType<typeof makeSucceededTask>[], successorTasks: ReturnType<typeof makeSucceededTask>[] = []) {
70
- mockListTasks
71
- .mockResolvedValueOnce(succeededTasks)
72
- .mockResolvedValueOnce(successorTasks)
73
- .mockResolvedValueOnce([])
74
- .mockResolvedValueOnce([])
75
- .mockResolvedValueOnce([])
76
- .mockResolvedValueOnce([])
77
- .mockResolvedValueOnce([]);
78
- }
79
-
80
- function makePIMetadata(overrides: Record<string, unknown> = {}): string {
81
- return JSON.stringify({
82
- dependencyTaskIds: [],
83
- channel: 'prompt',
84
- timeoutMs: 300_000,
85
- inputArtifactRefs: [],
86
- outputArtifactRefs: [],
87
- parentTaskId: null,
88
- correlationId: null,
89
- ...overrides,
90
- });
91
- }
92
-
93
- function makeSucceededTask(taskId: string, taskKind: string, metaOverrides: Record<string, unknown> = {}) {
94
- return {
95
- taskId,
96
- taskKind,
97
- status: 'succeeded',
98
- attemptCount: 1,
99
- maxAttempts: 3,
100
- inputRef: undefined,
101
- resultRef: `ref-${taskId}`,
102
- lastError: undefined,
103
- leaseOwner: undefined,
104
- leaseExpiresAt: undefined,
105
- diagnosticJson: makePIMetadata(metaOverrides),
106
- };
107
- }
108
-
109
- function makeMalformedTask(taskId: string, taskKind: string) {
110
- return {
111
- taskId,
112
- taskKind,
113
- status: 'succeeded',
114
- attemptCount: 1,
115
- maxAttempts: 3,
116
- inputRef: undefined,
117
- resultRef: `ref-${taskId}`,
118
- lastError: undefined,
119
- leaseOwner: undefined,
120
- leaseExpiresAt: undefined,
121
- diagnosticJson: 'not-valid-json{{{',
122
- };
123
- }
124
-
125
- function createTestProgram(): Command {
126
- const program = new Command();
127
- program.exitOverride();
128
-
129
- const internalizationCmd = program.command('internalization');
130
-
131
- internalizationCmd
132
- .command('enqueue-successors')
133
- .description('Enqueue successor tasks for succeeded internalization tasks missing successors')
134
- .option('-w, --workspace <path>', 'Workspace directory')
135
- .option('--dry-run', 'Report only, no modifications (default)')
136
- .option('--confirm', 'Actually create successor tasks')
137
- .option('--json', 'Output raw JSON')
138
- .action(async (opts) => {
139
- await handleRuntimeInternalizationEnqueueSuccessors({
140
- workspace: opts.workspace,
141
- dryRun: opts.dryRun,
142
- confirm: opts.confirm,
143
- json: opts.json,
144
- });
145
- });
146
-
147
- return program;
148
- }
149
-
150
- describe('handleRuntimeInternalizationEnqueueSuccessors', () => {
151
- let consoleLogSpy: ReturnType<typeof vi.spyOn>;
152
- let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
153
-
154
- beforeEach(() => {
155
- vi.clearAllMocks();
156
- process.exitCode = 0;
157
- consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
158
- consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
159
- mockInitialize.mockResolvedValue(undefined);
160
- mockClose.mockResolvedValue(undefined);
161
- });
162
-
163
- afterEach(() => {
164
- process.exitCode = 0;
165
- consoleLogSpy.mockRestore();
166
- consoleErrorSpy.mockRestore();
167
- });
168
-
169
- it('succeeded dreamer with artifact and no philosopher successor: dry-run reports would_create_successor', async () => {
170
- const dreamerTask = makeSucceededTask('dreamer-001', 'dreamer');
171
- mockDryRunListTasks([dreamerTask]);
172
- mockProposeNextTask.mockResolvedValue({
173
- decision: 'proposal_created',
174
- taskId: 'dreamer-001',
175
- taskKind: 'dreamer',
176
- proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-001'], inputArtifactRefs: [], parentTaskId: 'dreamer-001', correlationId: 'corr-001' },
177
- });
178
-
179
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, confirm: false, json: true });
180
-
181
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
182
- expect(output.status).toBe('dry_run');
183
- expect(output.dryRun).toBe(true);
184
- expect(output.scannedCount).toBe(1);
185
- expect(output.actions).toHaveLength(1);
186
- expect(output.actions[0].taskId).toBe('dreamer-001');
187
- expect(output.actions[0].taskKind).toBe('dreamer');
188
- expect(output.actions[0].decision).toBe('would_create_successor');
189
- expect(output.actions[0].successorKind).toBe('philosopher');
190
- });
191
-
192
- it('confirm creates exactly one philosopher successor', async () => {
193
- const dreamerTask = makeSucceededTask('dreamer-002', 'dreamer');
194
- mockListTasks.mockResolvedValue([dreamerTask]);
195
- mockCommitNextTaskProposal.mockResolvedValue({
196
- decision: 'successor_created',
197
- sourceTaskId: 'dreamer-002',
198
- successorTaskId: 'philosopher-dreamer-002-prompt',
199
- successorKind: 'philosopher',
200
- });
201
-
202
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
203
-
204
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
205
- expect(output.status).toBe('confirmed');
206
- expect(output.dryRun).toBe(false);
207
- expect(output.createdCount).toBe(1);
208
- expect(output.actions[0].decision).toBe('successor_created');
209
- expect(output.actions[0].successorTaskId).toBe('philosopher-dreamer-002-prompt');
210
- expect(output.actions[0].successorKind).toBe('philosopher');
211
- expect(mockCommitNextTaskProposal).toHaveBeenCalledWith('dreamer-002');
212
- });
213
-
214
- it('repeated confirm returns successor_exists, no duplicate task', async () => {
215
- const dreamerTask = makeSucceededTask('dreamer-003', 'dreamer');
216
- mockListTasks.mockResolvedValue([dreamerTask]);
217
- mockCommitNextTaskProposal.mockResolvedValue({
218
- decision: 'successor_exists',
219
- sourceTaskId: 'dreamer-003',
220
- successorTaskId: 'philosopher-dreamer-003-prompt',
221
- successorKind: 'philosopher',
222
- });
223
-
224
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
225
-
226
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
227
- expect(output.existingCount).toBe(1);
228
- expect(output.createdCount).toBe(0);
229
- expect(output.actions[0].decision).toBe('successor_exists');
230
- expect(output.actions[0].successorTaskId).toBe('philosopher-dreamer-003-prompt');
231
- });
232
-
233
-
234
- it('succeeded task with malformed metadata is skipped with reason; no successor created', async () => {
235
- const malformedTask = makeMalformedTask('malformed-001', 'dreamer');
236
- mockListTasks.mockResolvedValue([malformedTask]);
237
-
238
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
239
-
240
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
241
- expect(output.skippedCount).toBe(1);
242
- expect(output.actions[0].decision).toBe('skipped');
243
- expect(output.actions[0].taskId).toBe('malformed-001');
244
- expect(output.actions[0].reason).toBeDefined();
245
- expect(output.actions[0].nextAction).toBeDefined();
246
- expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
247
- });
248
-
249
- it('failed/retry_wait/leased tasks are not processed — only succeeded returned by listTasks', async () => {
250
- const succeededTask = makeSucceededTask('dreamer-ok', 'dreamer');
251
- mockListTasks.mockResolvedValue([succeededTask]);
252
- mockCommitNextTaskProposal.mockResolvedValue({
253
- decision: 'successor_created',
254
- sourceTaskId: 'dreamer-ok',
255
- successorTaskId: 'philosopher-dreamer-ok-prompt',
256
- successorKind: 'philosopher',
257
- });
258
-
259
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
260
-
261
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
262
- expect(output.scannedCount).toBe(1);
263
- expect(output.actions).toHaveLength(1);
264
- expect(output.actions[0].taskId).toBe('dreamer-ok');
265
- expect(mockCommitNextTaskProposal).toHaveBeenCalledTimes(1);
266
- expect(mockCommitNextTaskProposal).toHaveBeenCalledWith('dreamer-ok');
267
- });
268
-
269
- it('DB/storage unavailable fails closed', async () => {
270
- mockInitialize.mockRejectedValue(new Error('Cannot open database'));
271
-
272
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
273
-
274
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
275
- expect(output.status).toBe('failed');
276
- expect(output.scannedCount).toBe(0);
277
- expect(output.actions).toHaveLength(0);
278
- expect(process.exitCode).toBe(1);
279
- });
280
-
281
- it('listTasks throws: fails closed with structured error', async () => {
282
- mockListTasks.mockRejectedValue(new Error('Database locked'));
283
-
284
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
285
-
286
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
287
- expect(output.status).toBe('failed');
288
- expect(process.exitCode).toBe(1);
289
- });
290
-
291
- it('default mode is dry-run', async () => {
292
- const dreamerTask = makeSucceededTask('dreamer-default', 'dreamer');
293
- mockDryRunListTasks([dreamerTask]);
294
- mockProposeNextTask.mockResolvedValue({
295
- decision: 'proposal_created',
296
- taskId: 'dreamer-default',
297
- taskKind: 'dreamer',
298
- proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-default'], inputArtifactRefs: [], parentTaskId: 'dreamer-default', correlationId: 'corr-default' },
299
- });
300
-
301
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, json: true });
302
-
303
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
304
- expect(output.status).toBe('dry_run');
305
- expect(output.dryRun).toBe(true);
306
- expect(output.actions[0].decision).toBe('would_create_successor');
307
- });
308
-
309
- it('--confirm performs writes', async () => {
310
- const dreamerTask = makeSucceededTask('dreamer-confirm', 'dreamer');
311
- mockListTasks.mockResolvedValue([dreamerTask]);
312
- mockCommitNextTaskProposal.mockResolvedValue({
313
- decision: 'successor_created',
314
- sourceTaskId: 'dreamer-confirm',
315
- successorTaskId: 'philosopher-dreamer-confirm-prompt',
316
- successorKind: 'philosopher',
317
- });
318
-
319
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
320
-
321
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
322
- expect(output.status).toBe('confirmed');
323
- expect(output.dryRun).toBe(false);
324
- expect(output.actions[0].decision).toBe('successor_created');
325
- });
326
-
327
- it('--dry-run --confirm is rejected with exitCode 1 and no writes, JSON mode emits structured error with reason/nextAction', async () => {
328
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, confirm: true, json: true });
329
-
330
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
331
- expect(output.status).toBe('refused');
332
- expect(output.error).toContain('mutually exclusive');
333
- expect(output.reason).toContain('flag_conflict');
334
- expect(output.nextAction).toBeDefined();
335
- expect(process.exitCode).toBe(1);
336
-
337
- expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
338
- });
339
-
340
- it('--json emits parseable JSON only', async () => {
341
- const dreamerTask = makeSucceededTask('dreamer-json', 'dreamer');
342
- mockListTasks.mockResolvedValue([dreamerTask]);
343
- mockCommitNextTaskProposal.mockResolvedValue({
344
- decision: 'successor_created',
345
- sourceTaskId: 'dreamer-json',
346
- successorTaskId: 'philosopher-dreamer-json-prompt',
347
- successorKind: 'philosopher',
348
- });
349
-
350
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
351
-
352
- const rawOutput = consoleLogSpy.mock.calls[0][0];
353
- const parsed = JSON.parse(rawOutput);
354
- expect(parsed).toBeDefined();
355
- expect(parsed.status).toBe('confirmed');
356
- });
357
-
358
- it('text output is human-readable and includes counts', async () => {
359
- const dreamerTask = makeSucceededTask('dreamer-text', 'dreamer');
360
- mockListTasks.mockResolvedValue([dreamerTask]);
361
- mockCommitNextTaskProposal.mockResolvedValue({
362
- decision: 'successor_created',
363
- sourceTaskId: 'dreamer-text',
364
- successorTaskId: 'philosopher-dreamer-text-prompt',
365
- successorKind: 'philosopher',
366
- });
367
-
368
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: false });
369
-
370
- const text = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
371
- expect(text).toContain('Enqueue Successors');
372
- expect(text).toContain('scanned');
373
- expect(text).toContain('created');
374
- });
375
-
376
- it('commitNextTaskProposal returns source_not_succeeded: skipped with reason', async () => {
377
- const dreamerTask = makeSucceededTask('dreamer-not-succ', 'dreamer');
378
- mockListTasks.mockResolvedValue([dreamerTask]);
379
- mockCommitNextTaskProposal.mockResolvedValue({
380
- decision: 'source_not_succeeded',
381
- taskId: 'dreamer-not-succ',
382
- status: 'failed',
383
- });
384
-
385
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
386
-
387
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
388
- expect(output.actions[0].decision).toBe('skipped');
389
- expect(output.actions[0].reason).toContain('source_not_succeeded');
390
- });
391
-
392
- it('commitNextTaskProposal returns task_not_found: skipped with reason', async () => {
393
- const dreamerTask = makeSucceededTask('dreamer-not-found', 'dreamer');
394
- mockListTasks.mockResolvedValue([dreamerTask]);
395
- mockCommitNextTaskProposal.mockResolvedValue({
396
- decision: 'task_not_found',
397
- taskId: 'dreamer-not-found',
398
- });
399
-
400
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
401
-
402
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
403
- expect(output.actions[0].decision).toBe('skipped');
404
- expect(output.actions[0].reason).toContain('task_not_found');
405
- });
406
-
407
- it('commitNextTaskProposal returns invalid_task_metadata: skipped with reason', async () => {
408
- const dreamerTask = makeSucceededTask('dreamer-invalid-meta', 'dreamer');
409
- mockListTasks.mockResolvedValue([dreamerTask]);
410
- mockCommitNextTaskProposal.mockResolvedValue({
411
- decision: 'invalid_task_metadata',
412
- taskId: 'dreamer-invalid-meta',
413
- reason: 'Failed to hydrate PITaskRecord from diagnosticJson',
414
- });
415
-
416
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
417
-
418
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
419
- expect(output.actions[0].decision).toBe('skipped');
420
- expect(output.actions[0].reason).toContain('invalid_task_metadata');
421
- });
422
-
423
- it('multiple succeeded tasks: processes each independently', async () => {
424
- const dreamer1 = makeSucceededTask('dreamer-multi-1', 'dreamer');
425
- const dreamer2 = makeSucceededTask('dreamer-multi-2', 'dreamer');
426
- const philosopher1 = makeSucceededTask('philosopher-multi-1', 'philosopher');
427
- mockListTasks.mockResolvedValue([dreamer1, dreamer2, philosopher1]);
428
-
429
- mockCommitNextTaskProposal
430
- .mockResolvedValueOnce({
431
- decision: 'successor_created',
432
- sourceTaskId: 'dreamer-multi-1',
433
- successorTaskId: 'philosopher-dreamer-multi-1-prompt',
434
- successorKind: 'philosopher',
435
- })
436
- .mockResolvedValueOnce({
437
- decision: 'successor_exists',
438
- sourceTaskId: 'dreamer-multi-2',
439
- successorTaskId: 'philosopher-dreamer-multi-2-prompt',
440
- successorKind: 'philosopher',
441
- })
442
- .mockResolvedValueOnce({
443
- decision: 'successor_created',
444
- sourceTaskId: 'philosopher-multi-1',
445
- successorTaskId: 'scribe-philosopher-multi-1-prompt',
446
- successorKind: 'scribe',
447
- });
448
-
449
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
450
-
451
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
452
- expect(output.scannedCount).toBe(3);
453
- expect(output.createdCount).toBe(2);
454
- expect(output.existingCount).toBe(1);
455
- expect(output.actions).toHaveLength(3);
456
- expect(mockCommitNextTaskProposal).toHaveBeenCalledTimes(3);
457
- });
458
-
459
- it('non-PI task kinds (diagnostician) are not processed', async () => {
460
- const diagTask = {
461
- taskId: 'diag-001',
462
- taskKind: 'diagnostician',
463
- status: 'succeeded',
464
- attemptCount: 1,
465
- maxAttempts: 3,
466
- diagnosticJson: '{}',
467
- };
468
- mockListTasks.mockResolvedValue([diagTask]);
469
-
470
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
471
-
472
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
473
- expect(output.scannedCount).toBe(0);
474
- expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
475
- });
476
-
477
- it('dry-run does not call commitNextTaskProposal', async () => {
478
- const dreamerTask = makeSucceededTask('dreamer-dry', 'dreamer');
479
- mockDryRunListTasks([dreamerTask]);
480
- mockProposeNextTask.mockResolvedValue({
481
- decision: 'proposal_created',
482
- taskId: 'dreamer-dry',
483
- taskKind: 'dreamer',
484
- proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-dry'], inputArtifactRefs: [], parentTaskId: 'dreamer-dry', correlationId: 'corr-dry' },
485
- });
486
-
487
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
488
-
489
- expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
490
- });
491
-
492
- it('workspace does not exist: fails closed', async () => {
493
- mockInitialize.mockRejectedValue(new Error('ENOENT: no such file or directory'));
494
-
495
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: '/nonexistent/path', confirm: true, json: true });
496
-
497
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
498
- expect(output.status).toBe('failed');
499
- expect(process.exitCode).toBe(1);
500
- });
501
-
502
- it('confirm path commitNextTaskProposal throws: skipped with reason', async () => {
503
- const dreamerTask = makeSucceededTask('dreamer-commit-err', 'dreamer');
504
- mockListTasks.mockResolvedValue([dreamerTask]);
505
- mockCommitNextTaskProposal.mockRejectedValue(new Error('Database locked during commit'));
506
-
507
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
508
-
509
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
510
- expect(output.actions[0].decision).toBe('skipped');
511
- expect(output.actions[0].reason).toContain('commit_failed');
512
- expect(output.actions[0].nextAction).toBeDefined();
513
- expect(output.skippedCount).toBe(1);
514
- });
515
-
516
-
517
- it('successor index build failure: fails closed with structured error', async () => {
518
- const dreamerTask = makeSucceededTask('dreamer-index-err', 'dreamer');
519
- mockListTasks
520
- .mockResolvedValueOnce([dreamerTask])
521
- .mockRejectedValueOnce(new Error('Database locked during index build'));
522
-
523
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
524
-
525
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
526
- expect(output.status).toBe('failed');
527
- expect(output.reason).toContain('successor_index_failed');
528
- expect(output.nextAction).toBeDefined();
529
- expect(process.exitCode).toBe(1);
530
- });
531
-
532
- it('dry-run with existing successor: reports successor_exists', async () => {
533
- const dreamerTask = makeSucceededTask('dreamer-existing-succ', 'dreamer');
534
- const philosopherPending = makeSucceededTask('philosopher-dreamer-existing-succ-prompt', 'philosopher', { parentTaskId: 'dreamer-existing-succ', channel: 'prompt' });
535
- philosopherPending.status = 'pending';
536
- mockDryRunListTasks([dreamerTask], [philosopherPending]);
537
- mockProposeNextTask.mockResolvedValue({
538
- decision: 'proposal_created',
539
- taskId: 'dreamer-existing-succ',
540
- taskKind: 'dreamer',
541
- proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-existing-succ'], inputArtifactRefs: [], parentTaskId: 'dreamer-existing-succ', correlationId: 'corr-existing' },
542
- });
543
-
544
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
545
-
546
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
547
- expect(output.actions[0].decision).toBe('successor_exists');
548
- expect(output.actions[0].successorTaskId).toBe('philosopher-dreamer-existing-succ-prompt');
549
- expect(output.existingCount).toBe(1);
550
- expect(output.createdCount).toBe(0);
551
- });
552
-
553
- it('dry-run proposeNextTask throws: skipped with reason', async () => {
554
- const dreamerTask = makeSucceededTask('dreamer-propose-err', 'dreamer');
555
- mockListTasks.mockResolvedValueOnce([dreamerTask]);
556
- mockProposeNextTask.mockRejectedValue(new Error('Orchestrator internal error'));
557
-
558
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
559
-
560
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
561
- expect(output.actions[0].decision).toBe('skipped');
562
- expect(output.actions[0].reason).toContain('propose_failed');
563
- expect(output.actions[0].nextAction).toBeDefined();
564
- expect(output.skippedCount).toBe(1);
565
- });
566
-
567
- it('failed JSON output includes reason and nextAction', async () => {
568
- mockInitialize.mockRejectedValue(new Error('Cannot open database'));
569
-
570
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
571
-
572
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
573
- expect(output.status).toBe('failed');
574
- expect(output.reason).toContain('storage_init_failed');
575
- expect(output.nextAction).toBeDefined();
576
- expect(process.exitCode).toBe(1);
577
- });
578
-
579
- it('--confirm workspace resolve failure reports dryRun=false', async () => {
580
- const { resolveWorkspaceDir } = await import('../../src/resolve-workspace.js');
581
- vi.mocked(resolveWorkspaceDir).mockImplementationOnce(() => { throw new Error('No workspace found'); });
582
-
583
- await handleRuntimeInternalizationEnqueueSuccessors({ confirm: true, json: true });
584
-
585
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
586
- expect(output.status).toBe('failed');
587
- expect(output.dryRun).toBe(false);
588
- expect(output.reason).toContain('workspace_resolve_failed');
589
- expect(output.nextAction).toBeDefined();
590
- expect(process.exitCode).toBe(1);
591
- });
592
-
593
- it('dry-run existing successor with malformed metadata: skipped, not would_create_successor', async () => {
594
- const dreamerTask = makeSucceededTask('dreamer-malformed-succ', 'dreamer');
595
- const malformedSuccessor = {
596
- taskId: 'philosopher-dreamer-malformed-succ-prompt',
597
- taskKind: 'philosopher',
598
- status: 'pending' as const,
599
- attemptCount: 0,
600
- maxAttempts: 3,
601
- inputRef: undefined,
602
- resultRef: undefined,
603
- lastError: undefined,
604
- leaseOwner: undefined,
605
- leaseExpiresAt: undefined,
606
- diagnosticJson: 'not-valid-json{{{',
607
- };
608
- mockDryRunListTasks([dreamerTask], [malformedSuccessor]);
609
- mockProposeNextTask.mockResolvedValue({
610
- decision: 'proposal_created',
611
- taskId: 'dreamer-malformed-succ',
612
- taskKind: 'dreamer',
613
- proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-malformed-succ'], inputArtifactRefs: [], parentTaskId: 'dreamer-malformed-succ', correlationId: 'corr-malformed' },
614
- });
615
-
616
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
617
-
618
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
619
- expect(output.actions[0].decision).toBe('skipped');
620
- expect(output.actions[0].reason).toContain('successor_exists_with_malformed_metadata');
621
- expect(output.actions[0].nextAction).toContain('integrity-repair');
622
- expect(output.skippedCount).toBe(1);
623
- expect(output.createdCount).toBe(0);
624
- });
625
-
626
- it('dedupe scan is not N×full-table per source task (buildSuccessorIndex called once)', async () => {
627
- const dreamer1 = makeSucceededTask('dreamer-dedup-1', 'dreamer');
628
- const dreamer2 = makeSucceededTask('dreamer-dedup-2', 'dreamer');
629
- mockDryRunListTasks([dreamer1, dreamer2]);
630
- mockProposeNextTask
631
- .mockResolvedValueOnce({
632
- decision: 'proposal_created',
633
- taskId: 'dreamer-dedup-1',
634
- taskKind: 'dreamer',
635
- proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-dedup-1'], inputArtifactRefs: [], parentTaskId: 'dreamer-dedup-1', correlationId: 'corr-1' },
636
- })
637
- .mockResolvedValueOnce({
638
- decision: 'proposal_created',
639
- taskId: 'dreamer-dedup-2',
640
- taskKind: 'dreamer',
641
- proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-dedup-2'], inputArtifactRefs: [], parentTaskId: 'dreamer-dedup-2', correlationId: 'corr-2' },
642
- });
643
-
644
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
645
-
646
- expect(mockListTasks.mock.calls.length).toBe(7);
647
- const allCalls = mockListTasks.mock.calls.map(c => c[0]?.status);
648
- const succeededCalls = allCalls.filter(s => s === 'succeeded').length;
649
- expect(succeededCalls).toBe(2);
650
- });
651
-
652
- it('diagnosticJson non-string returns null, no throw', async () => {
653
- const taskWithNonStringDiag = {
654
- taskId: 'task-nonstring-diag',
655
- taskKind: 'dreamer',
656
- status: 'succeeded',
657
- attemptCount: 1,
658
- maxAttempts: 3,
659
- inputRef: undefined,
660
- resultRef: 'ref-nonstring',
661
- lastError: undefined,
662
- leaseOwner: undefined,
663
- leaseExpiresAt: undefined,
664
- diagnosticJson: 42,
665
- };
666
- mockListTasks.mockResolvedValue([taskWithNonStringDiag]);
667
-
668
- await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
669
-
670
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
671
- expect(output.scannedCount).toBe(1);
672
- expect(output.skippedCount).toBe(1);
673
- expect(output.actions[0].decision).toBe('skipped');
674
- expect(output.actions[0].reason).toContain('Failed to hydrate');
675
- expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
676
- });
677
-
678
- it('resolveWorkspaceDir throws: fails closed with structured error', async () => {
679
- const { resolveWorkspaceDir } = await import('../../src/resolve-workspace.js');
680
- vi.mocked(resolveWorkspaceDir).mockImplementationOnce(() => { throw new Error('No workspace found'); });
681
-
682
- await handleRuntimeInternalizationEnqueueSuccessors({ json: true });
683
-
684
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
685
- expect(output.status).toBe('failed');
686
- expect(output.error).toContain('Failed to resolve workspace');
687
- expect(process.exitCode).toBe(1);
688
- });
689
- });
690
-
691
- describe('Commander wiring for enqueue-successors', () => {
692
- let consoleLogSpy: ReturnType<typeof vi.spyOn>;
693
- let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
694
-
695
- beforeEach(() => {
696
- vi.clearAllMocks();
697
- process.exitCode = 0;
698
- consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
699
- consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
700
- mockInitialize.mockResolvedValue(undefined);
701
- mockClose.mockResolvedValue(undefined);
702
- mockListTasks.mockResolvedValue([]);
703
- });
704
-
705
- afterEach(() => {
706
- process.exitCode = 0;
707
- consoleLogSpy.mockRestore();
708
- consoleErrorSpy.mockRestore();
709
- });
710
-
711
- it('no flags → dry-run mode (confirm=undefined, dryRun=undefined)', async () => {
712
- const program = createTestProgram();
713
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--json']);
714
-
715
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
716
- expect(output.dryRun).toBe(true);
717
- expect(output.status).toBe('dry_run');
718
- });
719
-
720
- it('--confirm alone → confirm mode', async () => {
721
- const program = createTestProgram();
722
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--confirm', '--json']);
723
-
724
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
725
- expect(output.dryRun).toBe(false);
726
- expect(output.status).toBe('confirmed');
727
- });
728
-
729
- it('--dry-run alone → dry-run mode', async () => {
730
- const program = createTestProgram();
731
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--dry-run', '--json']);
732
-
733
- const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
734
- expect(output.dryRun).toBe(true);
735
- expect(output.status).toBe('dry_run');
736
- });
737
-
738
- it('--dry-run --confirm together → rejected with exitCode 1', async () => {
739
- const program = createTestProgram();
740
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--dry-run', '--confirm', '--json']);
741
-
742
- expect(process.exitCode).toBe(1);
743
- expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
744
- });
745
-
746
- it('--json flag produces parseable output', async () => {
747
- const program = createTestProgram();
748
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--json']);
749
-
750
- const rawOutput = consoleLogSpy.mock.calls[0][0];
751
- const parsed = JSON.parse(rawOutput);
752
- expect(parsed).toBeDefined();
753
- });
754
-
755
- it('no flags -> RuntimeStateManager readonly=true (dry-run default)', async () => {
756
- const program = createTestProgram();
757
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--json']);
758
-
759
- expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
760
- expect.objectContaining({ readonly: true }),
761
- );
762
- });
763
-
764
- it('--dry-run -> RuntimeStateManager readonly=true', async () => {
765
- const program = createTestProgram();
766
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--dry-run', '--json']);
767
-
768
- expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
769
- expect.objectContaining({ readonly: true }),
770
- );
771
- });
772
-
773
- it('--confirm -> RuntimeStateManager readonly=false', async () => {
774
- mockListTasks.mockResolvedValue([]);
775
- const program = createTestProgram();
776
- await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--confirm', '--json']);
777
-
778
- expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
779
- expect.objectContaining({ readonly: false }),
780
- );
781
- });
782
- });