@principles/pd-cli 1.98.0 → 1.100.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/dist/commands/diagnose.d.ts.map +1 -1
- package/dist/commands/diagnose.js +4 -3
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/pain-retry.d.ts.map +1 -1
- package/dist/commands/pain-retry.js +4 -3
- package/dist/commands/pain-retry.js.map +1 -1
- package/dist/commands/runtime-internalization-integrity.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-integrity.js +2 -0
- package/dist/commands/runtime-internalization-integrity.js.map +1 -1
- package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-run-once.js +58 -39
- package/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/dist/commands/runtime-recovery-failed-tasks.d.ts +10 -0
- package/dist/commands/runtime-recovery-failed-tasks.d.ts.map +1 -0
- package/dist/commands/runtime-recovery-failed-tasks.js +164 -0
- package/dist/commands/runtime-recovery-failed-tasks.js.map +1 -0
- package/dist/commands/task.d.ts.map +1 -1
- package/dist/commands/task.js +85 -4
- package/dist/commands/task.js.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/diagnose.ts +4 -3
- package/src/commands/pain-retry.ts +4 -3
- package/src/commands/runtime-internalization-integrity.ts +1 -0
- package/src/commands/runtime-internalization-run-once.ts +70 -54
- package/src/commands/runtime-recovery-failed-tasks.ts +181 -0
- package/src/commands/task.ts +80 -4
- package/src/index.ts +19 -0
- package/tests/commands/runtime-recovery-failed-tasks.test.ts +201 -0
- package/tests/commands/task.test.ts +145 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const mockGetTask = vi.hoisted(() => vi.fn());
|
|
4
|
+
const mockGetRunsByTask = vi.hoisted(() => vi.fn());
|
|
5
|
+
const mockInitialize = vi.hoisted(() => vi.fn());
|
|
6
|
+
const mockClose = vi.hoisted(() => vi.fn());
|
|
7
|
+
|
|
8
|
+
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
9
|
+
resolveWorkspaceDir: vi.fn().mockReturnValue('/fake/workspace'),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
vi.mock('@principles/core', async (importOriginal) => {
|
|
13
|
+
const original = await importOriginal<typeof import('@principles/core')>();
|
|
14
|
+
return {
|
|
15
|
+
...original,
|
|
16
|
+
RuntimeStateManager: vi.fn().mockImplementation(function() {
|
|
17
|
+
return {
|
|
18
|
+
initialize: mockInitialize,
|
|
19
|
+
getTask: mockGetTask,
|
|
20
|
+
getRunsByTask: mockGetRunsByTask,
|
|
21
|
+
close: mockClose,
|
|
22
|
+
};
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
import { handleTaskShow } from '../../src/commands/task.js';
|
|
28
|
+
import { MalformedRunError } from '@principles/core';
|
|
29
|
+
|
|
30
|
+
describe('pd task show command handler', () => {
|
|
31
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
32
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
|
33
|
+
let processExitSpy: ReturnType<typeof vi.spyOn>;
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
vi.clearAllMocks();
|
|
37
|
+
mockInitialize.mockResolvedValue(undefined);
|
|
38
|
+
mockGetTask.mockResolvedValue({
|
|
39
|
+
taskId: 'task-123',
|
|
40
|
+
taskKind: 'dreamer',
|
|
41
|
+
status: 'failed',
|
|
42
|
+
attemptCount: 1,
|
|
43
|
+
maxAttempts: 3,
|
|
44
|
+
createdAt: Date.now(),
|
|
45
|
+
updatedAt: Date.now(),
|
|
46
|
+
});
|
|
47
|
+
mockGetRunsByTask.mockResolvedValue([
|
|
48
|
+
{
|
|
49
|
+
runId: 'run-1',
|
|
50
|
+
executionStatus: 'failed',
|
|
51
|
+
attemptNumber: 1,
|
|
52
|
+
startedAt: Date.now(),
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
process.exitCode = 0;
|
|
56
|
+
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
57
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
58
|
+
processExitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('happy path JSON mode prints task and runs, exit code 0', async () => {
|
|
62
|
+
await handleTaskShow({ id: 'task-123', json: true });
|
|
63
|
+
|
|
64
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
65
|
+
expect(output).toMatchObject({
|
|
66
|
+
task: { taskId: 'task-123' },
|
|
67
|
+
runs: [{ runId: 'run-1' }],
|
|
68
|
+
});
|
|
69
|
+
expect(process.exitCode).toBe(0);
|
|
70
|
+
expect(processExitSpy).not.toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('task not found JSON mode prints ok: false and exits with non-zero code', async () => {
|
|
74
|
+
mockGetTask.mockResolvedValue(null);
|
|
75
|
+
|
|
76
|
+
await handleTaskShow({ id: 'nonexistent-task', json: true });
|
|
77
|
+
|
|
78
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
79
|
+
expect(output).toMatchObject({
|
|
80
|
+
ok: false,
|
|
81
|
+
reason: expect.stringContaining('Task not found'),
|
|
82
|
+
nextAction: expect.any(String),
|
|
83
|
+
});
|
|
84
|
+
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('degraded JSON mode prints ok: false, lists degraded runs, and sets exitCode to 1', async () => {
|
|
88
|
+
const malformedError = new MalformedRunError('Malformed schema', [
|
|
89
|
+
{
|
|
90
|
+
runId: 'run-valid',
|
|
91
|
+
executionStatus: 'succeeded',
|
|
92
|
+
attemptNumber: 1,
|
|
93
|
+
startedAt: Date.now(),
|
|
94
|
+
} as any,
|
|
95
|
+
], [
|
|
96
|
+
{
|
|
97
|
+
runId: 'run-bad',
|
|
98
|
+
error: 'runtimeKind missing',
|
|
99
|
+
rawRow: {},
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
mockGetRunsByTask.mockRejectedValue(malformedError);
|
|
104
|
+
|
|
105
|
+
await handleTaskShow({ id: 'task-123', json: true });
|
|
106
|
+
|
|
107
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0] as string);
|
|
108
|
+
expect(output).toMatchObject({
|
|
109
|
+
ok: false,
|
|
110
|
+
task: { taskId: 'task-123' },
|
|
111
|
+
runs: [{ runId: 'run-valid' }],
|
|
112
|
+
degradedRuns: [{ runId: 'run-bad', error: 'runtimeKind missing' }],
|
|
113
|
+
reason: expect.stringContaining('Malformed schema'),
|
|
114
|
+
nextAction: expect.stringContaining('integrity-repair'),
|
|
115
|
+
});
|
|
116
|
+
expect(process.exitCode).toBe(1);
|
|
117
|
+
expect(processExitSpy).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('degraded text mode prints warning and sets exitCode to 1', async () => {
|
|
121
|
+
const malformedError = new MalformedRunError('Malformed schema', [
|
|
122
|
+
{
|
|
123
|
+
runId: 'run-valid',
|
|
124
|
+
executionStatus: 'succeeded',
|
|
125
|
+
attemptNumber: 1,
|
|
126
|
+
startedAt: Date.now(),
|
|
127
|
+
} as any,
|
|
128
|
+
], [
|
|
129
|
+
{
|
|
130
|
+
runId: 'run-bad',
|
|
131
|
+
error: 'runtimeKind missing',
|
|
132
|
+
rawRow: {},
|
|
133
|
+
},
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
mockGetRunsByTask.mockRejectedValue(malformedError);
|
|
137
|
+
|
|
138
|
+
await handleTaskShow({ id: 'task-123', json: false });
|
|
139
|
+
|
|
140
|
+
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
141
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Task: task-123'));
|
|
142
|
+
expect(process.exitCode).toBe(1);
|
|
143
|
+
expect(processExitSpy).not.toHaveBeenCalled();
|
|
144
|
+
});
|
|
145
|
+
});
|