@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,589 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { handleCandidateIntake } from '../../src/commands/candidate.js';
|
|
3
|
+
|
|
4
|
+
// Use vi.hoisted to define mocks that can be referenced in vi.mock factory
|
|
5
|
+
const { mockStateManager, mockAdapter, mockService, MockRuntimeStateManager, MockCandidateIntakeService, MockPrincipleTreeLedgerAdapter, MockCandidateIntakeError } = vi.hoisted(() => {
|
|
6
|
+
const mockStateManager = {
|
|
7
|
+
initialize: vi.fn().mockResolvedValue(undefined),
|
|
8
|
+
getCandidate: vi.fn(),
|
|
9
|
+
getArtifact: vi.fn(),
|
|
10
|
+
close: vi.fn().mockResolvedValue(undefined),
|
|
11
|
+
connection: {
|
|
12
|
+
getDb: () => ({
|
|
13
|
+
prepare: () => ({
|
|
14
|
+
run: vi.fn().mockReturnValue({ changes: 1 }),
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const mockAdapter = {
|
|
21
|
+
writeProbationEntry: vi.fn(),
|
|
22
|
+
existsForCandidate: vi.fn().mockReturnValue(null),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const mockService = {
|
|
26
|
+
intake: vi.fn(),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Mock error class
|
|
30
|
+
class MockCandidateIntakeError extends Error {
|
|
31
|
+
code: string;
|
|
32
|
+
context?: Record<string, unknown>;
|
|
33
|
+
constructor(message: string, code: string, context?: Record<string, unknown>) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'CandidateIntakeError';
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.context = context;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Create mock constructors
|
|
42
|
+
function MockRuntimeStateManager(this: any) {
|
|
43
|
+
return mockStateManager;
|
|
44
|
+
}
|
|
45
|
+
MockRuntimeStateManager.prototype = {};
|
|
46
|
+
|
|
47
|
+
function MockCandidateIntakeService(this: any) {
|
|
48
|
+
return mockService;
|
|
49
|
+
}
|
|
50
|
+
MockCandidateIntakeService.prototype = {};
|
|
51
|
+
|
|
52
|
+
function MockPrincipleTreeLedgerAdapter(this: any) {
|
|
53
|
+
return mockAdapter;
|
|
54
|
+
}
|
|
55
|
+
MockPrincipleTreeLedgerAdapter.prototype = {};
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
mockStateManager,
|
|
59
|
+
mockAdapter,
|
|
60
|
+
mockService,
|
|
61
|
+
MockRuntimeStateManager,
|
|
62
|
+
MockCandidateIntakeService,
|
|
63
|
+
MockPrincipleTreeLedgerAdapter,
|
|
64
|
+
MockCandidateIntakeError,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Mock modules
|
|
69
|
+
vi.mock('@principles/core/runtime-v2', () => ({
|
|
70
|
+
CandidateIntakeService: MockCandidateIntakeService,
|
|
71
|
+
CandidateIntakeError: MockCandidateIntakeError,
|
|
72
|
+
RuntimeStateManager: MockRuntimeStateManager,
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
vi.mock('../../src/principle-tree-ledger-adapter.js', () => ({
|
|
76
|
+
PrincipleTreeLedgerAdapter: MockPrincipleTreeLedgerAdapter,
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
80
|
+
resolveWorkspaceDir: vi.fn().mockReturnValue('/tmp/test-workspace'),
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
describe('pd candidate intake', () => {
|
|
84
|
+
let consoleLogSpy: any;
|
|
85
|
+
let consoleErrorSpy: any;
|
|
86
|
+
let exitSpy: any;
|
|
87
|
+
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
vi.clearAllMocks();
|
|
90
|
+
|
|
91
|
+
// Reset mock implementations
|
|
92
|
+
mockStateManager.getCandidate.mockReset();
|
|
93
|
+
mockStateManager.getArtifact.mockReset();
|
|
94
|
+
mockAdapter.writeProbationEntry.mockReset();
|
|
95
|
+
mockAdapter.existsForCandidate.mockReset();
|
|
96
|
+
mockService.intake.mockReset();
|
|
97
|
+
|
|
98
|
+
// Set default mock implementations
|
|
99
|
+
mockStateManager.initialize.mockResolvedValue(undefined);
|
|
100
|
+
mockStateManager.close.mockResolvedValue(undefined);
|
|
101
|
+
mockAdapter.existsForCandidate.mockReturnValue(null);
|
|
102
|
+
|
|
103
|
+
// Spy on console methods
|
|
104
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
105
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
106
|
+
exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as () => never);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
afterEach(() => {
|
|
110
|
+
consoleLogSpy.mockRestore();
|
|
111
|
+
consoleErrorSpy.mockRestore();
|
|
112
|
+
exitSpy.mockRestore();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Test 1: Happy path JSON
|
|
116
|
+
it('Test 1 (happy path JSON): returns JSON with candidateId, status: consumed, ledgerEntryId', async () => {
|
|
117
|
+
const mockCandidate = {
|
|
118
|
+
candidateId: 'valid-id',
|
|
119
|
+
artifactId: 'artifact-1',
|
|
120
|
+
taskId: 'task-1',
|
|
121
|
+
title: 'Test Principle',
|
|
122
|
+
description: 'Test description',
|
|
123
|
+
status: 'pending',
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const mockEntry = {
|
|
127
|
+
id: 'ledger-entry-1',
|
|
128
|
+
title: 'Test Principle',
|
|
129
|
+
text: 'Test text',
|
|
130
|
+
triggerPattern: 'test pattern',
|
|
131
|
+
action: 'test action',
|
|
132
|
+
status: 'probation',
|
|
133
|
+
evaluability: 'weak_heuristic',
|
|
134
|
+
sourceRef: 'candidate://valid-id',
|
|
135
|
+
artifactRef: 'artifact://artifact-1',
|
|
136
|
+
taskRef: 'task://task-1',
|
|
137
|
+
createdAt: '2026-02-26T00:00:00.000Z',
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
141
|
+
mockService.intake.mockResolvedValue(mockEntry);
|
|
142
|
+
|
|
143
|
+
await handleCandidateIntake({
|
|
144
|
+
candidateId: 'valid-id',
|
|
145
|
+
workspace: '/tmp/test-workspace',
|
|
146
|
+
json: true,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Verify service.intake was called
|
|
150
|
+
expect(mockService.intake).toHaveBeenCalledWith('valid-id');
|
|
151
|
+
|
|
152
|
+
// Verify JSON output
|
|
153
|
+
const jsonOutput = consoleLogSpy.mock.calls.find(call => {
|
|
154
|
+
try {
|
|
155
|
+
const parsed = JSON.parse(call[0] as string);
|
|
156
|
+
return parsed.candidateId === 'valid-id' && parsed.status === 'consumed';
|
|
157
|
+
} catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
expect(jsonOutput).toBeDefined();
|
|
162
|
+
const parsed = JSON.parse((jsonOutput as [string])[0]);
|
|
163
|
+
expect(parsed.candidateId).toBe('valid-id');
|
|
164
|
+
expect(parsed.status).toBe('consumed');
|
|
165
|
+
expect(parsed.ledgerEntryId).toBe('ledger-entry-1');
|
|
166
|
+
|
|
167
|
+
// Verify exit was not called with 1
|
|
168
|
+
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Test 2: Happy path human-readable
|
|
172
|
+
it('Test 2 (happy path human-readable): prints human-readable format with "Intake complete" message', async () => {
|
|
173
|
+
const mockCandidate = {
|
|
174
|
+
candidateId: 'valid-id',
|
|
175
|
+
artifactId: 'artifact-1',
|
|
176
|
+
taskId: 'task-1',
|
|
177
|
+
title: 'Test Principle',
|
|
178
|
+
description: 'Test description',
|
|
179
|
+
status: 'pending',
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const mockEntry = {
|
|
183
|
+
id: 'ledger-entry-1',
|
|
184
|
+
title: 'Test Principle',
|
|
185
|
+
text: 'Test text',
|
|
186
|
+
status: 'probation',
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
190
|
+
mockService.intake.mockResolvedValue(mockEntry);
|
|
191
|
+
|
|
192
|
+
await handleCandidateIntake({
|
|
193
|
+
candidateId: 'valid-id',
|
|
194
|
+
workspace: '/tmp/test-workspace',
|
|
195
|
+
json: false,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Verify human-readable output
|
|
199
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Principle Candidate Intake:'));
|
|
200
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Intake complete.'));
|
|
201
|
+
|
|
202
|
+
// Verify no JSON.parse error (not JSON output)
|
|
203
|
+
const allOutput = consoleLogSpy.mock.calls.map(call => call[0]).join('\n');
|
|
204
|
+
expect(allOutput).toContain('valid-id');
|
|
205
|
+
expect(allOutput).toContain('ledger-entry-1');
|
|
206
|
+
|
|
207
|
+
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Test 3: Dry-run with complete 11-field entry (JSON output)
|
|
211
|
+
it('Test 3 (dry-run JSON): returns complete 11-field entry without writing to ledger', async () => {
|
|
212
|
+
const mockCandidate = {
|
|
213
|
+
candidateId: 'valid-id',
|
|
214
|
+
artifactId: 'artifact-1',
|
|
215
|
+
taskId: 'task-1',
|
|
216
|
+
title: 'Test Principle',
|
|
217
|
+
description: 'Test description',
|
|
218
|
+
status: 'pending',
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const mockArtifact = {
|
|
222
|
+
artifactId: 'artifact-1',
|
|
223
|
+
contentJson: JSON.stringify({
|
|
224
|
+
recommendation: {
|
|
225
|
+
title: 'Test Principle',
|
|
226
|
+
text: 'Test text',
|
|
227
|
+
triggerPattern: 'test pattern',
|
|
228
|
+
action: 'test action',
|
|
229
|
+
},
|
|
230
|
+
}),
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
234
|
+
mockStateManager.getArtifact.mockResolvedValue(mockArtifact);
|
|
235
|
+
|
|
236
|
+
await handleCandidateIntake({
|
|
237
|
+
candidateId: 'valid-id',
|
|
238
|
+
workspace: '/tmp/test-workspace',
|
|
239
|
+
dryRun: true,
|
|
240
|
+
json: true,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Verify service.intake was NOT called (dry-run skips service)
|
|
244
|
+
expect(mockService.intake).not.toHaveBeenCalled();
|
|
245
|
+
|
|
246
|
+
// Verify adapter.writeProbationEntry was NOT called
|
|
247
|
+
expect(mockAdapter.writeProbationEntry).not.toHaveBeenCalled();
|
|
248
|
+
|
|
249
|
+
// Verify JSON output has all 11 fields
|
|
250
|
+
const jsonOutput = consoleLogSpy.mock.calls.find(call => {
|
|
251
|
+
try {
|
|
252
|
+
const parsed = JSON.parse(call[0] as string);
|
|
253
|
+
return parsed.id && parsed.title && parsed.sourceRef === 'candidate://valid-id';
|
|
254
|
+
} catch {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
expect(jsonOutput).toBeDefined();
|
|
259
|
+
const entry = JSON.parse((jsonOutput as [string])[0]);
|
|
260
|
+
|
|
261
|
+
// Check all 11 fields exist
|
|
262
|
+
expect(entry.id).toBeDefined();
|
|
263
|
+
expect(entry.title).toBe('Test Principle');
|
|
264
|
+
expect(entry.text).toBe('Test text');
|
|
265
|
+
expect(entry.triggerPattern).toBe('test pattern');
|
|
266
|
+
expect(entry.action).toBe('test action');
|
|
267
|
+
expect(entry.status).toBe('probation');
|
|
268
|
+
expect(entry.evaluability).toBe('weak_heuristic');
|
|
269
|
+
expect(entry.sourceRef).toBe('candidate://valid-id');
|
|
270
|
+
expect(entry.artifactRef).toBe('artifact://artifact-1');
|
|
271
|
+
expect(entry.taskRef).toBe('task://task-1');
|
|
272
|
+
expect(entry.createdAt).toBeDefined();
|
|
273
|
+
|
|
274
|
+
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Test 3b: Dry-run with human-readable output (covers lines 193-194)
|
|
278
|
+
it('Test 3b (dry-run human-readable): outputs human-readable format without writing', async () => {
|
|
279
|
+
const mockCandidate = {
|
|
280
|
+
candidateId: 'valid-id',
|
|
281
|
+
artifactId: 'artifact-1',
|
|
282
|
+
taskId: 'task-1',
|
|
283
|
+
title: 'Test Principle',
|
|
284
|
+
description: 'Test description',
|
|
285
|
+
status: 'pending',
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const mockArtifact = {
|
|
289
|
+
artifactId: 'artifact-1',
|
|
290
|
+
contentJson: JSON.stringify({
|
|
291
|
+
recommendation: {
|
|
292
|
+
title: 'Test Principle',
|
|
293
|
+
text: 'Test text',
|
|
294
|
+
},
|
|
295
|
+
}),
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
299
|
+
mockStateManager.getArtifact.mockResolvedValue(mockArtifact);
|
|
300
|
+
|
|
301
|
+
await handleCandidateIntake({
|
|
302
|
+
candidateId: 'valid-id',
|
|
303
|
+
workspace: '/tmp/test-workspace',
|
|
304
|
+
dryRun: true,
|
|
305
|
+
json: false,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Verify human-readable output (covers lines 193-194)
|
|
309
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Dry-run: would write entry for candidate valid-id'));
|
|
310
|
+
|
|
311
|
+
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// Test 3c: Dry-run when candidate not found (covers line 165)
|
|
315
|
+
it('Test 3c (dry-run candidate not found): exits with error', async () => {
|
|
316
|
+
mockStateManager.getCandidate.mockResolvedValue(null);
|
|
317
|
+
|
|
318
|
+
await handleCandidateIntake({
|
|
319
|
+
candidateId: 'invalid-id',
|
|
320
|
+
workspace: '/tmp/test-workspace',
|
|
321
|
+
dryRun: true,
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('Candidate not found: invalid-id');
|
|
325
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Test 3d: Dry-run when artifact not found (covers line 165)
|
|
329
|
+
it('Test 3d (dry-run artifact not found): exits with error', async () => {
|
|
330
|
+
const mockCandidate = {
|
|
331
|
+
candidateId: 'valid-id',
|
|
332
|
+
artifactId: 'artifact-1',
|
|
333
|
+
title: 'Test',
|
|
334
|
+
description: 'Test',
|
|
335
|
+
status: 'pending',
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
339
|
+
mockStateManager.getArtifact.mockResolvedValue(null);
|
|
340
|
+
|
|
341
|
+
await handleCandidateIntake({
|
|
342
|
+
candidateId: 'valid-id',
|
|
343
|
+
workspace: '/tmp/test-workspace',
|
|
344
|
+
dryRun: true,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('Artifact not found for candidate: valid-id');
|
|
348
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Test 4: Non-existent candidate
|
|
352
|
+
it('Test 4 (non-existent candidate): throws CANDIDATE_NOT_FOUND error', async () => {
|
|
353
|
+
// Setup: service.intake throws CANDIDATE_NOT_FOUND when candidate doesn't exist
|
|
354
|
+
mockService.intake.mockImplementation(() => {
|
|
355
|
+
throw new MockCandidateIntakeError(
|
|
356
|
+
`Candidate invalid-id not found`,
|
|
357
|
+
'CANDIDATE_NOT_FOUND',
|
|
358
|
+
{ candidateId: 'invalid-id' }
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
await handleCandidateIntake({
|
|
363
|
+
candidateId: 'invalid-id',
|
|
364
|
+
workspace: '/tmp/test-workspace',
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Verify error output contains CANDIDATE_NOT_FOUND
|
|
368
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
369
|
+
expect.stringContaining('CANDIDATE_NOT_FOUND')
|
|
370
|
+
);
|
|
371
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// Test 5: Invalid candidateId (empty string)
|
|
375
|
+
it('Test 5 (invalid candidateId): empty string throws INPUT_INVALID error', async () => {
|
|
376
|
+
// Setup: service.intake throws INPUT_INVALID for empty candidateId
|
|
377
|
+
mockService.intake.mockImplementation(() => {
|
|
378
|
+
throw new MockCandidateIntakeError(
|
|
379
|
+
'candidateId must be a non-empty string',
|
|
380
|
+
'INPUT_INVALID',
|
|
381
|
+
{ candidateId: '' }
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
await handleCandidateIntake({
|
|
386
|
+
candidateId: '',
|
|
387
|
+
workspace: '/tmp/test-workspace',
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
391
|
+
expect.stringContaining('INPUT_INVALID')
|
|
392
|
+
);
|
|
393
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// Test 6: Already consumed candidate (human-readable)
|
|
397
|
+
it('Test 6 (already consumed human-readable): outputs info message and exits successfully', async () => {
|
|
398
|
+
const mockCandidate = {
|
|
399
|
+
candidateId: 'valid-id',
|
|
400
|
+
artifactId: 'artifact-1',
|
|
401
|
+
taskId: 'task-1',
|
|
402
|
+
title: 'Test Principle',
|
|
403
|
+
description: 'Test description',
|
|
404
|
+
status: 'consumed', // Already consumed
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const mockEntry = {
|
|
408
|
+
id: 'ledger-entry-1',
|
|
409
|
+
title: 'Test Principle',
|
|
410
|
+
text: 'Test text',
|
|
411
|
+
status: 'probation',
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
415
|
+
mockService.intake.mockResolvedValue(mockEntry);
|
|
416
|
+
|
|
417
|
+
await handleCandidateIntake({
|
|
418
|
+
candidateId: 'valid-id',
|
|
419
|
+
workspace: '/tmp/test-workspace',
|
|
420
|
+
json: false,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// Verify info message about already consumed
|
|
424
|
+
const allOutput = consoleLogSpy.mock.calls.map(call => call[0]).join('\n');
|
|
425
|
+
expect(allOutput).toContain('already consumed');
|
|
426
|
+
expect(allOutput).toContain('ledger-entry-1');
|
|
427
|
+
|
|
428
|
+
// Verify exit was not called with 1 (successful exit)
|
|
429
|
+
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// Test 6b: Already consumed candidate (JSON output, covers line 208)
|
|
433
|
+
it('Test 6b (already consumed JSON): outputs JSON with already_consumed status', async () => {
|
|
434
|
+
const mockCandidate = {
|
|
435
|
+
candidateId: 'valid-id',
|
|
436
|
+
artifactId: 'artifact-1',
|
|
437
|
+
taskId: 'task-1',
|
|
438
|
+
title: 'Test Principle',
|
|
439
|
+
description: 'Test description',
|
|
440
|
+
status: 'consumed', // Already consumed
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const mockEntry = {
|
|
444
|
+
id: 'ledger-entry-1',
|
|
445
|
+
title: 'Test Principle',
|
|
446
|
+
text: 'Test text',
|
|
447
|
+
status: 'probation',
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
451
|
+
mockService.intake.mockResolvedValue(mockEntry);
|
|
452
|
+
|
|
453
|
+
await handleCandidateIntake({
|
|
454
|
+
candidateId: 'valid-id',
|
|
455
|
+
workspace: '/tmp/test-workspace',
|
|
456
|
+
json: true,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// Verify JSON output for already consumed (covers line 208)
|
|
460
|
+
const jsonOutput = consoleLogSpy.mock.calls.find(call => {
|
|
461
|
+
try {
|
|
462
|
+
const parsed = JSON.parse(call[0] as string);
|
|
463
|
+
return parsed.status === 'already_consumed';
|
|
464
|
+
} catch {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
expect(jsonOutput).toBeDefined();
|
|
469
|
+
const parsed = JSON.parse((jsonOutput as [string])[0]);
|
|
470
|
+
expect(parsed.candidateId).toBe('valid-id');
|
|
471
|
+
expect(parsed.ledgerEntryId).toBe('ledger-entry-1');
|
|
472
|
+
expect(parsed.status).toBe('already_consumed');
|
|
473
|
+
expect(parsed.message).toContain('already consumed');
|
|
474
|
+
|
|
475
|
+
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// Test 7: Generic error (non-CandidateIntakeError, covers line 247)
|
|
479
|
+
it('Test 7 (generic error): handles non-CandidateIntakeError errors', async () => {
|
|
480
|
+
// Setup: service.intake throws a generic Error (not CandidateIntakeError)
|
|
481
|
+
mockService.intake.mockImplementation(() => {
|
|
482
|
+
throw new Error('Some unexpected error');
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
await handleCandidateIntake({
|
|
486
|
+
candidateId: 'valid-id',
|
|
487
|
+
workspace: '/tmp/test-workspace',
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// Verify generic error output (covers line 247)
|
|
491
|
+
// String(err) produces "Error: Some unexpected error"
|
|
492
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
493
|
+
expect.stringContaining('Intake failed: Error: Some unexpected error')
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it('guarded transition: UPDATE uses WHERE status = pending for intake path', async () => {
|
|
500
|
+
const mockCandidate = {
|
|
501
|
+
candidateId: 'valid-id',
|
|
502
|
+
artifactId: 'artifact-1',
|
|
503
|
+
taskId: 'task-1',
|
|
504
|
+
title: 'Test Principle',
|
|
505
|
+
description: 'Test description',
|
|
506
|
+
status: 'pending',
|
|
507
|
+
};
|
|
508
|
+
const mockEntry = {
|
|
509
|
+
id: 'ledger-entry-1',
|
|
510
|
+
title: 'Test Principle',
|
|
511
|
+
text: 'Test text',
|
|
512
|
+
status: 'probation',
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
516
|
+
mockService.intake.mockResolvedValue(mockEntry);
|
|
517
|
+
|
|
518
|
+
const capturedPrepareCalls: { sql: string; runArgs: unknown[] }[] = [];
|
|
519
|
+
const originalConnection = mockStateManager.connection;
|
|
520
|
+
mockStateManager.connection = {
|
|
521
|
+
getDb: () => ({
|
|
522
|
+
prepare: (sql: string) => ({
|
|
523
|
+
run: (...args: unknown[]) => {
|
|
524
|
+
capturedPrepareCalls.push({ sql, runArgs: args });
|
|
525
|
+
return { changes: 1 };
|
|
526
|
+
},
|
|
527
|
+
}),
|
|
528
|
+
}),
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
try {
|
|
532
|
+
await handleCandidateIntake({
|
|
533
|
+
candidateId: 'valid-id',
|
|
534
|
+
workspace: '/tmp/test-workspace',
|
|
535
|
+
json: true,
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
const updateCall = capturedPrepareCalls.find(c => c.sql.includes('UPDATE'));
|
|
539
|
+
expect(updateCall).toBeDefined();
|
|
540
|
+
expect(updateCall!.sql).toContain('AND status = ?');
|
|
541
|
+
expect(updateCall!.runArgs[0]).toBe('consumed');
|
|
542
|
+
expect(updateCall!.runArgs[3]).toBe('pending');
|
|
543
|
+
} finally {
|
|
544
|
+
mockStateManager.connection = originalConnection;
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it('guarded transition: intake fails when candidate is not pending', async () => {
|
|
549
|
+
const mockCandidate = {
|
|
550
|
+
candidateId: 'valid-id',
|
|
551
|
+
artifactId: 'artifact-1',
|
|
552
|
+
taskId: 'task-1',
|
|
553
|
+
title: 'Test Principle',
|
|
554
|
+
description: 'Test description',
|
|
555
|
+
status: 'pending',
|
|
556
|
+
};
|
|
557
|
+
const mockEntry = {
|
|
558
|
+
id: 'ledger-entry-1',
|
|
559
|
+
title: 'Test Principle',
|
|
560
|
+
text: 'Test text',
|
|
561
|
+
status: 'probation',
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
565
|
+
mockService.intake.mockResolvedValue(mockEntry);
|
|
566
|
+
|
|
567
|
+
const originalConnection = mockStateManager.connection;
|
|
568
|
+
mockStateManager.connection = {
|
|
569
|
+
getDb: () => ({
|
|
570
|
+
prepare: (sql: string) => ({
|
|
571
|
+
run: () => ({ changes: 0 }),
|
|
572
|
+
}),
|
|
573
|
+
}),
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
try {
|
|
577
|
+
await handleCandidateIntake({
|
|
578
|
+
candidateId: 'valid-id',
|
|
579
|
+
workspace: '/tmp/test-workspace',
|
|
580
|
+
json: true,
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Guarded transition failed'));
|
|
584
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
585
|
+
} finally {
|
|
586
|
+
mockStateManager.connection = originalConnection;
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
});
|