@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,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pd runtime internalization wake-once CLI unit tests.
|
|
3
|
+
*
|
|
4
|
+
* Tests the wake-once command handler: dry-run rejection, delegation to
|
|
5
|
+
* InternalizationOrchestrator, JSON/text output formatting, and exit codes.
|
|
6
|
+
* The orchestrator is mocked — its contract is tested in principles-core.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
9
|
+
|
|
10
|
+
const mockWakeOnce = vi.fn();
|
|
11
|
+
const mockClose = vi.fn().mockResolvedValue(undefined);
|
|
12
|
+
|
|
13
|
+
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
14
|
+
resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
vi.mock('@principles/core/runtime-v2', () => ({
|
|
18
|
+
RuntimeStateManager: vi.fn().mockImplementation(function () {
|
|
19
|
+
return { initialize: vi.fn().mockResolvedValue(undefined), close: mockClose };
|
|
20
|
+
}),
|
|
21
|
+
InternalizationOrchestrator: vi.fn().mockImplementation(function () {
|
|
22
|
+
return { wakeOnce: mockWakeOnce };
|
|
23
|
+
}),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
import { handleRuntimeInternalizationWakeOnce } from '../../src/commands/runtime-internalization-wake-once.js';
|
|
27
|
+
|
|
28
|
+
const WS = '/fake/workspace';
|
|
29
|
+
|
|
30
|
+
describe('handleRuntimeInternalizationWakeOnce', () => {
|
|
31
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
32
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
33
|
+
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
vi.clearAllMocks();
|
|
36
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
37
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
consoleLogSpy.mockRestore();
|
|
42
|
+
consoleErrorSpy.mockRestore();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ── would_lease ─────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
it('would_lease result serialized correctly in JSON', async () => {
|
|
48
|
+
mockWakeOnce.mockResolvedValue({
|
|
49
|
+
decision: 'would_lease',
|
|
50
|
+
taskId: 'task_001',
|
|
51
|
+
taskKind: 'dreamer',
|
|
52
|
+
gateResult: { decision: 'proceed', ready: true, blockedBy: [], failedDependencies: [] },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: true, json: true });
|
|
56
|
+
|
|
57
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
58
|
+
expect(output.decision).toBe('would_lease');
|
|
59
|
+
expect(output.taskId).toBe('task_001');
|
|
60
|
+
expect(output.taskKind).toBe('dreamer');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('would_lease text output is human-readable', async () => {
|
|
64
|
+
mockWakeOnce.mockResolvedValue({
|
|
65
|
+
decision: 'would_lease',
|
|
66
|
+
taskId: 'task_001',
|
|
67
|
+
taskKind: 'dreamer',
|
|
68
|
+
gateResult: { decision: 'proceed', ready: true, blockedBy: [], failedDependencies: [] },
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: true, json: false });
|
|
72
|
+
|
|
73
|
+
const text = consoleLogSpy.mock.calls[0][0];
|
|
74
|
+
expect(text).toContain('would_lease');
|
|
75
|
+
expect(text).toContain('task_001');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// ── no_ready_tasks ─────────────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
it('no_ready_tasks with reason in JSON', async () => {
|
|
81
|
+
mockWakeOnce.mockResolvedValue({
|
|
82
|
+
decision: 'no_ready_tasks',
|
|
83
|
+
inspectedCount: 5,
|
|
84
|
+
reason: 'all_blocked',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: true, json: true });
|
|
88
|
+
|
|
89
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
90
|
+
expect(output.decision).toBe('no_ready_tasks');
|
|
91
|
+
expect(output.reason).toBe('all_blocked');
|
|
92
|
+
expect(output.inspectedCount).toBe(5);
|
|
93
|
+
expect(process.exitCode).toBe(1);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// ── blocked ────────────────────────────────────────────────────────────────
|
|
97
|
+
|
|
98
|
+
it('blocked decision surfaces blockedBy task IDs', async () => {
|
|
99
|
+
mockWakeOnce.mockResolvedValue({
|
|
100
|
+
decision: 'blocked',
|
|
101
|
+
taskId: 'task_002',
|
|
102
|
+
taskKind: 'philosopher',
|
|
103
|
+
blockedBy: ['task_001'],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: true, json: true });
|
|
107
|
+
|
|
108
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
109
|
+
expect(output.decision).toBe('blocked');
|
|
110
|
+
expect(output.blockedBy).toContain('task_001');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('blocked text output shows blockedBy', async () => {
|
|
114
|
+
mockWakeOnce.mockResolvedValue({
|
|
115
|
+
decision: 'blocked',
|
|
116
|
+
taskId: 'task_002',
|
|
117
|
+
taskKind: 'philosopher',
|
|
118
|
+
blockedBy: ['task_001'],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: true, json: false });
|
|
122
|
+
|
|
123
|
+
expect(consoleLogSpy.mock.calls[0][0]).toContain('blocked');
|
|
124
|
+
expect(consoleLogSpy.mock.calls[0][0]).toContain('task_001');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// ── dependency_failed ─────────────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
it('dependency_failed surfaces failedDependencies', async () => {
|
|
130
|
+
mockWakeOnce.mockResolvedValue({
|
|
131
|
+
decision: 'dependency_failed',
|
|
132
|
+
taskId: 'task_003',
|
|
133
|
+
taskKind: 'scribe',
|
|
134
|
+
failedDependencies: ['task_002'],
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: true, json: true });
|
|
138
|
+
|
|
139
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
140
|
+
expect(output.decision).toBe('dependency_failed');
|
|
141
|
+
expect(output.failedDependencies).toContain('task_002');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// ── non-dry-run rejection ──────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
it('non-dry-run invocation exits with error before any state interaction', async () => {
|
|
147
|
+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
|
|
148
|
+
|
|
149
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: false, json: true });
|
|
150
|
+
|
|
151
|
+
expect(process.exitCode).toBe(1);
|
|
152
|
+
expect(mockWakeOnce).not.toHaveBeenCalled();
|
|
153
|
+
expect(consoleErrorSpy).toHaveBeenCalled();
|
|
154
|
+
|
|
155
|
+
exitSpy.mockRestore();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// ── error handling ──────────────────────────────────────────────────────────
|
|
159
|
+
|
|
160
|
+
it('orchestrator error leads to exit code 1', async () => {
|
|
161
|
+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
|
|
162
|
+
mockWakeOnce.mockRejectedValue(new Error('store unavailable'));
|
|
163
|
+
|
|
164
|
+
await handleRuntimeInternalizationWakeOnce({ workspace: WS, dryRun: true, json: true });
|
|
165
|
+
|
|
166
|
+
expect(process.exitCode).toBe(1);
|
|
167
|
+
|
|
168
|
+
exitSpy.mockRestore();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI command tree tests for pd runtime internalization queue / wake-once.
|
|
3
|
+
*
|
|
4
|
+
* TDD: Tests verify the command tree is registered correctly.
|
|
5
|
+
* These tests run against the built CLI (dist/index.js).
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect } from 'vitest';
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
|
|
10
|
+
function runPdHelp(args: string[]): string {
|
|
11
|
+
try {
|
|
12
|
+
return execFileSync('node', ['packages/pd-cli/dist/index.js', ...args], {
|
|
13
|
+
encoding: 'utf8',
|
|
14
|
+
cwd: 'D:/Code/principles',
|
|
15
|
+
});
|
|
16
|
+
} catch (err: unknown) {
|
|
17
|
+
if (err && typeof err === 'object' && 'stdout' in err) {
|
|
18
|
+
return String((err as { stdout: unknown }).stdout);
|
|
19
|
+
}
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe('CLI command tree: pd runtime internalization', () => {
|
|
25
|
+
it('runtime internalization --help lists queue subcommand', () => {
|
|
26
|
+
const output = runPdHelp(['runtime', 'internalization', '--help']);
|
|
27
|
+
expect(output).toMatch(/queue\s/);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('runtime internalization --help lists wake-once subcommand', () => {
|
|
31
|
+
const output = runPdHelp(['runtime', 'internalization', '--help']);
|
|
32
|
+
expect(output).toMatch(/wake-once\s/);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('queue --help shows --workspace and --json options', () => {
|
|
36
|
+
const output = runPdHelp(['runtime', 'internalization', 'queue', '--help']);
|
|
37
|
+
expect(output).toContain('--workspace');
|
|
38
|
+
expect(output).toContain('--json');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('wake-once --help shows --dry-run, --workspace, --json options', () => {
|
|
42
|
+
const output = runPdHelp(['runtime', 'internalization', 'wake-once', '--help']);
|
|
43
|
+
expect(output).toContain('--dry-run');
|
|
44
|
+
expect(output).toContain('--workspace');
|
|
45
|
+
expect(output).toContain('--json');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('runtime subcommand list includes internalization', () => {
|
|
49
|
+
const output = runPdHelp(['runtime', '--help']);
|
|
50
|
+
expect(output).toMatch(/internalization\s/);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const { mockRunPainFloodSimulation } = vi.hoisted(() => ({
|
|
4
|
+
mockRunPainFloodSimulation: vi.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock('../../src/services/pain-flood-simulation-runner.js', () => ({
|
|
8
|
+
runPainFloodSimulation: mockRunPainFloodSimulation,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import * as os from 'os';
|
|
14
|
+
import { handleRuntimePainFlood } from '../../src/commands/runtime-pain-flood-simulation.js';
|
|
15
|
+
|
|
16
|
+
function makePassedSummary() {
|
|
17
|
+
return {
|
|
18
|
+
status: 'healthy' as const,
|
|
19
|
+
workspaceMode: 'temp' as const,
|
|
20
|
+
generatedAt: new Date().toISOString(),
|
|
21
|
+
inputPainCount: 77,
|
|
22
|
+
acceptedPainCount: 22,
|
|
23
|
+
skippedDuplicateCount: 55,
|
|
24
|
+
failedCount: 0,
|
|
25
|
+
candidateCount: 22,
|
|
26
|
+
taskCount: 22,
|
|
27
|
+
maxEvidencePreviewLength: 450,
|
|
28
|
+
contextBudgetSummary: 'moderate (max 450 chars)',
|
|
29
|
+
stages: [
|
|
30
|
+
{
|
|
31
|
+
scenarioName: 'identical_flood' as const,
|
|
32
|
+
status: 'passed' as const,
|
|
33
|
+
inputCount: 10,
|
|
34
|
+
acceptedCount: 1,
|
|
35
|
+
skippedCount: 9,
|
|
36
|
+
failedCount: 0,
|
|
37
|
+
taskCount: 1,
|
|
38
|
+
candidateCount: 1,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
scenarioName: 'similar_flood' as const,
|
|
42
|
+
status: 'passed' as const,
|
|
43
|
+
inputCount: 10,
|
|
44
|
+
acceptedCount: 10,
|
|
45
|
+
skippedCount: 0,
|
|
46
|
+
failedCount: 0,
|
|
47
|
+
taskCount: 10,
|
|
48
|
+
candidateCount: 10,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
scenarioName: 'duplicate_submission' as const,
|
|
52
|
+
status: 'passed' as const,
|
|
53
|
+
inputCount: 2,
|
|
54
|
+
acceptedCount: 1,
|
|
55
|
+
skippedCount: 1,
|
|
56
|
+
failedCount: 0,
|
|
57
|
+
taskCount: 1,
|
|
58
|
+
candidateCount: 1,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
scenarioName: 'tool_failure_flood' as const,
|
|
62
|
+
status: 'passed' as const,
|
|
63
|
+
inputCount: 5,
|
|
64
|
+
acceptedCount: 1,
|
|
65
|
+
skippedCount: 4,
|
|
66
|
+
failedCount: 0,
|
|
67
|
+
taskCount: 1,
|
|
68
|
+
candidateCount: 1,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
scenarioName: 'stress_test' as const,
|
|
72
|
+
status: 'passed' as const,
|
|
73
|
+
inputCount: 50,
|
|
74
|
+
acceptedCount: 33,
|
|
75
|
+
skippedCount: 17,
|
|
76
|
+
failedCount: 0,
|
|
77
|
+
taskCount: 33,
|
|
78
|
+
candidateCount: 33,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('handleRuntimePainFlood (CLI handler)', () => {
|
|
85
|
+
let tempDir = '';
|
|
86
|
+
const originalExitCode = process.exitCode;
|
|
87
|
+
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-cli-pain-flood-test-'));
|
|
90
|
+
mockRunPainFloodSimulation.mockReset();
|
|
91
|
+
process.exitCode = undefined as unknown as number;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
afterEach(() => {
|
|
95
|
+
try {
|
|
96
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
97
|
+
} catch {
|
|
98
|
+
// ignore
|
|
99
|
+
}
|
|
100
|
+
process.exitCode = originalExitCode;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('uses temp workspace when no workspace specified', async () => {
|
|
104
|
+
mockRunPainFloodSimulation.mockResolvedValue({
|
|
105
|
+
...makePassedSummary(),
|
|
106
|
+
workspaceMode: 'temp',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await handleRuntimePainFlood({});
|
|
110
|
+
|
|
111
|
+
expect(mockRunPainFloodSimulation).toHaveBeenCalledWith(
|
|
112
|
+
expect.objectContaining({ workspaceMode: 'temp' }),
|
|
113
|
+
);
|
|
114
|
+
const calledDir = mockRunPainFloodSimulation.mock.calls[0][0].workspaceDir;
|
|
115
|
+
expect(calledDir).toContain('pd-pain-flood-');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('rejects explicit --workspace with error and does not call runner', async () => {
|
|
119
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
120
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
await handleRuntimePainFlood({ workspace: tempDir });
|
|
124
|
+
|
|
125
|
+
expect(mockRunPainFloodSimulation).not.toHaveBeenCalled();
|
|
126
|
+
expect(process.exitCode).toBe(1);
|
|
127
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('not allowed'));
|
|
128
|
+
} finally {
|
|
129
|
+
logSpy.mockRestore();
|
|
130
|
+
errorSpy.mockRestore();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('rejects explicit --workspace with JSON error output', async () => {
|
|
135
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
await handleRuntimePainFlood({ workspace: tempDir, json: true });
|
|
139
|
+
|
|
140
|
+
expect(mockRunPainFloodSimulation).not.toHaveBeenCalled();
|
|
141
|
+
expect(process.exitCode).toBe(1);
|
|
142
|
+
const output = JSON.parse(logSpy.mock.calls[0][0]);
|
|
143
|
+
expect(output.status).toBe('error');
|
|
144
|
+
expect(output.reason).toContain('not allowed');
|
|
145
|
+
expect(output.nextAction).toBeDefined();
|
|
146
|
+
} finally {
|
|
147
|
+
logSpy.mockRestore();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('--json output contains all expected measurement fields', async () => {
|
|
152
|
+
const summary = makePassedSummary();
|
|
153
|
+
mockRunPainFloodSimulation.mockResolvedValue(summary);
|
|
154
|
+
|
|
155
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
await handleRuntimePainFlood({ json: true });
|
|
159
|
+
|
|
160
|
+
expect(logSpy).toHaveBeenCalledTimes(1);
|
|
161
|
+
const output = logSpy.mock.calls[0][0];
|
|
162
|
+
const parsed = JSON.parse(output);
|
|
163
|
+
expect(parsed).toHaveProperty('inputPainCount');
|
|
164
|
+
expect(parsed).toHaveProperty('acceptedPainCount');
|
|
165
|
+
expect(parsed).toHaveProperty('skippedDuplicateCount');
|
|
166
|
+
expect(parsed).toHaveProperty('failedCount');
|
|
167
|
+
expect(parsed).toHaveProperty('candidateCount');
|
|
168
|
+
expect(parsed).toHaveProperty('taskCount');
|
|
169
|
+
expect(parsed).toHaveProperty('maxEvidencePreviewLength');
|
|
170
|
+
expect(parsed).toHaveProperty('contextBudgetSummary');
|
|
171
|
+
expect(parsed).toHaveProperty('status');
|
|
172
|
+
expect(parsed).toHaveProperty('stages');
|
|
173
|
+
expect(parsed.stages).toHaveLength(5);
|
|
174
|
+
} finally {
|
|
175
|
+
logSpy.mockRestore();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('passes count options to the runner', async () => {
|
|
180
|
+
mockRunPainFloodSimulation.mockResolvedValue(makePassedSummary());
|
|
181
|
+
|
|
182
|
+
await handleRuntimePainFlood({ identicalCount: 5, similarCount: 3, stressCount: 20 });
|
|
183
|
+
|
|
184
|
+
expect(mockRunPainFloodSimulation).toHaveBeenCalledWith(
|
|
185
|
+
expect.objectContaining({
|
|
186
|
+
identicalCount: 5,
|
|
187
|
+
similarCount: 3,
|
|
188
|
+
stressCount: 20,
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('rejects NaN count with error and does not call runner', async () => {
|
|
194
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
await handleRuntimePainFlood({ identicalCount: NaN });
|
|
198
|
+
|
|
199
|
+
expect(mockRunPainFloodSimulation).not.toHaveBeenCalled();
|
|
200
|
+
expect(process.exitCode).toBe(1);
|
|
201
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('finite integer'));
|
|
202
|
+
} finally {
|
|
203
|
+
errorSpy.mockRestore();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('rejects negative count with error and does not call runner', async () => {
|
|
208
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
await handleRuntimePainFlood({ stressCount: -5 });
|
|
212
|
+
|
|
213
|
+
expect(mockRunPainFloodSimulation).not.toHaveBeenCalled();
|
|
214
|
+
expect(process.exitCode).toBe(1);
|
|
215
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('finite integer'));
|
|
216
|
+
} finally {
|
|
217
|
+
errorSpy.mockRestore();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('rejects zero count with error and does not call runner', async () => {
|
|
222
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
await handleRuntimePainFlood({ similarCount: 0 });
|
|
226
|
+
|
|
227
|
+
expect(mockRunPainFloodSimulation).not.toHaveBeenCalled();
|
|
228
|
+
expect(process.exitCode).toBe(1);
|
|
229
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('finite integer'));
|
|
230
|
+
} finally {
|
|
231
|
+
errorSpy.mockRestore();
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('rejects non-integer count with JSON error output', async () => {
|
|
236
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
await handleRuntimePainFlood({ identicalCount: 3.5, json: true });
|
|
240
|
+
|
|
241
|
+
expect(mockRunPainFloodSimulation).not.toHaveBeenCalled();
|
|
242
|
+
expect(process.exitCode).toBe(1);
|
|
243
|
+
const output = JSON.parse(logSpy.mock.calls[0][0]);
|
|
244
|
+
expect(output.status).toBe('error');
|
|
245
|
+
expect(output.reason).toContain('finite integer');
|
|
246
|
+
} finally {
|
|
247
|
+
logSpy.mockRestore();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('sets process.exitCode = 1 when status is degraded', async () => {
|
|
252
|
+
mockRunPainFloodSimulation.mockResolvedValue({
|
|
253
|
+
...makePassedSummary(),
|
|
254
|
+
status: 'degraded',
|
|
255
|
+
reason: '1 scenario(s) failed: similar_flood. bridge error',
|
|
256
|
+
nextAction: 'Investigate: PRI-208: Similar pain flood caused unbounded task creation',
|
|
257
|
+
stages: [
|
|
258
|
+
{ scenarioName: 'identical_flood', status: 'passed', inputCount: 10, acceptedCount: 1, skippedCount: 9, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
259
|
+
{ scenarioName: 'similar_flood', status: 'failed', inputCount: 10, acceptedCount: 0, skippedCount: 0, failedCount: 10, taskCount: 0, candidateCount: 0, reason: 'bridge error' },
|
|
260
|
+
{ scenarioName: 'duplicate_submission', status: 'passed', inputCount: 2, acceptedCount: 1, skippedCount: 1, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
261
|
+
{ scenarioName: 'tool_failure_flood', status: 'passed', inputCount: 5, acceptedCount: 1, skippedCount: 4, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
262
|
+
{ scenarioName: 'stress_test', status: 'passed', inputCount: 50, acceptedCount: 33, skippedCount: 17, failedCount: 0, taskCount: 33, candidateCount: 33 },
|
|
263
|
+
],
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
267
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
268
|
+
|
|
269
|
+
try {
|
|
270
|
+
await handleRuntimePainFlood({});
|
|
271
|
+
expect(process.exitCode).toBe(1);
|
|
272
|
+
} finally {
|
|
273
|
+
logSpy.mockRestore();
|
|
274
|
+
errorSpy.mockRestore();
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('sets process.exitCode = 1 when status is error', async () => {
|
|
279
|
+
mockRunPainFloodSimulation.mockResolvedValue({
|
|
280
|
+
...makePassedSummary(),
|
|
281
|
+
status: 'error',
|
|
282
|
+
reason: 'Simulation error: unexpected failure',
|
|
283
|
+
nextAction: 'Check workspace permissions and disk space, then re-run',
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
287
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
await handleRuntimePainFlood({});
|
|
291
|
+
expect(process.exitCode).toBe(1);
|
|
292
|
+
} finally {
|
|
293
|
+
logSpy.mockRestore();
|
|
294
|
+
errorSpy.mockRestore();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('cleans up temp workspace on success', async () => {
|
|
299
|
+
mockRunPainFloodSimulation.mockResolvedValue(makePassedSummary());
|
|
300
|
+
|
|
301
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
302
|
+
|
|
303
|
+
try {
|
|
304
|
+
await handleRuntimePainFlood({});
|
|
305
|
+
|
|
306
|
+
const calledDir = mockRunPainFloodSimulation.mock.calls[0][0].workspaceDir;
|
|
307
|
+
expect(fs.existsSync(calledDir)).toBe(false);
|
|
308
|
+
} finally {
|
|
309
|
+
logSpy.mockRestore();
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('runner rejection propagates and temp workspace is still cleaned up', async () => {
|
|
314
|
+
mockRunPainFloodSimulation.mockRejectedValue(new Error('EACCES: permission denied, mkdir'));
|
|
315
|
+
|
|
316
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
317
|
+
|
|
318
|
+
try {
|
|
319
|
+
await expect(handleRuntimePainFlood({})).rejects.toThrow('EACCES');
|
|
320
|
+
const calledDir = mockRunPainFloodSimulation.mock.calls[0][0].workspaceDir;
|
|
321
|
+
expect(fs.existsSync(calledDir)).toBe(false);
|
|
322
|
+
} finally {
|
|
323
|
+
logSpy.mockRestore();
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('injected failure produces structured reason and recommendedNextIssue', async () => {
|
|
328
|
+
mockRunPainFloodSimulation.mockResolvedValue({
|
|
329
|
+
status: 'degraded',
|
|
330
|
+
workspaceMode: 'temp',
|
|
331
|
+
generatedAt: new Date().toISOString(),
|
|
332
|
+
inputPainCount: 77,
|
|
333
|
+
acceptedPainCount: 22,
|
|
334
|
+
skippedDuplicateCount: 31,
|
|
335
|
+
failedCount: 10,
|
|
336
|
+
candidateCount: 22,
|
|
337
|
+
taskCount: 22,
|
|
338
|
+
maxEvidencePreviewLength: 0,
|
|
339
|
+
contextBudgetSummary: 'no evidence produced',
|
|
340
|
+
reason: '1 scenario(s) failed: similar_flood. Injected failure: stress test overflow',
|
|
341
|
+
nextAction: 'Investigate: PRI-208: Similar pain flood caused unbounded task creation — check dedup and evidence budget',
|
|
342
|
+
stages: [
|
|
343
|
+
{ scenarioName: 'identical_flood', status: 'passed', inputCount: 10, acceptedCount: 1, skippedCount: 9, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
344
|
+
{ scenarioName: 'similar_flood', status: 'failed', inputCount: 10, acceptedCount: 0, skippedCount: 0, failedCount: 10, taskCount: 0, candidateCount: 0, reason: 'Injected failure: stress test overflow' },
|
|
345
|
+
{ scenarioName: 'duplicate_submission', status: 'passed', inputCount: 2, acceptedCount: 1, skippedCount: 1, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
346
|
+
{ scenarioName: 'tool_failure_flood', status: 'passed', inputCount: 5, acceptedCount: 1, skippedCount: 4, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
347
|
+
{ scenarioName: 'stress_test', status: 'passed', inputCount: 50, acceptedCount: 33, skippedCount: 17, failedCount: 0, taskCount: 33, candidateCount: 33 },
|
|
348
|
+
],
|
|
349
|
+
recommendedNextIssue: 'PRI-208: Similar pain flood caused unbounded task creation — check dedup and evidence budget',
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
353
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
await handleRuntimePainFlood({ json: true });
|
|
357
|
+
const output = logSpy.mock.calls[0][0];
|
|
358
|
+
const parsed = JSON.parse(output);
|
|
359
|
+
expect(parsed.status).toBe('degraded');
|
|
360
|
+
expect(parsed.recommendedNextIssue).toContain('PRI-208');
|
|
361
|
+
expect(parsed.reason).toContain('similar_flood');
|
|
362
|
+
expect(parsed.nextAction).toContain('Investigate');
|
|
363
|
+
expect(process.exitCode).toBe(1);
|
|
364
|
+
} finally {
|
|
365
|
+
logSpy.mockRestore();
|
|
366
|
+
errorSpy.mockRestore();
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('degraded JSON output includes reason and nextAction', async () => {
|
|
371
|
+
mockRunPainFloodSimulation.mockResolvedValue({
|
|
372
|
+
...makePassedSummary(),
|
|
373
|
+
status: 'degraded',
|
|
374
|
+
reason: '1 scenario(s) failed: identical_flood. dedupe violation',
|
|
375
|
+
nextAction: 'Investigate: PRI-208: Identical pain dedup failed',
|
|
376
|
+
stages: [
|
|
377
|
+
{ scenarioName: 'identical_flood', status: 'failed', inputCount: 10, acceptedCount: 10, skippedCount: 0, failedCount: 0, taskCount: 10, candidateCount: 10, reason: 'dedupe violation' },
|
|
378
|
+
{ scenarioName: 'similar_flood', status: 'passed', inputCount: 10, acceptedCount: 10, skippedCount: 0, failedCount: 0, taskCount: 10, candidateCount: 10 },
|
|
379
|
+
{ scenarioName: 'duplicate_submission', status: 'passed', inputCount: 2, acceptedCount: 1, skippedCount: 1, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
380
|
+
{ scenarioName: 'tool_failure_flood', status: 'passed', inputCount: 5, acceptedCount: 1, skippedCount: 4, failedCount: 0, taskCount: 1, candidateCount: 1 },
|
|
381
|
+
{ scenarioName: 'stress_test', status: 'passed', inputCount: 50, acceptedCount: 33, skippedCount: 17, failedCount: 0, taskCount: 33, candidateCount: 33 },
|
|
382
|
+
],
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
386
|
+
|
|
387
|
+
try {
|
|
388
|
+
await handleRuntimePainFlood({ json: true });
|
|
389
|
+
const parsed = JSON.parse(logSpy.mock.calls[0][0]);
|
|
390
|
+
expect(parsed.reason).toBeDefined();
|
|
391
|
+
expect(parsed.reason).toContain('identical_flood');
|
|
392
|
+
expect(parsed.nextAction).toBeDefined();
|
|
393
|
+
expect(parsed.nextAction).toContain('Investigate');
|
|
394
|
+
} finally {
|
|
395
|
+
logSpy.mockRestore();
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('error JSON output includes reason and nextAction', async () => {
|
|
400
|
+
mockRunPainFloodSimulation.mockResolvedValue({
|
|
401
|
+
...makePassedSummary(),
|
|
402
|
+
status: 'error',
|
|
403
|
+
reason: 'Simulation error: EACCES permission denied',
|
|
404
|
+
nextAction: 'Check workspace permissions and disk space, then re-run',
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
408
|
+
|
|
409
|
+
try {
|
|
410
|
+
await handleRuntimePainFlood({ json: true });
|
|
411
|
+
const parsed = JSON.parse(logSpy.mock.calls[0][0]);
|
|
412
|
+
expect(parsed.reason).toContain('EACCES');
|
|
413
|
+
expect(parsed.nextAction).toContain('permissions');
|
|
414
|
+
} finally {
|
|
415
|
+
logSpy.mockRestore();
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
});
|