@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,803 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
const mockListTasks = vi.hoisted(() => vi.fn());
|
|
5
|
+
const mockGetTask = vi.hoisted(() => vi.fn());
|
|
6
|
+
const mockCommitNextTaskProposal = vi.hoisted(() => vi.fn());
|
|
7
|
+
const mockProposeNextTask = vi.hoisted(() => vi.fn());
|
|
8
|
+
const mockClose = vi.hoisted(() => vi.fn().mockResolvedValue(undefined));
|
|
9
|
+
const mockInitialize = vi.hoisted(() => vi.fn().mockResolvedValue(undefined));
|
|
10
|
+
const mockRuntimeStateManagerOpts = vi.hoisted(() => vi.fn());
|
|
11
|
+
|
|
12
|
+
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
13
|
+
resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
vi.mock('@principles/core/runtime-v2', () => ({
|
|
17
|
+
RuntimeStateManager: vi.fn().mockImplementation(function (opts: Record<string, unknown>) {
|
|
18
|
+
mockRuntimeStateManagerOpts(opts);
|
|
19
|
+
return {
|
|
20
|
+
initialize: mockInitialize,
|
|
21
|
+
close: mockClose,
|
|
22
|
+
listTasks: mockListTasks,
|
|
23
|
+
getTask: mockGetTask,
|
|
24
|
+
};
|
|
25
|
+
}),
|
|
26
|
+
InternalizationOrchestrator: vi.fn().mockImplementation(function () {
|
|
27
|
+
return {
|
|
28
|
+
commitNextTaskProposal: mockCommitNextTaskProposal,
|
|
29
|
+
proposeNextTask: mockProposeNextTask,
|
|
30
|
+
};
|
|
31
|
+
}),
|
|
32
|
+
isPeerRunnerKind: vi.fn().mockImplementation((k: string) =>
|
|
33
|
+
['dreamer', 'philosopher', 'scribe', 'artificer', 'evaluator', 'rollout_reviewer', 'trainer'].includes(k),
|
|
34
|
+
),
|
|
35
|
+
hydratePITaskRecord: vi.fn().mockImplementation((task: Record<string, unknown>) => {
|
|
36
|
+
if (typeof task.diagnosticJson !== 'string' || task.diagnosticJson.length === 0) return null;
|
|
37
|
+
try {
|
|
38
|
+
const meta = JSON.parse(task.diagnosticJson);
|
|
39
|
+
if (typeof meta !== 'object' || meta === null || Array.isArray(meta)) return null;
|
|
40
|
+
return {
|
|
41
|
+
taskId: task.taskId,
|
|
42
|
+
taskKind: task.taskKind,
|
|
43
|
+
status: task.status,
|
|
44
|
+
attemptCount: task.attemptCount ?? 0,
|
|
45
|
+
dependencyTaskIds: meta.dependencyTaskIds ?? [],
|
|
46
|
+
channel: meta.channel ?? 'prompt',
|
|
47
|
+
timeoutMs: meta.timeoutMs ?? 300_000,
|
|
48
|
+
inputArtifactRefs: meta.inputArtifactRefs ?? [],
|
|
49
|
+
outputArtifactRefs: meta.outputArtifactRefs ?? [],
|
|
50
|
+
parentTaskId: meta.parentTaskId ?? null,
|
|
51
|
+
correlationId: meta.correlationId ?? null,
|
|
52
|
+
};
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
import { handleRuntimeInternalizationEnqueueSuccessors } from '../../src/commands/runtime-internalization-enqueue-successors.js';
|
|
60
|
+
|
|
61
|
+
const WS = '/fake/workspace';
|
|
62
|
+
|
|
63
|
+
function mockDryRunListTasks(succeededTasks: ReturnType<typeof makeSucceededTask>[], successorTasks: ReturnType<typeof makeSucceededTask>[] = []) {
|
|
64
|
+
mockListTasks
|
|
65
|
+
.mockResolvedValueOnce(succeededTasks)
|
|
66
|
+
.mockResolvedValueOnce(successorTasks)
|
|
67
|
+
.mockResolvedValueOnce([])
|
|
68
|
+
.mockResolvedValueOnce([])
|
|
69
|
+
.mockResolvedValueOnce([])
|
|
70
|
+
.mockResolvedValueOnce([])
|
|
71
|
+
.mockResolvedValueOnce([]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function makePIMetadata(overrides: Record<string, unknown> = {}): string {
|
|
75
|
+
return JSON.stringify({
|
|
76
|
+
dependencyTaskIds: [],
|
|
77
|
+
channel: 'prompt',
|
|
78
|
+
timeoutMs: 300_000,
|
|
79
|
+
inputArtifactRefs: [],
|
|
80
|
+
outputArtifactRefs: [],
|
|
81
|
+
parentTaskId: null,
|
|
82
|
+
correlationId: null,
|
|
83
|
+
...overrides,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function makeSucceededTask(taskId: string, taskKind: string, metaOverrides: Record<string, unknown> = {}) {
|
|
88
|
+
return {
|
|
89
|
+
taskId,
|
|
90
|
+
taskKind,
|
|
91
|
+
status: 'succeeded',
|
|
92
|
+
attemptCount: 1,
|
|
93
|
+
maxAttempts: 3,
|
|
94
|
+
inputRef: undefined,
|
|
95
|
+
resultRef: `ref-${taskId}`,
|
|
96
|
+
lastError: undefined,
|
|
97
|
+
leaseOwner: undefined,
|
|
98
|
+
leaseExpiresAt: undefined,
|
|
99
|
+
diagnosticJson: makePIMetadata(metaOverrides),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function makeMalformedTask(taskId: string, taskKind: string) {
|
|
104
|
+
return {
|
|
105
|
+
taskId,
|
|
106
|
+
taskKind,
|
|
107
|
+
status: 'succeeded',
|
|
108
|
+
attemptCount: 1,
|
|
109
|
+
maxAttempts: 3,
|
|
110
|
+
inputRef: undefined,
|
|
111
|
+
resultRef: `ref-${taskId}`,
|
|
112
|
+
lastError: undefined,
|
|
113
|
+
leaseOwner: undefined,
|
|
114
|
+
leaseExpiresAt: undefined,
|
|
115
|
+
diagnosticJson: 'not-valid-json{{{',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function createTestProgram(): Command {
|
|
120
|
+
const program = new Command();
|
|
121
|
+
program.exitOverride();
|
|
122
|
+
|
|
123
|
+
const internalizationCmd = program.command('internalization');
|
|
124
|
+
|
|
125
|
+
internalizationCmd
|
|
126
|
+
.command('enqueue-successors')
|
|
127
|
+
.description('Enqueue successor tasks for succeeded internalization tasks missing successors')
|
|
128
|
+
.option('-w, --workspace <path>', 'Workspace directory')
|
|
129
|
+
.option('--dry-run', 'Report only, no modifications (default)')
|
|
130
|
+
.option('--confirm', 'Actually create successor tasks')
|
|
131
|
+
.option('--json', 'Output raw JSON')
|
|
132
|
+
.action(async (opts) => {
|
|
133
|
+
await handleRuntimeInternalizationEnqueueSuccessors({
|
|
134
|
+
workspace: opts.workspace,
|
|
135
|
+
dryRun: opts.dryRun,
|
|
136
|
+
confirm: opts.confirm,
|
|
137
|
+
json: opts.json,
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return program;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
describe('handleRuntimeInternalizationEnqueueSuccessors', () => {
|
|
145
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
146
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
147
|
+
|
|
148
|
+
beforeEach(() => {
|
|
149
|
+
vi.clearAllMocks();
|
|
150
|
+
process.exitCode = 0;
|
|
151
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
152
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
153
|
+
mockInitialize.mockResolvedValue(undefined);
|
|
154
|
+
mockClose.mockResolvedValue(undefined);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
afterEach(() => {
|
|
158
|
+
process.exitCode = 0;
|
|
159
|
+
consoleLogSpy.mockRestore();
|
|
160
|
+
consoleErrorSpy.mockRestore();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('succeeded dreamer with artifact and no philosopher successor: dry-run reports would_create_successor', async () => {
|
|
164
|
+
const dreamerTask = makeSucceededTask('dreamer-001', 'dreamer');
|
|
165
|
+
mockDryRunListTasks([dreamerTask]);
|
|
166
|
+
mockProposeNextTask.mockResolvedValue({
|
|
167
|
+
decision: 'proposal_created',
|
|
168
|
+
taskId: 'dreamer-001',
|
|
169
|
+
taskKind: 'dreamer',
|
|
170
|
+
proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-001'], inputArtifactRefs: [], parentTaskId: 'dreamer-001', correlationId: 'corr-001' },
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, confirm: false, json: true });
|
|
174
|
+
|
|
175
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
176
|
+
expect(output.status).toBe('dry_run');
|
|
177
|
+
expect(output.dryRun).toBe(true);
|
|
178
|
+
expect(output.scannedCount).toBe(1);
|
|
179
|
+
expect(output.actions).toHaveLength(1);
|
|
180
|
+
expect(output.actions[0].taskId).toBe('dreamer-001');
|
|
181
|
+
expect(output.actions[0].taskKind).toBe('dreamer');
|
|
182
|
+
expect(output.actions[0].decision).toBe('would_create_successor');
|
|
183
|
+
expect(output.actions[0].successorKind).toBe('philosopher');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('confirm creates exactly one philosopher successor', async () => {
|
|
187
|
+
const dreamerTask = makeSucceededTask('dreamer-002', 'dreamer');
|
|
188
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
189
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
190
|
+
decision: 'successor_created',
|
|
191
|
+
sourceTaskId: 'dreamer-002',
|
|
192
|
+
successorTaskId: 'philosopher-dreamer-002-prompt',
|
|
193
|
+
successorKind: 'philosopher',
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
197
|
+
|
|
198
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
199
|
+
expect(output.status).toBe('confirmed');
|
|
200
|
+
expect(output.dryRun).toBe(false);
|
|
201
|
+
expect(output.createdCount).toBe(1);
|
|
202
|
+
expect(output.actions[0].decision).toBe('successor_created');
|
|
203
|
+
expect(output.actions[0].successorTaskId).toBe('philosopher-dreamer-002-prompt');
|
|
204
|
+
expect(output.actions[0].successorKind).toBe('philosopher');
|
|
205
|
+
expect(mockCommitNextTaskProposal).toHaveBeenCalledWith('dreamer-002');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('repeated confirm returns successor_exists, no duplicate task', async () => {
|
|
209
|
+
const dreamerTask = makeSucceededTask('dreamer-003', 'dreamer');
|
|
210
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
211
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
212
|
+
decision: 'successor_exists',
|
|
213
|
+
sourceTaskId: 'dreamer-003',
|
|
214
|
+
successorTaskId: 'philosopher-dreamer-003-prompt',
|
|
215
|
+
successorKind: 'philosopher',
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
219
|
+
|
|
220
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
221
|
+
expect(output.existingCount).toBe(1);
|
|
222
|
+
expect(output.createdCount).toBe(0);
|
|
223
|
+
expect(output.actions[0].decision).toBe('successor_exists');
|
|
224
|
+
expect(output.actions[0].successorTaskId).toBe('philosopher-dreamer-003-prompt');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('terminal runner returns no_successor', async () => {
|
|
228
|
+
const trainerTask = makeSucceededTask('trainer-001', 'trainer');
|
|
229
|
+
mockListTasks.mockResolvedValue([trainerTask]);
|
|
230
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
231
|
+
decision: 'no_successor',
|
|
232
|
+
sourceTaskId: 'trainer-001',
|
|
233
|
+
reason: 'No valid successor in job graph for this task kind and channel',
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
237
|
+
|
|
238
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
239
|
+
expect(output.actions[0].decision).toBe('no_successor');
|
|
240
|
+
expect(output.actions[0].taskId).toBe('trainer-001');
|
|
241
|
+
expect(output.actions[0].reason).toBe('No valid successor in job graph for this task kind and channel');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('succeeded task with malformed metadata is skipped with reason; no successor created', async () => {
|
|
245
|
+
const malformedTask = makeMalformedTask('malformed-001', 'dreamer');
|
|
246
|
+
mockListTasks.mockResolvedValue([malformedTask]);
|
|
247
|
+
|
|
248
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
249
|
+
|
|
250
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
251
|
+
expect(output.skippedCount).toBe(1);
|
|
252
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
253
|
+
expect(output.actions[0].taskId).toBe('malformed-001');
|
|
254
|
+
expect(output.actions[0].reason).toBeDefined();
|
|
255
|
+
expect(output.actions[0].nextAction).toBeDefined();
|
|
256
|
+
expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('failed/retry_wait/leased tasks are not processed — only succeeded returned by listTasks', async () => {
|
|
260
|
+
const succeededTask = makeSucceededTask('dreamer-ok', 'dreamer');
|
|
261
|
+
mockListTasks.mockResolvedValue([succeededTask]);
|
|
262
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
263
|
+
decision: 'successor_created',
|
|
264
|
+
sourceTaskId: 'dreamer-ok',
|
|
265
|
+
successorTaskId: 'philosopher-dreamer-ok-prompt',
|
|
266
|
+
successorKind: 'philosopher',
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
270
|
+
|
|
271
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
272
|
+
expect(output.scannedCount).toBe(1);
|
|
273
|
+
expect(output.actions).toHaveLength(1);
|
|
274
|
+
expect(output.actions[0].taskId).toBe('dreamer-ok');
|
|
275
|
+
expect(mockCommitNextTaskProposal).toHaveBeenCalledTimes(1);
|
|
276
|
+
expect(mockCommitNextTaskProposal).toHaveBeenCalledWith('dreamer-ok');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('DB/storage unavailable fails closed', async () => {
|
|
280
|
+
mockInitialize.mockRejectedValue(new Error('Cannot open database'));
|
|
281
|
+
|
|
282
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
283
|
+
|
|
284
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
285
|
+
expect(output.status).toBe('failed');
|
|
286
|
+
expect(output.scannedCount).toBe(0);
|
|
287
|
+
expect(output.actions).toHaveLength(0);
|
|
288
|
+
expect(process.exitCode).toBe(1);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('listTasks throws: fails closed with structured error', async () => {
|
|
292
|
+
mockListTasks.mockRejectedValue(new Error('Database locked'));
|
|
293
|
+
|
|
294
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
295
|
+
|
|
296
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
297
|
+
expect(output.status).toBe('failed');
|
|
298
|
+
expect(process.exitCode).toBe(1);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('default mode is dry-run', async () => {
|
|
302
|
+
const dreamerTask = makeSucceededTask('dreamer-default', 'dreamer');
|
|
303
|
+
mockDryRunListTasks([dreamerTask]);
|
|
304
|
+
mockProposeNextTask.mockResolvedValue({
|
|
305
|
+
decision: 'proposal_created',
|
|
306
|
+
taskId: 'dreamer-default',
|
|
307
|
+
taskKind: 'dreamer',
|
|
308
|
+
proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-default'], inputArtifactRefs: [], parentTaskId: 'dreamer-default', correlationId: 'corr-default' },
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, json: true });
|
|
312
|
+
|
|
313
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
314
|
+
expect(output.status).toBe('dry_run');
|
|
315
|
+
expect(output.dryRun).toBe(true);
|
|
316
|
+
expect(output.actions[0].decision).toBe('would_create_successor');
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('--confirm performs writes', async () => {
|
|
320
|
+
const dreamerTask = makeSucceededTask('dreamer-confirm', 'dreamer');
|
|
321
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
322
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
323
|
+
decision: 'successor_created',
|
|
324
|
+
sourceTaskId: 'dreamer-confirm',
|
|
325
|
+
successorTaskId: 'philosopher-dreamer-confirm-prompt',
|
|
326
|
+
successorKind: 'philosopher',
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
330
|
+
|
|
331
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
332
|
+
expect(output.status).toBe('confirmed');
|
|
333
|
+
expect(output.dryRun).toBe(false);
|
|
334
|
+
expect(output.actions[0].decision).toBe('successor_created');
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('--dry-run --confirm is rejected with exitCode 1 and no writes, JSON mode emits structured error with reason/nextAction', async () => {
|
|
338
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, confirm: true, json: true });
|
|
339
|
+
|
|
340
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
341
|
+
expect(output.status).toBe('refused');
|
|
342
|
+
expect(output.error).toContain('mutually exclusive');
|
|
343
|
+
expect(output.reason).toContain('flag_conflict');
|
|
344
|
+
expect(output.nextAction).toBeDefined();
|
|
345
|
+
expect(process.exitCode).toBe(1);
|
|
346
|
+
|
|
347
|
+
expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('--json emits parseable JSON only', async () => {
|
|
351
|
+
const dreamerTask = makeSucceededTask('dreamer-json', 'dreamer');
|
|
352
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
353
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
354
|
+
decision: 'successor_created',
|
|
355
|
+
sourceTaskId: 'dreamer-json',
|
|
356
|
+
successorTaskId: 'philosopher-dreamer-json-prompt',
|
|
357
|
+
successorKind: 'philosopher',
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
361
|
+
|
|
362
|
+
const rawOutput = consoleLogSpy.mock.calls[0][0];
|
|
363
|
+
const parsed = JSON.parse(rawOutput);
|
|
364
|
+
expect(parsed).toBeDefined();
|
|
365
|
+
expect(parsed.status).toBe('confirmed');
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('text output is human-readable and includes counts', async () => {
|
|
369
|
+
const dreamerTask = makeSucceededTask('dreamer-text', 'dreamer');
|
|
370
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
371
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
372
|
+
decision: 'successor_created',
|
|
373
|
+
sourceTaskId: 'dreamer-text',
|
|
374
|
+
successorTaskId: 'philosopher-dreamer-text-prompt',
|
|
375
|
+
successorKind: 'philosopher',
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: false });
|
|
379
|
+
|
|
380
|
+
const text = consoleLogSpy.mock.calls.map(c => c.join(' ')).join('\n');
|
|
381
|
+
expect(text).toContain('Enqueue Successors');
|
|
382
|
+
expect(text).toContain('scanned');
|
|
383
|
+
expect(text).toContain('created');
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it('commitNextTaskProposal returns source_not_succeeded: skipped with reason', async () => {
|
|
387
|
+
const dreamerTask = makeSucceededTask('dreamer-not-succ', 'dreamer');
|
|
388
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
389
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
390
|
+
decision: 'source_not_succeeded',
|
|
391
|
+
taskId: 'dreamer-not-succ',
|
|
392
|
+
status: 'failed',
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
396
|
+
|
|
397
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
398
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
399
|
+
expect(output.actions[0].reason).toContain('source_not_succeeded');
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('commitNextTaskProposal returns task_not_found: skipped with reason', async () => {
|
|
403
|
+
const dreamerTask = makeSucceededTask('dreamer-not-found', 'dreamer');
|
|
404
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
405
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
406
|
+
decision: 'task_not_found',
|
|
407
|
+
taskId: 'dreamer-not-found',
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
411
|
+
|
|
412
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
413
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
414
|
+
expect(output.actions[0].reason).toContain('task_not_found');
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it('commitNextTaskProposal returns invalid_task_metadata: skipped with reason', async () => {
|
|
418
|
+
const dreamerTask = makeSucceededTask('dreamer-invalid-meta', 'dreamer');
|
|
419
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
420
|
+
mockCommitNextTaskProposal.mockResolvedValue({
|
|
421
|
+
decision: 'invalid_task_metadata',
|
|
422
|
+
taskId: 'dreamer-invalid-meta',
|
|
423
|
+
reason: 'Failed to hydrate PITaskRecord from diagnosticJson',
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
427
|
+
|
|
428
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
429
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
430
|
+
expect(output.actions[0].reason).toContain('invalid_task_metadata');
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('multiple succeeded tasks: processes each independently', async () => {
|
|
434
|
+
const dreamer1 = makeSucceededTask('dreamer-multi-1', 'dreamer');
|
|
435
|
+
const dreamer2 = makeSucceededTask('dreamer-multi-2', 'dreamer');
|
|
436
|
+
const philosopher1 = makeSucceededTask('philosopher-multi-1', 'philosopher');
|
|
437
|
+
mockListTasks.mockResolvedValue([dreamer1, dreamer2, philosopher1]);
|
|
438
|
+
|
|
439
|
+
mockCommitNextTaskProposal
|
|
440
|
+
.mockResolvedValueOnce({
|
|
441
|
+
decision: 'successor_created',
|
|
442
|
+
sourceTaskId: 'dreamer-multi-1',
|
|
443
|
+
successorTaskId: 'philosopher-dreamer-multi-1-prompt',
|
|
444
|
+
successorKind: 'philosopher',
|
|
445
|
+
})
|
|
446
|
+
.mockResolvedValueOnce({
|
|
447
|
+
decision: 'successor_exists',
|
|
448
|
+
sourceTaskId: 'dreamer-multi-2',
|
|
449
|
+
successorTaskId: 'philosopher-dreamer-multi-2-prompt',
|
|
450
|
+
successorKind: 'philosopher',
|
|
451
|
+
})
|
|
452
|
+
.mockResolvedValueOnce({
|
|
453
|
+
decision: 'successor_created',
|
|
454
|
+
sourceTaskId: 'philosopher-multi-1',
|
|
455
|
+
successorTaskId: 'scribe-philosopher-multi-1-prompt',
|
|
456
|
+
successorKind: 'scribe',
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
460
|
+
|
|
461
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
462
|
+
expect(output.scannedCount).toBe(3);
|
|
463
|
+
expect(output.createdCount).toBe(2);
|
|
464
|
+
expect(output.existingCount).toBe(1);
|
|
465
|
+
expect(output.actions).toHaveLength(3);
|
|
466
|
+
expect(mockCommitNextTaskProposal).toHaveBeenCalledTimes(3);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it('non-PI task kinds (diagnostician) are not processed', async () => {
|
|
470
|
+
const diagTask = {
|
|
471
|
+
taskId: 'diag-001',
|
|
472
|
+
taskKind: 'diagnostician',
|
|
473
|
+
status: 'succeeded',
|
|
474
|
+
attemptCount: 1,
|
|
475
|
+
maxAttempts: 3,
|
|
476
|
+
diagnosticJson: '{}',
|
|
477
|
+
};
|
|
478
|
+
mockListTasks.mockResolvedValue([diagTask]);
|
|
479
|
+
|
|
480
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
481
|
+
|
|
482
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
483
|
+
expect(output.scannedCount).toBe(0);
|
|
484
|
+
expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it('dry-run does not call commitNextTaskProposal', async () => {
|
|
488
|
+
const dreamerTask = makeSucceededTask('dreamer-dry', 'dreamer');
|
|
489
|
+
mockDryRunListTasks([dreamerTask]);
|
|
490
|
+
mockProposeNextTask.mockResolvedValue({
|
|
491
|
+
decision: 'proposal_created',
|
|
492
|
+
taskId: 'dreamer-dry',
|
|
493
|
+
taskKind: 'dreamer',
|
|
494
|
+
proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-dry'], inputArtifactRefs: [], parentTaskId: 'dreamer-dry', correlationId: 'corr-dry' },
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
|
|
498
|
+
|
|
499
|
+
expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('workspace does not exist: fails closed', async () => {
|
|
503
|
+
mockInitialize.mockRejectedValue(new Error('ENOENT: no such file or directory'));
|
|
504
|
+
|
|
505
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: '/nonexistent/path', confirm: true, json: true });
|
|
506
|
+
|
|
507
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
508
|
+
expect(output.status).toBe('failed');
|
|
509
|
+
expect(process.exitCode).toBe(1);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('confirm path commitNextTaskProposal throws: skipped with reason', async () => {
|
|
513
|
+
const dreamerTask = makeSucceededTask('dreamer-commit-err', 'dreamer');
|
|
514
|
+
mockListTasks.mockResolvedValue([dreamerTask]);
|
|
515
|
+
mockCommitNextTaskProposal.mockRejectedValue(new Error('Database locked during commit'));
|
|
516
|
+
|
|
517
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
518
|
+
|
|
519
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
520
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
521
|
+
expect(output.actions[0].reason).toContain('commit_failed');
|
|
522
|
+
expect(output.actions[0].nextAction).toBeDefined();
|
|
523
|
+
expect(output.skippedCount).toBe(1);
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it('dry-run with no_successor proposal: reports no_successor', async () => {
|
|
527
|
+
const trainerTask = makeSucceededTask('trainer-dry-001', 'trainer');
|
|
528
|
+
mockListTasks.mockResolvedValue([trainerTask]);
|
|
529
|
+
mockProposeNextTask.mockResolvedValue(null);
|
|
530
|
+
|
|
531
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
|
|
532
|
+
|
|
533
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
534
|
+
expect(output.actions[0].decision).toBe('no_successor');
|
|
535
|
+
expect(output.actions[0].taskId).toBe('trainer-dry-001');
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it('successor index build failure: fails closed with structured error', async () => {
|
|
539
|
+
const dreamerTask = makeSucceededTask('dreamer-index-err', 'dreamer');
|
|
540
|
+
mockListTasks
|
|
541
|
+
.mockResolvedValueOnce([dreamerTask])
|
|
542
|
+
.mockRejectedValueOnce(new Error('Database locked during index build'));
|
|
543
|
+
|
|
544
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
|
|
545
|
+
|
|
546
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
547
|
+
expect(output.status).toBe('failed');
|
|
548
|
+
expect(output.reason).toContain('successor_index_failed');
|
|
549
|
+
expect(output.nextAction).toBeDefined();
|
|
550
|
+
expect(process.exitCode).toBe(1);
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
it('dry-run with existing successor: reports successor_exists', async () => {
|
|
554
|
+
const dreamerTask = makeSucceededTask('dreamer-existing-succ', 'dreamer');
|
|
555
|
+
const philosopherPending = makeSucceededTask('philosopher-dreamer-existing-succ-prompt', 'philosopher', { parentTaskId: 'dreamer-existing-succ', channel: 'prompt' });
|
|
556
|
+
philosopherPending.status = 'pending';
|
|
557
|
+
mockDryRunListTasks([dreamerTask], [philosopherPending]);
|
|
558
|
+
mockProposeNextTask.mockResolvedValue({
|
|
559
|
+
decision: 'proposal_created',
|
|
560
|
+
taskId: 'dreamer-existing-succ',
|
|
561
|
+
taskKind: 'dreamer',
|
|
562
|
+
proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-existing-succ'], inputArtifactRefs: [], parentTaskId: 'dreamer-existing-succ', correlationId: 'corr-existing' },
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
|
|
566
|
+
|
|
567
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
568
|
+
expect(output.actions[0].decision).toBe('successor_exists');
|
|
569
|
+
expect(output.actions[0].successorTaskId).toBe('philosopher-dreamer-existing-succ-prompt');
|
|
570
|
+
expect(output.existingCount).toBe(1);
|
|
571
|
+
expect(output.createdCount).toBe(0);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('dry-run proposeNextTask throws: skipped with reason', async () => {
|
|
575
|
+
const dreamerTask = makeSucceededTask('dreamer-propose-err', 'dreamer');
|
|
576
|
+
mockListTasks.mockResolvedValueOnce([dreamerTask]);
|
|
577
|
+
mockProposeNextTask.mockRejectedValue(new Error('Orchestrator internal error'));
|
|
578
|
+
|
|
579
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
|
|
580
|
+
|
|
581
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
582
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
583
|
+
expect(output.actions[0].reason).toContain('propose_failed');
|
|
584
|
+
expect(output.actions[0].nextAction).toBeDefined();
|
|
585
|
+
expect(output.skippedCount).toBe(1);
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it('failed JSON output includes reason and nextAction', async () => {
|
|
589
|
+
mockInitialize.mockRejectedValue(new Error('Cannot open database'));
|
|
590
|
+
|
|
591
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
592
|
+
|
|
593
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
594
|
+
expect(output.status).toBe('failed');
|
|
595
|
+
expect(output.reason).toContain('storage_init_failed');
|
|
596
|
+
expect(output.nextAction).toBeDefined();
|
|
597
|
+
expect(process.exitCode).toBe(1);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it('--confirm workspace resolve failure reports dryRun=false', async () => {
|
|
601
|
+
const { resolveWorkspaceDir } = await import('../../src/resolve-workspace.js');
|
|
602
|
+
vi.mocked(resolveWorkspaceDir).mockImplementationOnce(() => { throw new Error('No workspace found'); });
|
|
603
|
+
|
|
604
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ confirm: true, json: true });
|
|
605
|
+
|
|
606
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
607
|
+
expect(output.status).toBe('failed');
|
|
608
|
+
expect(output.dryRun).toBe(false);
|
|
609
|
+
expect(output.reason).toContain('workspace_resolve_failed');
|
|
610
|
+
expect(output.nextAction).toBeDefined();
|
|
611
|
+
expect(process.exitCode).toBe(1);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it('dry-run existing successor with malformed metadata: skipped, not would_create_successor', async () => {
|
|
615
|
+
const dreamerTask = makeSucceededTask('dreamer-malformed-succ', 'dreamer');
|
|
616
|
+
const malformedSuccessor = {
|
|
617
|
+
taskId: 'philosopher-dreamer-malformed-succ-prompt',
|
|
618
|
+
taskKind: 'philosopher',
|
|
619
|
+
status: 'pending' as const,
|
|
620
|
+
attemptCount: 0,
|
|
621
|
+
maxAttempts: 3,
|
|
622
|
+
inputRef: undefined,
|
|
623
|
+
resultRef: undefined,
|
|
624
|
+
lastError: undefined,
|
|
625
|
+
leaseOwner: undefined,
|
|
626
|
+
leaseExpiresAt: undefined,
|
|
627
|
+
diagnosticJson: 'not-valid-json{{{',
|
|
628
|
+
};
|
|
629
|
+
mockDryRunListTasks([dreamerTask], [malformedSuccessor]);
|
|
630
|
+
mockProposeNextTask.mockResolvedValue({
|
|
631
|
+
decision: 'proposal_created',
|
|
632
|
+
taskId: 'dreamer-malformed-succ',
|
|
633
|
+
taskKind: 'dreamer',
|
|
634
|
+
proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-malformed-succ'], inputArtifactRefs: [], parentTaskId: 'dreamer-malformed-succ', correlationId: 'corr-malformed' },
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
|
|
638
|
+
|
|
639
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
640
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
641
|
+
expect(output.actions[0].reason).toContain('successor_exists_with_malformed_metadata');
|
|
642
|
+
expect(output.actions[0].nextAction).toContain('integrity-repair');
|
|
643
|
+
expect(output.skippedCount).toBe(1);
|
|
644
|
+
expect(output.createdCount).toBe(0);
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
it('dedupe scan is not N×full-table per source task (buildSuccessorIndex called once)', async () => {
|
|
648
|
+
const dreamer1 = makeSucceededTask('dreamer-dedup-1', 'dreamer');
|
|
649
|
+
const dreamer2 = makeSucceededTask('dreamer-dedup-2', 'dreamer');
|
|
650
|
+
mockDryRunListTasks([dreamer1, dreamer2]);
|
|
651
|
+
mockProposeNextTask
|
|
652
|
+
.mockResolvedValueOnce({
|
|
653
|
+
decision: 'proposal_created',
|
|
654
|
+
taskId: 'dreamer-dedup-1',
|
|
655
|
+
taskKind: 'dreamer',
|
|
656
|
+
proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-dedup-1'], inputArtifactRefs: [], parentTaskId: 'dreamer-dedup-1', correlationId: 'corr-1' },
|
|
657
|
+
})
|
|
658
|
+
.mockResolvedValueOnce({
|
|
659
|
+
decision: 'proposal_created',
|
|
660
|
+
taskId: 'dreamer-dedup-2',
|
|
661
|
+
taskKind: 'dreamer',
|
|
662
|
+
proposal: { taskKind: 'philosopher', channel: 'prompt', dependencyTaskIds: ['dreamer-dedup-2'], inputArtifactRefs: [], parentTaskId: 'dreamer-dedup-2', correlationId: 'corr-2' },
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, dryRun: true, json: true });
|
|
666
|
+
|
|
667
|
+
expect(mockListTasks.mock.calls.length).toBe(7);
|
|
668
|
+
const allCalls = mockListTasks.mock.calls.map(c => c[0]?.status);
|
|
669
|
+
const succeededCalls = allCalls.filter(s => s === 'succeeded').length;
|
|
670
|
+
expect(succeededCalls).toBe(2);
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
it('diagnosticJson non-string returns null, no throw', async () => {
|
|
674
|
+
const taskWithNonStringDiag = {
|
|
675
|
+
taskId: 'task-nonstring-diag',
|
|
676
|
+
taskKind: 'dreamer',
|
|
677
|
+
status: 'succeeded',
|
|
678
|
+
attemptCount: 1,
|
|
679
|
+
maxAttempts: 3,
|
|
680
|
+
inputRef: undefined,
|
|
681
|
+
resultRef: 'ref-nonstring',
|
|
682
|
+
lastError: undefined,
|
|
683
|
+
leaseOwner: undefined,
|
|
684
|
+
leaseExpiresAt: undefined,
|
|
685
|
+
diagnosticJson: 42,
|
|
686
|
+
};
|
|
687
|
+
mockListTasks.mockResolvedValue([taskWithNonStringDiag]);
|
|
688
|
+
|
|
689
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ workspace: WS, confirm: true, json: true });
|
|
690
|
+
|
|
691
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
692
|
+
expect(output.scannedCount).toBe(1);
|
|
693
|
+
expect(output.skippedCount).toBe(1);
|
|
694
|
+
expect(output.actions[0].decision).toBe('skipped');
|
|
695
|
+
expect(output.actions[0].reason).toContain('Failed to hydrate');
|
|
696
|
+
expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
it('resolveWorkspaceDir throws: fails closed with structured error', async () => {
|
|
700
|
+
const { resolveWorkspaceDir } = await import('../../src/resolve-workspace.js');
|
|
701
|
+
vi.mocked(resolveWorkspaceDir).mockImplementationOnce(() => { throw new Error('No workspace found'); });
|
|
702
|
+
|
|
703
|
+
await handleRuntimeInternalizationEnqueueSuccessors({ json: true });
|
|
704
|
+
|
|
705
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
706
|
+
expect(output.status).toBe('failed');
|
|
707
|
+
expect(output.error).toContain('Failed to resolve workspace');
|
|
708
|
+
expect(process.exitCode).toBe(1);
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
describe('Commander wiring for enqueue-successors', () => {
|
|
713
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
714
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
715
|
+
|
|
716
|
+
beforeEach(() => {
|
|
717
|
+
vi.clearAllMocks();
|
|
718
|
+
process.exitCode = 0;
|
|
719
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
720
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
721
|
+
mockInitialize.mockResolvedValue(undefined);
|
|
722
|
+
mockClose.mockResolvedValue(undefined);
|
|
723
|
+
mockListTasks.mockResolvedValue([]);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
afterEach(() => {
|
|
727
|
+
process.exitCode = 0;
|
|
728
|
+
consoleLogSpy.mockRestore();
|
|
729
|
+
consoleErrorSpy.mockRestore();
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
it('no flags → dry-run mode (confirm=undefined, dryRun=undefined)', async () => {
|
|
733
|
+
const program = createTestProgram();
|
|
734
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--json']);
|
|
735
|
+
|
|
736
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
737
|
+
expect(output.dryRun).toBe(true);
|
|
738
|
+
expect(output.status).toBe('dry_run');
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
it('--confirm alone → confirm mode', async () => {
|
|
742
|
+
const program = createTestProgram();
|
|
743
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--confirm', '--json']);
|
|
744
|
+
|
|
745
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
746
|
+
expect(output.dryRun).toBe(false);
|
|
747
|
+
expect(output.status).toBe('confirmed');
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
it('--dry-run alone → dry-run mode', async () => {
|
|
751
|
+
const program = createTestProgram();
|
|
752
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--dry-run', '--json']);
|
|
753
|
+
|
|
754
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
755
|
+
expect(output.dryRun).toBe(true);
|
|
756
|
+
expect(output.status).toBe('dry_run');
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
it('--dry-run --confirm together → rejected with exitCode 1', async () => {
|
|
760
|
+
const program = createTestProgram();
|
|
761
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--dry-run', '--confirm', '--json']);
|
|
762
|
+
|
|
763
|
+
expect(process.exitCode).toBe(1);
|
|
764
|
+
expect(mockCommitNextTaskProposal).not.toHaveBeenCalled();
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
it('--json flag produces parseable output', async () => {
|
|
768
|
+
const program = createTestProgram();
|
|
769
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--json']);
|
|
770
|
+
|
|
771
|
+
const rawOutput = consoleLogSpy.mock.calls[0][0];
|
|
772
|
+
const parsed = JSON.parse(rawOutput);
|
|
773
|
+
expect(parsed).toBeDefined();
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
it('no flags -> RuntimeStateManager readonly=true (dry-run default)', async () => {
|
|
777
|
+
const program = createTestProgram();
|
|
778
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--json']);
|
|
779
|
+
|
|
780
|
+
expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
|
|
781
|
+
expect.objectContaining({ readonly: true }),
|
|
782
|
+
);
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
it('--dry-run -> RuntimeStateManager readonly=true', async () => {
|
|
786
|
+
const program = createTestProgram();
|
|
787
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--dry-run', '--json']);
|
|
788
|
+
|
|
789
|
+
expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
|
|
790
|
+
expect.objectContaining({ readonly: true }),
|
|
791
|
+
);
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
it('--confirm -> RuntimeStateManager readonly=false', async () => {
|
|
795
|
+
mockListTasks.mockResolvedValue([]);
|
|
796
|
+
const program = createTestProgram();
|
|
797
|
+
await program.parseAsync(['node', 'pd', 'internalization', 'enqueue-successors', '--workspace', WS, '--confirm', '--json']);
|
|
798
|
+
|
|
799
|
+
expect(mockRuntimeStateManagerOpts).toHaveBeenCalledWith(
|
|
800
|
+
expect.objectContaining({ readonly: false }),
|
|
801
|
+
);
|
|
802
|
+
});
|
|
803
|
+
});
|