@principles/pd-cli 1.152.11 → 1.152.13

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 (303) hide show
  1. package/dist/commands/candidate.d.ts +3 -3
  2. package/dist/commands/candidate.d.ts.map +1 -1
  3. package/dist/commands/candidate.js +9 -21
  4. package/dist/commands/candidate.js.map +1 -1
  5. package/dist/index.js +0 -0
  6. package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  7. package/dist/services/rulehost-pipeline-runner.js +4 -17
  8. package/dist/services/rulehost-pipeline-runner.js.map +1 -1
  9. package/package.json +13 -7
  10. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  11. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  12. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  13. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  14. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  15. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  16. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  17. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  18. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  19. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  20. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  21. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  22. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  23. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  24. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  25. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  26. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  27. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  28. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  29. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  30. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  31. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  32. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  33. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  34. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  35. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  36. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  37. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  38. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  39. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  40. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  41. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  42. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  43. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  44. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  45. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  46. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  47. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  48. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  49. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  50. package/dist/commands/__tests__/version.test.d.ts +0 -2
  51. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  52. package/dist/commands/__tests__/version.test.js +0 -238
  53. package/dist/commands/__tests__/version.test.js.map +0 -1
  54. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  55. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  56. package/dist/commands/runtime-uat.guard.test.js +0 -153
  57. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  58. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  59. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  60. package/dist/services/__tests__/cli-output.test.js +0 -103
  61. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  62. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  63. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  64. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  65. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  66. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  67. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  68. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  69. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  70. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  71. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  72. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  73. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  74. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  75. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  76. package/dist/utils/production-workspace-guard.test.js +0 -137
  77. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  78. package/scripts/llm-dogfood.ts +0 -456
  79. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  80. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  81. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  82. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  83. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  84. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  85. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  86. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  87. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  88. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  89. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  90. package/src/commands/__tests__/version.test.ts +0 -251
  91. package/src/commands/admission-gate.ts +0 -30
  92. package/src/commands/artifact.ts +0 -82
  93. package/src/commands/build-trajectory-evidence.ts +0 -298
  94. package/src/commands/candidate.ts +0 -1260
  95. package/src/commands/codex-ingest-catchup.ts +0 -114
  96. package/src/commands/codex-ingest-quarantine.ts +0 -127
  97. package/src/commands/codex-reconcile.ts +0 -84
  98. package/src/commands/codex-setup.ts +0 -476
  99. package/src/commands/codex-worker.ts +0 -185
  100. package/src/commands/command-helpers.ts +0 -24
  101. package/src/commands/config-doctor.ts +0 -193
  102. package/src/commands/console.ts +0 -797
  103. package/src/commands/context.ts +0 -72
  104. package/src/commands/demo-story-a.ts +0 -241
  105. package/src/commands/diagnose.ts +0 -756
  106. package/src/commands/errors-list.ts +0 -441
  107. package/src/commands/evolution-tasks-list.ts +0 -48
  108. package/src/commands/evolution-tasks-show.ts +0 -62
  109. package/src/commands/flow.ts +0 -60
  110. package/src/commands/health-codex.ts +0 -576
  111. package/src/commands/health.ts +0 -315
  112. package/src/commands/history.ts +0 -63
  113. package/src/commands/intent.ts +0 -457
  114. package/src/commands/legacy-cleanup.ts +0 -531
  115. package/src/commands/legacy-import.ts +0 -104
  116. package/src/commands/mvp-smoke.ts +0 -160
  117. package/src/commands/pain-evidence.ts +0 -226
  118. package/src/commands/pain-list.ts +0 -239
  119. package/src/commands/pain-record.ts +0 -612
  120. package/src/commands/pain-retry.ts +0 -916
  121. package/src/commands/principles-stats.ts +0 -700
  122. package/src/commands/proven-channel-baseline.ts +0 -115
  123. package/src/commands/quality-scorecard.ts +0 -272
  124. package/src/commands/remediation-output.ts +0 -66
  125. package/src/commands/rulecode.ts +0 -465
  126. package/src/commands/run.ts +0 -89
  127. package/src/commands/runtime-activation.ts +0 -1629
  128. package/src/commands/runtime-artifact-repair.ts +0 -524
  129. package/src/commands/runtime-canary.ts +0 -395
  130. package/src/commands/runtime-compatibility-scan.ts +0 -105
  131. package/src/commands/runtime-diagnostics-export.ts +0 -229
  132. package/src/commands/runtime-features.ts +0 -153
  133. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  134. package/src/commands/runtime-health-snapshot.ts +0 -108
  135. package/src/commands/runtime-init.ts +0 -429
  136. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  137. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  138. package/src/commands/runtime-internalization-integrity.ts +0 -107
  139. package/src/commands/runtime-internalization-queue.ts +0 -135
  140. package/src/commands/runtime-internalization-retry.ts +0 -191
  141. package/src/commands/runtime-internalization-run-once.ts +0 -791
  142. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  143. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  144. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  145. package/src/commands/runtime-pruning.ts +0 -438
  146. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  147. package/src/commands/runtime-recovery.ts +0 -109
  148. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  149. package/src/commands/runtime-uat.guard.test.ts +0 -175
  150. package/src/commands/runtime-uat.ts +0 -380
  151. package/src/commands/runtime.ts +0 -473
  152. package/src/commands/samples-list.ts +0 -39
  153. package/src/commands/samples-review.ts +0 -36
  154. package/src/commands/task.ts +0 -271
  155. package/src/commands/telemetry.ts +0 -349
  156. package/src/commands/trace.ts +0 -174
  157. package/src/commands/trajectory-db-unavailable.ts +0 -19
  158. package/src/commands/trajectory.ts +0 -64
  159. package/src/commands/version.ts +0 -49
  160. package/src/config-reader.ts +0 -122
  161. package/src/index.ts +0 -1276
  162. package/src/legacy/legacy-import.ts +0 -179
  163. package/src/legacy/session-history-import.ts +0 -203
  164. package/src/resolve-workspace.ts +0 -106
  165. package/src/services/__tests__/cli-output.test.ts +0 -130
  166. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  167. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  168. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  169. package/src/services/cli-output.ts +0 -95
  170. package/src/services/config-doctor.ts +0 -697
  171. package/src/services/console-launcher.ts +0 -537
  172. package/src/services/demo-rule-compiler.ts +0 -40
  173. package/src/services/demo-story-a-runner.ts +0 -471
  174. package/src/services/mainline-snapshot-assembler.ts +0 -579
  175. package/src/services/pain-flood-simulation-runner.ts +0 -462
  176. package/src/services/pd-config-loader.ts +0 -433
  177. package/src/services/proven-channel-baseline-runner.ts +0 -157
  178. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  179. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  180. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  181. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  182. package/src/services/rulehost-pipeline-runner.ts +0 -1216
  183. package/src/services/rulehost-readiness.ts +0 -326
  184. package/src/services/runtime-adapter-resolver.ts +0 -364
  185. package/src/services/synthetic-baseline-runner.ts +0 -400
  186. package/src/services/version-report.ts +0 -253
  187. package/src/services/workspace-tool-semantics.ts +0 -26
  188. package/src/utils/path-security.ts +0 -96
  189. package/src/utils/production-workspace-guard.test.ts +0 -157
  190. package/src/utils/production-workspace-guard.ts +0 -210
  191. package/tests/bdd/cli-contract.steps.ts +0 -346
  192. package/tests/bdd/principles-stats.steps.ts +0 -211
  193. package/tests/bdd/support/gherkin-loader.ts +0 -147
  194. package/tests/bdd/support/repo-root.ts +0 -62
  195. package/tests/bdd/support/vitest-bdd.ts +0 -179
  196. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  197. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  198. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  199. package/tests/commands/candidate-intake.test.ts +0 -732
  200. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  201. package/tests/commands/candidate-internalize-lineage.test.ts +0 -565
  202. package/tests/commands/candidate-internalize.test.ts +0 -299
  203. package/tests/commands/candidate-route.test.ts +0 -329
  204. package/tests/commands/candidate-show.test.ts +0 -95
  205. package/tests/commands/cli-command-tree.test.ts +0 -144
  206. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  207. package/tests/commands/cli-skill-contract.test.ts +0 -121
  208. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  209. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  210. package/tests/commands/codex-setup.test.ts +0 -297
  211. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  212. package/tests/commands/codex-worker-registration.test.ts +0 -207
  213. package/tests/commands/config-doctor.test.ts +0 -336
  214. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  215. package/tests/commands/console-open.test.ts +0 -1381
  216. package/tests/commands/context.test.ts +0 -114
  217. package/tests/commands/demo-story-a.test.ts +0 -318
  218. package/tests/commands/diagnose.test.ts +0 -1803
  219. package/tests/commands/errors-list.test.ts +0 -679
  220. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  221. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  222. package/tests/commands/health-codex.test.ts +0 -349
  223. package/tests/commands/health-host-wiring.test.ts +0 -76
  224. package/tests/commands/health-reliability.test.ts +0 -99
  225. package/tests/commands/health.test.ts +0 -413
  226. package/tests/commands/intent.test.ts +0 -321
  227. package/tests/commands/legacy-cleanup.test.ts +0 -148
  228. package/tests/commands/pain-evidence.test.ts +0 -518
  229. package/tests/commands/pain-list.test.ts +0 -219
  230. package/tests/commands/pain-record-async.test.ts +0 -335
  231. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  232. package/tests/commands/pain-record.test.ts +0 -851
  233. package/tests/commands/pain-retry.test.ts +0 -1121
  234. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  235. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  236. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  237. package/tests/commands/principles-stats.test.ts +0 -274
  238. package/tests/commands/product-path-regression.test.ts +0 -86
  239. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  240. package/tests/commands/rulecode.test.ts +0 -177
  241. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  242. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  243. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  244. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  245. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  246. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  247. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  248. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  249. package/tests/commands/runtime-activation.test.ts +0 -2052
  250. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  251. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  252. package/tests/commands/runtime-canary.test.ts +0 -430
  253. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  254. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  255. package/tests/commands/runtime-features.test.ts +0 -249
  256. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  257. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  258. package/tests/commands/runtime-init.test.ts +0 -420
  259. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  260. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  261. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  262. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  263. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  264. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  265. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  266. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  267. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  268. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  269. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  270. package/tests/commands/runtime-internalization.test.ts +0 -53
  271. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  272. package/tests/commands/runtime-pruning.test.ts +0 -694
  273. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  274. package/tests/commands/runtime-recovery.test.ts +0 -120
  275. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  276. package/tests/commands/runtime-uat.test.ts +0 -397
  277. package/tests/commands/runtime.test.ts +0 -392
  278. package/tests/commands/samples-list.test.ts +0 -43
  279. package/tests/commands/samples-review.test.ts +0 -41
  280. package/tests/commands/task.test.ts +0 -153
  281. package/tests/commands/telemetry.test.ts +0 -190
  282. package/tests/commands/trace.test.ts +0 -316
  283. package/tests/config-reader.test.ts +0 -143
  284. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  285. package/tests/e2e/cli-full-flow.test.ts +0 -233
  286. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  287. package/tests/helpers/pd-cli-path.ts +0 -5
  288. package/tests/pd-cli-smoke.test.ts +0 -13
  289. package/tests/resolve-workspace.test.ts +0 -196
  290. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  291. package/tests/services/console-launcher.test.ts +0 -114
  292. package/tests/services/demo-rule-compiler.test.ts +0 -242
  293. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  294. package/tests/services/pd-config-loader.test.ts +0 -505
  295. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  296. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  297. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  298. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  299. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1175
  300. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  301. package/tests/utils/path-security.test.ts +0 -180
  302. package/tsconfig.json +0 -26
  303. package/vitest.config.ts +0 -9
