@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,441 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
-
3
- const { mockRunProvenChannelBaseline } = vi.hoisted(() => ({
4
- mockRunProvenChannelBaseline: vi.fn(),
5
- }));
6
-
7
- vi.mock('../../src/services/proven-channel-baseline-runner.js', () => ({
8
- runProvenChannelBaseline: mockRunProvenChannelBaseline,
9
- }));
10
-
11
- import * as fs from 'fs';
12
- import * as path from 'path';
13
- import * as os from 'os';
14
- import { handleProvenChannelBaseline, cleanupTempWorkspace } from '../../src/commands/proven-channel-baseline.js';
15
-
16
- function makePassedSummary() {
17
- return {
18
- status: 'passed' as const,
19
- workspaceMode: 'temp' as const,
20
- generatedAt: new Date().toISOString(),
21
- channels: [
22
- {
23
- channel: 'prompt' as const,
24
- status: 'passed' as const,
25
- canActivateResult: { ok: true, riskLevel: 'low' as const },
26
- activationDecision: { decision: 'would_activate' as const, activationId: 'act_prompt_P_240', action: 'prompt_activate', targetRef: 'ledger://P_240' },
27
- evidence: { activationId: 'act_prompt_P_240', evidenceSource: 'ActivationDispatcher.dispatch → PromptWriter' },
28
- dependsOnLegacy: false,
29
- evidenceSource: 'ActivationDispatcher.dispatch → PromptWriter',
30
- },
31
- {
32
- channel: 'code_tool_hook' as const,
33
- status: 'passed' as const,
34
- canActivateResult: { ok: true, riskLevel: 'high' as const },
35
- activationDecision: { decision: 'would_activate' as const, activationId: 'act_code_R_240', action: 'code_tool_hook_shadow_activate', targetRef: 'impl://R_240' },
36
- evidence: { activationId: 'act_code_R_240', gateDecision: 'accepted_shadow', evidenceSource: 'ActivationDispatcher.dispatch → RuleHostWriter' },
37
- dependsOnLegacy: false,
38
- evidenceSource: 'ActivationDispatcher.dispatch → RuleHostWriter',
39
- },
40
- {
41
- channel: 'defer_archive' as const,
42
- status: 'passed' as const,
43
- canActivateResult: { ok: true, riskLevel: 'low' as const },
44
- activationDecision: { decision: 'would_activate' as const, activationId: 'act_archive_P_240', action: 'defer_archive', targetRef: 'ledger://P_240#archived' },
45
- evidence: { activationId: 'act_archive_P_240', evidenceSource: 'ActivationDispatcher.dispatch → DeferArchiveWriter' },
46
- dependsOnLegacy: false,
47
- evidenceSource: 'ActivationDispatcher.dispatch → DeferArchiveWriter',
48
- },
49
- ],
50
- continuityMatrix: [
51
- {
52
- channel: 'prompt' as const,
53
- entryPoint: 'ActivationDispatcher.dispatch → PromptWriter.canActivate → PromptWriter.activate',
54
- expectedObservable: 'activationId=act_prompt_{principleId}',
55
- testCommand: 'npx vitest run ...',
56
- dependsOnPluginDiscovery: false,
57
- pri119ReuseEvidence: 'ActivationDispatcher → PromptWriter contract',
58
- pri230ReuseEvidence: 'prompt risk level',
59
- },
60
- {
61
- channel: 'code_tool_hook' as const,
62
- entryPoint: 'ActivationDispatcher.dispatch → RuleHostWriter.canActivate → evaluateRefinerRuleHostGate → RuleHostWriter.activate',
63
- expectedObservable: 'activationId=act_code_{ruleId}',
64
- testCommand: 'npx vitest run ...',
65
- dependsOnPluginDiscovery: false,
66
- pri119ReuseEvidence: 'ActivationDispatcher → RuleHostWriter gate contract',
67
- pri230ReuseEvidence: 'code_tool_hook risk level',
68
- },
69
- {
70
- channel: 'defer_archive' as const,
71
- entryPoint: 'ActivationDispatcher.dispatch → DeferArchiveWriter.canActivate → DeferArchiveWriter.activate',
72
- expectedObservable: 'activationId=act_archive_{principleId}',
73
- testCommand: 'npx vitest run ...',
74
- dependsOnPluginDiscovery: false,
75
- pri119ReuseEvidence: 'ActivationDispatcher → DeferArchiveWriter contract',
76
- pri230ReuseEvidence: 'defer_archive risk level',
77
- },
78
- ],
79
- };
80
- }
81
-
82
- describe('handleProvenChannelBaseline (CLI handler)', () => {
83
- let tempDir = '';
84
- const originalExitCode = process.exitCode;
85
-
86
- beforeEach(() => {
87
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-cli-proven-test-'));
88
- mockRunProvenChannelBaseline.mockReset();
89
- process.exitCode = undefined;
90
- });
91
-
92
- afterEach(() => {
93
- try {
94
- fs.rmSync(tempDir, { recursive: true, force: true });
95
- } catch {
96
- void 0;
97
- }
98
- process.exitCode = originalExitCode;
99
- });
100
-
101
- it('uses temp workspace when no workspace specified', async () => {
102
- mockRunProvenChannelBaseline.mockResolvedValue({
103
- ...makePassedSummary(),
104
- workspaceMode: 'temp',
105
- });
106
-
107
- await handleProvenChannelBaseline({});
108
-
109
- expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
110
- expect.objectContaining({ workspaceMode: 'temp' }),
111
- );
112
- const calledDir = mockRunProvenChannelBaseline.mock.calls[0][0].workspaceDir;
113
- expect(calledDir).toContain('pd-proven-channel-');
114
- });
115
-
116
- it('uses explicit workspace when --workspace is provided', async () => {
117
- mockRunProvenChannelBaseline.mockResolvedValue({
118
- ...makePassedSummary(),
119
- workspaceMode: 'explicit_workspace',
120
- });
121
-
122
- await handleProvenChannelBaseline({ workspace: tempDir });
123
-
124
- expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
125
- expect.objectContaining({
126
- workspaceDir: tempDir,
127
- workspaceMode: 'explicit_workspace',
128
- }),
129
- );
130
- });
131
-
132
- it('--json output contains status, workspaceMode, generatedAt, channels, continuityMatrix', async () => {
133
- const summary = makePassedSummary();
134
- mockRunProvenChannelBaseline.mockResolvedValue(summary);
135
-
136
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
137
-
138
- try {
139
- await handleProvenChannelBaseline({ json: true });
140
-
141
- expect(logSpy).toHaveBeenCalledTimes(1);
142
- const output = logSpy.mock.calls[0][0];
143
- const parsed = JSON.parse(output);
144
- expect(parsed).toHaveProperty('status');
145
- expect(parsed).toHaveProperty('workspaceMode');
146
- expect(parsed).toHaveProperty('generatedAt');
147
- expect(parsed).toHaveProperty('channels');
148
- expect(parsed).toHaveProperty('continuityMatrix');
149
- expect(parsed.channels).toHaveLength(3);
150
- expect(parsed.continuityMatrix).toHaveLength(3);
151
- } finally {
152
- logSpy.mockRestore();
153
- }
154
- });
155
-
156
- it('sets process.exitCode = 1 when status is failed', async () => {
157
- mockRunProvenChannelBaseline.mockResolvedValue({
158
- ...makePassedSummary(),
159
- status: 'failed',
160
- channels: [
161
- { channel: 'prompt', status: 'failed', canActivateResult: { ok: false, reason: 'test', riskLevel: 'low' }, activationDecision: { decision: 'refused', reason: 'test', channel: 'prompt' }, evidence: {}, dependsOnLegacy: false, failureReason: 'test failure', evidenceSource: 'test' },
162
- { channel: 'code_tool_hook', status: 'failed', canActivateResult: { ok: false, reason: 'test', riskLevel: 'high' }, activationDecision: { decision: 'refused', reason: 'test', channel: 'code_tool_hook' }, evidence: {}, dependsOnLegacy: false, failureReason: 'test failure', evidenceSource: 'test' },
163
- { channel: 'defer_archive', status: 'failed', canActivateResult: { ok: false, reason: 'test', riskLevel: 'low' }, activationDecision: { decision: 'refused', reason: 'test', channel: 'defer_archive' }, evidence: {}, dependsOnLegacy: false, failureReason: 'test failure', evidenceSource: 'test' },
164
- ],
165
- });
166
-
167
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
168
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
169
-
170
- try {
171
- await handleProvenChannelBaseline({ workspace: tempDir });
172
- expect(process.exitCode).toBe(1);
173
- } finally {
174
- logSpy.mockRestore();
175
- errorSpy.mockRestore();
176
- }
177
- });
178
-
179
- it('cleans up temp workspace on success', async () => {
180
- mockRunProvenChannelBaseline.mockResolvedValue(makePassedSummary());
181
-
182
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
183
-
184
- try {
185
- await handleProvenChannelBaseline({});
186
-
187
- const calledDir = mockRunProvenChannelBaseline.mock.calls[0][0].workspaceDir;
188
- expect(fs.existsSync(calledDir)).toBe(false);
189
- } finally {
190
- logSpy.mockRestore();
191
- }
192
- });
193
-
194
- it('does not delete explicit workspace after run', async () => {
195
- fs.mkdirSync(path.join(tempDir, '.pd'), { recursive: true });
196
-
197
- mockRunProvenChannelBaseline.mockResolvedValue({
198
- ...makePassedSummary(),
199
- workspaceMode: 'explicit_workspace',
200
- });
201
-
202
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
203
-
204
- try {
205
- await handleProvenChannelBaseline({ workspace: tempDir });
206
- expect(fs.existsSync(tempDir)).toBe(true);
207
- } finally {
208
- logSpy.mockRestore();
209
- }
210
- });
211
-
212
- it('--channels with unknown values passes unknownChannels to runner', async () => {
213
- mockRunProvenChannelBaseline.mockResolvedValue({
214
- status: 'failed',
215
- generatedAt: new Date().toISOString(),
216
- workspaceMode: 'temp',
217
- channels: [],
218
- inputValidationFailure: {
219
- reason: 'unknown_channels',
220
- message: 'Unknown channels: skill, legacy_channel. Valid channels: prompt, code_tool_hook, defer_archive',
221
- nextAction: 'Use only valid MVP channels: prompt, code_tool_hook, defer_archive',
222
- unknownChannels: ['skill', 'legacy_channel'],
223
- },
224
- continuityMatrix: [],
225
- recommendedNextIssue: 'PRI-240: Unknown channels provided: skill, legacy_channel',
226
- });
227
-
228
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
229
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
230
-
231
- try {
232
- await handleProvenChannelBaseline({ json: true, channels: 'prompt,skill,legacy_channel' });
233
- expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
234
- expect.objectContaining({
235
- unknownChannels: ['skill', 'legacy_channel'],
236
- }),
237
- );
238
- } finally {
239
- logSpy.mockRestore();
240
- errorSpy.mockRestore();
241
- }
242
- });
243
-
244
- it('--channels "" returns failed with inputValidationFailure, no fixtures executed', async () => {
245
- mockRunProvenChannelBaseline.mockResolvedValue({
246
- status: 'failed',
247
- generatedAt: new Date().toISOString(),
248
- workspaceMode: 'temp',
249
- channels: [],
250
- inputValidationFailure: {
251
- reason: 'empty_channel_input',
252
- message: '--channels was provided but contained no valid channel names',
253
- nextAction: 'Provide at least one valid MVP channel: prompt, code_tool_hook, defer_archive',
254
- },
255
- continuityMatrix: [],
256
- recommendedNextIssue: 'PRI-240: --channels input was empty — no fixtures were executed',
257
- });
258
-
259
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
260
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
261
-
262
- try {
263
- await handleProvenChannelBaseline({ json: true, channels: '' });
264
- expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
265
- expect.objectContaining({
266
- emptyChannelInput: true,
267
- channels: undefined,
268
- unknownChannels: [],
269
- }),
270
- );
271
- expect(logSpy.mock.calls[0]?.[0]).toBeDefined();
272
- const output = logSpy.mock.calls[0][0];
273
- expect(typeof output).toBe('string');
274
- const parsed = JSON.parse(output);
275
- expect(parsed.status).toBe('failed');
276
- expect(parsed.inputValidationFailure).toBeDefined();
277
- expect(parsed.inputValidationFailure.reason).toBe('empty_channel_input');
278
- expect(parsed.channels).toHaveLength(0);
279
- } finally {
280
- logSpy.mockRestore();
281
- errorSpy.mockRestore();
282
- }
283
- });
284
-
285
- it('--channels "," returns failed with inputValidationFailure, no fixtures executed', async () => {
286
- mockRunProvenChannelBaseline.mockResolvedValue({
287
- status: 'failed',
288
- generatedAt: new Date().toISOString(),
289
- workspaceMode: 'temp',
290
- channels: [],
291
- inputValidationFailure: {
292
- reason: 'empty_channel_input',
293
- message: '--channels was provided but contained no valid channel names',
294
- nextAction: 'Provide at least one valid MVP channel: prompt, code_tool_hook, defer_archive',
295
- },
296
- continuityMatrix: [],
297
- });
298
-
299
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
300
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
301
-
302
- try {
303
- await handleProvenChannelBaseline({ json: true, channels: ',' });
304
- expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
305
- expect.objectContaining({
306
- emptyChannelInput: true,
307
- }),
308
- );
309
- } finally {
310
- logSpy.mockRestore();
311
- errorSpy.mockRestore();
312
- }
313
- });
314
-
315
- it('--channels bogus returns failed with unknown channels, no fixtures executed', async () => {
316
- mockRunProvenChannelBaseline.mockResolvedValue({
317
- status: 'failed',
318
- generatedAt: new Date().toISOString(),
319
- workspaceMode: 'temp',
320
- channels: [],
321
- inputValidationFailure: {
322
- reason: 'unknown_channels',
323
- message: 'Unknown channels: bogus. Valid channels: prompt, code_tool_hook, defer_archive',
324
- nextAction: 'Use only valid MVP channels: prompt, code_tool_hook, defer_archive',
325
- unknownChannels: ['bogus'],
326
- },
327
- continuityMatrix: [],
328
- });
329
-
330
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
331
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
332
-
333
- try {
334
- await handleProvenChannelBaseline({ json: true, channels: 'bogus' });
335
- expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
336
- expect.objectContaining({
337
- unknownChannels: ['bogus'],
338
- }),
339
- );
340
- expect(logSpy.mock.calls[0]?.[0]).toBeDefined();
341
- const output = logSpy.mock.calls[0][0];
342
- expect(typeof output).toBe('string');
343
- const parsed = JSON.parse(output);
344
- expect(parsed.inputValidationFailure.reason).toBe('unknown_channels');
345
- expect(parsed.inputValidationFailure.unknownChannels).not.toContain('prompt');
346
- } finally {
347
- logSpy.mockRestore();
348
- errorSpy.mockRestore();
349
- }
350
- });
351
-
352
- it('text mode output shows inputValidationFailure reason, message, nextAction', async () => {
353
- mockRunProvenChannelBaseline.mockResolvedValue({
354
- status: 'failed',
355
- generatedAt: new Date().toISOString(),
356
- workspaceMode: 'temp',
357
- channels: [],
358
- inputValidationFailure: {
359
- reason: 'unknown_channels',
360
- message: 'Unknown channels: bogus. Valid channels: prompt, code_tool_hook, defer_archive',
361
- nextAction: 'Use only valid MVP channels: prompt, code_tool_hook, defer_archive',
362
- unknownChannels: ['bogus'],
363
- },
364
- continuityMatrix: [],
365
- });
366
-
367
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
368
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
369
-
370
- try {
371
- await handleProvenChannelBaseline({ channels: 'bogus' });
372
- const output = logSpy.mock.calls[0]?.[0] ?? '';
373
- expect(output).toContain('Input Validation Failure:');
374
- expect(output).toContain('reason: unknown_channels');
375
- expect(output).toContain('message:');
376
- expect(output).toContain('nextAction:');
377
- } finally {
378
- logSpy.mockRestore();
379
- errorSpy.mockRestore();
380
- }
381
- });
382
-
383
- it('without --channels runs all default MVP channels', async () => {
384
- mockRunProvenChannelBaseline.mockResolvedValue(makePassedSummary());
385
-
386
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
387
-
388
- try {
389
- await handleProvenChannelBaseline({ json: true });
390
- expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
391
- expect.objectContaining({
392
- channels: undefined,
393
- unknownChannels: [],
394
- emptyChannelInput: false,
395
- }),
396
- );
397
- } finally {
398
- logSpy.mockRestore();
399
- }
400
- });
401
-
402
- it('cleanup failure outputs to stderr without polluting JSON stdout', () => {
403
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
404
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
405
-
406
- const failingRmSync = () => { throw new Error('permission denied'); };
407
- cleanupTempWorkspace('/tmp/fake-dir', failingRmSync);
408
-
409
- const errorCalls = errorSpy.mock.calls.map(c => c[0]);
410
- const cleanupWarningSeen = errorCalls.some(c => typeof c === 'string' && c.includes('[pd-cli] cleanup warning'));
411
- expect(cleanupWarningSeen).toBe(true);
412
- expect(logSpy).not.toHaveBeenCalled();
413
-
414
- logSpy.mockRestore();
415
- errorSpy.mockRestore();
416
- });
417
-
418
- it('command is registered in CLI entrypoint as runtime synthetic proven-channel', async () => {
419
- const { Command } = await import('commander');
420
- const program = new Command();
421
- program.exitOverride();
422
-
423
- const { handleProvenChannelBaseline: handler } = await import('../../src/commands/proven-channel-baseline.js');
424
-
425
- const synthCmd = program.command('runtime').command('synthetic');
426
- synthCmd
427
- .command('proven-channel')
428
- .option('-w, --workspace <path>', 'Workspace directory')
429
- .option('--json', 'Output raw JSON')
430
- .option('--channels <channels>', 'Comma-separated channel list')
431
- .action(async (opts) => {
432
- await handler(opts);
433
- });
434
-
435
- const found = program.commands.find(c => c.name() === 'runtime')
436
- ?.commands.find(c => c.name() === 'synthetic')
437
- ?.commands.find(c => c.name() === 'proven-channel');
438
- expect(found).toBeDefined();
439
- expect(found?.name()).toBe('proven-channel');
440
- });
441
- });
@@ -1,177 +0,0 @@
1
- /**
2
- * Tests for rulecode golden-trace path containment (CWE-22).
3
- *
4
- * Covers:
5
- * - Golden trace inside workspace accepted
6
- * - Golden trace outside workspace rejected
7
- * - Sibling-prefix attack (/work/a vs /work/ab) rejected
8
- * - Parent traversal rejected
9
- * - Relative workspace + relative golden trace accepted
10
- * - Empty path rejected
11
- */
12
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
13
- import * as fs from 'fs';
14
- import * as path from 'path';
15
- import os from 'os';
16
- import { loadGoldenTraceCases } from '../../src/commands/rulecode.js';
17
- import { vi } from 'vitest';
18
-
19
- const VALID_CASES = JSON.stringify([
20
- {
21
- caseId: 'c1',
22
- kind: 'positive',
23
- toolName: 'read',
24
- params: {},
25
- expectedDecision: 'allow',
26
- },
27
- {
28
- caseId: 'c2',
29
- kind: 'negative',
30
- toolName: 'read',
31
- params: {},
32
- expectedDecision: 'deny',
33
- },
34
- ]);
35
-
36
- function writeTrace(dir: string, name: string): string {
37
- const p = path.join(dir, name);
38
- fs.mkdirSync(dir, { recursive: true });
39
- fs.writeFileSync(p, VALID_CASES, 'utf8');
40
- return p;
41
- }
42
-
43
- describe('loadGoldenTraceCases containment', () => {
44
- let wsDir: string;
45
- let outsideDir: string;
46
-
47
- beforeEach(() => {
48
- wsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-rulecode-ws-'));
49
- outsideDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-rulecode-out-'));
50
- });
51
-
52
- afterEach(() => {
53
- fs.rmSync(wsDir, { recursive: true, force: true });
54
- fs.rmSync(outsideDir, { recursive: true, force: true });
55
- });
56
-
57
- it('accepts a golden trace inside the workspace', () => {
58
- const trace = writeTrace(path.join(wsDir, 'traces'), 'golden.json');
59
- const result = loadGoldenTraceCases(trace, wsDir);
60
- expect(result.error).toBeUndefined();
61
- expect(result.cases?.length).toBe(2);
62
- });
63
-
64
- it('rejects a golden trace outside the workspace', () => {
65
- const trace = writeTrace(outsideDir, 'golden.json');
66
- const result = loadGoldenTraceCases(trace, wsDir);
67
- expect(result.error).toBeDefined();
68
- expect(result.error?.reason).toContain('must be inside the workspace');
69
- });
70
-
71
- it('rejects sibling-prefix attack (/work/a vs /work/ab)', () => {
72
- // workspace root is /tmp/xxx-a; a sibling /tmp/xxx-ab must NOT be
73
- // considered inside it, even though its string starts with the root.
74
- const parent = wsDir;
75
- const siblingDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-rulecode-sib-'));
76
- // Build a sibling whose path starts with the workspace root string
77
- const trace = writeTrace(siblingDir, 'golden.json');
78
- // Also construct an explicit prefix-collision sibling: same basename + 'x'
79
- const collisionDir = path.join(path.dirname(parent), `${path.basename(parent)}x`);
80
- fs.mkdirSync(collisionDir, { recursive: true });
81
- const collisionTrace = writeTrace(collisionDir, 'golden.json');
82
-
83
- // Sibling with same prefix must be rejected
84
- const result = loadGoldenTraceCases(collisionTrace, parent);
85
- expect(result.error).toBeDefined();
86
- expect(result.error?.reason).toContain('must be inside the workspace');
87
-
88
- // Unrelated sibling also rejected
89
- const result2 = loadGoldenTraceCases(trace, parent);
90
- expect(result2.error).toBeDefined();
91
- });
92
-
93
- it('rejects parent traversal in golden trace path', () => {
94
- const traversal = path.join(wsDir, '..', '..', 'etc', 'passwd');
95
- const result = loadGoldenTraceCases(traversal, wsDir);
96
- expect(result.error).toBeDefined();
97
- });
98
-
99
- it('accepts relative workspace + relative golden trace', () => {
100
- // Regression: both relative; containment must canonicalize consistently.
101
- const relWs = fs.mkdtempSync(path.join(process.cwd(), '.tmp-rulecode-ws-'));
102
- try {
103
- const relTraceDir = path.join(relWs, 'traces');
104
- const absTrace = writeTrace(relTraceDir, 'golden.json');
105
- const relTrace = path.relative(process.cwd(), absTrace);
106
- const relWorkspace = path.relative(process.cwd(), relWs);
107
- expect(path.isAbsolute(relWorkspace)).toBe(false);
108
-
109
- const result = loadGoldenTraceCases(relTrace, relWorkspace);
110
- expect(result.error).toBeUndefined();
111
- expect(result.cases?.length).toBe(2);
112
- } finally {
113
- fs.rmSync(relWs, { recursive: true, force: true });
114
- }
115
- });
116
-
117
- it('rejects empty golden trace path', () => {
118
- const result = loadGoldenTraceCases('', wsDir);
119
- expect(result.error).toBeDefined();
120
- expect(result.error?.reason).toContain('path is empty');
121
- });
122
-
123
- it('rejects filesystem root when no workspace is supplied', () => {
124
- const result = loadGoldenTraceCases(path.parse(wsDir).root);
125
- expect(result.error).toBeDefined();
126
- expect(result.error?.reason).toContain('filesystem root');
127
- });
128
-
129
- it('rejects malformed trace JSON', () => {
130
- const p = writeTrace(wsDir, 'bad.json');
131
- fs.writeFileSync(p, '{not json', 'utf8');
132
- const result = loadGoldenTraceCases(p, wsDir);
133
- expect(result.error).toBeDefined();
134
- expect(result.error?.reason).toContain('not valid JSON');
135
- });
136
- });
137
-
138
-
139
- // ── PRI-634-F R2 (review P2): replay --json carries structured failure ──────
140
-
141
- describe('handleRulecodeReplay — structured failure attribution on --json', () => {
142
- it('a failing replay surfaces {layer, reasonCode, evidence, nextAction} in the JSON output', async () => {
143
- const { handleRulecodeReplay } = await import('../../src/commands/rulecode.js');
144
- const code = [
145
- 'const evaluate = (input) => {',
146
- ' return { decision: "allow", matched: false, reason: "never blocks" };',
147
- '};',
148
- ].join(String.fromCharCode(10));
149
- // The --golden-trace CLI input is a JSON ARRAY of cases (not the
150
- // persisted GoldenTrace envelope) — see loadGoldenTraceCases.
151
- const cases = [
152
- { caseId: 'negative-1', kind: 'negative', toolName: 'write_file', params: { file_path: '/prod.env' }, expectedDecision: 'block' },
153
- { caseId: 'positive-1', kind: 'positive', toolName: 'write_file', params: { file_path: '/repo/a.ts' }, expectedDecision: 'allow' },
154
- ];
155
- const traceDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-replay-'));
156
- const traceFile = path.join(traceDir, 'golden-trace-cases.json');
157
- fs.writeFileSync(traceFile, JSON.stringify(cases), 'utf8');
158
-
159
- const logs: string[] = [];
160
- const spy = vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => { logs.push(String(args[0])); });
161
- try {
162
- await handleRulecodeReplay({ code, goldenTrace: traceFile, json: true });
163
- } finally {
164
- spy.mockRestore();
165
- fs.rmSync(traceDir, { recursive: true, force: true });
166
- }
167
- expect(process.exitCode).toBe(1);
168
- process.exitCode = 0;
169
- const output = JSON.parse(logs[0]);
170
- expect(output.status).toBe('failed');
171
- expect(output.decision).toBe('rejected_validation_failed');
172
- expect(output.failure).toBeDefined();
173
- expect(output.failure.layer).toBe('rule');
174
- expect(output.failure.reasonCode).toBe('replay_decision_mismatch');
175
- expect(typeof output.failure.nextAction).toBe('string');
176
- });
177
- });