@principles/pd-cli 1.152.12 → 1.152.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/candidate.d.ts.map +1 -1
- package/dist/commands/candidate.js +34 -7
- package/dist/commands/candidate.js.map +1 -1
- package/dist/commands/diagnose.d.ts.map +1 -1
- package/dist/commands/diagnose.js +23 -7
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/pain-retry.d.ts.map +1 -1
- package/dist/commands/pain-retry.js +21 -7
- package/dist/commands/pain-retry.js.map +1 -1
- 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,430 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
const expectedCliVersion: string = ((): string => {
|
|
6
|
-
const pkg: unknown = require('../../package.json');
|
|
7
|
-
if (typeof pkg === 'object' && pkg !== null && Object.hasOwn(pkg, 'version')) {
|
|
8
|
-
const v: unknown = Reflect.get(pkg, 'version');
|
|
9
|
-
if (typeof v === 'string') return v;
|
|
10
|
-
}
|
|
11
|
-
return 'unknown';
|
|
12
|
-
})();
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
mockSchemaCheck,
|
|
16
|
-
mockHealthSnapshot,
|
|
17
|
-
mockHealthClose,
|
|
18
|
-
mockOrphanCandidates,
|
|
19
|
-
mockQueueSnapshot,
|
|
20
|
-
mockQueueClose,
|
|
21
|
-
mockAuditConsistency,
|
|
22
|
-
mockBuildGfiSnapshot,
|
|
23
|
-
mockClassifyGfiHealth,
|
|
24
|
-
} = vi.hoisted(() => ({
|
|
25
|
-
mockSchemaCheck: vi.fn(),
|
|
26
|
-
mockHealthSnapshot: vi.fn(),
|
|
27
|
-
mockHealthClose: vi.fn().mockResolvedValue(undefined),
|
|
28
|
-
mockOrphanCandidates: vi.fn(),
|
|
29
|
-
mockQueueSnapshot: vi.fn(),
|
|
30
|
-
mockQueueClose: vi.fn().mockResolvedValue(undefined),
|
|
31
|
-
mockAuditConsistency: vi.fn(),
|
|
32
|
-
mockBuildGfiSnapshot: vi.fn(),
|
|
33
|
-
mockClassifyGfiHealth: vi.fn(),
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
37
|
-
resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
vi.mock('@principles/core/runtime-v2', () => ({
|
|
41
|
-
SchemaConformanceReadModel: vi.fn().mockImplementation(function () {
|
|
42
|
-
return { check: mockSchemaCheck };
|
|
43
|
-
}),
|
|
44
|
-
OperatorHealthReadModel: vi.fn().mockImplementation(function () {
|
|
45
|
-
return { getSnapshot: mockHealthSnapshot, close: mockHealthClose };
|
|
46
|
-
}),
|
|
47
|
-
PruningReadModel: vi.fn().mockImplementation(function () {
|
|
48
|
-
return { getOrphanDerivedCandidates: mockOrphanCandidates };
|
|
49
|
-
}),
|
|
50
|
-
createInternalizationQueueReadModel: vi.fn().mockResolvedValue({
|
|
51
|
-
readModel: { getSnapshot: mockQueueSnapshot },
|
|
52
|
-
close: mockQueueClose,
|
|
53
|
-
}),
|
|
54
|
-
auditCandidateLedgerConsistency: mockAuditConsistency,
|
|
55
|
-
buildGfiWorkspaceSnapshot: mockBuildGfiSnapshot,
|
|
56
|
-
classifyGfiWorkspaceHealth: mockClassifyGfiHealth,
|
|
57
|
-
resolveOutputLanguage: vi.fn().mockReturnValue({ outputLanguage: 'zh-CN' }),
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
const { mockLoadPdConfig, mockComputeFlagsFromLoadResult } = vi.hoisted(() => ({
|
|
61
|
-
mockLoadPdConfig: vi.fn(),
|
|
62
|
-
mockComputeFlagsFromLoadResult: vi.fn(),
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
vi.mock('../../src/services/pd-config-loader.js', () => ({
|
|
66
|
-
loadPdConfig: mockLoadPdConfig,
|
|
67
|
-
computeFlagsFromLoadResult: mockComputeFlagsFromLoadResult,
|
|
68
|
-
}));
|
|
69
|
-
|
|
70
|
-
import { runCanaryChecks } from '../../src/commands/runtime-canary.js';
|
|
71
|
-
|
|
72
|
-
const WS = '/fake/workspace';
|
|
73
|
-
|
|
74
|
-
function healthySchemaResult() {
|
|
75
|
-
return {
|
|
76
|
-
overallStatus: 'ok' as const,
|
|
77
|
-
checkedDatabasePath: `${WS}/.pd/state.db`,
|
|
78
|
-
tables: {
|
|
79
|
-
tasks: { exists: true, missingColumns: [] },
|
|
80
|
-
runs: { exists: true, missingColumns: [] },
|
|
81
|
-
artifacts: { exists: true, missingColumns: [] },
|
|
82
|
-
commits: { exists: true, missingColumns: [] },
|
|
83
|
-
principle_candidates: { exists: true, missingColumns: [] },
|
|
84
|
-
pi_artifacts: { exists: true, missingColumns: [] },
|
|
85
|
-
},
|
|
86
|
-
indexes: { missingIndexes: [] },
|
|
87
|
-
migrationsNeeded: [],
|
|
88
|
-
generatedAt: new Date().toISOString(),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function healthyHealthSnapshot() {
|
|
93
|
-
return {
|
|
94
|
-
generatedAt: new Date().toISOString(),
|
|
95
|
-
workspace: WS,
|
|
96
|
-
painChain: { lastSuccessfulChain: null, failureCategory: null },
|
|
97
|
-
candidateLedger: { auditStatus: 'ok' as const, orphanCandidateCount: 0, missingLedgerCount: 0 },
|
|
98
|
-
pruning: { watchCount: 0, reviewCount: 0, orphanDerivedCandidateCount: 0 },
|
|
99
|
-
gfi: { active: null, staleSessionCount: 0, totalSessionCount: 0, activeSessionCount: 0, generatedAt: new Date().toISOString() },
|
|
100
|
-
overallStatus: 'healthy' as const,
|
|
101
|
-
recommendedActions: [],
|
|
102
|
-
totalTaskCount: 1,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function healthyQueueSnapshot() {
|
|
107
|
-
return {
|
|
108
|
-
pendingCount: 0, retryWaitCount: 0, countsByTaskKind: {}, countsByChannel: {},
|
|
109
|
-
invalidMetadataCount: 0, sampleInvalidTaskIds: [],
|
|
110
|
-
blockedSummary: { count: 0, samples: [] }, dependencyFailedSummary: { count: 0, samples: [] },
|
|
111
|
-
leaseConflictSummary: { count: 0, samples: [], sampleTaskIds: [] },
|
|
112
|
-
retryWaitPendingSummary: { count: 0, samples: [] },
|
|
113
|
-
unresolvableSummary: { count: 0, samples: [] },
|
|
114
|
-
readyTasks: [], noReadyTasks: null, suppressedTasks: [],
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function healthyGfiSnapshot() {
|
|
119
|
-
return {
|
|
120
|
-
active: null, staleSessionCount: 0, totalSessionCount: 0, activeSessionCount: 0, generatedAt: new Date().toISOString(),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
describe('runCanaryChecks', () => {
|
|
125
|
-
beforeEach(() => {
|
|
126
|
-
vi.clearAllMocks();
|
|
127
|
-
mockSchemaCheck.mockReturnValue(healthySchemaResult());
|
|
128
|
-
mockHealthSnapshot.mockResolvedValue(healthyHealthSnapshot());
|
|
129
|
-
mockHealthClose.mockResolvedValue(undefined);
|
|
130
|
-
mockOrphanCandidates.mockReturnValue({ candidates: [], dbReadable: true });
|
|
131
|
-
mockQueueSnapshot.mockResolvedValue(healthyQueueSnapshot());
|
|
132
|
-
mockQueueClose.mockResolvedValue(undefined);
|
|
133
|
-
mockAuditConsistency.mockResolvedValue({ status: 'ok', consumedCount: 0, orphanCandidateCount: 0, missingLedgerCount: 0 });
|
|
134
|
-
mockBuildGfiSnapshot.mockReturnValue(healthyGfiSnapshot());
|
|
135
|
-
mockClassifyGfiHealth.mockReturnValue({ status: 'healthy', reason: '0 active, 0 stale sessions', staleGfiDegradedThreshold: 40 });
|
|
136
|
-
// Default: GFI enabled, no warnings (canonical config loader)
|
|
137
|
-
mockLoadPdConfig.mockReturnValue({
|
|
138
|
-
ok: true,
|
|
139
|
-
effective: {},
|
|
140
|
-
source: 'defaults',
|
|
141
|
-
configPath: `${WS}/.pd/config.yaml`,
|
|
142
|
-
warnings: [],
|
|
143
|
-
legacyFilesDetected: [],
|
|
144
|
-
legacyFileNextActions: [],
|
|
145
|
-
});
|
|
146
|
-
mockComputeFlagsFromLoadResult.mockReturnValue({
|
|
147
|
-
flags: {
|
|
148
|
-
prompt: { id: 'prompt', category: 'core', enabled: true },
|
|
149
|
-
code_tool_hook: { id: 'code_tool_hook', category: 'core', enabled: true },
|
|
150
|
-
defer_archive: { id: 'defer_archive', category: 'core', enabled: true },
|
|
151
|
-
gfi: { id: 'gfi', category: 'quiet', enabled: true },
|
|
152
|
-
},
|
|
153
|
-
enabledChannels: ['prompt', 'code_tool_hook', 'defer_archive'],
|
|
154
|
-
warnings: [],
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('returns healthy when all checks are healthy', async () => {
|
|
159
|
-
const result = await runCanaryChecks(WS);
|
|
160
|
-
|
|
161
|
-
expect(result.overallStatus).toBe('healthy');
|
|
162
|
-
expect(result.checks.length).toBeGreaterThanOrEqual(5);
|
|
163
|
-
expect(result.checks.every(c => c.status === 'healthy')).toBe(true);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('returns degraded when a single check is degraded', async () => {
|
|
167
|
-
mockSchemaCheck.mockReturnValue({
|
|
168
|
-
...healthySchemaResult(),
|
|
169
|
-
overallStatus: 'degraded',
|
|
170
|
-
migrationsNeeded: ['add_trigger_pattern'],
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const result = await runCanaryChecks(WS);
|
|
174
|
-
|
|
175
|
-
expect(result.overallStatus).toBe('degraded');
|
|
176
|
-
const schemaCheck = result.checks.find(c => c.name === 'schema_conformance');
|
|
177
|
-
expect(schemaCheck?.status).toBe('degraded');
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('reports an unexercised runtime as degraded with a next action', async () => {
|
|
181
|
-
mockHealthSnapshot.mockResolvedValue({
|
|
182
|
-
...healthyHealthSnapshot(), totalTaskCount: 0,
|
|
183
|
-
recommendedActions: ['Runtime V2 pipeline has never been exercised.'],
|
|
184
|
-
});
|
|
185
|
-
const result = await runCanaryChecks(WS);
|
|
186
|
-
const runtimeCheck = result.checks.find(check => check.name === 'runtime_health');
|
|
187
|
-
expect(result.overallStatus).toBe('degraded');
|
|
188
|
-
expect(runtimeCheck?.status).toBe('degraded');
|
|
189
|
-
expect(runtimeCheck?.summary).toContain('not been exercised');
|
|
190
|
-
expect(result.recommendedNextActions).toContainEqual(expect.stringContaining('pain record'));
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('surfaces a real error (e.g. DB missing) as error, not masked by cold-start totalTaskCount=0', async () => {
|
|
194
|
-
// Simulates DB-missing scenario: overallStatus='error' while totalTaskCount stays 0
|
|
195
|
-
// (getTotalTaskCount() throws and the snapshot keeps the default 0).
|
|
196
|
-
mockHealthSnapshot.mockResolvedValue({
|
|
197
|
-
...healthyHealthSnapshot(),
|
|
198
|
-
overallStatus: 'error' as const,
|
|
199
|
-
totalTaskCount: 0,
|
|
200
|
-
recommendedActions: ['Re-initialize the runtime database.'],
|
|
201
|
-
});
|
|
202
|
-
const result = await runCanaryChecks(WS);
|
|
203
|
-
const runtimeCheck = result.checks.find(check => check.name === 'runtime_health');
|
|
204
|
-
expect(runtimeCheck?.status).toBe('error');
|
|
205
|
-
// Summary must surface the error, NOT the cold-start "not been exercised" message.
|
|
206
|
-
expect(runtimeCheck?.summary).not.toContain('not been exercised');
|
|
207
|
-
expect(runtimeCheck?.summary).toContain('error');
|
|
208
|
-
expect(runtimeCheck?.summary).toContain('Re-initialize the runtime database.');
|
|
209
|
-
expect(result.overallStatus).toBe('error');
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('reports the package version instead of a hard-coded shim version', async () => {
|
|
213
|
-
const result = await runCanaryChecks(WS);
|
|
214
|
-
const shimCheck = result.checks.find(check => check.name === 'pd_shim_info');
|
|
215
|
-
expect(shimCheck?.details).toMatchObject({ version: expectedCliVersion });
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('continues other checks when one throws', async () => {
|
|
219
|
-
mockAuditConsistency.mockRejectedValue(new Error('DB error'));
|
|
220
|
-
|
|
221
|
-
const result = await runCanaryChecks(WS);
|
|
222
|
-
|
|
223
|
-
expect(result.overallStatus).not.toBe('healthy');
|
|
224
|
-
const auditCheck = result.checks.find(c => c.name === 'candidate_audit');
|
|
225
|
-
expect(auditCheck?.status).toBe('error');
|
|
226
|
-
expect(auditCheck?.error).toBeTruthy();
|
|
227
|
-
const schemaCheck = result.checks.find(c => c.name === 'schema_conformance');
|
|
228
|
-
expect(schemaCheck?.status).toBe('healthy');
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('produces stable JSON-serializable output', async () => {
|
|
232
|
-
const result = await runCanaryChecks(WS);
|
|
233
|
-
|
|
234
|
-
const json = JSON.stringify(result);
|
|
235
|
-
const parsed = JSON.parse(json);
|
|
236
|
-
|
|
237
|
-
expect(parsed.overallStatus).toBe('healthy');
|
|
238
|
-
expect(parsed.checks).toBeInstanceOf(Array);
|
|
239
|
-
expect(parsed.recommendedNextActions).toBeInstanceOf(Array);
|
|
240
|
-
expect(parsed.generatedAt).toBeTruthy();
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('includes recommendedNextActions for schema mismatch', async () => {
|
|
244
|
-
mockSchemaCheck.mockReturnValue({
|
|
245
|
-
...healthySchemaResult(),
|
|
246
|
-
overallStatus: 'degraded',
|
|
247
|
-
migrationsNeeded: ['add_trigger_pattern'],
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
const result = await runCanaryChecks(WS);
|
|
251
|
-
|
|
252
|
-
expect(result.recommendedNextActions.length).toBeGreaterThan(0);
|
|
253
|
-
expect(result.recommendedNextActions.some(a => a.includes('migrate schema'))).toBe(true);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('includes recommendedNextActions for pruning orphans', async () => {
|
|
257
|
-
mockOrphanCandidates.mockReturnValue({
|
|
258
|
-
candidates: [{ candidateId: 'c1', principleId: 'p1', reason: 'not found' }],
|
|
259
|
-
dbReadable: true,
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
const result = await runCanaryChecks(WS);
|
|
263
|
-
|
|
264
|
-
expect(result.overallStatus).toBe('degraded');
|
|
265
|
-
expect(result.recommendedNextActions.some(a => a.includes('pruning orphans') || a.includes('dry-run'))).toBe(true);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it('uses createInternalizationQueueReadModel with readonly: true (no RuntimeStateManager)', async () => {
|
|
269
|
-
const fs = await import('fs');
|
|
270
|
-
const src = fs.readFileSync(require.resolve('../../src/commands/runtime-canary.ts'), 'utf-8');
|
|
271
|
-
expect(src).not.toContain('RuntimeStateManager');
|
|
272
|
-
expect(src).toContain('createInternalizationQueueReadModel');
|
|
273
|
-
expect(src).toMatch(/createInternalizationQueueReadModel\(\{[^}]*readonly:\s*true/);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it('calls queue close once on healthy path', async () => {
|
|
277
|
-
await runCanaryChecks(WS);
|
|
278
|
-
expect(mockQueueClose).toHaveBeenCalledTimes(1);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('includes nextReadyTaskKind and nextReadyTaskId in top-level internalizationQueueSummary when queue has ready tasks', async () => {
|
|
282
|
-
mockQueueSnapshot.mockResolvedValue({
|
|
283
|
-
pendingCount: 2,
|
|
284
|
-
retryWaitCount: 1,
|
|
285
|
-
countsByTaskKind: { dreamer: 3 },
|
|
286
|
-
countsByChannel: {},
|
|
287
|
-
invalidMetadataCount: 0,
|
|
288
|
-
sampleInvalidTaskIds: [],
|
|
289
|
-
blockedSummary: { count: 0, samples: [] },
|
|
290
|
-
dependencyFailedSummary: { count: 0, samples: [] },
|
|
291
|
-
leaseConflictSummary: { count: 0, samples: [], sampleTaskIds: [] },
|
|
292
|
-
retryWaitPendingSummary: { count: 0, samples: [] },
|
|
293
|
-
unresolvableSummary: { count: 0, samples: [] },
|
|
294
|
-
readyTasks: [
|
|
295
|
-
{ taskId: 'task-abc-123', taskKind: 'dreamer', channel: 'pi' },
|
|
296
|
-
{ taskId: 'task-def-456', taskKind: 'philosopher', channel: 'pi' },
|
|
297
|
-
],
|
|
298
|
-
noReadyTasks: null,
|
|
299
|
-
suppressedTasks: [],
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
const result = await runCanaryChecks(WS);
|
|
303
|
-
|
|
304
|
-
expect(result.internalizationQueueSummary).toBeDefined();
|
|
305
|
-
expect(result.internalizationQueueSummary?.readyCount).toBe(2);
|
|
306
|
-
expect(result.internalizationQueueSummary?.retryWaitCount).toBe(1);
|
|
307
|
-
expect(result.internalizationQueueSummary?.pendingCount).toBe(2);
|
|
308
|
-
expect(result.internalizationQueueSummary?.nextReadyTaskKind).toBe('dreamer');
|
|
309
|
-
expect(result.internalizationQueueSummary?.nextReadyTaskId).toBe('task-abc-123');
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
it('includes noReadyReason in internalizationQueueSummary when no ready tasks exist', async () => {
|
|
313
|
-
mockQueueSnapshot.mockResolvedValue({
|
|
314
|
-
pendingCount: 0,
|
|
315
|
-
retryWaitCount: 0,
|
|
316
|
-
countsByTaskKind: {},
|
|
317
|
-
countsByChannel: {},
|
|
318
|
-
invalidMetadataCount: 5,
|
|
319
|
-
sampleInvalidTaskIds: ['bad-1', 'bad-2'],
|
|
320
|
-
blockedSummary: { count: 0, samples: [] },
|
|
321
|
-
dependencyFailedSummary: { count: 0, samples: [] },
|
|
322
|
-
leaseConflictSummary: { count: 0, samples: [], sampleTaskIds: [] },
|
|
323
|
-
retryWaitPendingSummary: { count: 0, samples: [] },
|
|
324
|
-
unresolvableSummary: { count: 0, samples: [] },
|
|
325
|
-
readyTasks: [],
|
|
326
|
-
noReadyTasks: { reason: 'all_hydration_failed', inspectedCount: 5 },
|
|
327
|
-
suppressedTasks: [],
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
const result = await runCanaryChecks(WS);
|
|
331
|
-
|
|
332
|
-
expect(result.internalizationQueueSummary).toBeDefined();
|
|
333
|
-
expect(result.internalizationQueueSummary?.readyCount).toBe(0);
|
|
334
|
-
expect(result.internalizationQueueSummary?.retryWaitCount).toBe(0);
|
|
335
|
-
expect(result.internalizationQueueSummary?.pendingCount).toBe(0);
|
|
336
|
-
expect(result.internalizationQueueSummary?.nextReadyTaskKind).toBeNull();
|
|
337
|
-
expect(result.internalizationQueueSummary?.nextReadyTaskId).toBeNull();
|
|
338
|
-
expect(result.internalizationQueueSummary?.noReadyReason).toBe('all_hydration_failed');
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
describe('GFI config warning degraded status', () => {
|
|
342
|
-
it('returns healthy when GFI disabled with no warnings', async () => {
|
|
343
|
-
mockComputeFlagsFromLoadResult.mockReturnValue({
|
|
344
|
-
flags: {
|
|
345
|
-
gfi: { id: 'gfi', category: 'quiet', enabled: false },
|
|
346
|
-
},
|
|
347
|
-
enabledChannels: [],
|
|
348
|
-
warnings: [],
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
const result = await runCanaryChecks(WS);
|
|
352
|
-
const gfiCheck = result.checks.find(c => c.name === 'gfi_snapshot');
|
|
353
|
-
|
|
354
|
-
expect(gfiCheck?.status).toBe('healthy');
|
|
355
|
-
expect(gfiCheck?.summary).toContain('disabled');
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
it('returns degraded when GFI disabled but config has warnings (malformed YAML)', async () => {
|
|
359
|
-
mockComputeFlagsFromLoadResult.mockReturnValue({
|
|
360
|
-
flags: {
|
|
361
|
-
gfi: { id: 'gfi', category: 'quiet', enabled: false },
|
|
362
|
-
},
|
|
363
|
-
enabledChannels: [],
|
|
364
|
-
warnings: ['.pd/config.yaml: YAML parse error, using defaults'],
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
const result = await runCanaryChecks(WS);
|
|
368
|
-
const gfiCheck = result.checks.find(c => c.name === 'gfi_snapshot');
|
|
369
|
-
|
|
370
|
-
expect(gfiCheck?.status).toBe('degraded');
|
|
371
|
-
expect(gfiCheck?.summary).toContain('warnings');
|
|
372
|
-
expect(gfiCheck?.details).toBeDefined();
|
|
373
|
-
expect(result.recommendedNextActions.some(a => a.includes('config.yaml'))).toBe(true);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('returns degraded when GFI disabled but config has malformed override warning', async () => {
|
|
377
|
-
mockComputeFlagsFromLoadResult.mockReturnValue({
|
|
378
|
-
flags: {
|
|
379
|
-
gfi: { id: 'gfi', category: 'quiet', enabled: false },
|
|
380
|
-
},
|
|
381
|
-
enabledChannels: [],
|
|
382
|
-
warnings: ["flag 'gfi': malformed override kept default (enabled must be boolean)"],
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
const result = await runCanaryChecks(WS);
|
|
386
|
-
const gfiCheck = result.checks.find(c => c.name === 'gfi_snapshot');
|
|
387
|
-
|
|
388
|
-
expect(gfiCheck?.status).toBe('degraded');
|
|
389
|
-
expect(result.recommendedNextActions.some(a => a.includes('config.yaml') || a.includes('pd runtime features'))).toBe(true);
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it('runs GFI snapshot when flag enabled with no warnings', async () => {
|
|
393
|
-
mockComputeFlagsFromLoadResult.mockReturnValue({
|
|
394
|
-
flags: {
|
|
395
|
-
gfi: { id: 'gfi', category: 'quiet', enabled: true },
|
|
396
|
-
},
|
|
397
|
-
enabledChannels: [],
|
|
398
|
-
warnings: [],
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
const result = await runCanaryChecks(WS);
|
|
402
|
-
const gfiCheck = result.checks.find(c => c.name === 'gfi_snapshot');
|
|
403
|
-
|
|
404
|
-
expect(gfiCheck?.status).toBe('healthy');
|
|
405
|
-
expect(gfiCheck?.summary).toContain('OK');
|
|
406
|
-
expect(mockBuildGfiSnapshot).toHaveBeenCalled();
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
it('recommends session lifecycle review for GFI session issues (not config)', async () => {
|
|
410
|
-
mockComputeFlagsFromLoadResult.mockReturnValue({
|
|
411
|
-
flags: {
|
|
412
|
-
gfi: { id: 'gfi', category: 'quiet', enabled: true },
|
|
413
|
-
},
|
|
414
|
-
enabledChannels: [],
|
|
415
|
-
warnings: [],
|
|
416
|
-
});
|
|
417
|
-
mockClassifyGfiHealth.mockReturnValue({
|
|
418
|
-
status: 'degraded',
|
|
419
|
-
reason: '5 stale sessions found',
|
|
420
|
-
staleGfiDegradedThreshold: 40,
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
const result = await runCanaryChecks(WS);
|
|
424
|
-
const gfiCheck = result.checks.find(c => c.name === 'gfi_snapshot');
|
|
425
|
-
|
|
426
|
-
expect(gfiCheck?.status).toBe('degraded');
|
|
427
|
-
expect(result.recommendedNextActions.some(a => a.includes('GFI sessions') || a.includes('session lifecycle'))).toBe(true);
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* runtime compatibility-scan tests — pd runtime compatibility-scan (P1-3).
|
|
3
|
-
*
|
|
4
|
-
* Real persisted-workspace fixtures (SqliteConnection + activation store) —
|
|
5
|
-
* no DB mocks, the production read path is exercised end to end (EP-09).
|
|
6
|
-
*
|
|
7
|
-
* Covers:
|
|
8
|
-
* - SCAN-01: clean RuleContextV2-only active rule → exit 0, status clean (cli-1/cli-6)
|
|
9
|
-
* - SCAN-02: active rule reading session.recentThinking → exit 1,
|
|
10
|
-
* reason legacy_rule_contract_dependency, remediation names the rule (cli-6)
|
|
11
|
-
* - SCAN-03: workspace without state.db → exit 0, status no_state_db
|
|
12
|
-
* - SCAN-04: --json emits exactly one parseable JSON object (cli-1)
|
|
13
|
-
* - SCAN-05: command wiring — real Commander registration (cli-7)
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
17
|
-
import * as path from 'node:path';
|
|
18
|
-
import * as os from 'node:os';
|
|
19
|
-
import * as fs from 'node:fs';
|
|
20
|
-
import { SqliteConnection, SqliteActivationStateStore } from '@principles/core/runtime-v2';
|
|
21
|
-
import { handleRuntimeCompatibilityScan } from '../../src/commands/runtime-compatibility-scan.js';
|
|
22
|
-
|
|
23
|
-
const LEGACY_CODE = `
|
|
24
|
-
function evaluate(input, helpers) {
|
|
25
|
-
if (input.session && input.session.recentThinking === true) {
|
|
26
|
-
return { decision: 'block', matched: true };
|
|
27
|
-
}
|
|
28
|
-
return { decision: 'allow', matched: false };
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
const CLEAN_CODE = `
|
|
33
|
-
function evaluate(input, helpers) {
|
|
34
|
-
var h = input.context && input.context.history;
|
|
35
|
-
return { decision: 'allow', matched: false };
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
let tempWorkspaceDir: string;
|
|
40
|
-
let conn: SqliteConnection;
|
|
41
|
-
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
44
|
-
vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
45
|
-
process.exitCode = undefined;
|
|
46
|
-
tempWorkspaceDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-compat-cmd-'));
|
|
47
|
-
conn = new SqliteConnection(tempWorkspaceDir);
|
|
48
|
-
conn.getDb();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
afterEach(() => {
|
|
52
|
-
vi.restoreAllMocks();
|
|
53
|
-
try { conn?.close(); } catch { /* best-effort */ }
|
|
54
|
-
try { fs.rmSync(tempWorkspaceDir, { recursive: true, force: true }); } catch { /* Windows */ }
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
async function seedActiveRule(artifactId: string, ruleId: string, implementationCode: string): Promise<void> {
|
|
58
|
-
const now = new Date().toISOString();
|
|
59
|
-
conn.getDb().prepare(`
|
|
60
|
-
INSERT INTO pi_artifacts (artifact_id, artifact_kind, source_task_id, source_principle_id, source_rule_id, lineage_artifact_ids, validation_status, content_json, created_at, updated_at)
|
|
61
|
-
VALUES (?, 'rule', ?, ?, ?, '[]', 'validated', ?, ?, ?)
|
|
62
|
-
`).run(artifactId, `task-${artifactId}`, `principle-${ruleId}`, ruleId, JSON.stringify({ ruleId, implementationCode }), now, now);
|
|
63
|
-
await new SqliteActivationStateStore(conn).recordActivation({
|
|
64
|
-
activationId: `act-${artifactId}`,
|
|
65
|
-
idempotencyKey: `${artifactId}::code_tool_hook`,
|
|
66
|
-
artifactId,
|
|
67
|
-
channel: 'code_tool_hook',
|
|
68
|
-
action: 'code_tool_hook_live_activate',
|
|
69
|
-
targetRef: `impl://${ruleId}`,
|
|
70
|
-
activatedAt: now,
|
|
71
|
-
deactivatedAt: null,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function capturedStdout(): string {
|
|
76
|
-
const calls = (console.log as unknown as { mock: { calls: unknown[][] } }).mock.calls;
|
|
77
|
-
return calls.map(c => String(c[0] ?? '')).join('\n');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
describe('pd runtime compatibility-scan', () => {
|
|
81
|
-
it('SCAN-01: clean current-contract rule exits 0 with status clean', async () => {
|
|
82
|
-
await seedActiveRule('art-clean', 'rule-clean', CLEAN_CODE);
|
|
83
|
-
await handleRuntimeCompatibilityScan({ workspace: tempWorkspaceDir, json: true });
|
|
84
|
-
expect(process.exitCode).toBeUndefined();
|
|
85
|
-
const parsed = JSON.parse(capturedStdout()) as Record<string, unknown>;
|
|
86
|
-
expect(parsed['status']).toBe('clean');
|
|
87
|
-
expect(parsed['ok']).toBe(true);
|
|
88
|
-
expect(parsed['findings']).toEqual([]);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('SCAN-02: legacy recentThinking rule exits 1 with structured reason + remediation', async () => {
|
|
92
|
-
await seedActiveRule('art-legacy', 'rule-real-diagnosis-first', LEGACY_CODE);
|
|
93
|
-
await handleRuntimeCompatibilityScan({ workspace: tempWorkspaceDir, json: true });
|
|
94
|
-
expect(process.exitCode).toBe(1);
|
|
95
|
-
const parsed = JSON.parse(capturedStdout()) as Record<string, unknown>;
|
|
96
|
-
expect(parsed['ok']).toBe(false);
|
|
97
|
-
expect(parsed['status']).toBe('legacy_dependency');
|
|
98
|
-
expect(parsed['reason']).toBe('legacy_rule_contract_dependency');
|
|
99
|
-
const findings = parsed['findings'] as Array<Record<string, unknown>>;
|
|
100
|
-
expect(findings).toHaveLength(1);
|
|
101
|
-
expect(findings[0]).toMatchObject({ symbol: 'recentThinking', ruleId: 'rule-real-diagnosis-first' });
|
|
102
|
-
const remediation = parsed['remediation'] as string;
|
|
103
|
-
expect(remediation).toContain('rule-real-diagnosis-first');
|
|
104
|
-
expect(remediation).toContain('igrate or deactivate');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('SCAN-03: workspace without state.db exits 0 with status no_state_db', async () => {
|
|
108
|
-
const emptyDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-compat-empty-cmd-'));
|
|
109
|
-
try {
|
|
110
|
-
await handleRuntimeCompatibilityScan({ workspace: emptyDir, json: true });
|
|
111
|
-
expect(process.exitCode).toBeUndefined();
|
|
112
|
-
const parsed = JSON.parse(capturedStdout()) as Record<string, unknown>;
|
|
113
|
-
expect(parsed['status']).toBe('no_state_db');
|
|
114
|
-
expect(parsed['ok']).toBe(true);
|
|
115
|
-
// Side-effect-free: the scan must not create a state.db (cli-5).
|
|
116
|
-
expect(fs.existsSync(path.join(emptyDir, '.pd', 'state.db'))).toBe(false);
|
|
117
|
-
} finally {
|
|
118
|
-
fs.rmSync(emptyDir, { recursive: true, force: true });
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('SCAN-04: --json stdout is exactly one parseable JSON object (cli-1)', async () => {
|
|
123
|
-
await seedActiveRule('art-clean2', 'rule-clean2', CLEAN_CODE);
|
|
124
|
-
await handleRuntimeCompatibilityScan({ workspace: tempWorkspaceDir, json: true });
|
|
125
|
-
const out = capturedStdout().trim();
|
|
126
|
-
expect(out.startsWith('{')).toBe(true);
|
|
127
|
-
expect(out.endsWith('}')).toBe(true);
|
|
128
|
-
expect(() => JSON.parse(out)).not.toThrow();
|
|
129
|
-
expect((out.match(/\{/g) ?? []).length).toBeGreaterThanOrEqual(1);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('SCAN-05: command is registered on a real Commander program (cli-7)', async () => {
|
|
133
|
-
const { Command } = await import('commander');
|
|
134
|
-
const { registerRuntimeCompatibilityScanCommand } = await import('../../src/commands/runtime-compatibility-scan.js');
|
|
135
|
-
const program = new Command();
|
|
136
|
-
program.name('pd').exitOverride();
|
|
137
|
-
const runtimeCmd = program.command('runtime').description('Runtime inspection and health checks');
|
|
138
|
-
registerRuntimeCompatibilityScanCommand(runtimeCmd);
|
|
139
|
-
const scanCmd = runtimeCmd.commands.find(c => c.name() === 'compatibility-scan');
|
|
140
|
-
expect(scanCmd).toBeDefined();
|
|
141
|
-
expect(scanCmd?.description()).toContain('retired RuleHost contract');
|
|
142
|
-
// Flag wiring: -w/--workspace and --json registered; no mutating flags exist.
|
|
143
|
-
expect(scanCmd?.options.map(o => o.long)).toContain('--workspace');
|
|
144
|
-
expect(scanCmd?.options.map(o => o.long)).toContain('--json');
|
|
145
|
-
});
|
|
146
|
-
});
|