@@ -1,732 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { handleCandidateIntake } from '../../src/commands/candidate.js';
3
-
4
- // Use vi.hoisted to define mocks that can be referenced in vi.mock factory
5
- const { mockStateManager, mockAdapter, mockService, MockRuntimeStateManager, MockCandidateIntakeService, MockPrincipleTreeLedgerAdapter, MockCandidateIntakeError } = vi.hoisted(() => {
6
- const mockStateManager = {
7
- initialize: vi.fn().mockResolvedValue(undefined),
8
- getCandidate: vi.fn(),
9
- getArtifact: vi.fn(),
10
- close: vi.fn().mockResolvedValue(undefined),
11
- connection: {
12
- getDb: () => ({
13
- prepare: () => ({
14
- run: vi.fn().mockReturnValue({ changes: 1 }),
15
- }),
16
- }),
17
- },
18
- };
19
-
20
- const mockAdapter = {
21
- writeProbationEntry: vi.fn(),
22
- existsForCandidate: vi.fn().mockReturnValue(null),
23
- };
24
-
25
- const mockService = {
26
- intake: vi.fn(),
27
- };
28
-
29
- // Mock error class
30
- class MockCandidateIntakeError extends Error {
31
- code: string;
32
- context?: Record<string, unknown>;
33
- constructor(message: string, code: string, context?: Record<string, unknown>) {
34
- super(message);
35
- this.name = 'CandidateIntakeError';
36
- this.code = code;
37
- this.context = context;
38
- }
39
- }
40
-
41
- // Create mock constructors
42
- function MockRuntimeStateManager(this: any) {
43
- return mockStateManager;
44
- }
45
- MockRuntimeStateManager.prototype = {};
46
-
47
- function MockCandidateIntakeService(this: any) {
48
- return mockService;
49
- }
50
- MockCandidateIntakeService.prototype = {};
51
-
52
- function MockPrincipleTreeLedgerAdapter(this: any) {
53
- return mockAdapter;
54
- }
55
- MockPrincipleTreeLedgerAdapter.prototype = {};
56
-
57
- return {
58
- mockStateManager,
59
- mockAdapter,
60
- mockService,
61
- MockRuntimeStateManager,
62
- MockCandidateIntakeService,
63
- MockPrincipleTreeLedgerAdapter,
64
- MockCandidateIntakeError,
65
- };
66
- });
67
-
68
- // Mock modules
69
- vi.mock('@principles/core/runtime-v2', () => ({
70
- CandidateIntakeService: MockCandidateIntakeService,
71
- CandidateIntakeError: MockCandidateIntakeError,
72
- RuntimeStateManager: MockRuntimeStateManager,
73
- resolveOutputLanguage: vi.fn().mockReturnValue({ outputLanguage: 'zh-CN' }),
74
- PrincipleTreeLedgerAdapter: MockPrincipleTreeLedgerAdapter,
75
- evaluateCandidateAdmissionFromRecord: vi.fn((candidate: { recommendationKind: string; confidence: number | null }) => {
76
- // Mirror the real implementation for test purposes
77
- if (candidate.recommendationKind === 'defer') {
78
- return { decision: 'deferred', reason: 'recommendation_kind_defer_not_actionable', nextAction: 'review_defer_disposition_manually', evidenceStatus: 'unknown' };
79
- }
80
- if (candidate.confidence === null) {
81
- return { decision: 'needs_evidence', reason: 'confidence_missing_on_candidate_record', nextAction: 're_run_diagnosis_to_populate_confidence_or_manual_review', evidenceStatus: 'unknown' };
82
- }
83
- if (candidate.confidence < 0.5) {
84
- return { decision: 'needs_evidence', reason: `confidence_below_threshold:${candidate.confidence.toFixed(2)}<0.5`, nextAction: 'provide_additional_evidence_or_manual_review', evidenceStatus: 'unknown' };
85
- }
86
- return { decision: 'admitted', reason: 'cli_partial_check_passed_confidence_and_kind', nextAction: 'none', evidenceStatus: 'unknown' };
87
- }),
88
- }));
89
-
90
- vi.mock('../../src/resolve-workspace.js', () => ({
91
- resolveWorkspaceDir: vi.fn().mockReturnValue('/tmp/test-workspace'),
92
- }));
93
-
94
- describe('pd candidate intake', () => {
95
- let consoleLogSpy: any;
96
- let consoleErrorSpy: any;
97
- let exitSpy: any;
98
-
99
- beforeEach(() => {
100
- vi.clearAllMocks();
101
-
102
- // Reset mock implementations
103
- mockStateManager.getCandidate.mockReset();
104
- mockStateManager.getArtifact.mockReset();
105
- mockAdapter.writeProbationEntry.mockReset();
106
- mockAdapter.existsForCandidate.mockReset();
107
- mockService.intake.mockReset();
108
-
109
- // Set default mock implementations
110
- mockStateManager.initialize.mockResolvedValue(undefined);
111
- mockStateManager.close.mockResolvedValue(undefined);
112
- mockAdapter.existsForCandidate.mockReturnValue(null);
113
-
114
- // Spy on console methods
115
- consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
116
- consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
117
- exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as () => never);
118
- });
119
-
120
- afterEach(() => {
121
- consoleLogSpy.mockRestore();
122
- consoleErrorSpy.mockRestore();
123
- exitSpy.mockRestore();
124
- });
125
-
126
- // Test 1: Happy path JSON
127
- it('Test 1 (happy path JSON): returns JSON with candidateId, status: consumed, ledgerEntryId', async () => {
128
- const mockCandidate = {
129
- candidateId: 'valid-id',
130
- artifactId: 'artifact-1',
131
- taskId: 'task-1',
132
- title: 'Test Principle',
133
- description: 'Test description',
134
- status: 'pending',
135
- };
136
-
137
- const mockEntry = {
138
- id: 'ledger-entry-1',
139
- title: 'Test Principle',
140
- text: 'Test text',
141
- triggerPattern: 'test pattern',
142
- action: 'test action',
143
- status: 'probation',
144
- evaluability: 'weak_heuristic',
145
- sourceRef: 'candidate://valid-id',
146
- artifactRef: 'artifact://artifact-1',
147
- taskRef: 'task://task-1',
148
- createdAt: '2026-02-26T00:00:00.000Z',
149
- };
150
-
151
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
152
- mockService.intake.mockResolvedValue(mockEntry);
153
-
154
- await handleCandidateIntake({
155
- candidateId: 'valid-id',
156
- workspace: '/tmp/test-workspace',
157
- json: true,
158
- });
159
-
160
- // Verify service.intake was called
161
- expect(mockService.intake).toHaveBeenCalledWith('valid-id');
162
-
163
- // Verify JSON output
164
- const jsonOutput = consoleLogSpy.mock.calls.find(call => {
165
- try {
166
- const parsed = JSON.parse(call[0] as string);
167
- return parsed.candidateId === 'valid-id' && parsed.status === 'consumed';
168
- } catch {
169
- return false;
170
- }
171
- });
172
- expect(jsonOutput).toBeDefined();
173
- const parsed = JSON.parse((jsonOutput as [string])[0]);
174
- expect(parsed.candidateId).toBe('valid-id');
175
- expect(parsed.status).toBe('consumed');
176
- expect(parsed.ledgerEntryId).toBe('ledger-entry-1');
177
-
178
- // Verify exit was not called with 1
179
- expect(exitSpy).not.toHaveBeenCalledWith(1);
180
- });
181
-
182
- // Test 2: Happy path human-readable
183
- it('Test 2 (happy path human-readable): prints human-readable format with "Intake complete" message', async () => {
184
- const mockCandidate = {
185
- candidateId: 'valid-id',
186
- artifactId: 'artifact-1',
187
- taskId: 'task-1',
188
- title: 'Test Principle',
189
- description: 'Test description',
190
- status: 'pending',
191
- };
192
-
193
- const mockEntry = {
194
- id: 'ledger-entry-1',
195
- title: 'Test Principle',
196
- text: 'Test text',
197
- status: 'probation',
198
- };
199
-
200
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
201
- mockService.intake.mockResolvedValue(mockEntry);
202
-
203
- await handleCandidateIntake({
204
- candidateId: 'valid-id',
205
- workspace: '/tmp/test-workspace',
206
- json: false,
207
- });
208
-
209
- // Verify human-readable output
210
- expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Principle Candidate Intake:'));
211
- expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Intake complete.'));
212
-
213
- // Verify no JSON.parse error (not JSON output)
214
- const allOutput = consoleLogSpy.mock.calls.map(call => call[0]).join('\n');
215
- expect(allOutput).toContain('valid-id');
216
- expect(allOutput).toContain('ledger-entry-1');
217
-
218
- expect(exitSpy).not.toHaveBeenCalledWith(1);
219
- });
220
-
221
- // Test 3: Dry-run with complete 11-field entry (JSON output)
222
- it('Test 3 (dry-run JSON): returns complete 11-field entry without writing to ledger', async () => {
223
- const mockCandidate = {
224
- candidateId: 'valid-id',
225
- artifactId: 'artifact-1',
226
- taskId: 'task-1',
227
- title: 'Test Principle',
228
- description: 'Test description',
229
- status: 'pending',
230
- };
231
-
232
- const mockArtifact = {
233
- artifactId: 'artifact-1',
234
- contentJson: JSON.stringify({
235
- recommendation: {
236
- title: 'Test Principle',
237
- text: 'Test text',
238
- triggerPattern: 'test pattern',
239
- action: 'test action',
240
- },
241
- }),
242
- };
243
-
244
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
245
- mockStateManager.getArtifact.mockResolvedValue(mockArtifact);
246
-
247
- await handleCandidateIntake({
248
- candidateId: 'valid-id',
249
- workspace: '/tmp/test-workspace',
250
- dryRun: true,
251
- json: true,
252
- });
253
-
254
- // Verify service.intake was NOT called (dry-run skips service)
255
- expect(mockService.intake).not.toHaveBeenCalled();
256
-
257
- // Verify adapter.writeProbationEntry was NOT called
258
- expect(mockAdapter.writeProbationEntry).not.toHaveBeenCalled();
259
-
260
- // Verify JSON output has all 11 fields
261
- const jsonOutput = consoleLogSpy.mock.calls.find(call => {
262
- try {
263
- const parsed = JSON.parse(call[0] as string);
264
- return parsed.id && parsed.title && parsed.sourceRef === 'candidate://valid-id';
265
- } catch {
266
- return false;
267
- }
268
- });
269
- expect(jsonOutput).toBeDefined();
270
- const entry = JSON.parse((jsonOutput as [string])[0]);
271
-
272
- // Check all 11 fields exist
273
- expect(entry.id).toBeDefined();
274
- expect(entry.title).toBe('Test Principle');
275
- expect(entry.text).toBe('Test text');
276
- expect(entry.triggerPattern).toBe('test pattern');
277
- expect(entry.action).toBe('test action');
278
- expect(entry.status).toBe('probation');
279
- expect(entry.evaluability).toBe('weak_heuristic');
280
- expect(entry.sourceRef).toBe('candidate://valid-id');
281
- expect(entry.artifactRef).toBe('artifact://artifact-1');
282
- expect(entry.taskRef).toBe('task://task-1');
283
- expect(entry.createdAt).toBeDefined();
284
-
285
- expect(exitSpy).not.toHaveBeenCalledWith(1);
286
- });
287
-
288
- // Test 3b: Dry-run with human-readable output (covers lines 193-194)
289
- it('Test 3b (dry-run human-readable): outputs human-readable format without writing', async () => {
290
- const mockCandidate = {
291
- candidateId: 'valid-id',
292
- artifactId: 'artifact-1',
293
- taskId: 'task-1',
294
- title: 'Test Principle',
295
- description: 'Test description',
296
- status: 'pending',
297
- };
298
-
299
- const mockArtifact = {
300
- artifactId: 'artifact-1',
301
- contentJson: JSON.stringify({
302
- recommendation: {
303
- title: 'Test Principle',
304
- text: 'Test text',
305
- },
306
- }),
307
- };
308
-
309
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
310
- mockStateManager.getArtifact.mockResolvedValue(mockArtifact);
311
-
312
- await handleCandidateIntake({
313
- candidateId: 'valid-id',
314
- workspace: '/tmp/test-workspace',
315
- dryRun: true,
316
- json: false,
317
- });
318
-
319
- // Verify human-readable output (covers lines 193-194)
320
- expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Dry-run: would write entry for candidate valid-id'));
321
-
322
- expect(exitSpy).not.toHaveBeenCalledWith(1);
323
- });
324
-
325
- // Test 3c: Dry-run when candidate not found (covers line 165)
326
- it('Test 3c (dry-run candidate not found): exits with error', async () => {
327
- mockStateManager.getCandidate.mockResolvedValue(null);
328
-
329
- await handleCandidateIntake({
330
- candidateId: 'invalid-id',
331
- workspace: '/tmp/test-workspace',
332
- dryRun: true,
333
- });
334
-
335
- expect(consoleErrorSpy).toHaveBeenCalledWith('Candidate not found: invalid-id');
336
- expect(exitSpy).toHaveBeenCalledWith(1);
337
- });
338
-
339
- // Test 3d: Dry-run when artifact not found (covers line 165)
340
- it('Test 3d (dry-run artifact not found): exits with error', async () => {
341
- const mockCandidate = {
342
- candidateId: 'valid-id',
343
- artifactId: 'artifact-1',
344
- title: 'Test',
345
- description: 'Test',
346
- status: 'pending',
347
- };
348
-
349
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
350
- mockStateManager.getArtifact.mockResolvedValue(null);
351
-
352
- await handleCandidateIntake({
353
- candidateId: 'valid-id',
354
- workspace: '/tmp/test-workspace',
355
- dryRun: true,
356
- });
357
-
358
- expect(consoleErrorSpy).toHaveBeenCalledWith('Artifact not found for candidate: valid-id');
359
- expect(exitSpy).toHaveBeenCalledWith(1);
360
- });
361
-
362
- // Test 4: Non-existent candidate
363
- it('Test 4 (non-existent candidate): throws CANDIDATE_NOT_FOUND error', async () => {
364
- // PRI-442 Stage 4: getCandidate now returns null before service.intake is called.
365
- // The CLI exits with "Candidate not found" instead of relying on service.intake
366
- // to throw CANDIDATE_NOT_FOUND.
367
- mockStateManager.getCandidate.mockResolvedValue(null);
368
-
369
- await handleCandidateIntake({
370
- candidateId: 'invalid-id',
371
- workspace: '/tmp/test-workspace',
372
- });
373
-
374
- // Verify error output contains "Candidate not found"
375
- expect(consoleErrorSpy).toHaveBeenCalledWith(
376
- expect.stringContaining('Candidate not found')
377
- );
378
- expect(exitSpy).toHaveBeenCalledWith(1);
379
- });
380
-
381
- // Test 5: Invalid candidateId (empty string)
382
- it('Test 5 (invalid candidateId): empty string throws INPUT_INVALID error', async () => {
383
- // PRI-442 Stage 4: getCandidate is called before service.intake, so we need
384
- // to mock it to return a valid candidate so service.intake is reached.
385
- const mockCandidate = {
386
- candidateId: '',
387
- artifactId: 'artifact-1',
388
- taskId: 'task-1',
389
- title: 'Test',
390
- description: 'Test',
391
- status: 'pending',
392
- };
393
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
394
-
395
- // Setup: service.intake throws INPUT_INVALID for empty candidateId
396
- mockService.intake.mockImplementation(() => {
397
- throw new MockCandidateIntakeError(
398
- 'candidateId must be a non-empty string',
399
- 'INPUT_INVALID',
400
- { candidateId: '' }
401
- );
402
- });
403
-
404
- await handleCandidateIntake({
405
- candidateId: '',
406
- workspace: '/tmp/test-workspace',
407
- });
408
-
409
- expect(consoleErrorSpy).toHaveBeenCalledWith(
410
- expect.stringContaining('INPUT_INVALID')
411
- );
412
- expect(exitSpy).toHaveBeenCalledWith(1);
413
- });
414
-
415
- // Test 6: Already consumed candidate (human-readable)
416
- it('Test 6 (already consumed human-readable): outputs info message and exits successfully', async () => {
417
- const mockCandidate = {
418
- candidateId: 'valid-id',
419
- artifactId: 'artifact-1',
420
- taskId: 'task-1',
421
- title: 'Test Principle',
422
- description: 'Test description',
423
- status: 'consumed', // Already consumed
424
- };
425
-
426
- const mockEntry = {
427
- id: 'ledger-entry-1',
428
- title: 'Test Principle',
429
- text: 'Test text',
430
- status: 'probation',
431
- };
432
-
433
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
434
- mockService.intake.mockResolvedValue(mockEntry);
435
-
436
- await handleCandidateIntake({
437
- candidateId: 'valid-id',
438
- workspace: '/tmp/test-workspace',
439
- json: false,
440
- });
441
-
442
- // Verify info message about already consumed
443
- const allOutput = consoleLogSpy.mock.calls.map(call => call[0]).join('\n');
444
- expect(allOutput).toContain('already consumed');
445
- expect(allOutput).toContain('ledger-entry-1');
446
-
447
- // Verify exit was not called with 1 (successful exit)
448
- expect(exitSpy).not.toHaveBeenCalledWith(1);
449
- });
450
-
451
- // Test 6b: Already consumed candidate (JSON output, covers line 208)
452
- it('Test 6b (already consumed JSON): outputs JSON with already_consumed status', async () => {
453
- const mockCandidate = {
454
- candidateId: 'valid-id',
455
- artifactId: 'artifact-1',
456
- taskId: 'task-1',
457
- title: 'Test Principle',
458
- description: 'Test description',
459
- status: 'consumed', // Already consumed
460
- };
461
-
462
- const mockEntry = {
463
- id: 'ledger-entry-1',
464
- title: 'Test Principle',
465
- text: 'Test text',
466
- status: 'probation',
467
- };
468
-
469
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
470
- mockService.intake.mockResolvedValue(mockEntry);
471
-
472
- await handleCandidateIntake({
473
- candidateId: 'valid-id',
474
- workspace: '/tmp/test-workspace',
475
- json: true,
476
- });
477
-
478
- // Verify JSON output for already consumed (covers line 208)
479
- const jsonOutput = consoleLogSpy.mock.calls.find(call => {
480
- try {
481
- const parsed = JSON.parse(call[0] as string);
482
- return parsed.status === 'already_consumed';
483
- } catch {
484
- return false;
485
- }
486
- });
487
- expect(jsonOutput).toBeDefined();
488
- const parsed = JSON.parse((jsonOutput as [string])[0]);
489
- expect(parsed.candidateId).toBe('valid-id');
490
- expect(parsed.ledgerEntryId).toBe('ledger-entry-1');
491
- expect(parsed.status).toBe('already_consumed');
492
- expect(parsed.message).toContain('already consumed');
493
-
494
- expect(exitSpy).not.toHaveBeenCalledWith(1);
495
- });
496
-
497
- // Test 7: Generic error (non-CandidateIntakeError, covers line 247)
498
- it('Test 7 (generic error): handles non-CandidateIntakeError errors', async () => {
499
- // PRI-442 Stage 4: getCandidate is called before service.intake, so we need
500
- // to mock it to return a valid candidate so service.intake is reached.
501
- const mockCandidate = {
502
- candidateId: 'valid-id',
503
- artifactId: 'artifact-1',
504
- taskId: 'task-1',
505
- title: 'Test',
506
- description: 'Test',
507
- status: 'pending',
508
- };
509
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
510
-
511
- // Setup: service.intake throws a generic Error (not CandidateIntakeError)
512
- mockService.intake.mockImplementation(() => {
513
- throw new Error('Some unexpected error');
514
- });
515
-
516
- await handleCandidateIntake({
517
- candidateId: 'valid-id',
518
- workspace: '/tmp/test-workspace',
519
- });
520
-
521
- // Verify generic error output (covers line 247)
522
- // String(err) produces "Error: Some unexpected error"
523
- expect(consoleErrorSpy).toHaveBeenCalledWith(
524
- expect.stringContaining('Intake failed: Error: Some unexpected error')
525
- );
526
-
527
- expect(exitSpy).toHaveBeenCalledWith(1);
528
- });
529
-
530
- it('guarded transition: UPDATE uses WHERE status = pending for intake path', async () => {
531
- const mockCandidate = {
532
- candidateId: 'valid-id',
533
- artifactId: 'artifact-1',
534
- taskId: 'task-1',
535
- title: 'Test Principle',
536
- description: 'Test description',
537
- status: 'pending',
538
- };
539
- const mockEntry = {
540
- id: 'ledger-entry-1',
541
- title: 'Test Principle',
542
- text: 'Test text',
543
- status: 'probation',
544
- };
545
-
546
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
547
- mockService.intake.mockResolvedValue(mockEntry);
548
-
549
- const capturedPrepareCalls: { sql: string; runArgs: unknown[] }[] = [];
550
- const originalConnection = mockStateManager.connection;
551
- mockStateManager.connection = {
552
- getDb: () => ({
553
- prepare: (sql: string) => ({
554
- run: (...args: unknown[]) => {
555
- capturedPrepareCalls.push({ sql, runArgs: args });
556
- return { changes: 1 };
557
- },
558
- }),
559
- }),
560
- };
561
-
562
- try {
563
- await handleCandidateIntake({
564
- candidateId: 'valid-id',
565
- workspace: '/tmp/test-workspace',
566
- json: true,
567
- });
568
-
569
- const updateCall = capturedPrepareCalls.find(c => c.sql.includes('UPDATE'));
570
- expect(updateCall).toBeDefined();
571
- expect(updateCall!.sql).toContain('AND status = ?');
572
- expect(updateCall!.runArgs[0]).toBe('consumed');
573
- expect(updateCall!.runArgs[3]).toBe('pending');
574
- } finally {
575
- mockStateManager.connection = originalConnection;
576
- }
577
- });
578
-
579
- it('guarded transition: intake fails when candidate is not pending', async () => {
580
- const mockCandidate = {
581
- candidateId: 'valid-id',
582
- artifactId: 'artifact-1',
583
- taskId: 'task-1',
584
- title: 'Test Principle',
585
- description: 'Test description',
586
- status: 'pending',
587
- };
588
- const mockEntry = {
589
- id: 'ledger-entry-1',
590
- title: 'Test Principle',
591
- text: 'Test text',
592
- status: 'probation',
593
- };
594
-
595
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
596
- mockService.intake.mockResolvedValue(mockEntry);
597
-
598
- const originalConnection = mockStateManager.connection;
599
- mockStateManager.connection = {
600
- getDb: () => ({
601
- prepare: (sql: string) => ({
602
- run: () => ({ changes: 0 }),
603
- }),
604
- }),
605
- };
606
-
607
- try {
608
- await handleCandidateIntake({
609
- candidateId: 'valid-id',
610
- workspace: '/tmp/test-workspace',
611
- json: true,
612
- });
613
-
614
- expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Guarded transition failed'));
615
- expect(exitSpy).toHaveBeenCalledWith(1);
616
- } finally {
617
- mockStateManager.connection = originalConnection;
618
- }
619
- });
620
-
621
- // PRI-442 Stage 4: admission gate bypass tests
622
- describe('admission gate bypass prevention (PRI-442 Stage 4)', () => {
623
- it('refuses intake when recommendationKind is defer', async () => {
624
- const mockCandidate = {
625
- candidateId: 'defer-cand',
626
- artifactId: 'artifact-1',
627
- taskId: 'task-1',
628
- title: 'Deferred candidate',
629
- description: 'Should not be intakeable',
630
- status: 'pending',
631
- recommendationKind: 'defer',
632
- confidence: 0.9,
633
- };
634
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
635
-
636
- await handleCandidateIntake({
637
- candidateId: 'defer-cand',
638
- workspace: '/tmp/test-workspace',
639
- json: true,
640
- });
641
-
642
- // Should NOT call service.intake
643
- expect(mockService.intake).not.toHaveBeenCalled();
644
- // Should output refused status
645
- expect(consoleLogSpy).toHaveBeenCalledWith(
646
- expect.stringContaining('"status": "refused"')
647
- );
648
- expect(consoleLogSpy).toHaveBeenCalledWith(
649
- expect.stringContaining('"admissionDecision": "deferred"')
650
- );
651
- expect(exitSpy).toHaveBeenCalledWith(1);
652
- });
653
-
654
- it('refuses intake when confidence is below threshold', async () => {
655
- const mockCandidate = {
656
- candidateId: 'low-conf-cand',
657
- artifactId: 'artifact-1',
658
- taskId: 'task-1',
659
- title: 'Low confidence candidate',
660
- description: 'Should not be intakeable',
661
- status: 'pending',
662
- recommendationKind: 'principle',
663
- confidence: 0.3,
664
- };
665
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
666
-
667
- await handleCandidateIntake({
668
- candidateId: 'low-conf-cand',
669
- workspace: '/tmp/test-workspace',
670
- json: false,
671
- });
672
-
673
- expect(mockService.intake).not.toHaveBeenCalled();
674
- expect(consoleErrorSpy).toHaveBeenCalledWith(
675
- expect.stringContaining('Admission gate refused')
676
- );
677
- expect(consoleErrorSpy).toHaveBeenCalledWith(
678
- expect.stringContaining('needs_evidence')
679
- );
680
- expect(exitSpy).toHaveBeenCalledWith(1);
681
- });
682
-
683
- it('refuses intake when confidence is null (rc-3 fail loud)', async () => {
684
- const mockCandidate = {
685
- candidateId: 'null-conf-cand',
686
- artifactId: 'artifact-1',
687
- taskId: 'task-1',
688
- title: 'Null confidence candidate',
689
- description: 'Should not be intakeable',
690
- status: 'pending',
691
- recommendationKind: 'principle',
692
- confidence: null,
693
- };
694
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
695
-
696
- await handleCandidateIntake({
697
- candidateId: 'null-conf-cand',
698
- workspace: '/tmp/test-workspace',
699
- json: true,
700
- });
701
-
702
- expect(mockService.intake).not.toHaveBeenCalled();
703
- expect(consoleLogSpy).toHaveBeenCalledWith(
704
- expect.stringContaining('confidence_missing_on_candidate_record')
705
- );
706
- expect(exitSpy).toHaveBeenCalledWith(1);
707
- });
708
-
709
- it('allows intake when candidate passes admission gate', async () => {
710
- const mockCandidate = {
711
- candidateId: 'admitted-cand',
712
- artifactId: 'artifact-1',
713
- taskId: 'task-1',
714
- title: 'Admitted candidate',
715
- description: 'Should be intakeable',
716
- status: 'pending',
717
- recommendationKind: 'principle',
718
- confidence: 0.8,
719
- };
720
- mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
721
- mockService.intake.mockResolvedValue({ id: 'entry-1', title: 'Test', text: 'Test', status: 'probation' });
722
-
723
- await handleCandidateIntake({
724
- candidateId: 'admitted-cand',
725
- workspace: '/tmp/test-workspace',
726
- json: true,
727
- });
728
-
729
- expect(mockService.intake).toHaveBeenCalledWith('admitted-cand');
730
- });
731
- });
732
- });