@principles/pd-cli 1.73.0
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/README.md +90 -0
- package/dist/commands/artifact.d.ts +14 -0
- package/dist/commands/artifact.d.ts.map +1 -0
- package/dist/commands/artifact.js +67 -0
- package/dist/commands/artifact.js.map +1 -0
- package/dist/commands/candidate.d.ts +83 -0
- package/dist/commands/candidate.d.ts.map +1 -0
- package/dist/commands/candidate.js +891 -0
- package/dist/commands/candidate.js.map +1 -0
- package/dist/commands/central-sync.d.ts +10 -0
- package/dist/commands/central-sync.d.ts.map +1 -0
- package/dist/commands/central-sync.js +32 -0
- package/dist/commands/central-sync.js.map +1 -0
- package/dist/commands/console.d.ts +9 -0
- package/dist/commands/console.d.ts.map +1 -0
- package/dist/commands/console.js +114 -0
- package/dist/commands/console.js.map +1 -0
- package/dist/commands/context.d.ts +7 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +55 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/demo-story-a.d.ts +12 -0
- package/dist/commands/demo-story-a.d.ts.map +1 -0
- package/dist/commands/demo-story-a.js +175 -0
- package/dist/commands/demo-story-a.js.map +1 -0
- package/dist/commands/diagnose.d.ts +35 -0
- package/dist/commands/diagnose.d.ts.map +1 -0
- package/dist/commands/diagnose.js +390 -0
- package/dist/commands/diagnose.js.map +1 -0
- package/dist/commands/evolution-tasks-list.d.ts +15 -0
- package/dist/commands/evolution-tasks-list.d.ts.map +1 -0
- package/dist/commands/evolution-tasks-list.js +34 -0
- package/dist/commands/evolution-tasks-list.js.map +1 -0
- package/dist/commands/evolution-tasks-show.d.ts +14 -0
- package/dist/commands/evolution-tasks-show.d.ts.map +1 -0
- package/dist/commands/evolution-tasks-show.js +52 -0
- package/dist/commands/evolution-tasks-show.js.map +1 -0
- package/dist/commands/flow.d.ts +7 -0
- package/dist/commands/flow.d.ts.map +1 -0
- package/dist/commands/flow.js +57 -0
- package/dist/commands/flow.js.map +1 -0
- package/dist/commands/health.d.ts +16 -0
- package/dist/commands/health.d.ts.map +1 -0
- package/dist/commands/health.js +150 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/history.d.ts +11 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +50 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/legacy-cleanup.d.ts +27 -0
- package/dist/commands/legacy-cleanup.d.ts.map +1 -0
- package/dist/commands/legacy-cleanup.js +171 -0
- package/dist/commands/legacy-cleanup.js.map +1 -0
- package/dist/commands/legacy-import.d.ts +7 -0
- package/dist/commands/legacy-import.d.ts.map +1 -0
- package/dist/commands/legacy-import.js +86 -0
- package/dist/commands/legacy-import.js.map +1 -0
- package/dist/commands/pain-record.d.ts +10 -0
- package/dist/commands/pain-record.d.ts.map +1 -0
- package/dist/commands/pain-record.js +162 -0
- package/dist/commands/pain-record.js.map +1 -0
- package/dist/commands/proven-channel-baseline.d.ts +12 -0
- package/dist/commands/proven-channel-baseline.d.ts.map +1 -0
- package/dist/commands/proven-channel-baseline.js +97 -0
- package/dist/commands/proven-channel-baseline.js.map +1 -0
- package/dist/commands/remediation-output.d.ts +40 -0
- package/dist/commands/remediation-output.d.ts.map +1 -0
- package/dist/commands/remediation-output.js +23 -0
- package/dist/commands/remediation-output.js.map +1 -0
- package/dist/commands/run.d.ts +10 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +68 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/runtime-activation.d.ts +11 -0
- package/dist/commands/runtime-activation.d.ts.map +1 -0
- package/dist/commands/runtime-activation.js +150 -0
- package/dist/commands/runtime-activation.js.map +1 -0
- package/dist/commands/runtime-canary.d.ts +30 -0
- package/dist/commands/runtime-canary.d.ts.map +1 -0
- package/dist/commands/runtime-canary.js +343 -0
- package/dist/commands/runtime-canary.js.map +1 -0
- package/dist/commands/runtime-diagnostics-export.d.ts +20 -0
- package/dist/commands/runtime-diagnostics-export.d.ts.map +1 -0
- package/dist/commands/runtime-diagnostics-export.js +177 -0
- package/dist/commands/runtime-diagnostics-export.js.map +1 -0
- package/dist/commands/runtime-features.d.ts +26 -0
- package/dist/commands/runtime-features.d.ts.map +1 -0
- package/dist/commands/runtime-features.js +70 -0
- package/dist/commands/runtime-features.js.map +1 -0
- package/dist/commands/runtime-gfi-snapshot.d.ts +7 -0
- package/dist/commands/runtime-gfi-snapshot.d.ts.map +1 -0
- package/dist/commands/runtime-gfi-snapshot.js +101 -0
- package/dist/commands/runtime-gfi-snapshot.js.map +1 -0
- package/dist/commands/runtime-health-snapshot.d.ts +7 -0
- package/dist/commands/runtime-health-snapshot.d.ts.map +1 -0
- package/dist/commands/runtime-health-snapshot.js +93 -0
- package/dist/commands/runtime-health-snapshot.js.map +1 -0
- package/dist/commands/runtime-idle-trigger.d.ts +12 -0
- package/dist/commands/runtime-idle-trigger.d.ts.map +1 -0
- package/dist/commands/runtime-idle-trigger.js +102 -0
- package/dist/commands/runtime-idle-trigger.js.map +1 -0
- package/dist/commands/runtime-internalization-enqueue-successors.d.ts +9 -0
- package/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-enqueue-successors.js +393 -0
- package/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -0
- package/dist/commands/runtime-internalization-integrity-repair.d.ts +9 -0
- package/dist/commands/runtime-internalization-integrity-repair.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-integrity-repair.js +54 -0
- package/dist/commands/runtime-internalization-integrity-repair.js.map +1 -0
- package/dist/commands/runtime-internalization-integrity.d.ts +7 -0
- package/dist/commands/runtime-internalization-integrity.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-integrity.js +53 -0
- package/dist/commands/runtime-internalization-integrity.js.map +1 -0
- package/dist/commands/runtime-internalization-queue.d.ts +7 -0
- package/dist/commands/runtime-internalization-queue.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-queue.js +85 -0
- package/dist/commands/runtime-internalization-queue.js.map +1 -0
- package/dist/commands/runtime-internalization-run-once.d.ts +12 -0
- package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-run-once.js +546 -0
- package/dist/commands/runtime-internalization-run-once.js.map +1 -0
- package/dist/commands/runtime-internalization-wake-once.d.ts +8 -0
- package/dist/commands/runtime-internalization-wake-once.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-wake-once.js +72 -0
- package/dist/commands/runtime-internalization-wake-once.js.map +1 -0
- package/dist/commands/runtime-pain-flood-simulation.d.ts +10 -0
- package/dist/commands/runtime-pain-flood-simulation.d.ts.map +1 -0
- package/dist/commands/runtime-pain-flood-simulation.js +104 -0
- package/dist/commands/runtime-pain-flood-simulation.js.map +1 -0
- package/dist/commands/runtime-pruning.d.ts +45 -0
- package/dist/commands/runtime-pruning.d.ts.map +1 -0
- package/dist/commands/runtime-pruning.js +355 -0
- package/dist/commands/runtime-pruning.js.map +1 -0
- package/dist/commands/runtime-recovery.d.ts +9 -0
- package/dist/commands/runtime-recovery.d.ts.map +1 -0
- package/dist/commands/runtime-recovery.js +94 -0
- package/dist/commands/runtime-recovery.js.map +1 -0
- package/dist/commands/runtime-synthetic-baseline.d.ts +7 -0
- package/dist/commands/runtime-synthetic-baseline.d.ts.map +1 -0
- package/dist/commands/runtime-synthetic-baseline.js +59 -0
- package/dist/commands/runtime-synthetic-baseline.js.map +1 -0
- package/dist/commands/runtime-uat.d.ts +52 -0
- package/dist/commands/runtime-uat.d.ts.map +1 -0
- package/dist/commands/runtime-uat.js +274 -0
- package/dist/commands/runtime-uat.js.map +1 -0
- package/dist/commands/runtime.d.ts +20 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +256 -0
- package/dist/commands/runtime.js.map +1 -0
- package/dist/commands/samples-list.d.ts +11 -0
- package/dist/commands/samples-list.d.ts.map +1 -0
- package/dist/commands/samples-list.js +37 -0
- package/dist/commands/samples-list.js.map +1 -0
- package/dist/commands/samples-review.d.ts +14 -0
- package/dist/commands/samples-review.d.ts.map +1 -0
- package/dist/commands/samples-review.js +22 -0
- package/dist/commands/samples-review.js.map +1 -0
- package/dist/commands/task.d.ts +14 -0
- package/dist/commands/task.d.ts.map +1 -0
- package/dist/commands/task.js +92 -0
- package/dist/commands/task.js.map +1 -0
- package/dist/commands/trace.d.ts +19 -0
- package/dist/commands/trace.d.ts.map +1 -0
- package/dist/commands/trace.js +154 -0
- package/dist/commands/trace.js.map +1 -0
- package/dist/commands/trajectory.d.ts +11 -0
- package/dist/commands/trajectory.d.ts.map +1 -0
- package/dist/commands/trajectory.js +47 -0
- package/dist/commands/trajectory.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +736 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy/legacy-import.d.ts +15 -0
- package/dist/legacy/legacy-import.d.ts.map +1 -0
- package/dist/legacy/legacy-import.js +141 -0
- package/dist/legacy/legacy-import.js.map +1 -0
- package/dist/legacy/session-history-import.d.ts +26 -0
- package/dist/legacy/session-history-import.d.ts.map +1 -0
- package/dist/legacy/session-history-import.js +151 -0
- package/dist/legacy/session-history-import.js.map +1 -0
- package/dist/principle-tree-ledger-adapter.d.ts +12 -0
- package/dist/principle-tree-ledger-adapter.d.ts.map +1 -0
- package/dist/principle-tree-ledger-adapter.js +12 -0
- package/dist/principle-tree-ledger-adapter.js.map +1 -0
- package/dist/resolve-workspace.d.ts +12 -0
- package/dist/resolve-workspace.d.ts.map +1 -0
- package/dist/resolve-workspace.js +20 -0
- package/dist/resolve-workspace.js.map +1 -0
- package/dist/services/demo-story-a-runner.d.ts +8 -0
- package/dist/services/demo-story-a-runner.d.ts.map +1 -0
- package/dist/services/demo-story-a-runner.js +369 -0
- package/dist/services/demo-story-a-runner.js.map +1 -0
- package/dist/services/feature-flag-loader.d.ts +6 -0
- package/dist/services/feature-flag-loader.d.ts.map +1 -0
- package/dist/services/feature-flag-loader.js +54 -0
- package/dist/services/feature-flag-loader.js.map +1 -0
- package/dist/services/pain-flood-simulation-runner.d.ts +10 -0
- package/dist/services/pain-flood-simulation-runner.d.ts.map +1 -0
- package/dist/services/pain-flood-simulation-runner.js +289 -0
- package/dist/services/pain-flood-simulation-runner.js.map +1 -0
- package/dist/services/proven-channel-baseline-runner.d.ts +12 -0
- package/dist/services/proven-channel-baseline-runner.d.ts.map +1 -0
- package/dist/services/proven-channel-baseline-runner.js +114 -0
- package/dist/services/proven-channel-baseline-runner.js.map +1 -0
- package/dist/services/synthetic-baseline-runner.d.ts +8 -0
- package/dist/services/synthetic-baseline-runner.d.ts.map +1 -0
- package/dist/services/synthetic-baseline-runner.js +251 -0
- package/dist/services/synthetic-baseline-runner.js.map +1 -0
- package/package.json +35 -0
- package/src/commands/artifact.ts +82 -0
- package/src/commands/candidate.ts +1117 -0
- package/src/commands/central-sync.ts +44 -0
- package/src/commands/console.ts +121 -0
- package/src/commands/context.ts +72 -0
- package/src/commands/demo-story-a.ts +195 -0
- package/src/commands/diagnose.ts +452 -0
- package/src/commands/evolution-tasks-list.ts +44 -0
- package/src/commands/evolution-tasks-show.ts +60 -0
- package/src/commands/flow.ts +60 -0
- package/src/commands/health.ts +189 -0
- package/src/commands/history.ts +63 -0
- package/src/commands/legacy-cleanup.ts +206 -0
- package/src/commands/legacy-import.ts +104 -0
- package/src/commands/pain-record.ts +167 -0
- package/src/commands/proven-channel-baseline.ts +113 -0
- package/src/commands/remediation-output.ts +66 -0
- package/src/commands/run.ts +89 -0
- package/src/commands/runtime-activation.ts +176 -0
- package/src/commands/runtime-canary.ts +371 -0
- package/src/commands/runtime-diagnostics-export.ts +229 -0
- package/src/commands/runtime-features.ts +103 -0
- package/src/commands/runtime-gfi-snapshot.ts +135 -0
- package/src/commands/runtime-health-snapshot.ts +106 -0
- package/src/commands/runtime-internalization-enqueue-successors.ts +479 -0
- package/src/commands/runtime-internalization-integrity-repair.ts +69 -0
- package/src/commands/runtime-internalization-integrity.ts +63 -0
- package/src/commands/runtime-internalization-queue.ts +106 -0
- package/src/commands/runtime-internalization-run-once.ts +658 -0
- package/src/commands/runtime-internalization-wake-once.ts +87 -0
- package/src/commands/runtime-pain-flood-simulation.ts +121 -0
- package/src/commands/runtime-pruning.ts +438 -0
- package/src/commands/runtime-recovery.ts +107 -0
- package/src/commands/runtime-synthetic-baseline.ts +70 -0
- package/src/commands/runtime-uat.ts +339 -0
- package/src/commands/runtime.ts +281 -0
- package/src/commands/samples-list.ts +43 -0
- package/src/commands/samples-review.ts +32 -0
- package/src/commands/task.ts +130 -0
- package/src/commands/trace.ts +174 -0
- package/src/commands/trajectory.ts +64 -0
- package/src/index.ts +829 -0
- package/src/legacy/legacy-import.ts +179 -0
- package/src/legacy/session-history-import.ts +231 -0
- package/src/principle-tree-ledger-adapter.ts +13 -0
- package/src/resolve-workspace.ts +20 -0
- package/src/services/demo-story-a-runner.ts +472 -0
- package/src/services/feature-flag-loader.ts +73 -0
- package/src/services/pain-flood-simulation-runner.ts +354 -0
- package/src/services/proven-channel-baseline-runner.ts +150 -0
- package/src/services/synthetic-baseline-runner.ts +291 -0
- package/tests/commands/candidate-audit-repair.test.ts +338 -0
- package/tests/commands/candidate-intake.test.ts +589 -0
- package/tests/commands/candidate-internalization-backfill.test.ts +480 -0
- package/tests/commands/candidate-internalize.test.ts +272 -0
- package/tests/commands/candidate-route.test.ts +328 -0
- package/tests/commands/candidate-show.test.ts +95 -0
- package/tests/commands/cli-command-tree.test.ts +64 -0
- package/tests/commands/context.test.ts +114 -0
- package/tests/commands/demo-story-a.test.ts +255 -0
- package/tests/commands/diagnose.test.ts +792 -0
- package/tests/commands/health.test.ts +330 -0
- package/tests/commands/pain-record.test.ts +316 -0
- package/tests/commands/plugin-config-resolution-cutover.test.ts +220 -0
- package/tests/commands/proven-channel-baseline.test.ts +441 -0
- package/tests/commands/runtime-activation.test.ts +168 -0
- package/tests/commands/runtime-canary.test.ts +369 -0
- package/tests/commands/runtime-diagnostics-export.test.ts +170 -0
- package/tests/commands/runtime-features.test.ts +114 -0
- package/tests/commands/runtime-health-snapshot.test.ts +357 -0
- package/tests/commands/runtime-internalization-enqueue-successors.test.ts +803 -0
- package/tests/commands/runtime-internalization-integrity-repair.test.ts +169 -0
- package/tests/commands/runtime-internalization-integrity.test.ts +102 -0
- package/tests/commands/runtime-internalization-queue.test.ts +252 -0
- package/tests/commands/runtime-internalization-run-once.test.ts +1318 -0
- package/tests/commands/runtime-internalization-wake-once.test.ts +170 -0
- package/tests/commands/runtime-internalization.test.ts +52 -0
- package/tests/commands/runtime-pain-flood-simulation.test.ts +418 -0
- package/tests/commands/runtime-pruning.test.ts +693 -0
- package/tests/commands/runtime-recovery.test.ts +96 -0
- package/tests/commands/runtime-synthetic-baseline.test.ts +249 -0
- package/tests/commands/runtime-uat.test.ts +397 -0
- package/tests/commands/runtime.test.ts +262 -0
- package/tests/commands/trace.test.ts +314 -0
- package/tests/e2e/candidate-intake-e2e.test.ts +316 -0
- package/tests/services/feature-flag-loader.test.ts +207 -0
- package/tests/services/proven-channel-baseline-runner.test.ts +30 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as os from 'os';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
resolveRuntimeConfig,
|
|
8
|
+
isRuntimeConfigError,
|
|
9
|
+
validateRuntimeConfig,
|
|
10
|
+
invalidatePainSignalBridge,
|
|
11
|
+
createPainSignalBridge,
|
|
12
|
+
} from '@principles/core/runtime-v2';
|
|
13
|
+
|
|
14
|
+
const stubLedger = {
|
|
15
|
+
readPrincipleSubtree: () => undefined,
|
|
16
|
+
writePrinciple: () => ({ id: 'test' }) as never,
|
|
17
|
+
updatePrincipleValueMetrics: () => ({ principleId: 'test' }) as never,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('PRI-228: PD-owned config resolution cutover', () => {
|
|
21
|
+
describe('PD-owned config consumed by runtime entrypoint', () => {
|
|
22
|
+
let tmpDir: string;
|
|
23
|
+
let stateDir: string;
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-pri228-'));
|
|
27
|
+
stateDir = path.join(tmpDir, '.state');
|
|
28
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch {}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('resolveRuntimeConfig with explicit workspaceDir resolves pi-ai default', () => {
|
|
36
|
+
const result = resolveRuntimeConfig(stateDir);
|
|
37
|
+
expect(isRuntimeConfigError(result)).toBe(false);
|
|
38
|
+
if (!isRuntimeConfigError(result)) {
|
|
39
|
+
expect(result.runtimeKind).toBe('pi-ai');
|
|
40
|
+
expect(result.timeoutMs).toBeGreaterThan(0);
|
|
41
|
+
expect(result.agentId).toBe('main');
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('resolveRuntimeConfig with openclaw-cli requires explicit openclawMode', () => {
|
|
46
|
+
const result = resolveRuntimeConfig(stateDir, { requestedRuntimeKind: 'openclaw-cli' });
|
|
47
|
+
expect(isRuntimeConfigError(result)).toBe(true);
|
|
48
|
+
if (isRuntimeConfigError(result)) {
|
|
49
|
+
expect(result.reason).toBe('missing_openclaw_mode');
|
|
50
|
+
expect(result.nextAction).toBeTruthy();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('resolveRuntimeConfig with openclaw-cli + openclawLocal resolves correctly', () => {
|
|
55
|
+
const result = resolveRuntimeConfig(stateDir, {
|
|
56
|
+
requestedRuntimeKind: 'openclaw-cli',
|
|
57
|
+
openclawLocal: true,
|
|
58
|
+
});
|
|
59
|
+
expect(isRuntimeConfigError(result)).toBe(false);
|
|
60
|
+
if (!isRuntimeConfigError(result)) {
|
|
61
|
+
expect(result.runtimeKind).toBe('openclaw-cli');
|
|
62
|
+
expect(result.openclawMode).toBe('local');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('resolveRuntimeConfig does not derive config from idle/night state', () => {
|
|
67
|
+
const result = resolveRuntimeConfig(stateDir);
|
|
68
|
+
expect(isRuntimeConfigError(result)).toBe(false);
|
|
69
|
+
if (!isRuntimeConfigError(result)) {
|
|
70
|
+
expect(Object.keys(result)).not.toContain('idleThreshold');
|
|
71
|
+
expect(Object.keys(result)).not.toContain('triggerMode');
|
|
72
|
+
expect(Object.keys(result)).not.toContain('sleepReflection');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('Missing explicit config fails loud', () => {
|
|
78
|
+
let tmpDir: string;
|
|
79
|
+
let stateDir: string;
|
|
80
|
+
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-pri228-fail-'));
|
|
83
|
+
stateDir = path.join(tmpDir, '.state');
|
|
84
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch {}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('runtime=config without policy returns explicit_config_missing error', () => {
|
|
92
|
+
const result = resolveRuntimeConfig(stateDir, { requestedRuntimeKind: 'config' });
|
|
93
|
+
expect(isRuntimeConfigError(result)).toBe(true);
|
|
94
|
+
if (isRuntimeConfigError(result)) {
|
|
95
|
+
expect(result.reason).toBe('explicit_config_missing');
|
|
96
|
+
expect(result.nextAction).toBeTruthy();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('error result serializes to single parseable JSON with nextAction', () => {
|
|
101
|
+
const result = resolveRuntimeConfig(stateDir, { requestedRuntimeKind: 'config' });
|
|
102
|
+
expect(isRuntimeConfigError(result)).toBe(true);
|
|
103
|
+
if (isRuntimeConfigError(result)) {
|
|
104
|
+
const json = JSON.stringify(result);
|
|
105
|
+
const parsed = JSON.parse(json);
|
|
106
|
+
expect(parsed.ok).toBe(false);
|
|
107
|
+
expect(parsed.reason).toBeTruthy();
|
|
108
|
+
expect(parsed.message).toBeTruthy();
|
|
109
|
+
expect(parsed.nextAction).toBeTruthy();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('conflicting openclaw mode returns error with nextAction', () => {
|
|
114
|
+
const result = resolveRuntimeConfig(stateDir, {
|
|
115
|
+
requestedRuntimeKind: 'openclaw-cli',
|
|
116
|
+
openclawLocal: true,
|
|
117
|
+
openclawGateway: true,
|
|
118
|
+
});
|
|
119
|
+
expect(isRuntimeConfigError(result)).toBe(true);
|
|
120
|
+
if (isRuntimeConfigError(result)) {
|
|
121
|
+
expect(result.reason).toBe('conflicting_openclaw_mode');
|
|
122
|
+
expect(result.nextAction).toBeTruthy();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('validateRuntimeConfig throws for openclaw-cli without mode', () => {
|
|
127
|
+
const config = {
|
|
128
|
+
runtimeKind: 'openclaw-cli' as const,
|
|
129
|
+
timeoutMs: 300_000,
|
|
130
|
+
agentId: 'main',
|
|
131
|
+
};
|
|
132
|
+
expect(() => validateRuntimeConfig(config)).toThrow(/requires openclawMode/);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('Cache isolation between runtime modes', () => {
|
|
137
|
+
const testWsDir = '/test-pri228-cache-isolation';
|
|
138
|
+
const testStateDir = path.join(testWsDir, '.state');
|
|
139
|
+
|
|
140
|
+
beforeEach(() => {
|
|
141
|
+
invalidatePainSignalBridge(testWsDir);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
afterEach(() => {
|
|
145
|
+
invalidatePainSignalBridge(testWsDir);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('pi-ai and openclaw-cli produce different bridge instances', async () => {
|
|
149
|
+
const piAiConfig = resolveRuntimeConfig(testStateDir);
|
|
150
|
+
if (isRuntimeConfigError(piAiConfig)) {
|
|
151
|
+
expect.unreachable('pi-ai config should resolve');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const bridge1 = await createPainSignalBridge({
|
|
155
|
+
workspaceDir: testWsDir,
|
|
156
|
+
stateDir: testStateDir,
|
|
157
|
+
ledgerAdapter: stubLedger,
|
|
158
|
+
});
|
|
159
|
+
expect(bridge1).toBeDefined();
|
|
160
|
+
|
|
161
|
+
const openclawConfig = resolveRuntimeConfig(testStateDir, {
|
|
162
|
+
requestedRuntimeKind: 'openclaw-cli',
|
|
163
|
+
openclawLocal: true,
|
|
164
|
+
});
|
|
165
|
+
if (isRuntimeConfigError(openclawConfig)) {
|
|
166
|
+
expect.unreachable('openclaw-cli config should resolve');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const bridge2 = await createPainSignalBridge({
|
|
170
|
+
workspaceDir: testWsDir,
|
|
171
|
+
stateDir: testStateDir,
|
|
172
|
+
ledgerAdapter: stubLedger,
|
|
173
|
+
});
|
|
174
|
+
expect(bridge2).toBeDefined();
|
|
175
|
+
expect(bridge1).not.toBe(bridge2);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('invalidatePainSignalBridge with workspace-only clears all modes', async () => {
|
|
179
|
+
const piAiConfig = resolveRuntimeConfig(testStateDir);
|
|
180
|
+
if (isRuntimeConfigError(piAiConfig)) return;
|
|
181
|
+
await createPainSignalBridge({
|
|
182
|
+
workspaceDir: testWsDir,
|
|
183
|
+
stateDir: testStateDir,
|
|
184
|
+
ledgerAdapter: stubLedger,
|
|
185
|
+
});
|
|
186
|
+
invalidatePainSignalBridge(testWsDir);
|
|
187
|
+
const bridgeAfter = await createPainSignalBridge({
|
|
188
|
+
workspaceDir: testWsDir,
|
|
189
|
+
stateDir: testStateDir,
|
|
190
|
+
ledgerAdapter: stubLedger,
|
|
191
|
+
});
|
|
192
|
+
expect(bridgeAfter).toBeDefined();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('CLI resolveWorkspaceDir gate', () => {
|
|
197
|
+
it('resolveWorkspaceDir throws when no workspace provided', async () => {
|
|
198
|
+
const mod = await import('../../src/resolve-workspace.js');
|
|
199
|
+
delete process.env.PD_WORKSPACE_DIR;
|
|
200
|
+
expect(() => mod.resolveWorkspaceDir()).toThrow(/No workspace directory configured/);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('resolveWorkspaceDir uses explicit workspace when provided', async () => {
|
|
204
|
+
const mod = await import('../../src/resolve-workspace.js');
|
|
205
|
+
const result = mod.resolveWorkspaceDir('/explicit/workspace');
|
|
206
|
+
expect(result).toBe('/explicit/workspace');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('resolveWorkspaceDir uses PD_WORKSPACE_DIR env when no explicit', async () => {
|
|
210
|
+
const mod = await import('../../src/resolve-workspace.js');
|
|
211
|
+
process.env.PD_WORKSPACE_DIR = '/env/workspace';
|
|
212
|
+
try {
|
|
213
|
+
const result = mod.resolveWorkspaceDir();
|
|
214
|
+
expect(result).toBe('/env/workspace');
|
|
215
|
+
} finally {
|
|
216
|
+
delete process.env.PD_WORKSPACE_DIR;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const { mockRunProvenChannelBaseline } = vi.hoisted(() => ({
|
|
4
|
+
mockRunProvenChannelBaseline: vi.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock('../../src/services/proven-channel-baseline-runner.js', () => ({
|
|
8
|
+
runProvenChannelBaseline: mockRunProvenChannelBaseline,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import * as os from 'os';
|
|
14
|
+
import { handleProvenChannelBaseline, cleanupTempWorkspace } from '../../src/commands/proven-channel-baseline.js';
|
|
15
|
+
|
|
16
|
+
function makePassedSummary() {
|
|
17
|
+
return {
|
|
18
|
+
status: 'passed' as const,
|
|
19
|
+
workspaceMode: 'temp' as const,
|
|
20
|
+
generatedAt: new Date().toISOString(),
|
|
21
|
+
channels: [
|
|
22
|
+
{
|
|
23
|
+
channel: 'prompt' as const,
|
|
24
|
+
status: 'passed' as const,
|
|
25
|
+
canActivateResult: { ok: true, riskLevel: 'low' as const },
|
|
26
|
+
activationDecision: { decision: 'would_activate' as const, activationId: 'act_prompt_P_240', action: 'prompt_activate', targetRef: 'ledger://P_240' },
|
|
27
|
+
evidence: { activationId: 'act_prompt_P_240', evidenceSource: 'ActivationDispatcher.dispatch → PromptWriter' },
|
|
28
|
+
dependsOnLegacy: false,
|
|
29
|
+
evidenceSource: 'ActivationDispatcher.dispatch → PromptWriter',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
channel: 'code_tool_hook' as const,
|
|
33
|
+
status: 'passed' as const,
|
|
34
|
+
canActivateResult: { ok: true, riskLevel: 'high' as const },
|
|
35
|
+
activationDecision: { decision: 'would_activate' as const, activationId: 'act_code_R_240', action: 'code_tool_hook_shadow_activate', targetRef: 'impl://R_240' },
|
|
36
|
+
evidence: { activationId: 'act_code_R_240', gateDecision: 'accepted_shadow', evidenceSource: 'ActivationDispatcher.dispatch → RuleHostWriter' },
|
|
37
|
+
dependsOnLegacy: false,
|
|
38
|
+
evidenceSource: 'ActivationDispatcher.dispatch → RuleHostWriter',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
channel: 'defer_archive' as const,
|
|
42
|
+
status: 'passed' as const,
|
|
43
|
+
canActivateResult: { ok: true, riskLevel: 'low' as const },
|
|
44
|
+
activationDecision: { decision: 'would_activate' as const, activationId: 'act_archive_P_240', action: 'defer_archive', targetRef: 'ledger://P_240#archived' },
|
|
45
|
+
evidence: { activationId: 'act_archive_P_240', evidenceSource: 'ActivationDispatcher.dispatch → DeferArchiveWriter' },
|
|
46
|
+
dependsOnLegacy: false,
|
|
47
|
+
evidenceSource: 'ActivationDispatcher.dispatch → DeferArchiveWriter',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
continuityMatrix: [
|
|
51
|
+
{
|
|
52
|
+
channel: 'prompt' as const,
|
|
53
|
+
entryPoint: 'ActivationDispatcher.dispatch → PromptWriter.canActivate → PromptWriter.activate',
|
|
54
|
+
expectedObservable: 'activationId=act_prompt_{principleId}',
|
|
55
|
+
testCommand: 'npx vitest run ...',
|
|
56
|
+
dependsOnPluginDiscovery: false,
|
|
57
|
+
pri119ReuseEvidence: 'ActivationDispatcher → PromptWriter contract',
|
|
58
|
+
pri230ReuseEvidence: 'prompt risk level',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
channel: 'code_tool_hook' as const,
|
|
62
|
+
entryPoint: 'ActivationDispatcher.dispatch → RuleHostWriter.canActivate → evaluateRefinerRuleHostGate → RuleHostWriter.activate',
|
|
63
|
+
expectedObservable: 'activationId=act_code_{ruleId}',
|
|
64
|
+
testCommand: 'npx vitest run ...',
|
|
65
|
+
dependsOnPluginDiscovery: false,
|
|
66
|
+
pri119ReuseEvidence: 'ActivationDispatcher → RuleHostWriter gate contract',
|
|
67
|
+
pri230ReuseEvidence: 'code_tool_hook risk level',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
channel: 'defer_archive' as const,
|
|
71
|
+
entryPoint: 'ActivationDispatcher.dispatch → DeferArchiveWriter.canActivate → DeferArchiveWriter.activate',
|
|
72
|
+
expectedObservable: 'activationId=act_archive_{principleId}',
|
|
73
|
+
testCommand: 'npx vitest run ...',
|
|
74
|
+
dependsOnPluginDiscovery: false,
|
|
75
|
+
pri119ReuseEvidence: 'ActivationDispatcher → DeferArchiveWriter contract',
|
|
76
|
+
pri230ReuseEvidence: 'defer_archive risk level',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
describe('handleProvenChannelBaseline (CLI handler)', () => {
|
|
83
|
+
let tempDir = '';
|
|
84
|
+
const originalExitCode = process.exitCode;
|
|
85
|
+
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-cli-proven-test-'));
|
|
88
|
+
mockRunProvenChannelBaseline.mockReset();
|
|
89
|
+
process.exitCode = undefined;
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
afterEach(() => {
|
|
93
|
+
try {
|
|
94
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
95
|
+
} catch {
|
|
96
|
+
void 0;
|
|
97
|
+
}
|
|
98
|
+
process.exitCode = originalExitCode;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('uses temp workspace when no workspace specified', async () => {
|
|
102
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
103
|
+
...makePassedSummary(),
|
|
104
|
+
workspaceMode: 'temp',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
await handleProvenChannelBaseline({});
|
|
108
|
+
|
|
109
|
+
expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
|
|
110
|
+
expect.objectContaining({ workspaceMode: 'temp' }),
|
|
111
|
+
);
|
|
112
|
+
const calledDir = mockRunProvenChannelBaseline.mock.calls[0][0].workspaceDir;
|
|
113
|
+
expect(calledDir).toContain('pd-proven-channel-');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('uses explicit workspace when --workspace is provided', async () => {
|
|
117
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
118
|
+
...makePassedSummary(),
|
|
119
|
+
workspaceMode: 'explicit_workspace',
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
await handleProvenChannelBaseline({ workspace: tempDir });
|
|
123
|
+
|
|
124
|
+
expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
|
|
125
|
+
expect.objectContaining({
|
|
126
|
+
workspaceDir: tempDir,
|
|
127
|
+
workspaceMode: 'explicit_workspace',
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('--json output contains status, workspaceMode, generatedAt, channels, continuityMatrix', async () => {
|
|
133
|
+
const summary = makePassedSummary();
|
|
134
|
+
mockRunProvenChannelBaseline.mockResolvedValue(summary);
|
|
135
|
+
|
|
136
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
await handleProvenChannelBaseline({ json: true });
|
|
140
|
+
|
|
141
|
+
expect(logSpy).toHaveBeenCalledTimes(1);
|
|
142
|
+
const output = logSpy.mock.calls[0][0];
|
|
143
|
+
const parsed = JSON.parse(output);
|
|
144
|
+
expect(parsed).toHaveProperty('status');
|
|
145
|
+
expect(parsed).toHaveProperty('workspaceMode');
|
|
146
|
+
expect(parsed).toHaveProperty('generatedAt');
|
|
147
|
+
expect(parsed).toHaveProperty('channels');
|
|
148
|
+
expect(parsed).toHaveProperty('continuityMatrix');
|
|
149
|
+
expect(parsed.channels).toHaveLength(3);
|
|
150
|
+
expect(parsed.continuityMatrix).toHaveLength(3);
|
|
151
|
+
} finally {
|
|
152
|
+
logSpy.mockRestore();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('sets process.exitCode = 1 when status is failed', async () => {
|
|
157
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
158
|
+
...makePassedSummary(),
|
|
159
|
+
status: 'failed',
|
|
160
|
+
channels: [
|
|
161
|
+
{ channel: 'prompt', status: 'failed', canActivateResult: { ok: false, reason: 'test', riskLevel: 'low' }, activationDecision: { decision: 'refused', reason: 'test', channel: 'prompt' }, evidence: {}, dependsOnLegacy: false, failureReason: 'test failure', evidenceSource: 'test' },
|
|
162
|
+
{ channel: 'code_tool_hook', status: 'failed', canActivateResult: { ok: false, reason: 'test', riskLevel: 'high' }, activationDecision: { decision: 'refused', reason: 'test', channel: 'code_tool_hook' }, evidence: {}, dependsOnLegacy: false, failureReason: 'test failure', evidenceSource: 'test' },
|
|
163
|
+
{ channel: 'defer_archive', status: 'failed', canActivateResult: { ok: false, reason: 'test', riskLevel: 'low' }, activationDecision: { decision: 'refused', reason: 'test', channel: 'defer_archive' }, evidence: {}, dependsOnLegacy: false, failureReason: 'test failure', evidenceSource: 'test' },
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
168
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
await handleProvenChannelBaseline({ workspace: tempDir });
|
|
172
|
+
expect(process.exitCode).toBe(1);
|
|
173
|
+
} finally {
|
|
174
|
+
logSpy.mockRestore();
|
|
175
|
+
errorSpy.mockRestore();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('cleans up temp workspace on success', async () => {
|
|
180
|
+
mockRunProvenChannelBaseline.mockResolvedValue(makePassedSummary());
|
|
181
|
+
|
|
182
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
await handleProvenChannelBaseline({});
|
|
186
|
+
|
|
187
|
+
const calledDir = mockRunProvenChannelBaseline.mock.calls[0][0].workspaceDir;
|
|
188
|
+
expect(fs.existsSync(calledDir)).toBe(false);
|
|
189
|
+
} finally {
|
|
190
|
+
logSpy.mockRestore();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('does not delete explicit workspace after run', async () => {
|
|
195
|
+
fs.mkdirSync(path.join(tempDir, '.pd'), { recursive: true });
|
|
196
|
+
|
|
197
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
198
|
+
...makePassedSummary(),
|
|
199
|
+
workspaceMode: 'explicit_workspace',
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
await handleProvenChannelBaseline({ workspace: tempDir });
|
|
206
|
+
expect(fs.existsSync(tempDir)).toBe(true);
|
|
207
|
+
} finally {
|
|
208
|
+
logSpy.mockRestore();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('--channels with unknown values passes unknownChannels to runner', async () => {
|
|
213
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
214
|
+
status: 'failed',
|
|
215
|
+
generatedAt: new Date().toISOString(),
|
|
216
|
+
workspaceMode: 'temp',
|
|
217
|
+
channels: [],
|
|
218
|
+
inputValidationFailure: {
|
|
219
|
+
reason: 'unknown_channels',
|
|
220
|
+
message: 'Unknown channels: skill, model_training. Valid channels: prompt, code_tool_hook, defer_archive',
|
|
221
|
+
nextAction: 'Use only valid MVP channels: prompt, code_tool_hook, defer_archive',
|
|
222
|
+
unknownChannels: ['skill', 'model_training'],
|
|
223
|
+
},
|
|
224
|
+
continuityMatrix: [],
|
|
225
|
+
recommendedNextIssue: 'PRI-240: Unknown channels provided: skill, model_training',
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
229
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
await handleProvenChannelBaseline({ json: true, channels: 'prompt,skill,model_training' });
|
|
233
|
+
expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
|
|
234
|
+
expect.objectContaining({
|
|
235
|
+
unknownChannels: ['skill', 'model_training'],
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
} finally {
|
|
239
|
+
logSpy.mockRestore();
|
|
240
|
+
errorSpy.mockRestore();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('--channels "" returns failed with inputValidationFailure, no fixtures executed', async () => {
|
|
245
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
246
|
+
status: 'failed',
|
|
247
|
+
generatedAt: new Date().toISOString(),
|
|
248
|
+
workspaceMode: 'temp',
|
|
249
|
+
channels: [],
|
|
250
|
+
inputValidationFailure: {
|
|
251
|
+
reason: 'empty_channel_input',
|
|
252
|
+
message: '--channels was provided but contained no valid channel names',
|
|
253
|
+
nextAction: 'Provide at least one valid MVP channel: prompt, code_tool_hook, defer_archive',
|
|
254
|
+
},
|
|
255
|
+
continuityMatrix: [],
|
|
256
|
+
recommendedNextIssue: 'PRI-240: --channels input was empty — no fixtures were executed',
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
260
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
await handleProvenChannelBaseline({ json: true, channels: '' });
|
|
264
|
+
expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
|
|
265
|
+
expect.objectContaining({
|
|
266
|
+
emptyChannelInput: true,
|
|
267
|
+
channels: undefined,
|
|
268
|
+
unknownChannels: [],
|
|
269
|
+
}),
|
|
270
|
+
);
|
|
271
|
+
expect(logSpy.mock.calls[0]?.[0]).toBeDefined();
|
|
272
|
+
const output = logSpy.mock.calls[0][0];
|
|
273
|
+
expect(typeof output).toBe('string');
|
|
274
|
+
const parsed = JSON.parse(output);
|
|
275
|
+
expect(parsed.status).toBe('failed');
|
|
276
|
+
expect(parsed.inputValidationFailure).toBeDefined();
|
|
277
|
+
expect(parsed.inputValidationFailure.reason).toBe('empty_channel_input');
|
|
278
|
+
expect(parsed.channels).toHaveLength(0);
|
|
279
|
+
} finally {
|
|
280
|
+
logSpy.mockRestore();
|
|
281
|
+
errorSpy.mockRestore();
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('--channels "," returns failed with inputValidationFailure, no fixtures executed', async () => {
|
|
286
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
287
|
+
status: 'failed',
|
|
288
|
+
generatedAt: new Date().toISOString(),
|
|
289
|
+
workspaceMode: 'temp',
|
|
290
|
+
channels: [],
|
|
291
|
+
inputValidationFailure: {
|
|
292
|
+
reason: 'empty_channel_input',
|
|
293
|
+
message: '--channels was provided but contained no valid channel names',
|
|
294
|
+
nextAction: 'Provide at least one valid MVP channel: prompt, code_tool_hook, defer_archive',
|
|
295
|
+
},
|
|
296
|
+
continuityMatrix: [],
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
300
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
301
|
+
|
|
302
|
+
try {
|
|
303
|
+
await handleProvenChannelBaseline({ json: true, channels: ',' });
|
|
304
|
+
expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
|
|
305
|
+
expect.objectContaining({
|
|
306
|
+
emptyChannelInput: true,
|
|
307
|
+
}),
|
|
308
|
+
);
|
|
309
|
+
} finally {
|
|
310
|
+
logSpy.mockRestore();
|
|
311
|
+
errorSpy.mockRestore();
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('--channels bogus returns failed with unknown channels, no fixtures executed', async () => {
|
|
316
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
317
|
+
status: 'failed',
|
|
318
|
+
generatedAt: new Date().toISOString(),
|
|
319
|
+
workspaceMode: 'temp',
|
|
320
|
+
channels: [],
|
|
321
|
+
inputValidationFailure: {
|
|
322
|
+
reason: 'unknown_channels',
|
|
323
|
+
message: 'Unknown channels: bogus. Valid channels: prompt, code_tool_hook, defer_archive',
|
|
324
|
+
nextAction: 'Use only valid MVP channels: prompt, code_tool_hook, defer_archive',
|
|
325
|
+
unknownChannels: ['bogus'],
|
|
326
|
+
},
|
|
327
|
+
continuityMatrix: [],
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
331
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
332
|
+
|
|
333
|
+
try {
|
|
334
|
+
await handleProvenChannelBaseline({ json: true, channels: 'bogus' });
|
|
335
|
+
expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
|
|
336
|
+
expect.objectContaining({
|
|
337
|
+
unknownChannels: ['bogus'],
|
|
338
|
+
}),
|
|
339
|
+
);
|
|
340
|
+
expect(logSpy.mock.calls[0]?.[0]).toBeDefined();
|
|
341
|
+
const output = logSpy.mock.calls[0][0];
|
|
342
|
+
expect(typeof output).toBe('string');
|
|
343
|
+
const parsed = JSON.parse(output);
|
|
344
|
+
expect(parsed.inputValidationFailure.reason).toBe('unknown_channels');
|
|
345
|
+
expect(parsed.inputValidationFailure.unknownChannels).not.toContain('prompt');
|
|
346
|
+
} finally {
|
|
347
|
+
logSpy.mockRestore();
|
|
348
|
+
errorSpy.mockRestore();
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('text mode output shows inputValidationFailure reason, message, nextAction', async () => {
|
|
353
|
+
mockRunProvenChannelBaseline.mockResolvedValue({
|
|
354
|
+
status: 'failed',
|
|
355
|
+
generatedAt: new Date().toISOString(),
|
|
356
|
+
workspaceMode: 'temp',
|
|
357
|
+
channels: [],
|
|
358
|
+
inputValidationFailure: {
|
|
359
|
+
reason: 'unknown_channels',
|
|
360
|
+
message: 'Unknown channels: bogus. Valid channels: prompt, code_tool_hook, defer_archive',
|
|
361
|
+
nextAction: 'Use only valid MVP channels: prompt, code_tool_hook, defer_archive',
|
|
362
|
+
unknownChannels: ['bogus'],
|
|
363
|
+
},
|
|
364
|
+
continuityMatrix: [],
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
368
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
369
|
+
|
|
370
|
+
try {
|
|
371
|
+
await handleProvenChannelBaseline({ channels: 'bogus' });
|
|
372
|
+
const output = logSpy.mock.calls[0]?.[0] ?? '';
|
|
373
|
+
expect(output).toContain('Input Validation Failure:');
|
|
374
|
+
expect(output).toContain('reason: unknown_channels');
|
|
375
|
+
expect(output).toContain('message:');
|
|
376
|
+
expect(output).toContain('nextAction:');
|
|
377
|
+
} finally {
|
|
378
|
+
logSpy.mockRestore();
|
|
379
|
+
errorSpy.mockRestore();
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('without --channels runs all default MVP channels', async () => {
|
|
384
|
+
mockRunProvenChannelBaseline.mockResolvedValue(makePassedSummary());
|
|
385
|
+
|
|
386
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
387
|
+
|
|
388
|
+
try {
|
|
389
|
+
await handleProvenChannelBaseline({ json: true });
|
|
390
|
+
expect(mockRunProvenChannelBaseline).toHaveBeenCalledWith(
|
|
391
|
+
expect.objectContaining({
|
|
392
|
+
channels: undefined,
|
|
393
|
+
unknownChannels: [],
|
|
394
|
+
emptyChannelInput: false,
|
|
395
|
+
}),
|
|
396
|
+
);
|
|
397
|
+
} finally {
|
|
398
|
+
logSpy.mockRestore();
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('cleanup failure outputs to stderr without polluting JSON stdout', () => {
|
|
403
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
404
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
405
|
+
|
|
406
|
+
const failingRmSync = () => { throw new Error('permission denied'); };
|
|
407
|
+
cleanupTempWorkspace('/tmp/fake-dir', failingRmSync);
|
|
408
|
+
|
|
409
|
+
const errorCalls = errorSpy.mock.calls.map(c => c[0]);
|
|
410
|
+
const cleanupWarningSeen = errorCalls.some(c => typeof c === 'string' && c.includes('[pd-cli] cleanup warning'));
|
|
411
|
+
expect(cleanupWarningSeen).toBe(true);
|
|
412
|
+
expect(logSpy).not.toHaveBeenCalled();
|
|
413
|
+
|
|
414
|
+
logSpy.mockRestore();
|
|
415
|
+
errorSpy.mockRestore();
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('command is registered in CLI entrypoint as runtime synthetic proven-channel', async () => {
|
|
419
|
+
const { Command } = await import('commander');
|
|
420
|
+
const program = new Command();
|
|
421
|
+
program.exitOverride();
|
|
422
|
+
|
|
423
|
+
const { handleProvenChannelBaseline: handler } = await import('../../src/commands/proven-channel-baseline.js');
|
|
424
|
+
|
|
425
|
+
const synthCmd = program.command('runtime').command('synthetic');
|
|
426
|
+
synthCmd
|
|
427
|
+
.command('proven-channel')
|
|
428
|
+
.option('-w, --workspace <path>', 'Workspace directory')
|
|
429
|
+
.option('--json', 'Output raw JSON')
|
|
430
|
+
.option('--channels <channels>', 'Comma-separated channel list')
|
|
431
|
+
.action(async (opts) => {
|
|
432
|
+
await handler(opts);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const found = program.commands.find(c => c.name() === 'runtime')
|
|
436
|
+
?.commands.find(c => c.name() === 'synthetic')
|
|
437
|
+
?.commands.find(c => c.name() === 'proven-channel');
|
|
438
|
+
expect(found).toBeDefined();
|
|
439
|
+
expect(found?.name()).toBe('proven-channel');
|
|
440
|
+
});
|
|
441
|
+
});
|