@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,95 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import * as path from 'node:path';
3
-
4
- const { mockClose, mockDeactivate, mockWriteGovernanceAction } = vi.hoisted(() => ({
5
- mockClose: vi.fn().mockResolvedValue(undefined),
6
- mockDeactivate: vi.fn().mockResolvedValue(true),
7
- mockWriteGovernanceAction: vi.fn(),
8
- }));
9
-
10
- vi.mock('../../src/resolve-workspace.js', () => ({
11
- resolveWorkspaceDir: vi.fn(() => '/workspace'),
12
- }));
13
-
14
- vi.mock('principles-disciple/governance-audit', () => ({
15
- writeGovernanceAction: mockWriteGovernanceAction,
16
- authorizeGovernanceAction: vi.fn(async (_stateDir, _data, mutation) => mutation()),
17
- }));
18
-
19
- vi.mock('@principles/core/runtime-v2', async (importOriginal) => {
20
- const original = await importOriginal() as Record<string, unknown>;
21
- return {
22
- ...original,
23
- RuntimeStateManager: vi.fn().mockImplementation(function () {
24
- return {
25
- initialize: vi.fn().mockResolvedValue(undefined),
26
- close: mockClose,
27
- connection: {},
28
- };
29
- }),
30
- SqliteActivationStateStore: vi.fn().mockImplementation(function () {
31
- return { deactivateActivation: mockDeactivate };
32
- }),
33
- };
34
- });
35
-
36
- import { handleRuntimeActivationDeactivate } from '../../src/commands/runtime-activation.js';
37
-
38
- beforeEach(() => {
39
- vi.clearAllMocks();
40
- mockDeactivate.mockResolvedValue(true);
41
- process.exitCode = 0;
42
- });
43
-
44
- afterEach(() => {
45
- process.exitCode = 0;
46
- });
47
-
48
- describe('deactivate governance audit ordering (PRI-566)', () => {
49
- it('durably authorizes the canonical audit event before mutating activation state', async () => {
50
- const callOrder: string[] = [];
51
- mockWriteGovernanceAction.mockImplementation(() => { callOrder.push('audit'); });
52
- mockDeactivate.mockImplementation(async () => { callOrder.push('mutation'); return true; });
53
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
54
-
55
- await handleRuntimeActivationDeactivate({
56
- workspace: '/workspace',
57
- activationId: 'act-566',
58
- reasonCode: 'owner_requested_rollback',
59
- json: true,
60
- });
61
-
62
- expect(callOrder).toEqual(['audit', 'mutation']);
63
- expect(mockWriteGovernanceAction).toHaveBeenCalledWith(path.join(path.resolve('/workspace'), '.pd'), {
64
- action: 'deactivate',
65
- activationId: 'act-566',
66
- actor: 'cli',
67
- reasonCode: 'owner_requested_rollback',
68
- outcome: 'authorized',
69
- });
70
- expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({ ok: true, activationId: 'act-566' });
71
- logSpy.mockRestore();
72
- });
73
-
74
- it('refuses without mutation when the audit event cannot be persisted', async () => {
75
- mockWriteGovernanceAction.mockImplementation(() => { throw new Error('disk full'); });
76
- const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
77
-
78
- await handleRuntimeActivationDeactivate({
79
- workspace: '/workspace',
80
- activationId: 'act-566',
81
- reasonCode: 'owner_requested_rollback',
82
- json: true,
83
- });
84
-
85
- expect(mockDeactivate).not.toHaveBeenCalled();
86
- expect(process.exitCode).toBe(1);
87
- expect(logSpy).toHaveBeenCalledTimes(1);
88
- expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({
89
- ok: false,
90
- reason: 'governance_audit_failed: disk full',
91
- nextAction: expect.stringMatching(/retry/i),
92
- });
93
- logSpy.mockRestore();
94
- });
95
- });
@@ -1,193 +0,0 @@
1
- /**
2
- * Parser-level tests for `pd activation list` flags (CLI gate rule 7).
3
- *
4
- * Mirrors `runtime-activation-promote-flag-wiring.test.ts`. Exercises the real
5
- * `registerRuntimeActivationListCommand` helper (single source of truth
6
- * shared with `index.ts`). Flag typos in production surface here at
7
- * parseAsync time, not at handler dispatch.
8
- *
9
- * Covers:
10
- * - --json is registered
11
- * - --workspace / -w and --channel / -c shorthand flags are registered
12
- * - --include-deactivated is registered
13
- * - --dry-run / --confirm / --no-json are NOT registered
14
- *
15
- * Handler-level behavior (filtering, JSON output shape) is covered by
16
- * runtime-activation.test.ts.
17
- */
18
-
19
- import { describe, it, expect } from 'vitest';
20
- import { Command } from 'commander';
21
-
22
- import { registerRuntimeActivationListCommand } from '../../src/commands/runtime-activation.js';
23
-
24
- type ActionOptions = Record<string, unknown>;
25
-
26
- interface CapturedAction {
27
- opts: ActionOptions | null;
28
- }
29
-
30
- function attachCapture(cmd: Command, state: CapturedAction): void {
31
- cmd.action(function captureAction(...args: unknown[]): void {
32
- let optsArg: unknown = null;
33
- for (let i = args.length - 1; i >= 0; i--) {
34
- const arg: unknown = args[i];
35
- if (arg !== null && typeof arg === 'object' && !(arg instanceof Command)) {
36
- optsArg = arg;
37
- break;
38
- }
39
- }
40
- if (optsArg !== null && typeof optsArg === 'object') {
41
- state.opts = optsArg as ActionOptions;
42
- } else {
43
- state.opts = {};
44
- }
45
- });
46
- }
47
-
48
- function freshProgram(): Command {
49
- const program = new Command();
50
- program.name('pd').exitOverride();
51
- return program;
52
- }
53
-
54
- describe('pd activation list — flag wiring (CLI gate rule 7)', () => {
55
- // ── Option metadata ──────────────────────────────────────────────────────
56
-
57
- it('registers --json flag', () => {
58
- const program = freshProgram();
59
- const activationCmd = program.command('activation');
60
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
61
-
62
- const opt = listCmd.options.find((o) => o.long === '--json');
63
- expect(opt).toBeDefined();
64
- expect(opt?.long).toBe('--json');
65
- });
66
-
67
- it('registers -w shorthand for --workspace', () => {
68
- const program = freshProgram();
69
- const activationCmd = program.command('activation');
70
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
71
-
72
- const opt = listCmd.options.find((o) => o.short === '-w');
73
- expect(opt).toBeDefined();
74
- expect(opt?.long).toBe('--workspace');
75
- });
76
-
77
- it('registers -c shorthand for --channel', () => {
78
- const program = freshProgram();
79
- const activationCmd = program.command('activation');
80
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
81
-
82
- const opt = listCmd.options.find((o) => o.short === '-c');
83
- expect(opt).toBeDefined();
84
- expect(opt?.long).toBe('--channel');
85
- });
86
-
87
- it('registers --include-deactivated', () => {
88
- const program = freshProgram();
89
- const activationCmd = program.command('activation');
90
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
91
-
92
- const opt = listCmd.options.find((o) => o.long === '--include-deactivated');
93
- expect(opt).toBeDefined();
94
- expect(opt?.long).toBe('--include-deactivated');
95
- });
96
-
97
- it('does NOT register --dry-run', () => {
98
- const program = freshProgram();
99
- const activationCmd = program.command('activation');
100
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
101
-
102
- const opt = listCmd.options.find((o) => o.long === '--dry-run');
103
- expect(opt).toBeUndefined();
104
- });
105
-
106
- it('does NOT register --confirm', () => {
107
- const program = freshProgram();
108
- const activationCmd = program.command('activation');
109
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
110
-
111
- const opt = listCmd.options.find((o) => o.long === '--confirm');
112
- expect(opt).toBeUndefined();
113
- });
114
-
115
- it('does NOT register --no-json (no accidental negation)', () => {
116
- const program = freshProgram();
117
- const activationCmd = program.command('activation');
118
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
119
-
120
- const noForm = listCmd.options.find((o) => o.long === '--no-json');
121
- expect(noForm).toBeUndefined();
122
- });
123
-
124
- // ── Parser-level tests (program.parseAsync) ───────────────────────────────
125
-
126
- it('parses --json as true', async () => {
127
- const program = freshProgram();
128
- const activationCmd = program.command('activation');
129
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
130
- const captured: CapturedAction = { opts: null };
131
- attachCapture(listCmd, captured);
132
-
133
- await program.parseAsync(['node', 'pd', 'activation', 'list', '--json']);
134
-
135
- expect(captured.opts).not.toBeNull();
136
- expect(captured.opts?.json).toBe(true);
137
- });
138
-
139
- it('parses -w shorthand for --workspace', async () => {
140
- const program = freshProgram();
141
- const activationCmd = program.command('activation');
142
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
143
- const captured: CapturedAction = { opts: null };
144
- attachCapture(listCmd, captured);
145
-
146
- await program.parseAsync(['node', 'pd', 'activation', 'list', '-w', '/tmp/test']);
147
-
148
- expect(captured.opts).not.toBeNull();
149
- expect(captured.opts?.workspace).toBe('/tmp/test');
150
- });
151
-
152
- it('parses -c shorthand for --channel', async () => {
153
- const program = freshProgram();
154
- const activationCmd = program.command('activation');
155
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
156
- const captured: CapturedAction = { opts: null };
157
- attachCapture(listCmd, captured);
158
-
159
- await program.parseAsync(['node', 'pd', 'activation', 'list', '-c', 'prompt']);
160
-
161
- expect(captured.opts).not.toBeNull();
162
- expect(captured.opts?.channel).toBe('prompt');
163
- });
164
-
165
- it('parses --include-deactivated as true', async () => {
166
- const program = freshProgram();
167
- const activationCmd = program.command('activation');
168
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
169
- const captured: CapturedAction = { opts: null };
170
- attachCapture(listCmd, captured);
171
-
172
- await program.parseAsync(['node', 'pd', 'activation', 'list', '--include-deactivated']);
173
-
174
- expect(captured.opts).not.toBeNull();
175
- expect(captured.opts?.includeDeactivated).toBe(true);
176
- });
177
-
178
- it('defaults all flags to undefined when none passed', async () => {
179
- const program = freshProgram();
180
- const activationCmd = program.command('activation');
181
- const listCmd = registerRuntimeActivationListCommand(activationCmd);
182
- const captured: CapturedAction = { opts: null };
183
- attachCapture(listCmd, captured);
184
-
185
- await program.parseAsync(['node', 'pd', 'activation', 'list']);
186
-
187
- expect(captured.opts).not.toBeNull();
188
- expect(captured.opts?.json).toBeUndefined();
189
- expect(captured.opts?.workspace).toBeUndefined();
190
- expect(captured.opts?.channel).toBeUndefined();
191
- expect(captured.opts?.includeDeactivated).toBeUndefined();
192
- });
193
- });
@@ -1,248 +0,0 @@
1
- /**
2
- * Parser-level tests for `pd activation promote` flags (CLI gate rule 7).
3
- *
4
- * Mirrors `run-rulehost-flag-wiring.test.ts`. Exercises the real
5
- * `registerRuntimeActivationPromoteCommand` helper (single source of truth
6
- * shared with `index.ts`). Flag typos in production surface here at
7
- * parseAsync time, not at handler dispatch.
8
- *
9
- * Covers:
10
- * - --dry-run and --confirm are registered
11
- * - --json is registered
12
- * - --activation-id is required (Commander rejects missing required option)
13
- * - --workspace / -w shorthand is registered
14
- * - --no-dry-run / --no-confirm are NOT registered (no accidental negation)
15
- *
16
- * Handler-level behavior (mutual exclusivity enforcement, JSON output shape,
17
- * refusal reasons) is covered by runtime-activation.test.ts.
18
- */
19
-
20
- import { describe, it, expect } from 'vitest';
21
- import { Command } from 'commander';
22
-
23
- import { registerRuntimeActivationPromoteCommand } from '../../src/commands/runtime-activation.js';
24
-
25
- type ActionOptions = Record<string, unknown>;
26
-
27
- interface CapturedAction {
28
- opts: ActionOptions | null;
29
- }
30
-
31
- function attachCapture(cmd: Command, state: CapturedAction): void {
32
- cmd.action(function captureAction(...args: unknown[]): void {
33
- let optsArg: unknown = null;
34
- for (let i = args.length - 1; i >= 0; i--) {
35
- const arg: unknown = args[i];
36
- if (arg !== null && typeof arg === 'object' && !(arg instanceof Command)) {
37
- optsArg = arg;
38
- break;
39
- }
40
- }
41
- if (optsArg !== null && typeof optsArg === 'object') {
42
- state.opts = optsArg as ActionOptions;
43
- } else {
44
- state.opts = {};
45
- }
46
- });
47
- }
48
-
49
- function freshProgram(): Command {
50
- const program = new Command();
51
- program.name('pd').exitOverride();
52
- return program;
53
- }
54
-
55
- describe('pd activation promote — flag wiring (CLI gate rule 7)', () => {
56
- // ── Option metadata ──────────────────────────────────────────────────────
57
-
58
- it('registers --dry-run flag', () => {
59
- const program = freshProgram();
60
- const activationCmd = program.command('activation');
61
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
62
-
63
- const opt = promoteCmd.options.find((o) => o.long === '--dry-run');
64
- expect(opt).toBeDefined();
65
- expect(opt?.long).toBe('--dry-run');
66
- });
67
-
68
- it('registers --confirm flag', () => {
69
- const program = freshProgram();
70
- const activationCmd = program.command('activation');
71
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
72
-
73
- const opt = promoteCmd.options.find((o) => o.long === '--confirm');
74
- expect(opt).toBeDefined();
75
- expect(opt?.long).toBe('--confirm');
76
- });
77
-
78
- it('registers --json flag', () => {
79
- const program = freshProgram();
80
- const activationCmd = program.command('activation');
81
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
82
-
83
- const opt = promoteCmd.options.find((o) => o.long === '--json');
84
- expect(opt).toBeDefined();
85
- expect(opt?.long).toBe('--json');
86
- });
87
-
88
- it.each(['--artifact-id', '--artifact-digest', '--control-version', '--idempotency-key', '--reason', '--note'])(
89
- 'registers Owner authority binding option %s', (flag) => {
90
- const program = freshProgram();
91
- const promoteCmd = registerRuntimeActivationPromoteCommand(program.command('activation'));
92
- expect(promoteCmd.options.find(option => option.long === flag)).toBeDefined();
93
- },
94
- );
95
-
96
- it('registers --activation-id as required option', () => {
97
- const program = freshProgram();
98
- const activationCmd = program.command('activation');
99
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
100
-
101
- const opt = promoteCmd.options.find((o) => o.long === '--activation-id');
102
- expect(opt).toBeDefined();
103
- expect(opt?.long).toBe('--activation-id');
104
- expect(opt?.required).toBe(true);
105
- });
106
-
107
- it('registers -w shorthand for --workspace', () => {
108
- const program = freshProgram();
109
- const activationCmd = program.command('activation');
110
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
111
-
112
- const opt = promoteCmd.options.find((o) => o.short === '-w');
113
- expect(opt).toBeDefined();
114
- expect(opt?.long).toBe('--workspace');
115
- });
116
-
117
- it('does NOT register --no-dry-run (no accidental negation)', () => {
118
- const program = freshProgram();
119
- const activationCmd = program.command('activation');
120
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
121
-
122
- const noForm = promoteCmd.options.find((o) => o.long === '--no-dry-run');
123
- expect(noForm).toBeUndefined();
124
- });
125
-
126
- it('does NOT register --no-confirm (no accidental negation)', () => {
127
- const program = freshProgram();
128
- const activationCmd = program.command('activation');
129
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
130
-
131
- const noForm = promoteCmd.options.find((o) => o.long === '--no-confirm');
132
- expect(noForm).toBeUndefined();
133
- });
134
-
135
- // ── Parser-level tests (program.parseAsync) ───────────────────────────────
136
-
137
- it('parses --dry-run as true', async () => {
138
- const program = freshProgram();
139
- const activationCmd = program.command('activation');
140
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
141
- const captured: CapturedAction = { opts: null };
142
- attachCapture(promoteCmd, captured);
143
-
144
- await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--dry-run']);
145
-
146
- expect(captured.opts).not.toBeNull();
147
- expect(captured.opts?.dryRun).toBe(true);
148
- });
149
-
150
- it('parses --confirm as true', async () => {
151
- const program = freshProgram();
152
- const activationCmd = program.command('activation');
153
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
154
- const captured: CapturedAction = { opts: null };
155
- attachCapture(promoteCmd, captured);
156
-
157
- await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--confirm']);
158
-
159
- expect(captured.opts).not.toBeNull();
160
- expect(captured.opts?.confirm).toBe(true);
161
- });
162
-
163
- it('parses both --dry-run and --confirm (handler enforces mutual exclusivity)', async () => {
164
- // Commander parses both flags; the handler validates mutual exclusivity.
165
- // This test proves the parser accepts both — the handler test in
166
- // runtime-activation.test.ts proves the handler rejects the combination.
167
- const program = freshProgram();
168
- const activationCmd = program.command('activation');
169
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
170
- const captured: CapturedAction = { opts: null };
171
- attachCapture(promoteCmd, captured);
172
-
173
- await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--dry-run', '--confirm']);
174
-
175
- expect(captured.opts).not.toBeNull();
176
- expect(captured.opts?.dryRun).toBe(true);
177
- expect(captured.opts?.confirm).toBe(true);
178
- });
179
-
180
- it('defaults --dry-run and --confirm to undefined when neither is passed', async () => {
181
- const program = freshProgram();
182
- const activationCmd = program.command('activation');
183
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
184
- const captured: CapturedAction = { opts: null };
185
- attachCapture(promoteCmd, captured);
186
-
187
- await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1']);
188
-
189
- expect(captured.opts).not.toBeNull();
190
- expect(captured.opts?.dryRun).toBeUndefined();
191
- expect(captured.opts?.confirm).toBeUndefined();
192
- });
193
-
194
- it('parses --json as true', async () => {
195
- const program = freshProgram();
196
- const activationCmd = program.command('activation');
197
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
198
- const captured: CapturedAction = { opts: null };
199
- attachCapture(promoteCmd, captured);
200
-
201
- await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--json']);
202
-
203
- expect(captured.opts).not.toBeNull();
204
- expect(captured.opts?.json).toBe(true);
205
- });
206
-
207
- it('parses -w shorthand for --workspace', async () => {
208
- const program = freshProgram();
209
- const activationCmd = program.command('activation');
210
- const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
211
- const captured: CapturedAction = { opts: null };
212
- attachCapture(promoteCmd, captured);
213
-
214
- await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '-w', '/tmp/test']);
215
-
216
- expect(captured.opts).not.toBeNull();
217
- expect(captured.opts?.workspace).toBe('/tmp/test');
218
- });
219
-
220
- it('parses all Owner authority binding values through the real command', async () => {
221
- const program = freshProgram();
222
- const promoteCmd = registerRuntimeActivationPromoteCommand(program.command('activation'));
223
- const captured: CapturedAction = { opts: null };
224
- attachCapture(promoteCmd, captured);
225
-
226
- await program.parseAsync([
227
- 'node', 'pd', 'activation', 'promote', '--activation-id', 'act-1',
228
- '--artifact-id', 'art-1', '--artifact-digest', 'sha256:one', '--control-version', '7',
229
- '--idempotency-key', 'idem-1', '--reason', 'owner_review', '--note', 'reviewed', '--confirm',
230
- ]);
231
-
232
- expect(captured.opts).toMatchObject({
233
- artifactId: 'art-1', artifactDigest: 'sha256:one', controlVersion: 7,
234
- idempotencyKey: 'idem-1', reason: 'owner_review', note: 'reviewed', confirm: true,
235
- });
236
- });
237
-
238
- it('rejects missing --activation-id (required option)', async () => {
239
- const program = freshProgram();
240
- const activationCmd = program.command('activation');
241
- registerRuntimeActivationPromoteCommand(activationCmd);
242
-
243
- // Commander should throw on missing required option
244
- await expect(
245
- program.parseAsync(['node', 'pd', 'activation', 'promote', '--dry-run']),
246
- ).rejects.toThrow(/activation-id/);
247
- });
248
- });
@@ -1,130 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import * as fs from 'node:fs';
3
- import * as os from 'node:os';
4
- import * as path from 'node:path';
5
- import {
6
- collectRuleCodeEventEntries,
7
- readShadowSummaryForActivation,
8
- } from '../../src/commands/runtime-activation.js';
9
-
10
- /**
11
- * PRI-577 regression tests — RuleCode shadow telemetry directory mismatch.
12
- *
13
- * Production writes rulehost_evaluated events to `{workspace}/.state/logs/` via the
14
- * v1 EventLog component, while the reader used to scan only `{workspace}/.pd/logs/`
15
- * (a directory no production code ever creates). These tests pin the real-world
16
- * directory layout so a future refactor cannot silently re-break the channel.
17
- */
18
-
19
- const ACTIVATION_ID = 'act_code_test-rule';
20
-
21
- function makeEventLine(eventOverrides: Record<string, unknown> = {}, dataOverrides: Record<string, unknown> = {}): string {
22
- return JSON.stringify({
23
- ts: '2026-08-21T00:47:00.469Z',
24
- type: 'rulehost_evaluated',
25
- category: 'evaluated',
26
- data: {
27
- toolName: 'write_file',
28
- filePath: '<redacted>',
29
- matched: true,
30
- decision: 'block',
31
- ruleId: 'rule-1',
32
- activationId: ACTIVATION_ID,
33
- activationMode: 'shadow',
34
- ...dataOverrides,
35
- },
36
- ...eventOverrides,
37
- });
38
- }
39
-
40
- describe('PRI-577 shadow telemetry dual-directory reading', () => {
41
- let workspaceDir: string;
42
-
43
- beforeEach(() => {
44
- workspaceDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pri577-ws-'));
45
- });
46
-
47
- afterEach(() => {
48
- fs.rmSync(workspaceDir, { recursive: true, force: true });
49
- });
50
-
51
- function writeEventsFile(relLogsDir: string, date: string, lines: string[]): void {
52
- const dir = path.join(workspaceDir, ...relLogsDir.split('/'));
53
- fs.mkdirSync(dir, { recursive: true });
54
- fs.writeFileSync(path.join(dir, `events_${date}.jsonl`), lines.join('\n') + '\n', 'utf8');
55
- }
56
-
57
- it('reads shadow metrics when events live only in legacy .state/logs (production layout)', () => {
58
- writeEventsFile('.state/logs', '2026-08-21', [
59
- makeEventLine(),
60
- makeEventLine({}, { toolName: 'exec', filePath: 'x', matched: false, decision: 'allow' }),
61
- ]);
62
-
63
- const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
64
- expect(summary.observed).toBe(2);
65
- expect(summary.matched).toBe(1);
66
- expect(summary.wouldBlock).toBe(1);
67
- expect(summary.firstObservedAt).not.toBeNull();
68
- });
69
-
70
- it('merges entries when both .pd/logs and .state/logs exist', () => {
71
- writeEventsFile('.state/logs', '2026-08-21', [makeEventLine()]);
72
- writeEventsFile('.pd/logs', '2026-08-22', [
73
- makeEventLine({ ts: '2026-08-22T10:00:00.000Z' }),
74
- ]);
75
- const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
76
- expect(summary.observed).toBe(2);
77
- expect(summary.lastObservedAt).toBe('2026-08-22T10:00:00.000Z');
78
- });
79
-
80
- it('keeps distinct events from same-named daily files and deduplicates exact copied lines', () => {
81
- const copied = makeEventLine();
82
- writeEventsFile('.state/logs', '2026-08-21', [
83
- copied,
84
- makeEventLine({}, { toolName: 'exec', filePath: 'x', matched: false, decision: 'allow' }),
85
- ]);
86
- writeEventsFile('.pd/logs', '2026-08-21', [copied]);
87
-
88
- const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
89
- expect(summary.observed).toBe(2);
90
- expect(summary.wouldAllow).toBe(1);
91
- });
92
-
93
- it('reports zero (not unavailable) when a log dir exists but has no matching events', () => {
94
- writeEventsFile('.state/logs', '2026-08-21', [
95
- JSON.stringify({ ts: '2026-08-21T00:00:00.000Z', type: 'other_event', category: 'x', data: {} }),
96
- ]);
97
-
98
- const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
99
- // Distinguishes "channel alive, no data" (zeros) from "no channel" (nulls).
100
- expect(summary.observed).toBe(0);
101
- expect(summary.matched).toBe(0);
102
- });
103
-
104
- it('returns unavailable summary only when neither candidate directory exists', () => {
105
- const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
106
- expect(summary).toEqual({
107
- observed: null, matched: null, wouldBlock: null, wouldAllow: null,
108
- requireApproval: null, autoCorrect: null, errors: null, neutralControl: null,
109
- firstObservedAt: null, lastObservedAt: null,
110
- });
111
- });
112
-
113
- it('does not report an unreadable candidate path as a healthy zero-event channel', () => {
114
- fs.mkdirSync(path.join(workspaceDir, '.state'), { recursive: true });
115
- fs.writeFileSync(path.join(workspaceDir, '.state', 'logs'), 'not a directory');
116
- const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
117
- expect(summary.observed).toBeNull();
118
- });
119
-
120
- it('excludes malformed telemetry lines instead of failing the whole scan', () => {
121
- writeEventsFile('.state/logs', '2026-08-21', [
122
- '{not-valid-json',
123
- makeEventLine(),
124
- ]);
125
-
126
- const collected = collectRuleCodeEventEntries(workspaceDir);
127
- expect(collected.entries.length).toBe(1);
128
- expect(collected.sourceDirsFound).toBeGreaterThanOrEqual(1);
129
- });
130
- });