@principles/pd-cli 1.152.12 → 1.152.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -7
- package/CHANGELOG.md +0 -23
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
- package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
- package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
- package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
- package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
- package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
- package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
- package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/version.test.d.ts +0 -2
- package/dist/commands/__tests__/version.test.d.ts.map +0 -1
- package/dist/commands/__tests__/version.test.js +0 -238
- package/dist/commands/__tests__/version.test.js.map +0 -1
- package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
- package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
- package/dist/commands/runtime-uat.guard.test.js +0 -153
- package/dist/commands/runtime-uat.guard.test.js.map +0 -1
- package/dist/services/__tests__/cli-output.test.d.ts +0 -18
- package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
- package/dist/services/__tests__/cli-output.test.js +0 -103
- package/dist/services/__tests__/cli-output.test.js.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
- package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
- package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
- package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
- package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
- package/dist/utils/production-workspace-guard.test.d.ts +0 -2
- package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
- package/dist/utils/production-workspace-guard.test.js +0 -137
- package/dist/utils/production-workspace-guard.test.js.map +0 -1
- package/scripts/llm-dogfood.ts +0 -456
- package/scripts/migrate-illegal-expected-decision.ts +0 -252
- package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
- package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
- package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
- package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
- package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
- package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
- package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
- package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
- package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
- package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
- package/src/commands/__tests__/version.test.ts +0 -251
- package/src/commands/admission-gate.ts +0 -30
- package/src/commands/artifact.ts +0 -82
- package/src/commands/build-trajectory-evidence.ts +0 -298
- package/src/commands/candidate.ts +0 -1250
- package/src/commands/codex-ingest-catchup.ts +0 -114
- package/src/commands/codex-ingest-quarantine.ts +0 -127
- package/src/commands/codex-reconcile.ts +0 -84
- package/src/commands/codex-setup.ts +0 -476
- package/src/commands/codex-worker.ts +0 -185
- package/src/commands/command-helpers.ts +0 -24
- package/src/commands/config-doctor.ts +0 -193
- package/src/commands/console.ts +0 -797
- package/src/commands/context.ts +0 -72
- package/src/commands/demo-story-a.ts +0 -241
- package/src/commands/diagnose.ts +0 -756
- package/src/commands/errors-list.ts +0 -441
- package/src/commands/evolution-tasks-list.ts +0 -48
- package/src/commands/evolution-tasks-show.ts +0 -62
- package/src/commands/flow.ts +0 -60
- package/src/commands/health-codex.ts +0 -576
- package/src/commands/health.ts +0 -315
- package/src/commands/history.ts +0 -63
- package/src/commands/intent.ts +0 -457
- package/src/commands/legacy-cleanup.ts +0 -531
- package/src/commands/legacy-import.ts +0 -104
- package/src/commands/mvp-smoke.ts +0 -160
- package/src/commands/pain-evidence.ts +0 -226
- package/src/commands/pain-list.ts +0 -239
- package/src/commands/pain-record.ts +0 -612
- package/src/commands/pain-retry.ts +0 -916
- package/src/commands/principles-stats.ts +0 -700
- package/src/commands/proven-channel-baseline.ts +0 -115
- package/src/commands/quality-scorecard.ts +0 -272
- package/src/commands/remediation-output.ts +0 -66
- package/src/commands/rulecode.ts +0 -465
- package/src/commands/run.ts +0 -89
- package/src/commands/runtime-activation.ts +0 -1629
- package/src/commands/runtime-artifact-repair.ts +0 -524
- package/src/commands/runtime-canary.ts +0 -395
- package/src/commands/runtime-compatibility-scan.ts +0 -105
- package/src/commands/runtime-diagnostics-export.ts +0 -229
- package/src/commands/runtime-features.ts +0 -153
- package/src/commands/runtime-gfi-snapshot.ts +0 -135
- package/src/commands/runtime-health-snapshot.ts +0 -108
- package/src/commands/runtime-init.ts +0 -429
- package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
- package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
- package/src/commands/runtime-internalization-integrity.ts +0 -107
- package/src/commands/runtime-internalization-queue.ts +0 -135
- package/src/commands/runtime-internalization-retry.ts +0 -191
- package/src/commands/runtime-internalization-run-once.ts +0 -791
- package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
- package/src/commands/runtime-internalization-wake-once.ts +0 -87
- package/src/commands/runtime-pain-flood-simulation.ts +0 -121
- package/src/commands/runtime-pruning.ts +0 -438
- package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
- package/src/commands/runtime-recovery.ts +0 -109
- package/src/commands/runtime-synthetic-baseline.ts +0 -70
- package/src/commands/runtime-uat.guard.test.ts +0 -175
- package/src/commands/runtime-uat.ts +0 -380
- package/src/commands/runtime.ts +0 -473
- package/src/commands/samples-list.ts +0 -39
- package/src/commands/samples-review.ts +0 -36
- package/src/commands/task.ts +0 -271
- package/src/commands/telemetry.ts +0 -349
- package/src/commands/trace.ts +0 -174
- package/src/commands/trajectory-db-unavailable.ts +0 -19
- package/src/commands/trajectory.ts +0 -64
- package/src/commands/version.ts +0 -49
- package/src/config-reader.ts +0 -122
- package/src/index.ts +0 -1276
- package/src/legacy/legacy-import.ts +0 -179
- package/src/legacy/session-history-import.ts +0 -203
- package/src/resolve-workspace.ts +0 -106
- package/src/services/__tests__/cli-output.test.ts +0 -130
- package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
- package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
- package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
- package/src/services/cli-output.ts +0 -95
- package/src/services/config-doctor.ts +0 -697
- package/src/services/console-launcher.ts +0 -537
- package/src/services/demo-rule-compiler.ts +0 -40
- package/src/services/demo-story-a-runner.ts +0 -471
- package/src/services/mainline-snapshot-assembler.ts +0 -579
- package/src/services/pain-flood-simulation-runner.ts +0 -462
- package/src/services/pd-config-loader.ts +0 -433
- package/src/services/proven-channel-baseline-runner.ts +0 -157
- package/src/services/quality-scorecard/data-extractor.ts +0 -150
- package/src/services/quality-scorecard/local-evaluator.ts +0 -142
- package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
- package/src/services/resolve-runtime-from-pd-config.ts +0 -230
- package/src/services/rulehost-pipeline-runner.ts +0 -1214
- package/src/services/rulehost-readiness.ts +0 -326
- package/src/services/runtime-adapter-resolver.ts +0 -364
- package/src/services/synthetic-baseline-runner.ts +0 -400
- package/src/services/version-report.ts +0 -253
- package/src/services/workspace-tool-semantics.ts +0 -26
- package/src/utils/path-security.ts +0 -96
- package/src/utils/production-workspace-guard.test.ts +0 -157
- package/src/utils/production-workspace-guard.ts +0 -210
- package/tests/bdd/cli-contract.steps.ts +0 -346
- package/tests/bdd/principles-stats.steps.ts +0 -211
- package/tests/bdd/support/gherkin-loader.ts +0 -147
- package/tests/bdd/support/repo-root.ts +0 -62
- package/tests/bdd/support/vitest-bdd.ts +0 -179
- package/tests/commands/admission-gate-coverage.test.ts +0 -79
- package/tests/commands/build-trajectory-evidence.test.ts +0 -508
- package/tests/commands/candidate-audit-repair.test.ts +0 -421
- package/tests/commands/candidate-intake.test.ts +0 -732
- package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
- package/tests/commands/candidate-internalize-lineage.test.ts +0 -628
- package/tests/commands/candidate-internalize.test.ts +0 -299
- package/tests/commands/candidate-route.test.ts +0 -329
- package/tests/commands/candidate-show.test.ts +0 -95
- package/tests/commands/cli-command-tree.test.ts +0 -144
- package/tests/commands/cli-help-snapshot.test.ts +0 -155
- package/tests/commands/cli-skill-contract.test.ts +0 -121
- package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
- package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
- package/tests/commands/codex-setup.test.ts +0 -297
- package/tests/commands/codex-worker-daemon.test.ts +0 -95
- package/tests/commands/codex-worker-registration.test.ts +0 -207
- package/tests/commands/config-doctor.test.ts +0 -336
- package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
- package/tests/commands/console-open.test.ts +0 -1381
- package/tests/commands/context.test.ts +0 -114
- package/tests/commands/demo-story-a.test.ts +0 -318
- package/tests/commands/diagnose.test.ts +0 -1803
- package/tests/commands/errors-list.test.ts +0 -679
- package/tests/commands/evolution-tasks-list.test.ts +0 -41
- package/tests/commands/evolution-tasks-show.test.ts +0 -46
- package/tests/commands/health-codex.test.ts +0 -349
- package/tests/commands/health-host-wiring.test.ts +0 -76
- package/tests/commands/health-reliability.test.ts +0 -99
- package/tests/commands/health.test.ts +0 -413
- package/tests/commands/intent.test.ts +0 -321
- package/tests/commands/legacy-cleanup.test.ts +0 -148
- package/tests/commands/pain-evidence.test.ts +0 -518
- package/tests/commands/pain-list.test.ts +0 -219
- package/tests/commands/pain-record-async.test.ts +0 -335
- package/tests/commands/pain-record-session-parser.test.ts +0 -228
- package/tests/commands/pain-record.test.ts +0 -851
- package/tests/commands/pain-retry.test.ts +0 -1121
- package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
- package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
- package/tests/commands/principles-stats-wiring.test.ts +0 -135
- package/tests/commands/principles-stats.test.ts +0 -274
- package/tests/commands/product-path-regression.test.ts +0 -86
- package/tests/commands/proven-channel-baseline.test.ts +0 -441
- package/tests/commands/rulecode.test.ts +0 -177
- package/tests/commands/run-rulehost-handler.test.ts +0 -908
- package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
- package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
- package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
- package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
- package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
- package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
- package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
- package/tests/commands/runtime-activation.test.ts +0 -2052
- package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
- package/tests/commands/runtime-artifact-repair.test.ts +0 -404
- package/tests/commands/runtime-canary.test.ts +0 -430
- package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
- package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
- package/tests/commands/runtime-features.test.ts +0 -249
- package/tests/commands/runtime-health-snapshot.test.ts +0 -358
- package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
- package/tests/commands/runtime-init.test.ts +0 -420
- package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
- package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
- package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
- package/tests/commands/runtime-internalization-queue.test.ts +0 -380
- package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
- package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
- package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
- package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
- package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
- package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
- package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
- package/tests/commands/runtime-internalization.test.ts +0 -53
- package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
- package/tests/commands/runtime-pruning.test.ts +0 -694
- package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
- package/tests/commands/runtime-recovery.test.ts +0 -120
- package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
- package/tests/commands/runtime-uat.test.ts +0 -397
- package/tests/commands/runtime.test.ts +0 -392
- package/tests/commands/samples-list.test.ts +0 -43
- package/tests/commands/samples-review.test.ts +0 -41
- package/tests/commands/task.test.ts +0 -153
- package/tests/commands/telemetry.test.ts +0 -190
- package/tests/commands/trace.test.ts +0 -316
- package/tests/config-reader.test.ts +0 -143
- package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
- package/tests/e2e/cli-full-flow.test.ts +0 -233
- package/tests/e2e/cross-package-acceptance.test.ts +0 -635
- package/tests/helpers/pd-cli-path.ts +0 -5
- package/tests/pd-cli-smoke.test.ts +0 -13
- package/tests/resolve-workspace.test.ts +0 -196
- package/tests/services/config-doctor-signal-health.test.ts +0 -109
- package/tests/services/console-launcher.test.ts +0 -114
- package/tests/services/demo-rule-compiler.test.ts +0 -242
- package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
- package/tests/services/pd-config-loader.test.ts +0 -505
- package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
- package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
- package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
- package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
- package/tests/services/rulehost-pipeline-runner.test.ts +0 -1242
- package/tests/services/workspace-tool-semantics.test.ts +0 -76
- package/tests/utils/path-security.test.ts +0 -180
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -10
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pd evolution tasks list command tests — PRI-753 (Trajectory Reader Reality Fix).
|
|
3
|
-
*
|
|
4
|
-
* Before PRI-753 this handler wrapped every error as "No evolution tasks
|
|
5
|
-
* found." — including a missing database and real database failures. A
|
|
6
|
-
* missing trajectory database must now fail loud with reason and next action
|
|
7
|
-
* (cli-6), never masquerade as an empty task list (rc-9).
|
|
8
|
-
*/
|
|
9
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
10
|
-
|
|
11
|
-
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
12
|
-
resolveWorkspaceDir: vi.fn().mockReturnValue('/tmp/pri753-missing-workspace'),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
import { handleEvolutionTasksList } from '../../src/commands/evolution-tasks-list.js';
|
|
16
|
-
|
|
17
|
-
describe('handleEvolutionTasksList — unavailable database (PRI-753)', () => {
|
|
18
|
-
let errorSpy: ReturnType<typeof vi.spyOn>;
|
|
19
|
-
let exitSpy: ReturnType<typeof vi.spyOn>;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
23
|
-
exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code: number) => {
|
|
24
|
-
throw new Error(`process.exit:${String(code)}`);
|
|
25
|
-
}) as never);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
vi.restoreAllMocks();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('fails loud with reason and next action when trajectory.db is missing', async () => {
|
|
33
|
-
await expect(handleEvolutionTasksList({ status: 'all' })).rejects.toThrow('process.exit:1');
|
|
34
|
-
|
|
35
|
-
const stderrText = errorSpy.mock.calls.map((call) => String(call[0])).join('');
|
|
36
|
-
expect(stderrText).toContain('Trajectory database unavailable');
|
|
37
|
-
expect(stderrText).toContain('trajectory.db');
|
|
38
|
-
expect(stderrText).toContain('pd runtime init --confirm');
|
|
39
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pd evolution tasks show command tests — PRI-753 (Trajectory Reader Reality Fix).
|
|
3
|
-
*
|
|
4
|
-
* "Task not found" (database present, row absent) and "database unavailable"
|
|
5
|
-
* (file missing) are different failures and must stay distinguishable (cli-6).
|
|
6
|
-
*/
|
|
7
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
8
|
-
|
|
9
|
-
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
10
|
-
resolveWorkspaceDir: vi.fn().mockReturnValue('/tmp/pri753-missing-workspace'),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
import { handleEvolutionTasksShow } from '../../src/commands/evolution-tasks-show.js';
|
|
14
|
-
|
|
15
|
-
describe('handleEvolutionTasksShow — unavailable database (PRI-753)', () => {
|
|
16
|
-
let errorSpy: ReturnType<typeof vi.spyOn>;
|
|
17
|
-
let exitSpy: ReturnType<typeof vi.spyOn>;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
21
|
-
exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code: number) => {
|
|
22
|
-
throw new Error(`process.exit:${String(code)}`);
|
|
23
|
-
}) as never);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
vi.restoreAllMocks();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('fails loud with reason and next action when trajectory.db is missing', async () => {
|
|
31
|
-
await expect(handleEvolutionTasksShow({ id: 'task-001' })).rejects.toThrow('process.exit:1');
|
|
32
|
-
|
|
33
|
-
const stderrText = errorSpy.mock.calls.map((call) => String(call[0])).join('');
|
|
34
|
-
expect(stderrText).toContain('Trajectory database unavailable');
|
|
35
|
-
expect(stderrText).toContain('trajectory.db');
|
|
36
|
-
expect(stderrText).toContain('pd runtime init --confirm');
|
|
37
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('reports unavailable instead of "Task not found" when the database is missing', async () => {
|
|
41
|
-
await expect(handleEvolutionTasksShow({ id: 'task-001' })).rejects.toThrow('process.exit:1');
|
|
42
|
-
|
|
43
|
-
const stderrText = errorSpy.mock.calls.map((call) => String(call[0])).join('');
|
|
44
|
-
expect(stderrText).not.toContain('Task not found');
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pd health --host codex command tests — §15 health surface (Slice D).
|
|
3
|
-
*
|
|
4
|
-
* Module-boundary mock style (the handler is a read-model aggregator): every
|
|
5
|
-
* collaborator is mocked, the handler logic (§15 ready conjunction, consent
|
|
6
|
-
* states, blockers, exit codes) is exercised for real.
|
|
7
|
-
*
|
|
8
|
-
* Covers:
|
|
9
|
-
* - cli-1: --json outputs exactly one parseable JSON object.
|
|
10
|
-
* - §15 ready conjunction: full green ⇒ ready + exit 0.
|
|
11
|
-
* - "unknown is not healthy": a degraded section ⇒ not ready + blocker.
|
|
12
|
-
* - consent: flag_on_without_consent blocker; stale disclosure; decline.
|
|
13
|
-
* - admissions without task ⇒ blocker with `pd codex reconcile` nextAction.
|
|
14
|
-
* - hooks trust untrusted ⇒ blocker + exit 1.
|
|
15
|
-
* - legacy dual registration ⇒ migration nextAction (§17 retirement).
|
|
16
|
-
* - worker mode manual_action_required/degraded ⇒ not ready.
|
|
17
|
-
* - per-rollout lag detection from checkpoint + transcript stat.
|
|
18
|
-
*/
|
|
19
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
mockResolveNearestPdWorkspace,
|
|
23
|
-
mockLoadPdConfigForPlugin,
|
|
24
|
-
mockComputeFeatureFlagsFromConfig,
|
|
25
|
-
mockIsFeatureEnabled,
|
|
26
|
-
mockReadCodexIngestionConsent,
|
|
27
|
-
mockDeriveConsentState,
|
|
28
|
-
mockListGovernanceCheckpoints,
|
|
29
|
-
mockReadObservationStats,
|
|
30
|
-
mockReadAdmissionCounts,
|
|
31
|
-
mockComputeWorkerMode,
|
|
32
|
-
mockLocateTranscript,
|
|
33
|
-
mockGetInstallLayoutPaths,
|
|
34
|
-
mockParseInstallManifest,
|
|
35
|
-
mockExistsSync,
|
|
36
|
-
mockReadFileSync,
|
|
37
|
-
mockStatSync,
|
|
38
|
-
mockHomedir,
|
|
39
|
-
mockRequireResolve,
|
|
40
|
-
mockConsoleLog,
|
|
41
|
-
mockConsoleWarn,
|
|
42
|
-
} = vi.hoisted(() => ({
|
|
43
|
-
mockResolveNearestPdWorkspace: vi.fn(),
|
|
44
|
-
mockLoadPdConfigForPlugin: vi.fn(),
|
|
45
|
-
mockComputeFeatureFlagsFromConfig: vi.fn(),
|
|
46
|
-
mockIsFeatureEnabled: vi.fn(),
|
|
47
|
-
mockReadCodexIngestionConsent: vi.fn(),
|
|
48
|
-
mockDeriveConsentState: vi.fn(),
|
|
49
|
-
mockListGovernanceCheckpoints: vi.fn(),
|
|
50
|
-
mockReadObservationStats: vi.fn(),
|
|
51
|
-
mockReadAdmissionCounts: vi.fn(),
|
|
52
|
-
mockComputeWorkerMode: vi.fn(),
|
|
53
|
-
mockLocateTranscript: vi.fn(),
|
|
54
|
-
mockGetInstallLayoutPaths: vi.fn(),
|
|
55
|
-
mockParseInstallManifest: vi.fn(),
|
|
56
|
-
mockExistsSync: vi.fn(),
|
|
57
|
-
mockReadFileSync: vi.fn(),
|
|
58
|
-
mockStatSync: vi.fn(),
|
|
59
|
-
mockHomedir: vi.fn(),
|
|
60
|
-
mockRequireResolve: vi.fn(),
|
|
61
|
-
mockConsoleLog: vi.fn(),
|
|
62
|
-
mockConsoleWarn: vi.fn(),
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
vi.mock('@principles/host-runtime', () => ({
|
|
66
|
-
loadPdConfigForPlugin: mockLoadPdConfigForPlugin,
|
|
67
|
-
resolveNearestPdWorkspace: mockResolveNearestPdWorkspace,
|
|
68
|
-
readCodexIngestionConsent: mockReadCodexIngestionConsent,
|
|
69
|
-
deriveCodexIngestionConsentState: mockDeriveConsentState,
|
|
70
|
-
listGovernanceCheckpoints: mockListGovernanceCheckpoints,
|
|
71
|
-
readGovernanceObservationStats: mockReadObservationStats,
|
|
72
|
-
readGovernanceAdmissionCounts: mockReadAdmissionCounts,
|
|
73
|
-
detectLegacyCodexHookRegistration: (hooksJsonPath?: string) => {
|
|
74
|
-
// Mirrors the host-runtime FS edge: read via the mocked fs, delegate the
|
|
75
|
-
// parse semantics (marker + legacy async PostToolUse) exactly as
|
|
76
|
-
// codex-legacy-registration.ts does over @principles/core/host.
|
|
77
|
-
try {
|
|
78
|
-
const parsed = JSON.parse(mockReadFileSync(hooksJsonPath ?? '/fake/home/.codex/hooks.json', 'utf8')) as Record<string, unknown>;
|
|
79
|
-
const result = { detected: false, legacyAsyncPostToolUse: false };
|
|
80
|
-
for (const eventName of ['PreToolUse', 'PostToolUse', 'UserPromptSubmit', 'SessionStart']) {
|
|
81
|
-
const groups = parsed[eventName];
|
|
82
|
-
if (!Array.isArray(groups)) continue;
|
|
83
|
-
for (const group of groups) {
|
|
84
|
-
if (typeof group !== 'object' || group === null || !Object.hasOwn(group, '__pd_marker') || (group as Record<string, unknown>).__pd_marker !== 'pd-owned') continue;
|
|
85
|
-
result.detected = true;
|
|
86
|
-
const entries = (group as Record<string, unknown>).hooks;
|
|
87
|
-
if (Array.isArray(entries)) {
|
|
88
|
-
for (const entry of entries) {
|
|
89
|
-
if (typeof entry === 'object' && entry !== null && eventName === 'PostToolUse' && Object.hasOwn(entry, 'async') && (entry as Record<string, unknown>).async === true) {
|
|
90
|
-
result.legacyAsyncPostToolUse = true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
} catch {
|
|
98
|
-
return { detected: false, legacyAsyncPostToolUse: false };
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
CODEX_INGESTION_DISCLOSURE_VERSION: 'g2a-2026-08-28',
|
|
102
|
-
}));
|
|
103
|
-
|
|
104
|
-
vi.mock('@principles/codex-adapter', () => ({
|
|
105
|
-
computeCodexWorkerStatusMode: mockComputeWorkerMode,
|
|
106
|
-
locateCodexTranscriptByRolloutIdentity: mockLocateTranscript,
|
|
107
|
-
CODEX_INGESTION_MIN_VERSION: '0.148.0',
|
|
108
|
-
CODEX_INGESTION_VERIFIED_VERSION: '0.150.1',
|
|
109
|
-
}));
|
|
110
|
-
|
|
111
|
-
vi.mock('@principles/install-layout', () => ({
|
|
112
|
-
getInstallLayoutPaths: mockGetInstallLayoutPaths,
|
|
113
|
-
parseInstallManifest: mockParseInstallManifest,
|
|
114
|
-
}));
|
|
115
|
-
|
|
116
|
-
vi.mock('@principles/core/runtime-v2', () => ({
|
|
117
|
-
SqliteConnection: class {},
|
|
118
|
-
SqliteTaskStore: class {
|
|
119
|
-
listTasks = vi.fn().mockResolvedValue([]);
|
|
120
|
-
},
|
|
121
|
-
computeFeatureFlagsFromConfig: mockComputeFeatureFlagsFromConfig,
|
|
122
|
-
isFeatureEnabled: mockIsFeatureEnabled,
|
|
123
|
-
}));
|
|
124
|
-
|
|
125
|
-
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
126
|
-
resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
|
|
127
|
-
}));
|
|
128
|
-
|
|
129
|
-
vi.mock('fs', () => ({
|
|
130
|
-
existsSync: mockExistsSync,
|
|
131
|
-
readFileSync: mockReadFileSync,
|
|
132
|
-
statSync: mockStatSync,
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
vi.mock('os', () => ({
|
|
136
|
-
default: { homedir: mockHomedir, userInfo: vi.fn().mockReturnValue({ username: 'tester' }) },
|
|
137
|
-
homedir: mockHomedir,
|
|
138
|
-
userInfo: vi.fn().mockReturnValue({ username: 'tester' }),
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
vi.mock('module', () => ({
|
|
142
|
-
createRequire: () => ({ resolve: mockRequireResolve }),
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
import { handleHealthCodex } from '../../src/commands/health-codex.js';
|
|
146
|
-
|
|
147
|
-
function flagMap(): Record<string, { enabled: boolean }> {
|
|
148
|
-
return {
|
|
149
|
-
'host.codex': { enabled: true },
|
|
150
|
-
codex_conversation_ingestion: { enabled: true },
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function grantedConsentRecord(): Record<string, unknown> {
|
|
155
|
-
return { decision: 'granted', disclosureVersion: 'g2a-2026-08-28', decidedAt: '2026-09-06T00:00:00.000Z', decidedVia: 'pd_codex_setup', schemaVersion: '1' };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function greenSetup(): void {
|
|
159
|
-
mockResolveNearestPdWorkspace.mockReturnValue({ ok: true, workspaceDir: '/fake/workspace', configPath: '/fake/workspace/.pd/config.yaml', source: 'nearest' });
|
|
160
|
-
mockLoadPdConfigForPlugin.mockReturnValue({ ok: true, source: 'user_config', effective: {}, configPath: '/fake/workspace/.pd/config.yaml', warnings: [], errors: [] });
|
|
161
|
-
mockComputeFeatureFlagsFromConfig.mockReturnValue({ flags: flagMap() });
|
|
162
|
-
mockIsFeatureEnabled.mockImplementation((_flags: unknown, id: string) => (flagMap())[id]?.enabled ?? false);
|
|
163
|
-
mockReadCodexIngestionConsent.mockReturnValue({ ok: true, existed: true, record: grantedConsentRecord() });
|
|
164
|
-
mockDeriveConsentState.mockReturnValue('granted');
|
|
165
|
-
mockListGovernanceCheckpoints.mockReturnValue({ ok: true, checkpoints: [] });
|
|
166
|
-
mockReadObservationStats.mockReturnValue({ ok: true, stats: { operational: 3, promoted: 1, quarantined: 0, terminalOther: 0, nextExpiryAt: '2026-09-07T00:00:00.000Z', lastObservationAt: '2026-09-06T00:00:00.000Z' } });
|
|
167
|
-
mockReadAdmissionCounts.mockReturnValue({ ok: true, counts: { admitted: 1, admittedWithoutTask: 0, pendingTails: 0, staleTails: 0, completedTails: 1, lastAdmissionAt: '2026-09-06T00:00:00.000Z' } });
|
|
168
|
-
mockComputeWorkerMode.mockReturnValue({ mode: 'ready' });
|
|
169
|
-
mockLocateTranscript.mockReturnValue({ ok: false, reason: 'not_found' });
|
|
170
|
-
mockGetInstallLayoutPaths.mockReturnValue({ manifest: '/fake/manifest.json' });
|
|
171
|
-
mockParseInstallManifest.mockReturnValue({ manifest: { workspaces: ['/fake/workspace'] } });
|
|
172
|
-
// Green hooks environment: ~/.codex exists with config.toml hooks = true.
|
|
173
|
-
// NOTE: the handler joins paths with the REAL path module, so on Windows
|
|
174
|
-
// the separators are backslashes — match by suffix, never full equality.
|
|
175
|
-
mockHomedir.mockReturnValue('/fake/home');
|
|
176
|
-
mockExistsSync.mockImplementation((candidate: string | Buffer) => {
|
|
177
|
-
const value = String(candidate);
|
|
178
|
-
return value.endsWith('.codex') || value.endsWith('config.toml');
|
|
179
|
-
});
|
|
180
|
-
mockRequireResolve.mockImplementation((name: string) => `/fake/node_modules/${name}/package.json`);
|
|
181
|
-
mockReadFileSync.mockImplementation((candidate: string | Buffer) => {
|
|
182
|
-
const value = String(candidate);
|
|
183
|
-
if (value.endsWith('config.toml')) return '[features]\nhooks = true\n';
|
|
184
|
-
if (value.includes('package.json')) return JSON.stringify({ version: '0.1.0' });
|
|
185
|
-
return '';
|
|
186
|
-
});
|
|
187
|
-
mockStatSync.mockReturnValue({ size: 0 });
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function runJson(): Promise<Record<string, unknown>> {
|
|
191
|
-
await handleHealthCodex({ json: true });
|
|
192
|
-
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
|
|
193
|
-
return JSON.parse(mockConsoleLog.mock.calls[0]?.[0] as string) as Record<string, unknown>;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
beforeEach(() => {
|
|
197
|
-
vi.clearAllMocks();
|
|
198
|
-
greenSetup();
|
|
199
|
-
vi.spyOn(console, 'log').mockImplementation(mockConsoleLog);
|
|
200
|
-
vi.spyOn(console, 'warn').mockImplementation(mockConsoleWarn);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
afterEach(() => {
|
|
204
|
-
process.exitCode = undefined;
|
|
205
|
-
vi.restoreAllMocks();
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
describe('pd health --host codex — §15 ready semantics', () => {
|
|
209
|
-
it('cli-1 + full green ⇒ ready true, exit 0, one JSON object with §15 fields', async () => {
|
|
210
|
-
const report = await runJson();
|
|
211
|
-
expect(report.ready, JSON.stringify(report.readyBlockers)).toBe(true);
|
|
212
|
-
expect(report.readyBlockers).toHaveLength(0);
|
|
213
|
-
expect(report.host).toBe('codex');
|
|
214
|
-
expect(report.codexIngestionMinVersion).toBe('0.148.0');
|
|
215
|
-
expect((report.consent as { state: string }).state).toBe('granted');
|
|
216
|
-
expect((report.workspaceInit as { initialized: boolean }).initialized).toBe(true);
|
|
217
|
-
expect((report.observations as { operational: number }).operational).toBe(3);
|
|
218
|
-
expect((report.diagnosticianTasks as { pending: number }).pending).toBe(0);
|
|
219
|
-
expect(process.exitCode ?? 0).toBe(0);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('untrusted hooks ⇒ not ready with blocker and exit 1', async () => {
|
|
223
|
-
mockExistsSync.mockImplementation((candidate: string | Buffer) => String(candidate).endsWith('config.toml'));
|
|
224
|
-
mockReadFileSync.mockImplementation((candidate: string | Buffer) => (String(candidate).endsWith('config.toml') ? '[features]\nhooks = false\n' : ''));
|
|
225
|
-
const report = await runJson();
|
|
226
|
-
expect(report.ready).toBe(false);
|
|
227
|
-
expect((report.readyBlockers as string[]).some((blocker) => blocker.startsWith('hooks_trust'))).toBe(true);
|
|
228
|
-
expect(process.exitCode).toBe(1);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('degraded admission counts ⇒ unknown is not healthy (§15)', async () => {
|
|
232
|
-
mockReadAdmissionCounts.mockReturnValue({ ok: false, reason: 'governance_admission_counts_unavailable', nextAction: 'inspect trajectory.db' });
|
|
233
|
-
const report = await runJson();
|
|
234
|
-
expect(report.ready).toBe(false);
|
|
235
|
-
expect((report.readyBlockers as string[]).some((blocker) => blocker.startsWith('admissions'))).toBe(true);
|
|
236
|
-
expect((report.admissions as { reason: string }).reason).toBe('governance_admission_counts_unavailable');
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('admitted pains without task ⇒ blocker recommending reconcile', async () => {
|
|
240
|
-
mockReadAdmissionCounts.mockReturnValue({ ok: true, counts: { admitted: 2, admittedWithoutTask: 1, pendingTails: 0, staleTails: 0, completedTails: 0, lastAdmissionAt: null } });
|
|
241
|
-
const report = await runJson();
|
|
242
|
-
expect(report.ready).toBe(false);
|
|
243
|
-
const blocker = (report.readyBlockers as string[]).find((entry) => entry.startsWith('admissions'));
|
|
244
|
-
expect(blocker).toContain('reconcile');
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('worker degraded ⇒ not ready', async () => {
|
|
248
|
-
mockComputeWorkerMode.mockReturnValue({ mode: 'degraded', reason: 'workspace_missing', nextAction: 'restore the workspace' });
|
|
249
|
-
const report = await runJson();
|
|
250
|
-
expect(report.ready).toBe(false);
|
|
251
|
-
expect((report.worker as { mode: string }).mode).toBe('degraded');
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('no Companion worker ⇒ manual_action_required, never ready (no automatic closure)', async () => {
|
|
255
|
-
mockParseInstallManifest.mockReturnValue({ manifest: { workspaces: [] } });
|
|
256
|
-
mockComputeWorkerMode.mockReturnValue({ mode: 'manual_action_required', reason: 'workspace_not_in_install_manifest' });
|
|
257
|
-
const report = await runJson();
|
|
258
|
-
expect((report.worker as { mode: string }).mode).toBe('manual_action_required');
|
|
259
|
-
expect(report.ready).toBe(false);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('diagnostician needs_human_review tasks ⇒ not ready with review blocker', async () => {
|
|
263
|
-
// Override the task store default via the mocked class instance.
|
|
264
|
-
const coreModule = (await vi.importMock('@principles/core/runtime-v2')) as { SqliteTaskStore: new () => { listTasks: (filter: { status: string }) => Promise<unknown[]> } };
|
|
265
|
-
const original = coreModule.SqliteTaskStore;
|
|
266
|
-
class FakeStore {
|
|
267
|
-
listTasks(filter: { status: string }): Promise<unknown[]> {
|
|
268
|
-
return Promise.resolve(filter.status === 'needs_human_review' ? [{ id: 't1' }] : []);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
vi.doMock('@principles/core/runtime-v2', () => ({ SqliteConnection: class {}, SqliteTaskStore: FakeStore, computeFeatureFlagsFromConfig: mockComputeFeatureFlagsFromConfig, isFeatureEnabled: mockIsFeatureEnabled }));
|
|
272
|
-
void original;
|
|
273
|
-
vi.resetModules();
|
|
274
|
-
const { handleHealthCodex: freshHandler } = await import('../../src/commands/health-codex.js');
|
|
275
|
-
await freshHandler({ json: true });
|
|
276
|
-
const output = mockConsoleLog.mock.calls[mockConsoleLog.mock.calls.length - 1]?.[0] as string;
|
|
277
|
-
const report = JSON.parse(output) as { ready: boolean; readyBlockers: string[] };
|
|
278
|
-
expect(report.ready).toBe(false);
|
|
279
|
-
expect(report.readyBlockers.some((blocker) => blocker.includes('human review'))).toBe(true);
|
|
280
|
-
process.exitCode = undefined;
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe('pd health --host codex — consent surface (no captured text)', () => {
|
|
285
|
-
it('flag on without consent record ⇒ governance blocker with setup nextAction', async () => {
|
|
286
|
-
mockReadCodexIngestionConsent.mockReturnValue({ ok: true, existed: false, record: null });
|
|
287
|
-
mockDeriveConsentState.mockReturnValue('flag_on_without_grant');
|
|
288
|
-
const report = await runJson();
|
|
289
|
-
const consent = report.consent as { state: string; nextAction?: string };
|
|
290
|
-
expect(consent.state).toBe('flag_on_without_grant');
|
|
291
|
-
expect(consent.nextAction).toContain('pd codex setup');
|
|
292
|
-
expect(report.ready).toBe(false);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it('declined consent with flag off does not block readiness on consent', async () => {
|
|
296
|
-
mockIsFeatureEnabled.mockImplementation((_flags: unknown, id: string) => id === 'host.codex');
|
|
297
|
-
mockReadCodexIngestionConsent.mockReturnValue({ ok: true, existed: true, record: { ...grantedConsentRecord(), decision: 'revoked' } });
|
|
298
|
-
mockDeriveConsentState.mockReturnValue('revoked');
|
|
299
|
-
const report = await runJson();
|
|
300
|
-
expect((report.consent as { state: string }).state).toBe('revoked');
|
|
301
|
-
expect((report.readyBlockers as string[]).some((blocker) => blocker.startsWith('consent'))).toBe(false);
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
it('stale disclosure version is surfaced as re-consent nextAction', async () => {
|
|
305
|
-
mockReadCodexIngestionConsent.mockReturnValue({ ok: true, existed: true, record: { ...grantedConsentRecord(), disclosureVersion: 'g2a-2020-01-01' } });
|
|
306
|
-
const report = await runJson();
|
|
307
|
-
expect((report.consent as { disclosureStale: boolean }).disclosureStale).toBe(true);
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
describe('pd health --host codex — legacy registration (§17 retirement)', () => {
|
|
312
|
-
it('legacy async PostToolUse registration ⇒ migration nextAction', async () => {
|
|
313
|
-
mockHomedir.mockReturnValue('/fake/home');
|
|
314
|
-
mockExistsSync.mockImplementation((candidate: string | Buffer) => {
|
|
315
|
-
const value = String(candidate);
|
|
316
|
-
return value.endsWith('.codex') || value.endsWith('hooks.json') || value.endsWith('config.toml');
|
|
317
|
-
});
|
|
318
|
-
mockReadFileSync.mockImplementation((candidate: string | Buffer) => {
|
|
319
|
-
const value = String(candidate);
|
|
320
|
-
if (value.endsWith('hooks.json')) {
|
|
321
|
-
return JSON.stringify({
|
|
322
|
-
PreToolUse: [{ matcher: 'Bash|apply_patch', hooks: [{ type: 'command', command: 'node pd-hook.cjs' }], __pd_marker: 'pd-owned' }],
|
|
323
|
-
PostToolUse: [{ matcher: '.*', hooks: [{ type: 'command', command: 'node pd-hook.cjs', timeout: 5, async: true }], __pd_marker: 'pd-owned' }],
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
if (value.endsWith('config.toml')) return '[features]\nhooks = true\n';
|
|
327
|
-
if (value.includes('package.json')) return JSON.stringify({ version: '0.1.0' });
|
|
328
|
-
return '';
|
|
329
|
-
});
|
|
330
|
-
const report = await runJson();
|
|
331
|
-
expect((report.dualRegistration as { detected: boolean; legacyAsyncPostToolUse: boolean }).legacyAsyncPostToolUse, JSON.stringify(report.dualRegistration)).toBe(true);
|
|
332
|
-
expect((report.dualRegistration as { nextAction?: string }).nextAction).toContain('Marketplace');
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
describe('pd health --host codex — per-rollout lag', () => {
|
|
337
|
-
it('checkpoint lag over zero ⇒ rollout blocker with byte lag', async () => {
|
|
338
|
-
mockListGovernanceCheckpoints.mockReturnValue({
|
|
339
|
-
ok: true,
|
|
340
|
-
checkpoints: [{ hostKind: 'codex', rolloutIdentity: 'r-1', byteOffset: 10, lastOrdinal: 1, cliVersion: null, rootSessionId: 'root', incompleteTail: false, lastDegradationReason: null, lastDegradationOrdinal: null, updatedAt: '2026-09-06T00:00:00.000Z' }],
|
|
341
|
-
});
|
|
342
|
-
mockLocateTranscript.mockReturnValue({ ok: true, transcriptPath: '/fake/home/.codex/sessions/r-1.jsonl' });
|
|
343
|
-
mockStatSync.mockReturnValue({ size: 512 });
|
|
344
|
-
const report = await runJson();
|
|
345
|
-
expect(report.ready).toBe(false);
|
|
346
|
-
expect(((report.rollouts as { checkpoints: { lagBytes: number | null }[] }).checkpoints[0]?.lagBytes) ?? -1).toBe(502);
|
|
347
|
-
expect((report.readyBlockers as string[]).some((blocker) => blocker.includes('r-1'))).toBe(true);
|
|
348
|
-
});
|
|
349
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cli-7 test-wiring: prove the real `registerHealthCommand` (used by the CLI
|
|
3
|
-
* entrypoint) wires the `--host codex` flag, dispatches to handleHealthCodex,
|
|
4
|
-
* and rejects unknown host values with a structured error + non-zero exit.
|
|
5
|
-
*
|
|
6
|
-
* Handlers are injected so the test exercises the real production registration
|
|
7
|
-
* without executing real workspace/DB I/O.
|
|
8
|
-
*/
|
|
9
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
10
|
-
import { Command } from 'commander';
|
|
11
|
-
import { registerHealthCommand } from '../../src/commands/health.js';
|
|
12
|
-
|
|
13
|
-
const mockHandleHealth = vi.fn();
|
|
14
|
-
const mockHandleHealthCodex = vi.fn();
|
|
15
|
-
|
|
16
|
-
const originalExitCode = process.exitCode;
|
|
17
|
-
|
|
18
|
-
function buildHealthCommand(): Command {
|
|
19
|
-
const program = new Command();
|
|
20
|
-
registerHealthCommand(program, { health: mockHandleHealth, healthCodex: mockHandleHealthCodex });
|
|
21
|
-
return program;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe('cli-7: pd health --host flag wiring (production registration)', () => {
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
vi.clearAllMocks();
|
|
27
|
-
process.exitCode = originalExitCode;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
process.exitCode = originalExitCode;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('dispatches to handleHealthCodex when --host codex is passed', async () => {
|
|
35
|
-
const program = buildHealthCommand();
|
|
36
|
-
await program.parseAsync(['node', 'pd', 'health', '--host', 'codex', '--json']);
|
|
37
|
-
expect(mockHandleHealthCodex).toHaveBeenCalledTimes(1);
|
|
38
|
-
expect(mockHandleHealthCodex).toHaveBeenCalledWith(expect.objectContaining({ host: 'codex', json: true }));
|
|
39
|
-
expect(mockHandleHealth).not.toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('dispatches to handleHealth when --host is omitted (defaults to openclaw)', async () => {
|
|
43
|
-
const program = buildHealthCommand();
|
|
44
|
-
await program.parseAsync(['node', 'pd', 'health']);
|
|
45
|
-
expect(mockHandleHealth).toHaveBeenCalledTimes(1);
|
|
46
|
-
expect(mockHandleHealthCodex).not.toHaveBeenCalled();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('dispatches to handleHealth when --host openclaw is passed', async () => {
|
|
50
|
-
const program = buildHealthCommand();
|
|
51
|
-
await program.parseAsync(['node', 'pd', 'health', '--host', 'openclaw']);
|
|
52
|
-
expect(mockHandleHealth).toHaveBeenCalledTimes(1);
|
|
53
|
-
expect(mockHandleHealthCodex).not.toHaveBeenCalled();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('passes --workspace through to handleHealthCodex', async () => {
|
|
57
|
-
const program = buildHealthCommand();
|
|
58
|
-
await program.parseAsync(['node', 'pd', 'health', '--host', 'codex', '-w', '/some/path']);
|
|
59
|
-
expect(mockHandleHealthCodex).toHaveBeenCalledWith(expect.objectContaining({ workspace: '/some/path' }));
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('rejects an unknown --host value without dispatching', async () => {
|
|
63
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
64
|
-
const program = buildHealthCommand();
|
|
65
|
-
await program.parseAsync(['node', 'pd', 'health', '--host', 'codxe', '--json']);
|
|
66
|
-
expect(mockHandleHealth).not.toHaveBeenCalled();
|
|
67
|
-
expect(mockHandleHealthCodex).not.toHaveBeenCalled();
|
|
68
|
-
expect(process.exitCode).toBe(1);
|
|
69
|
-
const payload = JSON.parse(String(logSpy.mock.calls[0][0]));
|
|
70
|
-
expect(payload.ok).toBe(false);
|
|
71
|
-
expect(payload.reason).toBe('invalid_host');
|
|
72
|
-
expect(payload.host).toBe('codxe');
|
|
73
|
-
expect(payload.nextAction).toBeTruthy();
|
|
74
|
-
logSpy.mockRestore();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PRI-662 — reliability readiness section of `pd health`, against REAL
|
|
3
|
-
* declaration files on disk (no fs mock, no host-runtime mock): the upgrade
|
|
4
|
-
* validation surface must observe exactly what the production paths observe.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect, afterEach, vi } from 'vitest';
|
|
7
|
-
import * as fs from 'node:fs';
|
|
8
|
-
import * as os from 'node:os';
|
|
9
|
-
import * as path from 'node:path';
|
|
10
|
-
import { saveHostToolDeclaration } from '@principles/host-runtime';
|
|
11
|
-
import { handleHealth } from '../../src/commands/health.js';
|
|
12
|
-
|
|
13
|
-
const dirs: string[] = [];
|
|
14
|
-
|
|
15
|
-
function makeWorkspace(): string {
|
|
16
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-health-reliability-'));
|
|
17
|
-
dirs.push(dir);
|
|
18
|
-
return dir;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
vi.restoreAllMocks();
|
|
23
|
-
for (const dir of dirs.splice(0)) {
|
|
24
|
-
try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* temp */ }
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('pd health reliability section (real declaration files)', () => {
|
|
29
|
-
it('fresh workspace (no declaration): explicit degraded + host_tool_declaration_missing, informational only', async () => {
|
|
30
|
-
const workspaceDir = makeWorkspace();
|
|
31
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
32
|
-
try {
|
|
33
|
-
await handleHealth({ workspace: workspaceDir, json: true });
|
|
34
|
-
const parsed = JSON.parse(logSpy.mock.calls[0][0]) as {
|
|
35
|
-
reliability: { registry: { status: string }; resolver: string; replay: string; reason?: string; nextAction?: string };
|
|
36
|
-
};
|
|
37
|
-
expect(parsed.reliability.registry.status).toBe('degraded');
|
|
38
|
-
expect(parsed.reliability.resolver).toBe('not_ready');
|
|
39
|
-
expect(parsed.reliability.replay).toBe('not_ready');
|
|
40
|
-
expect(parsed.reliability.reason).toBe('host_tool_declaration_missing');
|
|
41
|
-
expect(parsed.reliability.nextAction ?? '').not.toBe('');
|
|
42
|
-
} finally {
|
|
43
|
-
vi.restoreAllMocks();
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('declared workspace: registry ok with per-host counts, resolver/replay ready', async () => {
|
|
48
|
-
const workspaceDir = makeWorkspace();
|
|
49
|
-
saveHostToolDeclaration(workspaceDir, {
|
|
50
|
-
version: 1,
|
|
51
|
-
hostKind: 'openclaw',
|
|
52
|
-
mappings: [
|
|
53
|
-
{ rawToolName: 'Write', canonicalKind: 'write' },
|
|
54
|
-
{ rawToolName: 'Edit', canonicalKind: 'write' },
|
|
55
|
-
{ rawToolName: 'Bash', canonicalKind: 'execute' },
|
|
56
|
-
],
|
|
57
|
-
declaredAt: new Date().toISOString(),
|
|
58
|
-
});
|
|
59
|
-
saveHostToolDeclaration(workspaceDir, {
|
|
60
|
-
version: 1,
|
|
61
|
-
hostKind: 'codex',
|
|
62
|
-
mappings: [{ rawToolName: 'shell', canonicalKind: 'execute' }],
|
|
63
|
-
declaredAt: new Date().toISOString(),
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
67
|
-
try {
|
|
68
|
-
await handleHealth({ workspace: workspaceDir, json: false });
|
|
69
|
-
const allOutput = logSpy.mock.calls.map((c) => c.join(' ')).join('\n');
|
|
70
|
-
expect(allOutput).toContain('reliability.registry.status: ok');
|
|
71
|
-
expect(allOutput).toContain('reliability.registry.hosts: codex+openclaw');
|
|
72
|
-
expect(allOutput).toContain('reliability.registry.declaredTools: 4');
|
|
73
|
-
expect(allOutput).toContain('reliability.resolver: ready');
|
|
74
|
-
expect(allOutput).toContain('reliability.replay: ready');
|
|
75
|
-
} finally {
|
|
76
|
-
vi.restoreAllMocks();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('malformed declaration: explicit invalid reason with a repair action', async () => {
|
|
81
|
-
const workspaceDir = makeWorkspace();
|
|
82
|
-
const dir = path.join(workspaceDir, '.pd', 'host-tool-semantics');
|
|
83
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
84
|
-
fs.writeFileSync(path.join(dir, 'openclaw.json'), '{broken', 'utf-8');
|
|
85
|
-
|
|
86
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
87
|
-
try {
|
|
88
|
-
await handleHealth({ workspace: workspaceDir, json: true });
|
|
89
|
-
const parsed = JSON.parse(logSpy.mock.calls[0][0]) as {
|
|
90
|
-
reliability: { registry: { status: string }; reason?: string; nextAction?: string };
|
|
91
|
-
};
|
|
92
|
-
expect(parsed.reliability.registry.status).toBe('degraded');
|
|
93
|
-
expect(parsed.reliability.reason).toContain('host_tool_declaration_invalid');
|
|
94
|
-
expect(parsed.reliability.nextAction ?? '').not.toBe('');
|
|
95
|
-
} finally {
|
|
96
|
-
vi.restoreAllMocks();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|