@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,299 +0,0 @@
1
- import { afterEach, beforeEach, expect, vi } from 'vitest';
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import * as yaml from 'js-yaml';
6
- import { getDefaultPdConfig } from '@principles/core/runtime-v2';
7
- import { catchUpCodexIngestion } from '@principles/codex-adapter';
8
- import {
9
- ingestGovernanceObservations,
10
- listGovernanceObservations,
11
- promoteGovernanceEvidence,
12
- readCodexIngestionConsent,
13
- CODEX_INGESTION_DISCLOSURE_VERSION,
14
- } from '@principles/host-runtime';
15
- import { createStepRegistry, defineFeature } from '../../../principles-core/tests/bdd/support/vitest-bdd.js';
16
- import { resolveFeaturePath } from '../../../principles-core/tests/bdd/support/repo-root.js';
17
-
18
- /**
19
- * Codex Governance Closure Slice D (PRI-625): consent & reversibility BDD
20
- * steps for SPEC rev 2 §18 scenarios 17 and 15 (flag-off half). Drives the
21
- * REAL setup handler (the installed-path consent authority) and the REAL
22
- * catch-up/consent/evidence seams. The uninstall/legacy-migration half of
23
- * §18-15 is bound in create-principles-disciple's installer suites.
24
- *
25
- * R1 behaviors proven here (SPEC §3):
26
- * R1-1 the disclosure is presented before ingestion can be enabled;
27
- * R1-2 declining leaves the flag off and governance working unchanged;
28
- * R1-3 declining never opens or reads the transcript;
29
- * R1-4 upgrade/machine paths never enable ingestion implicitly.
30
- */
31
-
32
- let logLines: string[];
33
-
34
- /** Guarded path builder: only allowlisted basenames under <root>/.pd. */
35
- function pdFile(root: string, name: string): string | null {
36
- if (!FILENAME_ALLOWLIST.includes(name)) return null;
37
- const base = path.join(root, '.pd');
38
- const target = path.join(base, name);
39
- if (!target.startsWith(base + path.sep)) return null;
40
- return target;
41
- }
42
-
43
- const FILENAME_ALLOWLIST = ['config.yaml', 'codex-ingestion-consent.json'];
44
-
45
- function makeWorkspace(options: { handEnableIngestion?: boolean } = {}): string {
46
- const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-bdd-consent-'));
47
- fs.mkdirSync(path.join(ws, '.pd'), { recursive: true });
48
- fs.mkdirSync(path.join(ws, '.state'), { recursive: true });
49
- fs.writeFileSync(path.join(ws, '.state', 'trajectory.db'), '');
50
- const config = getDefaultPdConfig();
51
- config.features['host.codex'].enabled = true;
52
- if (options.handEnableIngestion) {
53
- config.features['codex_conversation_ingestion'].enabled = true;
54
- }
55
- // Multi-line YAML dump: the line-targeted editor needs a `features:` line.
56
- fs.writeFileSync(path.join(ws, '.pd', 'config.yaml'), yaml.dump(config, { indent: 2, lineWidth: 200, noRefs: true }));
57
- return ws;
58
- }
59
-
60
- /** Snapshot the fixed, allowlisted file set a consent run may touch. */
61
- function snapshot(root: string): Map<string, string> {
62
- const files = new Map<string, string>();
63
- for (const name of FILENAME_ALLOWLIST) {
64
- const full = pdFile(root, name);
65
- if (full === null) continue;
66
- // Read first, no stat-then-read window (CodeQL FS race): ENOENT simply
67
- // means the file is absent for this snapshot.
68
- try {
69
- files.set(full, fs.readFileSync(full, 'utf8'));
70
- } catch {
71
- // absent file — snapshot stays empty for it
72
- }
73
- }
74
- return files;
75
- }
76
-
77
- async function runSetup(options: Record<string, unknown>): Promise<Record<string, unknown>> {
78
- const { handleCodexSetup } = await import('../../src/commands/codex-setup.js');
79
- const captured: string[] = [];
80
- // Install the capture INSIDE the step: defineFeature-created tests may not
81
- // see file-level console/stdout spies reliably, and the capture must wrap
82
- // exactly the handler call.
83
- const logSpy = vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
84
- captured.push(args.map(String).join(' '));
85
- });
86
- const outSpy = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown) => {
87
- captured.push(String(chunk));
88
- return true;
89
- }) as typeof process.stdout.write);
90
- try {
91
- await handleCodexSetup({ ...options, json: options.json === true } as never);
92
- } finally {
93
- logSpy.mockRestore();
94
- outSpy.mockRestore();
95
- }
96
- logLines.push(...captured);
97
- const jsonLine = captured.reverse().find((line) => line.startsWith('{'));
98
- if (jsonLine === undefined) return {};
99
- try {
100
- return JSON.parse(jsonLine) as Record<string, unknown>;
101
- } catch {
102
- return {};
103
- }
104
- }
105
-
106
- beforeEach(() => {
107
- logLines = [];
108
- vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
109
- logLines.push(args.map(String).join(' '));
110
- });
111
- vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown) => {
112
- logLines.push(String(chunk));
113
- return true;
114
- }) as typeof process.stdout.write);
115
- });
116
-
117
- afterEach(() => {
118
- vi.restoreAllMocks();
119
- process.exitCode = undefined;
120
- });
121
-
122
- const registry = createStepRegistry();
123
- let ws: string;
124
- let beforeFiles: Map<string, string>;
125
-
126
- registry.given('an isolated Codex Workspace without a consent record', () => {
127
- ws = makeWorkspace();
128
- beforeFiles = snapshot(ws);
129
- });
130
-
131
- registry.given('an isolated Codex Workspace with the ingestion flag hand-enabled and no consent record', () => {
132
- ws = makeWorkspace({ handEnableIngestion: true });
133
- beforeFiles = snapshot(ws);
134
- });
135
-
136
- registry.when('setup presents the ingestion disclosure', async () => {
137
- await runSetup({ workspace: ws, showDisclosure: true });
138
- });
139
-
140
- registry.then('the frozen Chinese text is shown verbatim with the version of the approved decision package', () => {
141
- const output = logLines.join('\n');
142
- expect(output, `captured=${JSON.stringify(logLines).slice(0, 200)}`).toContain('### Principles Disciple — 对话观察与治理闭环(Codex)');
143
- expect(output).toContain('默认关闭。只有你在看到本说明后明确选择开启才会生效;升级 PD 永远不会替你开启。');
144
- expect(CODEX_INGESTION_DISCLOSURE_VERSION).toBe('g2a-2026-08-28');
145
- const read = readCodexIngestionConsent(ws);
146
- expect(read.ok && read.record).toBeNull();
147
- });
148
-
149
- registry.when('the Owner explicitly accepts after the disclosure', async () => {
150
- // The disclosure was presented first (R1-1 ordering): show, then accept.
151
- await runSetup({ workspace: ws, showDisclosure: true });
152
- const report = await runSetup({ workspace: ws, accept: true, json: true });
153
- expect(report.status, JSON.stringify(report)).toBe('ok');
154
- });
155
-
156
- registry.then('the consent record exists with the granted decision and the ingestion flag is enabled', () => {
157
- const read = readCodexIngestionConsent(ws);
158
- expect(read.ok && read.record?.decision).toBe('granted');
159
- if (read.ok && read.record) {
160
- expect(read.record.disclosureVersion).toBe(CODEX_INGESTION_DISCLOSURE_VERSION);
161
- expect(read.record.decidedVia).toBe('pd_codex_setup');
162
- }
163
- const config = pdFile(ws, 'config.yaml');
164
- expect(config).not.toBeNull();
165
- if (config !== null) {
166
- expect(fs.readFileSync(config, 'utf8')).toContain('enabled: true');
167
- }
168
- });
169
-
170
- registry.then('no config outside the workspace consent flow was modified', () => {
171
- // The consent flow touches exactly two files: config.yaml and the consent
172
- // record (the allowlisted snapshot). New files may only be the consent
173
- // record; every pre-existing file may only be the config.yaml flip.
174
- const after = snapshot(ws);
175
- for (const [file, content] of beforeFiles) {
176
- if (file.endsWith('config.yaml')) continue; // the flag flip is the point
177
- expect(after.get(file) ?? '', `unexpected change: ${file}`).toBe(content);
178
- }
179
- const consentPath = path.join(ws, '.pd', 'codex-ingestion-consent.json');
180
- expect(after.has(consentPath), 'the consent record must be the only new file').toBe(true);
181
- });
182
-
183
- registry.when('the Owner explicitly declines', async () => {
184
- const report = await runSetup({ workspace: ws, decline: true, json: true });
185
- expect(report.status).toBe('ok');
186
- expect(report.decision).toBe('revoked');
187
- });
188
-
189
- registry.then('the consent record exists with the declined decision and the ingestion flag is off', () => {
190
- const read = readCodexIngestionConsent(ws);
191
- expect(read.ok && read.record?.decision).toBe('revoked');
192
- const config = pdFile(ws, 'config.yaml');
193
- expect(config).not.toBeNull();
194
- if (config !== null) {
195
- const content = fs.readFileSync(config, 'utf8');
196
- expect(content).toContain('codex_conversation_ingestion:');
197
- expect(content).toContain('enabled: false');
198
- }
199
- });
200
-
201
- registry.then('no transcript was opened by the decline', () => {
202
- // The decline only rewrites the two allowlisted .pd files; the handler has
203
- // no transcript argument and no Codex-home FS surface. (The CODEX_HOME env
204
- // assertion was removed in review round 3: it depends on the developer's
205
- // machine environment, not on the behavior under test.)
206
- expect(readCodexIngestionConsent(ws).ok && readCodexIngestionConsent(ws).record?.decision).toBe('revoked');
207
- });
208
-
209
- registry.when('setup runs in machine mode without an explicit accept or decline', async () => {
210
- const report = await runSetup({ workspace: ws, json: true });
211
- expect(report.reason).toBe('decision_required');
212
- });
213
-
214
- registry.then('nothing is recorded and nothing is enabled', () => {
215
- expect(readCodexIngestionConsent(ws).ok && readCodexIngestionConsent(ws).record).toBeNull();
216
- const after = snapshot(ws);
217
- for (const [file, content] of beforeFiles) {
218
- expect(after.get(file) ?? '').toBe(content);
219
- }
220
- });
221
-
222
- // ── §18-15 flag-off reversibility ─────────────────────────────────────────────
223
-
224
- registry.given('an isolated Codex Workspace with conversation ingestion enabled and evidence recorded', () => {
225
- ws = makeWorkspace({ handEnableIngestion: true });
226
- const now = new Date();
227
- const seeded = ingestGovernanceObservations({
228
- workspaceDir: ws,
229
- now,
230
- observations: [{
231
- hostKind: 'codex', rolloutIdentity: 'r-evidence', rootSessionId: 'root-evidence',
232
- hostTurnId: 't1', kind: 'user_turn', logicalObservationKey: 'codex|r-evidence|t1|user',
233
- source: 'transcript', completeness: 'complete', observedAt: now.toISOString(),
234
- recordByteStart: 100, recordOrdinal: 1, visibleText: 'owner correction evidence',
235
- }],
236
- });
237
- expect(seeded.ok).toBe(true);
238
- });
239
-
240
- registry.when('the ingestion flag is turned off', async () => {
241
- const report = await runSetup({ workspace: ws, decline: true, json: true });
242
- expect(report.status).toBe('ok');
243
- });
244
-
245
- registry.then('catch-up reports feature_disabled with zero transcript reads', async () => {
246
- const result = await catchUpCodexIngestion({ workspaceDir: ws });
247
- expect(result.status).toBe('skipped');
248
- if (result.status === 'skipped') {
249
- expect(result.reason).toBe('feature_disabled');
250
- expect(result.nextAction).toContain('codex_conversation_ingestion');
251
- }
252
- });
253
-
254
- registry.then('previously promoted evidence remains intact', async () => {
255
- const promotion = promoteGovernanceEvidence({
256
- workspaceDir: ws, hostKind: 'codex', rolloutIdentity: 'r-evidence',
257
- triggerLogicalKey: 'codex|r-evidence|t1|user', painRef: 'pain_reversibility_1',
258
- });
259
- expect(promotion.ok).toBe(true);
260
- const listed = listGovernanceObservations({ workspaceDir: ws });
261
- expect(listed.ok).toBe(true);
262
- if (!listed.ok) return;
263
- expect(listed.observations.find((row) => row.logicalKey === 'codex|r-evidence|t1|user')?.retentionClass).toBe('promoted');
264
- });
265
-
266
- // ── §18-15 / R1-4: the upgrade path never enables ingestion ──────────────────
267
-
268
- registry.given('an isolated Codex Workspace where the Owner declined ingestion', async () => {
269
- ws = makeWorkspace();
270
- const report = await runSetup({ workspace: ws, decline: true, json: true });
271
- expect(report.status).toBe('ok');
272
- expect(report.decision).toBe('revoked');
273
- });
274
-
275
- registry.when('the production runtime initializer re-runs over the workspace', async () => {
276
- // `pd runtime init` is the upgrade/re-init entry over an existing workspace.
277
- const { handleRuntimeInit } = await import('../../src/commands/runtime-init.js');
278
- const captured: string[] = [];
279
- const logSpy = vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
280
- captured.push(args.map(String).join(' '));
281
- });
282
- try {
283
- await handleRuntimeInit({ workspace: ws, confirm: true, json: true });
284
- } finally {
285
- logSpy.mockRestore();
286
- }
287
- void captured;
288
- });
289
-
290
- registry.then('the ingestion flag is still off and the declined consent record is untouched', () => {
291
- const read = readCodexIngestionConsent(ws);
292
- expect(read.ok && read.record?.decision).toBe('revoked');
293
- const config = fs.readFileSync(path.join(ws, '.pd', 'config.yaml'), 'utf8');
294
- expect(config).toContain('codex_conversation_ingestion:');
295
- expect(config).toContain('enabled: false');
296
- expect(config).not.toMatch(/codex_conversation_ingestion:[\s\S]{0,40}enabled: true/);
297
- });
298
-
299
- defineFeature(fs.readFileSync(resolveFeaturePath('docs/specs/features/codex-governance/codex-consent-reversibility.feature'), 'utf8'), registry);
@@ -1,136 +0,0 @@
1
- /**
2
- * pd codex ingest quarantine command tests (Slice D, SPEC §15).
3
- *
4
- * Functional, real-filesystem: seeds a workspace trajectory.db through the
5
- * production store, then exercises the handler. Proven:
6
- * - dry run is the DEFAULT: --json reports dryRun=true and the record row is
7
- * untouched;
8
- * - --confirm quarantines (row becomes terminal, bodies dropped);
9
- * - missing/invalid flags are refused with reason + nextAction, exit 1, and
10
- * mutate nothing (cli-5);
11
- * - --json emits exactly one parseable object (cli-1).
12
- */
13
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
14
- import fs from 'node:fs';
15
- import os from 'node:os';
16
- import path from 'node:path';
17
- import { getDefaultPdConfig } from '@principles/core/runtime-v2';
18
- import { ingestGovernanceObservations, listGovernanceObservations } from '@principles/host-runtime';
19
-
20
- let workspaceDir: string;
21
- let corruptRecordId = 0;
22
- let logSpy: ReturnType<typeof vi.spyOn>;
23
- let savedExitCode: number | undefined;
24
-
25
- beforeEach(() => {
26
- workspaceDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-cli-quarantine-'));
27
- fs.mkdirSync(path.join(workspaceDir, '.pd'), { recursive: true });
28
- fs.mkdirSync(path.join(workspaceDir, '.state'), { recursive: true });
29
- fs.writeFileSync(path.join(workspaceDir, '.state', 'trajectory.db'), '');
30
- const config = getDefaultPdConfig();
31
- config.features['host.codex'].enabled = true;
32
- config.features.codex_conversation_ingestion.enabled = true;
33
- fs.writeFileSync(path.join(workspaceDir, '.pd', 'config.yaml'), JSON.stringify(config));
34
- const now = new Date('2026-08-29T12:00:00.000Z');
35
- const seeded = ingestGovernanceObservations({
36
- workspaceDir,
37
- now,
38
- observations: [
39
- { hostKind: 'codex', rolloutIdentity: 'rollout-uuid-1', rootSessionId: 'root-1', hostTurnId: 't1', kind: 'user_turn', logicalObservationKey: 'codex|rollout-uuid-1|t1|user', source: 'transcript', completeness: 'complete', observedAt: now.toISOString(), recordByteStart: 100, recordOrdinal: 1, visibleText: 'first' },
40
- { hostKind: 'codex', rolloutIdentity: 'rollout-uuid-1', rootSessionId: 'root-1', hostTurnId: 't2', kind: 'user_turn', logicalObservationKey: 'codex|rollout-uuid-1|t2|user', source: 'transcript', completeness: 'partial', observedAt: now.toISOString(), recordByteStart: 300, recordOrdinal: 3, visibleText: 'corrupt record' },
41
- ],
42
- });
43
- expect(seeded.ok, JSON.stringify(seeded)).toBe(true);
44
- const listed = listGovernanceObservations({ workspaceDir });
45
- expect(listed.ok).toBe(true);
46
- if (!listed.ok) throw new Error('unreachable');
47
- const corrupt = listed.observations.find((row) => row.logicalKey === 'codex|rollout-uuid-1|t2|user');
48
- expect(corrupt).toBeDefined();
49
- corruptRecordId = corrupt.id;
50
-
51
- savedExitCode = process.exitCode;
52
- process.exitCode = undefined;
53
- logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
54
- });
55
-
56
- afterEach(() => {
57
- logSpy.mockRestore();
58
- process.exitCode = savedExitCode;
59
- fs.rmSync(workspaceDir, { recursive: true, force: true });
60
- });
61
-
62
- function findRecord(): { retentionClass: string; visibleText: string | null } {
63
- const listed = listGovernanceObservations({ workspaceDir });
64
- if (!listed.ok) throw new Error('list failed');
65
- const row = listed.observations.find((entry) => entry.id === corruptRecordId);
66
- if (!row) throw new Error('record vanished');
67
- return row;
68
- }
69
-
70
- async function run(options: Record<string, unknown>): Promise<Record<string, unknown>> {
71
- const { handleCodexIngestQuarantine } = await import('../../src/commands/codex-ingest-quarantine.js');
72
- const callsBefore = logSpy.mock.calls.length;
73
- await handleCodexIngestQuarantine({ workspace: workspaceDir, ...options } as never);
74
- const newOutput = logSpy.mock.calls.slice(callsBefore).map((call) => String(call[0]));
75
- const jsonLine = newOutput.reverse().find((line) => line.startsWith('{'));
76
- expect(jsonLine, 'handler must emit exactly one JSON object for --json').toBeDefined();
77
- return JSON.parse(jsonLine as string) as Record<string, unknown>;
78
- }
79
-
80
- describe('pd codex ingest quarantine (functional)', () => {
81
- it('dry run is the default: reports digest/gap, mutates nothing, exits 0', { timeout: 20_000 }, async () => {
82
- const report = await run({ rollout: 'rollout-uuid-1', record: String(corruptRecordId), reason: 'stable-invalid', json: true });
83
- expect(report.status).toBe('ok');
84
- expect(report.dryRun).toBe(true);
85
- expect(report.confirmed).toBe(false);
86
- expect(report.transcriptTouched).toBe(false);
87
- const record = report.record as { digest: string; gap: string; id: number };
88
- expect(record.id).toBe(corruptRecordId);
89
- expect(record.digest).toMatch(/^[0-9a-f]{64}$/);
90
- expect(record.gap).toContain('prev=');
91
- expect(findRecord().retentionClass).toBe('operational');
92
- expect(process.exitCode ?? 0).toBe(0);
93
- });
94
-
95
- it('--confirm quarantines the record; a repeat is idempotent', { timeout: 20_000 }, async () => {
96
- const report = await run({ rollout: 'rollout-uuid-1', record: String(corruptRecordId), reason: 'stable-invalid', operator: 'tester', confirm: true, json: true });
97
- expect(report.dryRun).toBe(false);
98
- expect(report.alreadyQuarantined).toBe(false);
99
- expect(findRecord().retentionClass).toBe('quarantined');
100
- expect(findRecord().visibleText).toBeNull();
101
-
102
- const repeat = await run({ rollout: 'rollout-uuid-1', record: String(corruptRecordId), reason: 'stable-invalid', confirm: true, json: true });
103
- expect(repeat.alreadyQuarantined).toBe(true);
104
- });
105
-
106
- it('refuses invalid arguments with reason+nextAction and no mutation (cli-5/cli-6)', { timeout: 30_000 }, async () => {
107
- // Case table is built INSIDE the test so record ids reference the row
108
- // seeded in beforeEach (an it.each table would evaluate before seeding).
109
- const cases: [Record<string, unknown>, string][] = [
110
- [{ reason: 'x' }, 'rollout_required'],
111
- [{ rollout: 'rollout-uuid-1', reason: 'x' }, 'record_required'],
112
- [{ rollout: 'rollout-uuid-1', record: 'abc' }, 'record_required'],
113
- [{ rollout: 'rollout-uuid-1', record: String(corruptRecordId) }, 'reason_required'],
114
- [{ rollout: 'unknown-rollout', record: String(corruptRecordId), reason: 'x' }, 'rollout_not_found'],
115
- ];
116
- for (const [options, expectedReason] of cases) {
117
- process.exitCode = undefined;
118
- const report = await run({ ...options, json: true });
119
- expect(report.status, JSON.stringify({ options, report })).toBe('refused');
120
- expect(report.reason).toBe(expectedReason);
121
- expect(String(report.nextAction).length).toBeGreaterThan(0);
122
- expect(process.exitCode).toBe(1);
123
- expect(findRecord().retentionClass, String(expectedReason)).toBe('operational');
124
- }
125
- });
126
-
127
- it('text output includes the dry-run next action', { timeout: 20_000 }, async () => {
128
- const { handleCodexIngestQuarantine } = await import('../../src/commands/codex-ingest-quarantine.js');
129
- await handleCodexIngestQuarantine({ workspace: workspaceDir, rollout: 'rollout-uuid-1', record: String(corruptRecordId), reason: 'stable-invalid' });
130
- const output = logSpy.mock.calls.map((call) => String(call[0])).join('\n');
131
- expect(output).toContain('dry-run');
132
- expect(output).toContain('digest:');
133
- expect(output).toContain('--confirm');
134
- expect(process.exitCode ?? 0).toBe(0);
135
- });
136
- });