@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,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pd runtime trace show command unit tests.
|
|
3
|
+
*
|
|
4
|
+
* Tests the trace command's external contract via mocked PainChainReadModel.
|
|
5
|
+
* Tests pain-to-ledger chain tracing, latency reporting, consistency checks,
|
|
6
|
+
* and failure classification output.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
9
|
+
|
|
10
|
+
const mockTraceByPainId = vi.fn();
|
|
11
|
+
const mockPainChainClose = vi.fn().mockResolvedValue(undefined);
|
|
12
|
+
|
|
13
|
+
vi.mock('@principles/core/runtime-v2', () => ({
|
|
14
|
+
PainChainReadModel: vi.fn().mockImplementation(function () {
|
|
15
|
+
return { traceByPainId: mockTraceByPainId, close: mockPainChainClose };
|
|
16
|
+
}),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
20
|
+
resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
import { handleTraceShow } from '../../src/commands/trace.js';
|
|
24
|
+
|
|
25
|
+
const WS = '/fake/workspace';
|
|
26
|
+
|
|
27
|
+
function fullChainTrace() {
|
|
28
|
+
return {
|
|
29
|
+
painId: 'pain_001',
|
|
30
|
+
taskId: 'diagnosis_pain_001',
|
|
31
|
+
runId: 'run_001',
|
|
32
|
+
artifactId: 'art_001',
|
|
33
|
+
candidateIds: ['c1', 'c2'],
|
|
34
|
+
ledgerEntryIds: ['l1'],
|
|
35
|
+
status: 'succeeded',
|
|
36
|
+
latencyMs: {
|
|
37
|
+
painToTask: 100,
|
|
38
|
+
taskToRun: 200,
|
|
39
|
+
runToArtifact: 50,
|
|
40
|
+
artifactToCandidate: 30,
|
|
41
|
+
candidateToLedger: 20,
|
|
42
|
+
},
|
|
43
|
+
failureCategory: null,
|
|
44
|
+
checkedAt: '2026-05-03T12:00:00.000Z',
|
|
45
|
+
missingLinks: [],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function mockProcessExit() {
|
|
50
|
+
return vi.spyOn(process, 'exit').mockImplementation((() => undefined) as () => never);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe('handleTraceShow', () => {
|
|
54
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
55
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
vi.clearAllMocks();
|
|
59
|
+
process.exitCode = undefined;
|
|
60
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
61
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
consoleLogSpy.mockRestore();
|
|
66
|
+
consoleErrorSpy.mockRestore();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('outputs full chain trace with all fields (--json)', async () => {
|
|
70
|
+
mockTraceByPainId.mockResolvedValue(fullChainTrace());
|
|
71
|
+
|
|
72
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: true });
|
|
73
|
+
|
|
74
|
+
expect(consoleLogSpy).toHaveBeenCalled();
|
|
75
|
+
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
76
|
+
expect(jsonOutput.painId).toBe('pain_001');
|
|
77
|
+
expect(jsonOutput.taskId).toBe('diagnosis_pain_001');
|
|
78
|
+
expect(jsonOutput.runId).toBe('run_001');
|
|
79
|
+
expect(jsonOutput.artifactId).toBe('art_001');
|
|
80
|
+
expect(jsonOutput.candidateIds).toEqual(['c1', 'c2']);
|
|
81
|
+
expect(jsonOutput.ledgerEntryIds).toEqual(['l1']);
|
|
82
|
+
expect(jsonOutput.status).toBe('succeeded');
|
|
83
|
+
expect(jsonOutput.latencyMs).toBeDefined();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('outputs readable text with latency breakdown', async () => {
|
|
87
|
+
mockTraceByPainId.mockResolvedValue(fullChainTrace());
|
|
88
|
+
|
|
89
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
90
|
+
|
|
91
|
+
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
92
|
+
expect(allOutput).toContain('Pain ID: pain_001');
|
|
93
|
+
expect(allOutput).toContain('Task ID: diagnosis_pain_001');
|
|
94
|
+
expect(allOutput).toContain('Status: succeeded');
|
|
95
|
+
expect(allOutput).toContain('Run ID: run_001');
|
|
96
|
+
expect(allOutput).toContain('Artifact ID: art_001');
|
|
97
|
+
expect(allOutput).toContain('Candidate IDs: c1, c2');
|
|
98
|
+
expect(allOutput).toContain('Ledger Entries: l1');
|
|
99
|
+
expect(allOutput).toContain('Checked at: 2026-05-03T12:00:00.000Z');
|
|
100
|
+
expect(allOutput).toContain('Latency:');
|
|
101
|
+
expect(allOutput).toContain('pain→task: 100ms');
|
|
102
|
+
expect(allOutput).toContain('task→run: 200ms');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('outputs all latency segments in text mode', async () => {
|
|
106
|
+
mockTraceByPainId.mockResolvedValue(fullChainTrace());
|
|
107
|
+
|
|
108
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
109
|
+
|
|
110
|
+
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
111
|
+
expect(allOutput).toContain('run→artifact: 50ms');
|
|
112
|
+
expect(allOutput).toContain('artifact→candidate: 30ms');
|
|
113
|
+
expect(allOutput).toContain('candidate→ledger: 20ms');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('outputs failure category in text mode when present', async () => {
|
|
117
|
+
mockTraceByPainId.mockResolvedValue({
|
|
118
|
+
...fullChainTrace(),
|
|
119
|
+
status: 'failed',
|
|
120
|
+
failureCategory: 'runtime_timeout',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
124
|
+
|
|
125
|
+
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
126
|
+
expect(allOutput).toContain('Failure: runtime_timeout');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('omits candidate/ledger lines when arrays are empty', async () => {
|
|
130
|
+
mockTraceByPainId.mockResolvedValue({
|
|
131
|
+
...fullChainTrace(),
|
|
132
|
+
candidateIds: [],
|
|
133
|
+
ledgerEntryIds: [],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
137
|
+
|
|
138
|
+
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
139
|
+
expect(allOutput).not.toContain('Candidate IDs:');
|
|
140
|
+
expect(allOutput).not.toContain('Ledger Entries:');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('handles not_found status with exit code 1', async () => {
|
|
144
|
+
mockTraceByPainId.mockResolvedValue({
|
|
145
|
+
painId: 'pain_001',
|
|
146
|
+
taskId: 'diagnosis_pain_001',
|
|
147
|
+
status: 'not_found',
|
|
148
|
+
failureCategory: 'runtime_unavailable',
|
|
149
|
+
checkedAt: '2026-05-03T12:00:00.000Z',
|
|
150
|
+
missingLinks: ['task'],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
154
|
+
|
|
155
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('No task found'));
|
|
156
|
+
expect(process.exitCode).toBe(1);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('handles not_found in text mode with derived taskId and workspace', async () => {
|
|
160
|
+
mockTraceByPainId.mockResolvedValue({
|
|
161
|
+
painId: 'pain_001',
|
|
162
|
+
taskId: 'diagnosis_pain_001',
|
|
163
|
+
status: 'not_found',
|
|
164
|
+
failureCategory: 'runtime_unavailable',
|
|
165
|
+
checkedAt: '2026-05-03T12:00:00.000Z',
|
|
166
|
+
missingLinks: ['task'],
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
170
|
+
|
|
171
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('diagnosis_pain_001'));
|
|
172
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(WS));
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('handles error status with config_missing in JSON mode', async () => {
|
|
176
|
+
mockTraceByPainId.mockResolvedValue({
|
|
177
|
+
painId: 'pain_001',
|
|
178
|
+
taskId: 'diagnosis_pain_001',
|
|
179
|
+
status: 'error',
|
|
180
|
+
failureCategory: 'config_missing',
|
|
181
|
+
checkedAt: '2026-05-03T12:00:00.000Z',
|
|
182
|
+
missingLinks: ['state_manager_init'],
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: true });
|
|
186
|
+
|
|
187
|
+
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
188
|
+
expect(jsonOutput.status).toBe('error');
|
|
189
|
+
expect(jsonOutput.failureCategory).toBe('config_missing');
|
|
190
|
+
expect(jsonOutput.message).toContain('Failed to initialize state manager');
|
|
191
|
+
expect(process.exitCode).toBe(1);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('handles error status in text mode', async () => {
|
|
195
|
+
mockTraceByPainId.mockResolvedValue({
|
|
196
|
+
painId: 'pain_001',
|
|
197
|
+
taskId: 'diagnosis_pain_001',
|
|
198
|
+
status: 'error',
|
|
199
|
+
failureCategory: 'config_missing',
|
|
200
|
+
checkedAt: '2026-05-03T12:00:00.000Z',
|
|
201
|
+
missingLinks: ['state_manager_init'],
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
205
|
+
|
|
206
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Failed to open workspace'));
|
|
207
|
+
expect(process.exitCode).toBe(1);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('reports missing links in text output', async () => {
|
|
211
|
+
mockTraceByPainId.mockResolvedValue({
|
|
212
|
+
...fullChainTrace(),
|
|
213
|
+
status: 'degraded',
|
|
214
|
+
failureCategory: 'ledger_write_failed',
|
|
215
|
+
missingLinks: ['candidate:c1 consumed but missing from ledger'],
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
219
|
+
|
|
220
|
+
const allOutput = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
221
|
+
expect(allOutput).toContain('Missing links');
|
|
222
|
+
expect(allOutput).toContain('candidate:c1 consumed but missing from ledger');
|
|
223
|
+
expect(process.exitCode).toBe(1);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('handles missing painId gracefully', async () => {
|
|
227
|
+
await handleTraceShow({ painId: '', workspace: WS, json: false });
|
|
228
|
+
|
|
229
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('--pain-id'));
|
|
230
|
+
expect(process.exitCode).toBe(1);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('reports failed status with exit code 1', async () => {
|
|
234
|
+
mockTraceByPainId.mockResolvedValue({
|
|
235
|
+
...fullChainTrace(),
|
|
236
|
+
status: 'failed',
|
|
237
|
+
failureCategory: 'runtime_timeout',
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
241
|
+
|
|
242
|
+
expect(process.exitCode).toBe(1);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('reports degraded status with exit code 1', async () => {
|
|
246
|
+
mockTraceByPainId.mockResolvedValue({
|
|
247
|
+
...fullChainTrace(),
|
|
248
|
+
status: 'degraded',
|
|
249
|
+
failureCategory: 'candidate_missing',
|
|
250
|
+
missingLinks: ['No candidates generated for succeeded task'],
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: false });
|
|
254
|
+
|
|
255
|
+
expect(process.exitCode).toBe(1);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('closes PainChainReadModel after use', async () => {
|
|
259
|
+
mockTraceByPainId.mockResolvedValue(fullChainTrace());
|
|
260
|
+
|
|
261
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: true });
|
|
262
|
+
|
|
263
|
+
expect(mockPainChainClose).toHaveBeenCalled();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('closes PainChainReadModel even when traceByPainId throws', async () => {
|
|
267
|
+
mockTraceByPainId.mockRejectedValue(new Error('Database connection failed'));
|
|
268
|
+
|
|
269
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: true });
|
|
270
|
+
|
|
271
|
+
expect(mockPainChainClose).toHaveBeenCalled();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('handles traceByPainId throwing an error', async () => {
|
|
275
|
+
mockTraceByPainId.mockRejectedValue(new Error('Database connection failed'));
|
|
276
|
+
|
|
277
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: true });
|
|
278
|
+
|
|
279
|
+
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
280
|
+
expect(jsonOutput.status).toBe('error');
|
|
281
|
+
expect(jsonOutput.failureCategory).toBe('runtime_unavailable');
|
|
282
|
+
expect(jsonOutput.message).toContain('Database connection failed');
|
|
283
|
+
expect(process.exitCode).toBe(1);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('outputs not_found in JSON format with correct fields', async () => {
|
|
287
|
+
mockTraceByPainId.mockResolvedValue({
|
|
288
|
+
painId: 'pain_001',
|
|
289
|
+
taskId: 'diagnosis_pain_001',
|
|
290
|
+
status: 'not_found',
|
|
291
|
+
failureCategory: 'runtime_unavailable',
|
|
292
|
+
checkedAt: '2026-05-03T12:00:00.000Z',
|
|
293
|
+
missingLinks: ['task'],
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: true });
|
|
297
|
+
|
|
298
|
+
const jsonOutput = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
299
|
+
expect(jsonOutput.painId).toBe('pain_001');
|
|
300
|
+
expect(jsonOutput.taskId).toBe('diagnosis_pain_001');
|
|
301
|
+
expect(jsonOutput.status).toBe('not_found');
|
|
302
|
+
expect(jsonOutput.message).toContain('No task found');
|
|
303
|
+
expect(jsonOutput.workspace).toBe(WS);
|
|
304
|
+
expect(process.exitCode).toBe(1);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('does not set exit code for succeeded status', async () => {
|
|
308
|
+
mockTraceByPainId.mockResolvedValue(fullChainTrace());
|
|
309
|
+
|
|
310
|
+
await handleTraceShow({ painId: 'pain_001', workspace: WS, json: true });
|
|
311
|
+
|
|
312
|
+
expect(process.exitCode).toBeUndefined();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { execFileSync } from 'child_process';
|
|
3
|
+
import { mkdtempSync, rmSync, existsSync, readFileSync, mkdirSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { tmpdir } from 'os';
|
|
6
|
+
import Database from 'better-sqlite3';
|
|
7
|
+
|
|
8
|
+
describe('E2E: pd candidate intake flow', () => {
|
|
9
|
+
let tempWorkspace: string;
|
|
10
|
+
let db: Database.Database;
|
|
11
|
+
const pdCliPath = join(process.cwd(), 'dist/index.js');
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
tempWorkspace = mkdtempSync(join(tmpdir(), 'pd-e2e-'));
|
|
15
|
+
const pdDir = join(tempWorkspace, '.pd');
|
|
16
|
+
mkdirSync(pdDir, { recursive: true });
|
|
17
|
+
|
|
18
|
+
const dbPath = join(pdDir, 'state.db');
|
|
19
|
+
db = new Database(dbPath);
|
|
20
|
+
|
|
21
|
+
db.exec(`
|
|
22
|
+
CREATE TABLE IF NOT EXISTS tasks (
|
|
23
|
+
task_id TEXT PRIMARY KEY,
|
|
24
|
+
task_kind TEXT NOT NULL,
|
|
25
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
26
|
+
created_at TEXT NOT NULL,
|
|
27
|
+
updated_at TEXT NOT NULL,
|
|
28
|
+
lease_owner TEXT,
|
|
29
|
+
lease_expires_at TEXT,
|
|
30
|
+
attempt_count INTEGER NOT NULL DEFAULT 0,
|
|
31
|
+
max_attempts INTEGER NOT NULL DEFAULT 3,
|
|
32
|
+
last_error TEXT,
|
|
33
|
+
input_ref TEXT,
|
|
34
|
+
result_ref TEXT,
|
|
35
|
+
diagnostic_json TEXT
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
CREATE TABLE IF NOT EXISTS runs (
|
|
39
|
+
run_id TEXT PRIMARY KEY,
|
|
40
|
+
task_id TEXT NOT NULL,
|
|
41
|
+
runtime_kind TEXT NOT NULL,
|
|
42
|
+
execution_status TEXT NOT NULL DEFAULT 'queued',
|
|
43
|
+
started_at TEXT NOT NULL,
|
|
44
|
+
ended_at TEXT,
|
|
45
|
+
reason TEXT,
|
|
46
|
+
output_ref TEXT,
|
|
47
|
+
input_payload TEXT,
|
|
48
|
+
output_payload TEXT,
|
|
49
|
+
error_category TEXT,
|
|
50
|
+
attempt_number INTEGER NOT NULL DEFAULT 0,
|
|
51
|
+
created_at TEXT NOT NULL,
|
|
52
|
+
updated_at TEXT NOT NULL,
|
|
53
|
+
FOREIGN KEY (task_id) REFERENCES tasks(task_id) ON DELETE CASCADE
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
CREATE TABLE IF NOT EXISTS artifacts (
|
|
57
|
+
artifact_id TEXT PRIMARY KEY,
|
|
58
|
+
run_id TEXT NOT NULL,
|
|
59
|
+
task_id TEXT NOT NULL,
|
|
60
|
+
artifact_kind TEXT NOT NULL,
|
|
61
|
+
content_json TEXT NOT NULL,
|
|
62
|
+
created_at TEXT NOT NULL,
|
|
63
|
+
FOREIGN KEY (run_id) REFERENCES runs(run_id) ON DELETE CASCADE
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
CREATE TABLE IF NOT EXISTS commits (
|
|
67
|
+
commit_id TEXT PRIMARY KEY,
|
|
68
|
+
task_id TEXT NOT NULL,
|
|
69
|
+
run_id TEXT NOT NULL UNIQUE,
|
|
70
|
+
artifact_id TEXT NOT NULL,
|
|
71
|
+
idempotency_key TEXT NOT NULL UNIQUE,
|
|
72
|
+
status TEXT NOT NULL DEFAULT 'committed',
|
|
73
|
+
created_at TEXT NOT NULL,
|
|
74
|
+
FOREIGN KEY (task_id) REFERENCES tasks(task_id) ON DELETE CASCADE,
|
|
75
|
+
FOREIGN KEY (run_id) REFERENCES runs(run_id) ON DELETE CASCADE,
|
|
76
|
+
FOREIGN KEY (artifact_id) REFERENCES artifacts(artifact_id) ON DELETE CASCADE
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
CREATE TABLE IF NOT EXISTS principle_candidates (
|
|
80
|
+
candidate_id TEXT PRIMARY KEY,
|
|
81
|
+
artifact_id TEXT NOT NULL,
|
|
82
|
+
task_id TEXT NOT NULL,
|
|
83
|
+
source_run_id TEXT NOT NULL,
|
|
84
|
+
title TEXT NOT NULL,
|
|
85
|
+
description TEXT NOT NULL,
|
|
86
|
+
confidence REAL,
|
|
87
|
+
source_recommendation_json TEXT,
|
|
88
|
+
idempotency_key TEXT NOT NULL UNIQUE,
|
|
89
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
90
|
+
created_at TEXT NOT NULL,
|
|
91
|
+
consumed_at TEXT,
|
|
92
|
+
FOREIGN KEY (artifact_id) REFERENCES artifacts(artifact_id) ON DELETE CASCADE,
|
|
93
|
+
FOREIGN KEY (task_id) REFERENCES tasks(task_id) ON DELETE CASCADE,
|
|
94
|
+
FOREIGN KEY (source_run_id) REFERENCES runs(run_id) ON DELETE CASCADE
|
|
95
|
+
);
|
|
96
|
+
`);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
afterEach(() => {
|
|
100
|
+
if (db) db.close();
|
|
101
|
+
if (existsSync(tempWorkspace)) {
|
|
102
|
+
rmSync(tempWorkspace, { recursive: true, force: true });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
function insertPendingCandidate(candidateId: string, taskId: string, artifactId: string, runId: string) {
|
|
107
|
+
const now = new Date().toISOString();
|
|
108
|
+
|
|
109
|
+
db.prepare('INSERT OR IGNORE INTO tasks (task_id, task_kind, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?)')
|
|
110
|
+
.run(taskId, 'diagnostician', 'succeeded', now, now);
|
|
111
|
+
|
|
112
|
+
db.prepare('INSERT OR IGNORE INTO runs (run_id, task_id, runtime_kind, execution_status, attempt_number, started_at, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')
|
|
113
|
+
.run(runId, taskId, 'openclaw-cli', 'completed', 1, now, now, now);
|
|
114
|
+
|
|
115
|
+
const artifactContent = JSON.stringify({
|
|
116
|
+
recommendation: {
|
|
117
|
+
title: 'Test Principle',
|
|
118
|
+
text: 'Always write tests',
|
|
119
|
+
triggerPattern: 'missing tests',
|
|
120
|
+
action: 'add test files',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
db.prepare('INSERT OR IGNORE INTO artifacts (artifact_id, run_id, task_id, artifact_kind, content_json, created_at) VALUES (?, ?, ?, ?, ?, ?)')
|
|
124
|
+
.run(artifactId, runId, taskId, 'diagnostician_output_v1', artifactContent, now);
|
|
125
|
+
|
|
126
|
+
db.prepare('INSERT OR IGNORE INTO commits (commit_id, task_id, run_id, artifact_id, idempotency_key, status, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)')
|
|
127
|
+
.run(`commit-${candidateId}`, taskId, runId, artifactId, `key-${candidateId}`, 'committed', now);
|
|
128
|
+
|
|
129
|
+
db.prepare(`INSERT INTO principle_candidates (candidate_id, artifact_id, task_id, source_run_id, title, description, confidence, source_recommendation_json, idempotency_key, status, created_at)
|
|
130
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
131
|
+
.run(candidateId, artifactId, taskId, runId, 'Test Principle', 'Always write tests', 0.95, artifactContent, `candidate-key-${candidateId}`, 'pending', now);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function runPdCommand(args: string[]): { stdout: string; stderr: string; status: number } {
|
|
135
|
+
try {
|
|
136
|
+
const stdout = execFileSync('node', [pdCliPath, ...args], {
|
|
137
|
+
env: { ...process.env, NODE_PATH: '' },
|
|
138
|
+
encoding: 'utf-8',
|
|
139
|
+
timeout: 30000,
|
|
140
|
+
});
|
|
141
|
+
return { stdout, stderr: '', status: 0 };
|
|
142
|
+
} catch (err: any) {
|
|
143
|
+
return {
|
|
144
|
+
stdout: err.stdout || '',
|
|
145
|
+
stderr: err.stderr || '',
|
|
146
|
+
status: err.status || 1,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function readLedgerFile(workspace: string): any[] {
|
|
152
|
+
const ledgerPath = join(workspace, '.pd', 'principle-tree-ledger.json');
|
|
153
|
+
if (!existsSync(ledgerPath)) return [];
|
|
154
|
+
const content = readFileSync(ledgerPath, 'utf-8');
|
|
155
|
+
const data = JSON.parse(content);
|
|
156
|
+
return data.principles || [];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
it('Test 1 (Happy path E2E): pending candidate → intake → consumed → ledgerEntryId in output', () => {
|
|
160
|
+
const candidateId = 'e2e-cand-001';
|
|
161
|
+
const taskId = 'e2e-task-001';
|
|
162
|
+
const artifactId = 'e2e-art-001';
|
|
163
|
+
const runId = 'e2e-run-001';
|
|
164
|
+
|
|
165
|
+
insertPendingCandidate(candidateId, taskId, artifactId, runId);
|
|
166
|
+
|
|
167
|
+
const { stdout, status } = runPdCommand([
|
|
168
|
+
'candidate', 'intake',
|
|
169
|
+
'--candidate-id', candidateId,
|
|
170
|
+
'--workspace', tempWorkspace,
|
|
171
|
+
'--json',
|
|
172
|
+
]);
|
|
173
|
+
|
|
174
|
+
expect(status).toBe(0);
|
|
175
|
+
|
|
176
|
+
const result = JSON.parse(stdout);
|
|
177
|
+
expect(result.candidateId).toBe(candidateId);
|
|
178
|
+
expect(result.status).toBe('consumed');
|
|
179
|
+
expect(result.ledgerEntryId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('Test 2 (Ledger entry created): ledger file contains entry with correct sourceRef', () => {
|
|
183
|
+
const candidateId = 'e2e-cand-002';
|
|
184
|
+
const taskId = 'e2e-task-002';
|
|
185
|
+
const artifactId = 'e2e-art-002';
|
|
186
|
+
const runId = 'e2e-run-002';
|
|
187
|
+
|
|
188
|
+
insertPendingCandidate(candidateId, taskId, artifactId, runId);
|
|
189
|
+
|
|
190
|
+
runPdCommand([
|
|
191
|
+
'candidate', 'intake',
|
|
192
|
+
'--candidate-id', candidateId,
|
|
193
|
+
'--workspace', tempWorkspace,
|
|
194
|
+
'--json',
|
|
195
|
+
]);
|
|
196
|
+
|
|
197
|
+
const ledgerEntries = readLedgerFile(tempWorkspace);
|
|
198
|
+
expect(ledgerEntries.length).toBe(1);
|
|
199
|
+
expect(ledgerEntries[0].sourceRef).toBe(`candidate://${candidateId}`);
|
|
200
|
+
expect(ledgerEntries[0].status).toBe('probation');
|
|
201
|
+
expect(ledgerEntries[0].evaluability).toBe('weak_heuristic');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('Test 3 (Idempotency): intake same candidate twice → one ledger entry, no duplicate', () => {
|
|
205
|
+
const candidateId = 'e2e-cand-003';
|
|
206
|
+
const taskId = 'e2e-task-003';
|
|
207
|
+
const artifactId = 'e2e-art-003';
|
|
208
|
+
const runId = 'e2e-run-003';
|
|
209
|
+
|
|
210
|
+
insertPendingCandidate(candidateId, taskId, artifactId, runId);
|
|
211
|
+
|
|
212
|
+
const { stdout: stdout1 } = runPdCommand([
|
|
213
|
+
'candidate', 'intake',
|
|
214
|
+
'--candidate-id', candidateId,
|
|
215
|
+
'--workspace', tempWorkspace,
|
|
216
|
+
'--json',
|
|
217
|
+
]);
|
|
218
|
+
const result1 = JSON.parse(stdout1);
|
|
219
|
+
expect(result1.status).toBe('consumed');
|
|
220
|
+
|
|
221
|
+
const { stdout: stdout2, status: status2 } = runPdCommand([
|
|
222
|
+
'candidate', 'intake',
|
|
223
|
+
'--candidate-id', candidateId,
|
|
224
|
+
'--workspace', tempWorkspace,
|
|
225
|
+
'--json',
|
|
226
|
+
]);
|
|
227
|
+
expect(status2).toBe(0);
|
|
228
|
+
const result2 = JSON.parse(stdout2);
|
|
229
|
+
expect(result2.status).toBe('already_consumed');
|
|
230
|
+
expect(result2.ledgerEntryId).toBe(result1.ledgerEntryId);
|
|
231
|
+
|
|
232
|
+
const ledgerEntries = readLedgerFile(tempWorkspace);
|
|
233
|
+
expect(ledgerEntries.length).toBe(1);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('Test 4 (pd candidate list): shows candidate with consumed status after intake', () => {
|
|
237
|
+
const candidateId = 'e2e-cand-004';
|
|
238
|
+
const taskId = 'e2e-task-004';
|
|
239
|
+
const artifactId = 'e2e-art-004';
|
|
240
|
+
const runId = 'e2e-run-004';
|
|
241
|
+
|
|
242
|
+
insertPendingCandidate(candidateId, taskId, artifactId, runId);
|
|
243
|
+
|
|
244
|
+
runPdCommand([
|
|
245
|
+
'candidate', 'intake',
|
|
246
|
+
'--candidate-id', candidateId,
|
|
247
|
+
'--workspace', tempWorkspace,
|
|
248
|
+
'--json',
|
|
249
|
+
]);
|
|
250
|
+
|
|
251
|
+
const { stdout, status } = runPdCommand([
|
|
252
|
+
'candidate', 'list',
|
|
253
|
+
'--task-id', taskId,
|
|
254
|
+
'--workspace', tempWorkspace,
|
|
255
|
+
'--json',
|
|
256
|
+
]);
|
|
257
|
+
expect(status).toBe(0);
|
|
258
|
+
|
|
259
|
+
const result = JSON.parse(stdout);
|
|
260
|
+
expect(result.taskId).toBe(taskId);
|
|
261
|
+
expect(result.candidates.length).toBe(1);
|
|
262
|
+
expect(result.candidates[0].candidateId).toBe(candidateId);
|
|
263
|
+
expect(result.candidates[0].status).toBe('consumed');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('Test 5 (pd candidate show with ledger link): shows ledgerEntryId after intake', () => {
|
|
267
|
+
const candidateId = 'e2e-cand-005';
|
|
268
|
+
const taskId = 'e2e-task-005';
|
|
269
|
+
const artifactId = 'e2e-art-005';
|
|
270
|
+
const runId = 'e2e-run-005';
|
|
271
|
+
|
|
272
|
+
insertPendingCandidate(candidateId, taskId, artifactId, runId);
|
|
273
|
+
|
|
274
|
+
const { stdout: intakeStdout } = runPdCommand([
|
|
275
|
+
'candidate', 'intake',
|
|
276
|
+
'--candidate-id', candidateId,
|
|
277
|
+
'--workspace', tempWorkspace,
|
|
278
|
+
'--json',
|
|
279
|
+
]);
|
|
280
|
+
const intakeResult = JSON.parse(intakeStdout);
|
|
281
|
+
const ledgerEntryId = intakeResult.ledgerEntryId;
|
|
282
|
+
|
|
283
|
+
const { stdout, status } = runPdCommand([
|
|
284
|
+
'candidate', 'show',
|
|
285
|
+
candidateId,
|
|
286
|
+
'--workspace', tempWorkspace,
|
|
287
|
+
'--json',
|
|
288
|
+
]);
|
|
289
|
+
expect(status).toBe(0);
|
|
290
|
+
|
|
291
|
+
const result = JSON.parse(stdout);
|
|
292
|
+
expect(result.candidateId).toBe(candidateId);
|
|
293
|
+
expect(result.status).toBe('consumed');
|
|
294
|
+
expect(result.ledgerEntryId).toBe(ledgerEntryId);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('Test 6 (DB state): candidate status is consumed in DB after intake', () => {
|
|
298
|
+
const candidateId = 'e2e-cand-006';
|
|
299
|
+
const taskId = 'e2e-task-006';
|
|
300
|
+
const artifactId = 'e2e-art-006';
|
|
301
|
+
const runId = 'e2e-run-006';
|
|
302
|
+
|
|
303
|
+
insertPendingCandidate(candidateId, taskId, artifactId, runId);
|
|
304
|
+
|
|
305
|
+
runPdCommand([
|
|
306
|
+
'candidate', 'intake',
|
|
307
|
+
'--candidate-id', candidateId,
|
|
308
|
+
'--workspace', tempWorkspace,
|
|
309
|
+
'--json',
|
|
310
|
+
]);
|
|
311
|
+
|
|
312
|
+
const row = db.prepare('SELECT status FROM principle_candidates WHERE candidate_id = ?')
|
|
313
|
+
.get(candidateId) as { status: string };
|
|
314
|
+
expect(row.status).toBe('consumed');
|
|
315
|
+
});
|
|
316
|
+
});
|