@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,480 @@
|
|
|
1
|
+
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
const mockInitialize = vi.hoisted(() => vi.fn());
|
|
5
|
+
const mockClose = vi.hoisted(() => vi.fn());
|
|
6
|
+
const mockGetCandidate = vi.hoisted(() => vi.fn());
|
|
7
|
+
const mockGetTask = vi.hoisted(() => vi.fn());
|
|
8
|
+
const mockCreateTask = vi.hoisted(() => vi.fn());
|
|
9
|
+
const mockUpdateTaskDiagnosticJson = vi.hoisted(() => vi.fn());
|
|
10
|
+
const mockPrepareAll = vi.hoisted(() => vi.fn());
|
|
11
|
+
const mockPrepareRun = vi.hoisted(() => vi.fn());
|
|
12
|
+
const mockRuntimeStateManagerOpts = vi.hoisted(() => vi.fn());
|
|
13
|
+
const mockIntake = vi.hoisted(() => vi.fn());
|
|
14
|
+
const mockExistsForCandidate = vi.hoisted(() => vi.fn());
|
|
15
|
+
|
|
16
|
+
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
17
|
+
resolveWorkspaceDir: vi.fn((workspace?: string) => workspace ?? '/fake/workspace'),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
vi.mock('../../src/principle-tree-ledger-adapter.js', () => ({
|
|
21
|
+
PrincipleTreeLedgerAdapter: vi.fn().mockImplementation(function () {
|
|
22
|
+
return {
|
|
23
|
+
intake: mockIntake,
|
|
24
|
+
existsForCandidate: mockExistsForCandidate,
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
vi.mock('@principles/core/runtime-v2', async (importOriginal) => {
|
|
30
|
+
const original = await importOriginal() as Record<string, unknown>;
|
|
31
|
+
return {
|
|
32
|
+
...original,
|
|
33
|
+
RuntimeStateManager: vi.fn().mockImplementation(function (opts: Record<string, unknown>) {
|
|
34
|
+
mockRuntimeStateManagerOpts(opts);
|
|
35
|
+
return {
|
|
36
|
+
initialize: mockInitialize,
|
|
37
|
+
close: mockClose,
|
|
38
|
+
getCandidate: mockGetCandidate,
|
|
39
|
+
getTask: mockGetTask,
|
|
40
|
+
createTask: mockCreateTask,
|
|
41
|
+
updateTaskDiagnosticJson: mockUpdateTaskDiagnosticJson,
|
|
42
|
+
connection: {
|
|
43
|
+
getDb: () => ({
|
|
44
|
+
prepare: (sql: string) => ({ all: () => mockPrepareAll(sql), get: vi.fn(), run: () => mockPrepareRun(sql) }),
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}),
|
|
49
|
+
CandidateIntakeService: vi.fn().mockImplementation(function () {
|
|
50
|
+
return { intake: mockIntake };
|
|
51
|
+
}),
|
|
52
|
+
CandidateIntakeError: class CandidateIntakeError extends Error {
|
|
53
|
+
code: string;
|
|
54
|
+
constructor(code: string, message: string) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.code = code;
|
|
57
|
+
this.name = 'CandidateIntakeError';
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
decideInternalizationRoute: vi.fn(() => ({
|
|
61
|
+
ready: true,
|
|
62
|
+
route: 'principle-ledger',
|
|
63
|
+
reason: 'ready',
|
|
64
|
+
missingFields: [],
|
|
65
|
+
nextAction: 'internalize',
|
|
66
|
+
})),
|
|
67
|
+
computeBridgeDecision: vi.fn(() => ({
|
|
68
|
+
decision: 'seeded',
|
|
69
|
+
taskId: 'dreamer-cand-1-prompt',
|
|
70
|
+
channel: 'prompt',
|
|
71
|
+
})),
|
|
72
|
+
buildDreamerTaskSeed: vi.fn(() => ({
|
|
73
|
+
taskId: 'dreamer-cand-1-prompt',
|
|
74
|
+
taskKind: 'dreamer',
|
|
75
|
+
status: 'pending',
|
|
76
|
+
attemptCount: 0,
|
|
77
|
+
maxAttempts: 3,
|
|
78
|
+
diagnosticJson: '{}',
|
|
79
|
+
})),
|
|
80
|
+
createRemediationResult: vi.fn((input: { mode: string; status?: string; safeToConfirm?: boolean; repairedCount?: number; skippedCount?: number; actions?: unknown[]; warnings?: unknown[] }) => ({
|
|
81
|
+
mode: input.mode,
|
|
82
|
+
status: input.status ?? (input.mode === 'dry_run'
|
|
83
|
+
? ((input.actions?.length ?? 0) > 0 ? 'would_change' : 'no_op')
|
|
84
|
+
: ((input.repairedCount ?? 0) > 0 ? 'changed' : 'no_op')),
|
|
85
|
+
safeToConfirm: input.safeToConfirm ?? false,
|
|
86
|
+
repairedCount: input.repairedCount ?? 0,
|
|
87
|
+
skippedCount: input.skippedCount ?? 0,
|
|
88
|
+
actions: input.actions ?? [],
|
|
89
|
+
warnings: input.warnings ?? [],
|
|
90
|
+
})),
|
|
91
|
+
remediationAction: vi.fn((input: unknown) => input),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
import { handleCandidateInternalizationBackfill } from '../../src/commands/candidate.js';
|
|
96
|
+
|
|
97
|
+
function createBackfillTestProgram(): Command {
|
|
98
|
+
const program = new Command();
|
|
99
|
+
program.exitOverride();
|
|
100
|
+
|
|
101
|
+
const candidateCmd = program.command('candidate');
|
|
102
|
+
const internalizationCmd = candidateCmd.command('internalization');
|
|
103
|
+
|
|
104
|
+
internalizationCmd
|
|
105
|
+
.command('backfill')
|
|
106
|
+
.description('Backfill dreamer tasks for consumed candidates')
|
|
107
|
+
.option('-w, --workspace <path>', 'Workspace directory')
|
|
108
|
+
.option('--dry-run', 'Report only, no modifications (default)')
|
|
109
|
+
.option('--confirm', 'Actually create missing dreamer tasks')
|
|
110
|
+
.option('--include-pending', 'Include pending candidates (intake first, then seed dreamer)')
|
|
111
|
+
.option('--json', 'Output as JSON')
|
|
112
|
+
.action(async (opts) => {
|
|
113
|
+
await handleCandidateInternalizationBackfill({
|
|
114
|
+
workspace: opts.workspace,
|
|
115
|
+
dryRun: opts.dryRun,
|
|
116
|
+
confirm: opts.confirm,
|
|
117
|
+
includePending: opts.includePending,
|
|
118
|
+
json: opts.json,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return program;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const WS = '/fake/workspace';
|
|
126
|
+
|
|
127
|
+
function setupDefaultMocks(): void {
|
|
128
|
+
mockInitialize.mockResolvedValue(undefined);
|
|
129
|
+
mockClose.mockResolvedValue(undefined);
|
|
130
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
131
|
+
if (sql.includes("'consumed'")) return [{ candidate_id: 'cand-consumed-1' }];
|
|
132
|
+
if (sql.includes("'pending'")) return [];
|
|
133
|
+
return [];
|
|
134
|
+
});
|
|
135
|
+
mockPrepareRun.mockReturnValue({ changes: 1 });
|
|
136
|
+
mockGetCandidate.mockImplementation((id: string) =>
|
|
137
|
+
Promise.resolve({
|
|
138
|
+
candidateId: id,
|
|
139
|
+
description: `candidate ${id}`,
|
|
140
|
+
sourceRecommendationJson: JSON.stringify({ kind: 'principle', description: `candidate ${id}` }),
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
mockGetTask.mockResolvedValue(null);
|
|
144
|
+
mockCreateTask.mockImplementation((input: { taskId: string }) =>
|
|
145
|
+
Promise.resolve({ taskId: input.taskId }),
|
|
146
|
+
);
|
|
147
|
+
mockIntake.mockResolvedValue({ id: 'ledger-entry-1' });
|
|
148
|
+
mockExistsForCandidate.mockReturnValue(null);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
describe('pd candidate internalization backfill', () => {
|
|
152
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
153
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
154
|
+
|
|
155
|
+
beforeEach(() => {
|
|
156
|
+
vi.clearAllMocks();
|
|
157
|
+
setupDefaultMocks();
|
|
158
|
+
process.exitCode = 0;
|
|
159
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
160
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
afterEach(() => {
|
|
164
|
+
process.exitCode = 0;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('default (no --include-pending) only processes consumed candidates', async () => {
|
|
168
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
169
|
+
if (sql.includes("'consumed'")) return [{ candidate_id: 'cand-consumed-1' }];
|
|
170
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
171
|
+
return [];
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, dryRun: true, json: true });
|
|
175
|
+
|
|
176
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
177
|
+
expect(output.details.totalConsumed).toBe(1);
|
|
178
|
+
expect(output.details.totalPending).toBe(0);
|
|
179
|
+
expect(output.details.results).toHaveLength(1);
|
|
180
|
+
expect(output.details.results[0].candidateId).toBe('cand-consumed-1');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('--include-pending --dry-run discovers pending candidates but zero mutation', async () => {
|
|
184
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
185
|
+
if (sql.includes("'consumed'")) return [];
|
|
186
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
187
|
+
return [];
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, includePending: true, dryRun: true, json: true });
|
|
191
|
+
|
|
192
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
193
|
+
expect(output.details.totalConsumed).toBe(0);
|
|
194
|
+
expect(output.details.totalPending).toBe(1);
|
|
195
|
+
expect(output.details.results).toHaveLength(1);
|
|
196
|
+
expect(output.details.results[0]).toMatchObject({
|
|
197
|
+
candidateId: 'cand-pending-1',
|
|
198
|
+
status: 'would_intake_and_create',
|
|
199
|
+
statusBefore: 'pending',
|
|
200
|
+
statusAfter: 'pending',
|
|
201
|
+
intakeDecision: 'would_intake',
|
|
202
|
+
seedDecision: 'would_seed',
|
|
203
|
+
});
|
|
204
|
+
expect(mockIntake).not.toHaveBeenCalled();
|
|
205
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('--include-pending --confirm: pending -> intake -> seed dreamer', async () => {
|
|
209
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
210
|
+
if (sql.includes("'consumed'")) return [];
|
|
211
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
212
|
+
return [];
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, includePending: true, confirm: true, json: true });
|
|
216
|
+
|
|
217
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
218
|
+
expect(output.details.intakeSucceeded).toBe(1);
|
|
219
|
+
expect(output.details.created).toBe(1);
|
|
220
|
+
expect(output.details.results).toHaveLength(1);
|
|
221
|
+
expect(output.details.results[0]).toMatchObject({
|
|
222
|
+
candidateId: 'cand-pending-1',
|
|
223
|
+
status: 'created',
|
|
224
|
+
statusBefore: 'pending',
|
|
225
|
+
statusAfter: 'consumed',
|
|
226
|
+
intakeDecision: 'intake_succeeded',
|
|
227
|
+
seedDecision: 'seeded',
|
|
228
|
+
});
|
|
229
|
+
expect(mockIntake).toHaveBeenCalledWith('cand-pending-1');
|
|
230
|
+
expect(mockCreateTask).toHaveBeenCalled();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('intake failure: no seed, no fake consumed, returns reason/nextAction', async () => {
|
|
234
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
235
|
+
if (sql.includes("'consumed'")) return [];
|
|
236
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
237
|
+
return [];
|
|
238
|
+
});
|
|
239
|
+
mockIntake.mockRejectedValue(new Error('Artifact not found for candidate'));
|
|
240
|
+
|
|
241
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, includePending: true, confirm: true, json: true });
|
|
242
|
+
|
|
243
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
244
|
+
expect(output.details.intakeFailed).toBe(1);
|
|
245
|
+
expect(output.details.created).toBe(0);
|
|
246
|
+
expect(output.details.results).toHaveLength(1);
|
|
247
|
+
expect(output.details.results[0]).toMatchObject({
|
|
248
|
+
candidateId: 'cand-pending-1',
|
|
249
|
+
status: 'intake_failed',
|
|
250
|
+
statusBefore: 'pending',
|
|
251
|
+
statusAfter: 'pending',
|
|
252
|
+
intakeDecision: 'intake_failed',
|
|
253
|
+
seedDecision: 'skipped',
|
|
254
|
+
nextAction: 'Fix intake issue and re-run backfill',
|
|
255
|
+
});
|
|
256
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('duplicate confirm: no duplicate dreamer task (idempotent)', async () => {
|
|
260
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
261
|
+
if (sql.includes("'consumed'")) return [];
|
|
262
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
263
|
+
return [];
|
|
264
|
+
});
|
|
265
|
+
mockGetTask.mockResolvedValue({ taskId: 'dreamer-cand-pending-1-prompt' });
|
|
266
|
+
|
|
267
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, includePending: true, confirm: true, json: true });
|
|
268
|
+
|
|
269
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
270
|
+
expect(output.details.intakeSucceeded).toBe(1);
|
|
271
|
+
expect(output.details.alreadyHaveTask).toBe(1);
|
|
272
|
+
expect(output.details.created).toBe(0);
|
|
273
|
+
expect(output.details.results).toHaveLength(1);
|
|
274
|
+
expect(output.details.results[0]).toMatchObject({
|
|
275
|
+
candidateId: 'cand-pending-1',
|
|
276
|
+
status: 'intake_succeeded_existing_task',
|
|
277
|
+
intakeDecision: 'intake_succeeded',
|
|
278
|
+
seedDecision: 'existing',
|
|
279
|
+
});
|
|
280
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('guarded transition: status update fails when candidate is not pending', async () => {
|
|
284
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
285
|
+
if (sql.includes("'consumed'")) return [];
|
|
286
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
287
|
+
return [];
|
|
288
|
+
});
|
|
289
|
+
mockPrepareRun.mockImplementation((sql: string) => {
|
|
290
|
+
if (sql.includes('UPDATE')) return { changes: 0 };
|
|
291
|
+
return { changes: 1 };
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, includePending: true, confirm: true, json: true });
|
|
295
|
+
|
|
296
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
297
|
+
expect(output.details.intakeFailed).toBe(1);
|
|
298
|
+
expect(output.details.created).toBe(0);
|
|
299
|
+
expect(output.details.results).toHaveLength(1);
|
|
300
|
+
expect(output.details.results[0]).toMatchObject({
|
|
301
|
+
candidateId: 'cand-pending-1',
|
|
302
|
+
statusBefore: 'pending',
|
|
303
|
+
statusAfter: 'pending',
|
|
304
|
+
intakeDecision: 'intake_failed',
|
|
305
|
+
seedDecision: 'skipped',
|
|
306
|
+
});
|
|
307
|
+
expect(output.details.results[0].reason).toContain('Guarded transition failed');
|
|
308
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('consumed candidate original behavior regression unchanged', async () => {
|
|
312
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
313
|
+
if (sql.includes("'consumed'")) return [{ candidate_id: 'cand-consumed-1' }];
|
|
314
|
+
return [];
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, dryRun: true, json: true });
|
|
318
|
+
|
|
319
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
320
|
+
expect(output).toMatchObject({
|
|
321
|
+
mode: 'dry_run',
|
|
322
|
+
status: 'would_change',
|
|
323
|
+
safeToConfirm: true,
|
|
324
|
+
repairedCount: 0,
|
|
325
|
+
});
|
|
326
|
+
expect(output.details.results[0]).toMatchObject({
|
|
327
|
+
candidateId: 'cand-consumed-1',
|
|
328
|
+
status: 'would_create',
|
|
329
|
+
intakeDecision: 'not_needed',
|
|
330
|
+
seedDecision: 'would_seed',
|
|
331
|
+
});
|
|
332
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('rejects --dry-run and --confirm together before writing', async () => {
|
|
336
|
+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation((code) => { throw new Error(`process.exit:${code}`); });
|
|
337
|
+
|
|
338
|
+
await expect(
|
|
339
|
+
handleCandidateInternalizationBackfill({ workspace: WS, dryRun: true, confirm: true, json: true }),
|
|
340
|
+
).rejects.toThrow('process.exit:1');
|
|
341
|
+
|
|
342
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
343
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('mutually exclusive'));
|
|
344
|
+
exitSpy.mockRestore();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('--json output is single parseable object with required fields per candidate', async () => {
|
|
348
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
349
|
+
if (sql.includes("'consumed'")) return [{ candidate_id: 'cand-consumed-1' }];
|
|
350
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
351
|
+
return [];
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
await handleCandidateInternalizationBackfill({ workspace: WS, includePending: true, dryRun: true, json: true });
|
|
355
|
+
|
|
356
|
+
const rawOutput = consoleLogSpy.mock.calls[0][0] as string;
|
|
357
|
+
const output = JSON.parse(rawOutput);
|
|
358
|
+
expect(output).toBeDefined();
|
|
359
|
+
|
|
360
|
+
for (const result of output.details.results) {
|
|
361
|
+
expect(result).toHaveProperty('candidateId');
|
|
362
|
+
expect(result).toHaveProperty('statusBefore');
|
|
363
|
+
expect(result).toHaveProperty('statusAfter');
|
|
364
|
+
expect(result).toHaveProperty('intakeDecision');
|
|
365
|
+
expect(result).toHaveProperty('seedDecision');
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('exit path: process.exit(1) after flag conflict does not continue to mutation', async () => {
|
|
370
|
+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation((code) => { throw new Error(`process.exit:${code}`); });
|
|
371
|
+
|
|
372
|
+
await expect(
|
|
373
|
+
handleCandidateInternalizationBackfill({ workspace: WS, dryRun: true, confirm: true }),
|
|
374
|
+
).rejects.toThrow('process.exit:1');
|
|
375
|
+
|
|
376
|
+
expect(mockIntake).not.toHaveBeenCalled();
|
|
377
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
378
|
+
exitSpy.mockRestore();
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
describe('Commander wiring for backfill --include-pending', () => {
|
|
383
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
384
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
385
|
+
|
|
386
|
+
beforeEach(() => {
|
|
387
|
+
vi.clearAllMocks();
|
|
388
|
+
process.exitCode = 0;
|
|
389
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
390
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
391
|
+
mockInitialize.mockResolvedValue(undefined);
|
|
392
|
+
mockClose.mockResolvedValue(undefined);
|
|
393
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
394
|
+
if (sql.includes("'consumed'")) return [];
|
|
395
|
+
if (sql.includes("'pending'")) return [];
|
|
396
|
+
return [];
|
|
397
|
+
});
|
|
398
|
+
mockGetCandidate.mockImplementation((id: string) =>
|
|
399
|
+
Promise.resolve({
|
|
400
|
+
candidateId: id,
|
|
401
|
+
description: `candidate ${id}`,
|
|
402
|
+
sourceRecommendationJson: JSON.stringify({ kind: 'principle', description: `candidate ${id}` }),
|
|
403
|
+
}),
|
|
404
|
+
);
|
|
405
|
+
mockGetTask.mockResolvedValue(null);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
afterEach(() => {
|
|
409
|
+
process.exitCode = 0;
|
|
410
|
+
consoleLogSpy.mockRestore();
|
|
411
|
+
consoleErrorSpy.mockRestore();
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('no flags -> dry-run mode, includePending undefined', async () => {
|
|
415
|
+
const program = createBackfillTestProgram();
|
|
416
|
+
await program.parseAsync(['node', 'pd', 'candidate', 'internalization', 'backfill', '--workspace', WS, '--json']);
|
|
417
|
+
|
|
418
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
419
|
+
expect(output.details.mode).toBe('dry-run');
|
|
420
|
+
expect(output.details.totalPending).toBe(0);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('--include-pending -> includePending=true', async () => {
|
|
424
|
+
mockPrepareAll.mockImplementation((sql: string) => {
|
|
425
|
+
if (sql.includes("'consumed'")) return [];
|
|
426
|
+
if (sql.includes("'pending'")) return [{ candidate_id: 'cand-pending-1' }];
|
|
427
|
+
return [];
|
|
428
|
+
});
|
|
429
|
+
mockGetCandidate.mockResolvedValue({
|
|
430
|
+
candidateId: 'cand-pending-1',
|
|
431
|
+
description: 'test',
|
|
432
|
+
sourceRecommendationJson: JSON.stringify({ kind: 'principle', description: 'test' }),
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const program = createBackfillTestProgram();
|
|
436
|
+
await program.parseAsync(['node', 'pd', 'candidate', 'internalization', 'backfill', '--workspace', WS, '--include-pending', '--dry-run', '--json']);
|
|
437
|
+
|
|
438
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
439
|
+
expect(output.details.totalPending).toBe(1);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it('--dry-run -> RuntimeStateManager readonly=true', async () => {
|
|
443
|
+
const program = createBackfillTestProgram();
|
|
444
|
+
await program.parseAsync(['node', 'pd', 'candidate', 'internalization', 'backfill', '--workspace', WS, '--dry-run', '--json']);
|
|
445
|
+
|
|
446
|
+
expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
|
|
447
|
+
expect.objectContaining({ readonly: true }),
|
|
448
|
+
);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it('--confirm -> RuntimeStateManager readonly=false', async () => {
|
|
452
|
+
const program = createBackfillTestProgram();
|
|
453
|
+
await program.parseAsync(['node', 'pd', 'candidate', 'internalization', 'backfill', '--workspace', WS, '--confirm', '--json']);
|
|
454
|
+
|
|
455
|
+
expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
|
|
456
|
+
expect.objectContaining({ readonly: false }),
|
|
457
|
+
);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('--dry-run --confirm together -> rejected', async () => {
|
|
461
|
+
const program = createBackfillTestProgram();
|
|
462
|
+
try {
|
|
463
|
+
await program.parseAsync(['node', 'pd', 'candidate', 'internalization', 'backfill', '--workspace', WS, '--dry-run', '--confirm', '--json']);
|
|
464
|
+
} catch {
|
|
465
|
+
// process.exit throws via exitOverride or handler throws
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
expect(mockCreateTask).not.toHaveBeenCalled();
|
|
469
|
+
expect(mockIntake).not.toHaveBeenCalled();
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('no flags -> RuntimeStateManager readonly=true (dry-run default)', async () => {
|
|
473
|
+
const program = createBackfillTestProgram();
|
|
474
|
+
await program.parseAsync(['node', 'pd', 'candidate', 'internalization', 'backfill', '--workspace', WS, '--json']);
|
|
475
|
+
|
|
476
|
+
expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
|
|
477
|
+
expect.objectContaining({ readonly: true }),
|
|
478
|
+
);
|
|
479
|
+
});
|
|
480
|
+
});
|