@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,358 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pd runtime health snapshot CLI unit tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests the CLI adapter layer: validation, OperatorHealthReadModel delegation,
|
|
5
|
-
* JSON/text output formatting, and exit code behavior.
|
|
6
|
-
* OperatorHealthReadModel is mocked — its own contract is tested in principles-core.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
9
|
-
|
|
10
|
-
// ── Mock setup ──────────────────────────────────────────────────────────────
|
|
11
|
-
|
|
12
|
-
const mockSnapshotFn = vi.fn();
|
|
13
|
-
const mockCloseFn = vi.fn().mockResolvedValue(undefined);
|
|
14
|
-
|
|
15
|
-
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
16
|
-
resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
vi.mock('@principles/core/runtime-v2', () => ({
|
|
20
|
-
OperatorHealthReadModel: vi.fn().mockImplementation(function () {
|
|
21
|
-
return { getSnapshot: mockSnapshotFn, close: mockCloseFn };
|
|
22
|
-
}),
|
|
23
|
-
resolveOutputLanguage: vi.fn().mockReturnValue({ outputLanguage: 'zh-CN' }),
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
import { handleRuntimeHealthSnapshot } from '../../src/commands/runtime-health-snapshot.js';
|
|
27
|
-
|
|
28
|
-
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
29
|
-
|
|
30
|
-
const WS = '/fake/workspace';
|
|
31
|
-
|
|
32
|
-
function healthySnapshot() {
|
|
33
|
-
return {
|
|
34
|
-
generatedAt: '2026-05-03T12:00:00.000Z',
|
|
35
|
-
workspace: WS,
|
|
36
|
-
painChain: {
|
|
37
|
-
lastSuccessfulChain: {
|
|
38
|
-
painId: 'pain_001',
|
|
39
|
-
taskId: 'task_001',
|
|
40
|
-
runId: 'run_001',
|
|
41
|
-
artifactId: 'art_001',
|
|
42
|
-
candidateIds: ['c1'],
|
|
43
|
-
ledgerEntryIds: ['l1'],
|
|
44
|
-
status: 'succeeded',
|
|
45
|
-
latencyMs: { painToTask: 100 },
|
|
46
|
-
failureCategory: null,
|
|
47
|
-
checkedAt: '2026-05-03T12:00:00.000Z',
|
|
48
|
-
missingLinks: [],
|
|
49
|
-
},
|
|
50
|
-
failureCategory: null,
|
|
51
|
-
},
|
|
52
|
-
candidateLedger: {
|
|
53
|
-
auditStatus: 'ok' as const,
|
|
54
|
-
orphanCandidateCount: 0,
|
|
55
|
-
missingLedgerCount: 0,
|
|
56
|
-
},
|
|
57
|
-
pruning: {
|
|
58
|
-
watchCount: 0,
|
|
59
|
-
reviewCount: 0,
|
|
60
|
-
orphanDerivedCandidateCount: 0,
|
|
61
|
-
},
|
|
62
|
-
gfi: {
|
|
63
|
-
active: null,
|
|
64
|
-
staleSessionCount: 0,
|
|
65
|
-
staleGfiRange: null,
|
|
66
|
-
totalSessionCount: 0,
|
|
67
|
-
activeSessionCount: 0,
|
|
68
|
-
generatedAt: '2026-05-03T12:00:00.000Z',
|
|
69
|
-
},
|
|
70
|
-
overallStatus: 'healthy' as const,
|
|
71
|
-
recommendedActions: [],
|
|
72
|
-
totalTaskCount: 1,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function mockProcessExit() {
|
|
77
|
-
return vi.spyOn(process, 'exit').mockImplementation((() => undefined) as () => never);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ── Tests ───────────────────────────────────────────────────────────────────
|
|
81
|
-
|
|
82
|
-
describe('handleRuntimeHealthSnapshot', () => {
|
|
83
|
-
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
84
|
-
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
85
|
-
|
|
86
|
-
beforeEach(() => {
|
|
87
|
-
vi.clearAllMocks();
|
|
88
|
-
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
89
|
-
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
afterEach(() => {
|
|
93
|
-
consoleLogSpy.mockRestore();
|
|
94
|
-
consoleErrorSpy.mockRestore();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// ── Healthy ──────────────────────────────────────────────────────────────
|
|
98
|
-
|
|
99
|
-
it('outputs healthy JSON snapshot with all required fields (--json)', async () => {
|
|
100
|
-
mockSnapshotFn.mockResolvedValue(healthySnapshot());
|
|
101
|
-
|
|
102
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
103
|
-
|
|
104
|
-
expect(consoleLogSpy).toHaveBeenCalled();
|
|
105
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
106
|
-
expect(jsonOutput.generatedAt).toBe('2026-05-03T12:00:00.000Z');
|
|
107
|
-
expect(jsonOutput.workspace).toBe(WS);
|
|
108
|
-
expect(jsonOutput.painChain).toBeDefined();
|
|
109
|
-
expect(jsonOutput.painChain.lastSuccessfulChain).toBeDefined();
|
|
110
|
-
expect(jsonOutput.candidateLedger.auditStatus).toBe('ok');
|
|
111
|
-
expect(jsonOutput.pruning.watchCount).toBe(0);
|
|
112
|
-
expect(jsonOutput.overallStatus).toBe('healthy');
|
|
113
|
-
expect(jsonOutput.recommendedActions).toEqual([]);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('outputs readable text for healthy snapshot', async () => {
|
|
117
|
-
mockSnapshotFn.mockResolvedValue(healthySnapshot());
|
|
118
|
-
|
|
119
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: false });
|
|
120
|
-
|
|
121
|
-
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
122
|
-
expect(allOutput).toContain('HEALTHY');
|
|
123
|
-
expect(allOutput).toContain('No actions recommended');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// ── Degraded: candidate audit ────────────────────────────────────────────
|
|
127
|
-
|
|
128
|
-
it('reflects candidate audit degraded in overallStatus', async () => {
|
|
129
|
-
const snapshot = {
|
|
130
|
-
...healthySnapshot(),
|
|
131
|
-
candidateLedger: {
|
|
132
|
-
auditStatus: 'degraded' as const,
|
|
133
|
-
orphanCandidateCount: 2,
|
|
134
|
-
missingLedgerCount: 2,
|
|
135
|
-
},
|
|
136
|
-
overallStatus: 'degraded' as const,
|
|
137
|
-
recommendedActions: [
|
|
138
|
-
'Run `pd candidate audit --workspace <path> --json` for details.',
|
|
139
|
-
],
|
|
140
|
-
};
|
|
141
|
-
mockSnapshotFn.mockResolvedValue(snapshot);
|
|
142
|
-
const exitSpy = mockProcessExit();
|
|
143
|
-
|
|
144
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
145
|
-
|
|
146
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
147
|
-
expect(jsonOutput.overallStatus).toBe('degraded');
|
|
148
|
-
expect(jsonOutput.recommendedActions).toContain(
|
|
149
|
-
'Run `pd candidate audit --workspace <path> --json` for details.',
|
|
150
|
-
);
|
|
151
|
-
expect(process.exitCode).toBe(1);
|
|
152
|
-
|
|
153
|
-
exitSpy.mockRestore();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// ── Degraded: pruning signals ────────────────────────────────────────────
|
|
157
|
-
|
|
158
|
-
it('reflects pruning watch/review signals in recommendedActions', async () => {
|
|
159
|
-
const snapshot = {
|
|
160
|
-
...healthySnapshot(),
|
|
161
|
-
pruning: {
|
|
162
|
-
watchCount: 2,
|
|
163
|
-
reviewCount: 1,
|
|
164
|
-
orphanDerivedCandidateCount: 0,
|
|
165
|
-
},
|
|
166
|
-
overallStatus: 'degraded' as const,
|
|
167
|
-
recommendedActions: [
|
|
168
|
-
'Run `pd runtime pruning report --workspace <path> --json` for lifecycle signals.',
|
|
169
|
-
],
|
|
170
|
-
};
|
|
171
|
-
mockSnapshotFn.mockResolvedValue(snapshot);
|
|
172
|
-
const exitSpy = mockProcessExit();
|
|
173
|
-
|
|
174
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
175
|
-
|
|
176
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
177
|
-
expect(jsonOutput.overallStatus).toBe('degraded');
|
|
178
|
-
expect(jsonOutput.pruning.watchCount).toBe(2);
|
|
179
|
-
expect(jsonOutput.recommendedActions).toContain(
|
|
180
|
-
'Run `pd runtime pruning report --workspace <path> --json` for lifecycle signals.',
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
exitSpy.mockRestore();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// ── Degraded: no successful chain ────────────────────────────────────────
|
|
187
|
-
|
|
188
|
-
it('recommends UAT baseline when no successful chain exists', async () => {
|
|
189
|
-
const snapshot = {
|
|
190
|
-
...healthySnapshot(),
|
|
191
|
-
painChain: {
|
|
192
|
-
lastSuccessfulChain: null,
|
|
193
|
-
failureCategory: null,
|
|
194
|
-
},
|
|
195
|
-
overallStatus: 'degraded' as const,
|
|
196
|
-
recommendedActions: [
|
|
197
|
-
'Run `pd runtime uat --workspace <path> --count 3` to establish baseline.',
|
|
198
|
-
],
|
|
199
|
-
};
|
|
200
|
-
mockSnapshotFn.mockResolvedValue(snapshot);
|
|
201
|
-
const exitSpy = mockProcessExit();
|
|
202
|
-
|
|
203
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
204
|
-
|
|
205
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
206
|
-
expect(jsonOutput.painChain.lastSuccessfulChain).toBeNull();
|
|
207
|
-
expect(jsonOutput.recommendedActions).toContain(
|
|
208
|
-
'Run `pd runtime uat --workspace <path> --count 3` to establish baseline.',
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
exitSpy.mockRestore();
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// ── Error ────────────────────────────────────────────────────────────────
|
|
215
|
-
|
|
216
|
-
it('handles error status from missing state.db', async () => {
|
|
217
|
-
const snapshot = {
|
|
218
|
-
...healthySnapshot(),
|
|
219
|
-
candidateLedger: {
|
|
220
|
-
auditStatus: 'error' as const,
|
|
221
|
-
orphanCandidateCount: 0,
|
|
222
|
-
missingLedgerCount: 0,
|
|
223
|
-
},
|
|
224
|
-
overallStatus: 'error' as const,
|
|
225
|
-
recommendedActions: ['Initialize workspace with `pd pain record`.'],
|
|
226
|
-
};
|
|
227
|
-
mockSnapshotFn.mockResolvedValue(snapshot);
|
|
228
|
-
const exitSpy = mockProcessExit();
|
|
229
|
-
|
|
230
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
231
|
-
|
|
232
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
233
|
-
expect(jsonOutput.overallStatus).toBe('error');
|
|
234
|
-
expect(jsonOutput.candidateLedger.auditStatus).toBe('error');
|
|
235
|
-
expect(process.exitCode).toBe(1);
|
|
236
|
-
|
|
237
|
-
exitSpy.mockRestore();
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// ── Multiple degraded conditions ─────────────────────────────────────────
|
|
241
|
-
|
|
242
|
-
it('accumulates multiple recommendedActions for multiple issues', async () => {
|
|
243
|
-
const snapshot = {
|
|
244
|
-
...healthySnapshot(),
|
|
245
|
-
painChain: { lastSuccessfulChain: null, failureCategory: null },
|
|
246
|
-
candidateLedger: {
|
|
247
|
-
auditStatus: 'degraded' as const,
|
|
248
|
-
orphanCandidateCount: 2,
|
|
249
|
-
missingLedgerCount: 2,
|
|
250
|
-
},
|
|
251
|
-
pruning: { watchCount: 3, reviewCount: 1, orphanDerivedCandidateCount: 0 },
|
|
252
|
-
overallStatus: 'degraded' as const,
|
|
253
|
-
recommendedActions: [
|
|
254
|
-
'Run `pd candidate audit --workspace <path> --json` for details.',
|
|
255
|
-
'Run `pd runtime pruning report --workspace <path> --json` for lifecycle signals.',
|
|
256
|
-
'Run `pd runtime uat --workspace <path> --count 3` to establish baseline.',
|
|
257
|
-
],
|
|
258
|
-
};
|
|
259
|
-
mockSnapshotFn.mockResolvedValue(snapshot);
|
|
260
|
-
const exitSpy = mockProcessExit();
|
|
261
|
-
|
|
262
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
263
|
-
|
|
264
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
265
|
-
expect(jsonOutput.recommendedActions).toHaveLength(3);
|
|
266
|
-
|
|
267
|
-
exitSpy.mockRestore();
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
// ── GFI section (PRI-83) ──────────────────────────────────────────────────
|
|
271
|
-
|
|
272
|
-
it('includes gfi section in JSON output with active session data', async () => {
|
|
273
|
-
const snapshot = {
|
|
274
|
-
...healthySnapshot(),
|
|
275
|
-
gfi: {
|
|
276
|
-
active: {
|
|
277
|
-
currentGfi: 42,
|
|
278
|
-
stage: 'elevated',
|
|
279
|
-
dominantSource: 'tool_failure',
|
|
280
|
-
consecutiveErrors: 2,
|
|
281
|
-
dailyGfiPeak: 55,
|
|
282
|
-
consumers: {
|
|
283
|
-
attitudeMode: 'conciliatory',
|
|
284
|
-
painDiagnosticReason: 'high_gfi',
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
staleSessionCount: 1,
|
|
288
|
-
staleGfiRange: { min: 10, max: 20 },
|
|
289
|
-
totalSessionCount: 2,
|
|
290
|
-
activeSessionCount: 1,
|
|
291
|
-
generatedAt: '2026-05-03T12:00:00.000Z',
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
mockSnapshotFn.mockResolvedValue(snapshot);
|
|
295
|
-
|
|
296
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
297
|
-
|
|
298
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
299
|
-
expect(jsonOutput.gfi).toBeDefined();
|
|
300
|
-
expect(jsonOutput.gfi.active).not.toBeNull();
|
|
301
|
-
expect(jsonOutput.gfi.active.currentGfi).toBe(42);
|
|
302
|
-
expect(jsonOutput.gfi.active.stage).toBe('elevated');
|
|
303
|
-
expect(jsonOutput.gfi.active.dominantSource).toBe('tool_failure');
|
|
304
|
-
expect(jsonOutput.gfi.activeSessionCount).toBe(1);
|
|
305
|
-
expect(jsonOutput.gfi.staleSessionCount).toBe(1);
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('includes compact GFI line in text output', async () => {
|
|
309
|
-
const snapshot = {
|
|
310
|
-
...healthySnapshot(),
|
|
311
|
-
gfi: {
|
|
312
|
-
active: {
|
|
313
|
-
currentGfi: 42,
|
|
314
|
-
stage: 'elevated',
|
|
315
|
-
dominantSource: 'tool_failure',
|
|
316
|
-
consecutiveErrors: 2,
|
|
317
|
-
dailyGfiPeak: 55,
|
|
318
|
-
consumers: {
|
|
319
|
-
attitudeMode: 'conciliatory',
|
|
320
|
-
painDiagnosticReason: 'high_gfi',
|
|
321
|
-
},
|
|
322
|
-
},
|
|
323
|
-
staleSessionCount: 0,
|
|
324
|
-
staleGfiRange: null,
|
|
325
|
-
totalSessionCount: 1,
|
|
326
|
-
activeSessionCount: 1,
|
|
327
|
-
generatedAt: '2026-05-03T12:00:00.000Z',
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
mockSnapshotFn.mockResolvedValue(snapshot);
|
|
331
|
-
|
|
332
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: false });
|
|
333
|
-
|
|
334
|
-
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
335
|
-
expect(allOutput).toContain('gfi:');
|
|
336
|
-
expect(allOutput).toContain('elevated');
|
|
337
|
-
expect(allOutput).toContain('42');
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
it('shows no active sessions in text when gfi.active is null', async () => {
|
|
341
|
-
mockSnapshotFn.mockResolvedValue(healthySnapshot());
|
|
342
|
-
|
|
343
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: false });
|
|
344
|
-
|
|
345
|
-
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
346
|
-
expect(allOutput).toContain('no active sessions');
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('does not mark runtime unhealthy solely for missing GFI data', async () => {
|
|
350
|
-
mockSnapshotFn.mockResolvedValue(healthySnapshot());
|
|
351
|
-
|
|
352
|
-
await handleRuntimeHealthSnapshot({ workspace: WS, json: true });
|
|
353
|
-
|
|
354
|
-
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
355
|
-
expect(jsonOutput.gfi.active).toBeNull();
|
|
356
|
-
expect(jsonOutput.overallStatus).toBe('healthy');
|
|
357
|
-
});
|
|
358
|
-
});
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* runtime-init empty-workspace integration tests — verifies real DB initialization.
|
|
3
|
-
*
|
|
4
|
-
* Does NOT mock the DB layer. Uses real better-sqlite3 to create actual database
|
|
5
|
-
* files in a temp workspace, then verifies all expected tables exist.
|
|
6
|
-
*
|
|
7
|
-
* Covers:
|
|
8
|
-
* - EMPTY-01: initialize empty workspace → all 3 DBs have full schema
|
|
9
|
-
* - EMPTY-02: idempotency — running twice does not error or lose data
|
|
10
|
-
*
|
|
11
|
-
* Prerequisites: @principles/core and principles-disciple must be built.
|
|
12
|
-
*
|
|
13
|
-
* ERR refs:
|
|
14
|
-
* - rc-7-loop-state-freshness: idempotency test uses fresh workspace each run
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
18
|
-
import * as fs from 'node:fs';
|
|
19
|
-
import * as path from 'node:path';
|
|
20
|
-
import * as os from 'node:os';
|
|
21
|
-
import * as yaml from 'js-yaml';
|
|
22
|
-
import Database from 'better-sqlite3';
|
|
23
|
-
import { validatePdConfig } from '@principles/core/runtime-v2';
|
|
24
|
-
import { buildRuntimeInitOutput } from '../../src/commands/runtime-init.js';
|
|
25
|
-
|
|
26
|
-
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
27
|
-
|
|
28
|
-
function mkTmpDir(): string {
|
|
29
|
-
return fs.mkdtempSync(path.join(os.tmpdir(), 'pd-runtime-init-empty-'));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function rmTmpDir(dir: string): void {
|
|
33
|
-
try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getTableNames(dbPath: string): string[] {
|
|
37
|
-
const db = new Database(dbPath, { readonly: true });
|
|
38
|
-
try {
|
|
39
|
-
const rows = db.prepare(
|
|
40
|
-
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name"
|
|
41
|
-
).all() as { name: string }[];
|
|
42
|
-
return rows.map(r => r.name);
|
|
43
|
-
} finally {
|
|
44
|
-
db.close();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getIndexNames(dbPath: string): string[] {
|
|
49
|
-
const db = new Database(dbPath, { readonly: true });
|
|
50
|
-
try {
|
|
51
|
-
const rows = db.prepare(
|
|
52
|
-
"SELECT name FROM sqlite_master WHERE type='index' AND name NOT LIKE 'sqlite_%' ORDER BY name"
|
|
53
|
-
).all() as { name: string }[];
|
|
54
|
-
return rows.map(r => r.name);
|
|
55
|
-
} finally {
|
|
56
|
-
db.close();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// ── Expected schema ─────────────────────────────────────────────────────────
|
|
61
|
-
|
|
62
|
-
const EXPECTED_STATE_TABLES = [
|
|
63
|
-
'tasks', 'runs', 'artifacts', 'commits',
|
|
64
|
-
'principle_candidates', 'pi_artifacts',
|
|
65
|
-
'approvals', 'activations', 'intent_decisions',
|
|
66
|
-
'schema_version',
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
const EXPECTED_TRAJECTORY_TABLES = [
|
|
70
|
-
'schema_version', 'ingest_checkpoint', 'sessions', 'assistant_turns',
|
|
71
|
-
'user_turns', 'tool_calls', 'pain_events', 'gate_blocks', 'trust_changes',
|
|
72
|
-
'principle_events', 'task_outcomes', 'correction_samples', 'sample_reviews',
|
|
73
|
-
// PRI-790 G2: Stage2 待确认信号的持久队列(observer 周期批量确认的输入)。
|
|
74
|
-
'signal_confirmations',
|
|
75
|
-
'exports_audit',
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
const EXPECTED_TRAJECTORY_INDEXES = [
|
|
79
|
-
'idx_assistant_turns_session_id',
|
|
80
|
-
'idx_assistant_turns_created_at',
|
|
81
|
-
'idx_assistant_turns_provider_model',
|
|
82
|
-
'idx_user_turns_session_id',
|
|
83
|
-
'idx_tool_calls_session_id',
|
|
84
|
-
'idx_tool_calls_created_at',
|
|
85
|
-
'idx_pain_events_session_id',
|
|
86
|
-
'idx_pain_events_canonical_pain_id',
|
|
87
|
-
'idx_correction_samples_review_status',
|
|
88
|
-
// PRI-790 G2: 队列扫描索引(status + attempts)。
|
|
89
|
-
'idx_signal_confirmations_status',
|
|
90
|
-
];
|
|
91
|
-
|
|
92
|
-
// ── Tests ───────────────────────────────────────────────────────────────────
|
|
93
|
-
|
|
94
|
-
describe('pd runtime init — empty workspace integration', () => {
|
|
95
|
-
let tmpDir: string;
|
|
96
|
-
|
|
97
|
-
beforeEach(() => {
|
|
98
|
-
tmpDir = mkTmpDir();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
afterEach(() => {
|
|
102
|
-
rmTmpDir(tmpDir);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// ── EMPTY-01: initialize empty workspace ───────────────────────────────────
|
|
106
|
-
|
|
107
|
-
describe('EMPTY-01: initialize empty workspace', () => {
|
|
108
|
-
it('returns ok=true with 2 initialized databases', () => {
|
|
109
|
-
const output = buildRuntimeInitOutput(tmpDir, true);
|
|
110
|
-
expect(output.ok).toBe(true);
|
|
111
|
-
expect(output.mode).toBe('confirm');
|
|
112
|
-
expect(output.databases).toHaveLength(2);
|
|
113
|
-
for (const db of output.databases) {
|
|
114
|
-
expect(db.status).toBe('initialized');
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('creates state.db with all expected tables', () => {
|
|
119
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
120
|
-
const stateDbPath = path.join(tmpDir, '.pd', 'state.db');
|
|
121
|
-
expect(fs.existsSync(stateDbPath)).toBe(true);
|
|
122
|
-
const tables = getTableNames(stateDbPath);
|
|
123
|
-
for (const expected of EXPECTED_STATE_TABLES) {
|
|
124
|
-
expect(tables).toContain(expected);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('creates trajectory.db with all 15 expected tables', () => {
|
|
129
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
130
|
-
const trajDbPath = path.join(tmpDir, '.state', 'trajectory.db');
|
|
131
|
-
expect(fs.existsSync(trajDbPath)).toBe(true);
|
|
132
|
-
const tables = getTableNames(trajDbPath);
|
|
133
|
-
expect(tables).toHaveLength(EXPECTED_TRAJECTORY_TABLES.length);
|
|
134
|
-
for (const expected of EXPECTED_TRAJECTORY_TABLES) {
|
|
135
|
-
expect(tables).toContain(expected);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('creates trajectory.db with all expected indexes', () => {
|
|
140
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
141
|
-
const trajDbPath = path.join(tmpDir, '.state', 'trajectory.db');
|
|
142
|
-
const indexes = getIndexNames(trajDbPath);
|
|
143
|
-
for (const expected of EXPECTED_TRAJECTORY_INDEXES) {
|
|
144
|
-
expect(indexes).toContain(expected);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('no longer creates subagent_workflows.db (legacy workflow store retired in PRI-737)', () => {
|
|
149
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
150
|
-
const wfDbPath = path.join(tmpDir, '.state', 'subagent_workflows.db');
|
|
151
|
-
expect(fs.existsSync(wfDbPath)).toBe(false);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('pain_events table has canonical_pain_id and runtime_task_id columns', () => {
|
|
155
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
156
|
-
const trajDbPath = path.join(tmpDir, '.state', 'trajectory.db');
|
|
157
|
-
const db = new Database(trajDbPath, { readonly: true });
|
|
158
|
-
try {
|
|
159
|
-
const cols = db.prepare('PRAGMA table_info(pain_events)').all() as { name: string }[];
|
|
160
|
-
const colNames = cols.map(c => c.name);
|
|
161
|
-
expect(colNames).toContain('canonical_pain_id');
|
|
162
|
-
expect(colNames).toContain('runtime_task_id');
|
|
163
|
-
expect(colNames).toContain('text');
|
|
164
|
-
} finally {
|
|
165
|
-
db.close();
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('no longer creates evolution tables (retired in PRI-770, writer path gone since PRI-737)', () => {
|
|
170
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
171
|
-
const trajDbPath = path.join(tmpDir, '.state', 'trajectory.db');
|
|
172
|
-
const db = new Database(trajDbPath, { readonly: true });
|
|
173
|
-
try {
|
|
174
|
-
const tables = getTableNames(trajDbPath);
|
|
175
|
-
expect(tables).not.toContain('evolution_tasks');
|
|
176
|
-
expect(tables).not.toContain('evolution_events');
|
|
177
|
-
const legacy = db.prepare(
|
|
178
|
-
"SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('evolution_tasks','evolution_events')"
|
|
179
|
-
).all();
|
|
180
|
-
expect(legacy).toHaveLength(0);
|
|
181
|
-
} finally {
|
|
182
|
-
db.close();
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// ── P0: config.yaml scaffolding (Issue 1b) ────────────────────────────────
|
|
187
|
-
|
|
188
|
-
it('creates .pd/config.yaml with version 1 and workspace.default set', () => {
|
|
189
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
190
|
-
const configPath = path.join(tmpDir, '.pd', 'config.yaml');
|
|
191
|
-
expect(fs.existsSync(configPath)).toBe(true);
|
|
192
|
-
const parsed = yaml.load(fs.readFileSync(configPath, 'utf8'), { schema: yaml.JSON_SCHEMA });
|
|
193
|
-
const obj = parsed as { version?: unknown; workspace?: { default?: unknown } };
|
|
194
|
-
expect(obj.version).toBe(1);
|
|
195
|
-
expect(obj.workspace?.default).toBe(path.resolve(tmpDir));
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('generated config.yaml passes validatePdConfig (round-trip)', () => {
|
|
199
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
200
|
-
const configPath = path.join(tmpDir, '.pd', 'config.yaml');
|
|
201
|
-
const parsed: unknown = yaml.load(fs.readFileSync(configPath, 'utf8'), { schema: yaml.JSON_SCHEMA });
|
|
202
|
-
const result = validatePdConfig(parsed);
|
|
203
|
-
expect(result.ok).toBe(true);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// ── EMPTY-02: idempotency ──────────────────────────────────────────────────
|
|
208
|
-
|
|
209
|
-
describe('EMPTY-02: idempotency', () => {
|
|
210
|
-
it('running twice does not error and tables remain intact', () => {
|
|
211
|
-
// First initialization
|
|
212
|
-
const output1 = buildRuntimeInitOutput(tmpDir, true);
|
|
213
|
-
expect(output1.ok).toBe(true);
|
|
214
|
-
|
|
215
|
-
// Capture table counts after first init
|
|
216
|
-
const trajDbPath = path.join(tmpDir, '.state', 'trajectory.db');
|
|
217
|
-
const tables1 = getTableNames(trajDbPath);
|
|
218
|
-
|
|
219
|
-
// Second initialization (should be idempotent)
|
|
220
|
-
const output2 = buildRuntimeInitOutput(tmpDir, true);
|
|
221
|
-
expect(output2.ok).toBe(true);
|
|
222
|
-
expect(output2.databases).toHaveLength(2);
|
|
223
|
-
for (const db of output2.databases) {
|
|
224
|
-
expect(db.status).toBe('initialized');
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Table set should be unchanged
|
|
228
|
-
const tables2 = getTableNames(trajDbPath);
|
|
229
|
-
expect(tables2).toEqual(tables1);
|
|
230
|
-
|
|
231
|
-
// config.yaml is preserved: second run reports skipped, content unchanged
|
|
232
|
-
expect(output2.config?.status).toBe('skipped');
|
|
233
|
-
const configPath = path.join(tmpDir, '.pd', 'config.yaml');
|
|
234
|
-
const config1 = fs.readFileSync(configPath, 'utf8');
|
|
235
|
-
expect(fs.readFileSync(configPath, 'utf8')).toBe(config1);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('dry-run after confirm does not modify existing DBs', () => {
|
|
239
|
-
// First: confirm mode (real init)
|
|
240
|
-
buildRuntimeInitOutput(tmpDir, true);
|
|
241
|
-
const trajDbPath = path.join(tmpDir, '.state', 'trajectory.db');
|
|
242
|
-
const tablesBefore = getTableNames(trajDbPath);
|
|
243
|
-
|
|
244
|
-
// Second: dry-run mode (should not modify)
|
|
245
|
-
const output = buildRuntimeInitOutput(tmpDir, false);
|
|
246
|
-
expect(output.mode).toBe('dry-run');
|
|
247
|
-
|
|
248
|
-
const tablesAfter = getTableNames(trajDbPath);
|
|
249
|
-
expect(tablesAfter).toEqual(tablesBefore);
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
});
|