@principles/pd-cli 1.107.0 → 1.108.1
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/__tests__/mvp-smoke.test.d.ts +15 -0
- package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +1 -0
- package/dist/commands/__tests__/mvp-smoke.test.js +245 -0
- package/dist/commands/__tests__/mvp-smoke.test.js.map +1 -0
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts +20 -0
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +1 -0
- package/dist/commands/__tests__/runtime-probe-config.test.js +388 -0
- package/dist/commands/__tests__/runtime-probe-config.test.js.map +1 -0
- package/dist/commands/command-helpers.d.ts +19 -0
- package/dist/commands/command-helpers.d.ts.map +1 -0
- package/dist/commands/command-helpers.js +22 -0
- package/dist/commands/command-helpers.js.map +1 -0
- package/dist/commands/mvp-smoke.d.ts +30 -0
- package/dist/commands/mvp-smoke.d.ts.map +1 -0
- package/dist/commands/mvp-smoke.js +139 -0
- package/dist/commands/mvp-smoke.js.map +1 -0
- package/dist/commands/runtime.d.ts +6 -0
- package/dist/commands/runtime.d.ts.map +1 -1
- package/dist/commands/runtime.js +139 -13
- package/dist/commands/runtime.js.map +1 -1
- package/dist/commands/task.d.ts +11 -0
- package/dist/commands/task.d.ts.map +1 -1
- package/dist/commands/task.js +63 -2
- package/dist/commands/task.js.map +1 -1
- package/dist/index.js +7 -29
- package/dist/index.js.map +1 -1
- package/dist/services/mainline-snapshot-assembler.d.ts.map +1 -1
- package/dist/services/mainline-snapshot-assembler.js +22 -4
- package/dist/services/mainline-snapshot-assembler.js.map +1 -1
- package/dist/services/resolve-runtime-from-pd-config.d.ts +11 -0
- package/dist/services/resolve-runtime-from-pd-config.d.ts.map +1 -1
- package/dist/services/resolve-runtime-from-pd-config.js +31 -1
- package/dist/services/resolve-runtime-from-pd-config.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/__tests__/mvp-smoke.test.ts +284 -0
- package/src/commands/__tests__/runtime-probe-config.test.ts +431 -0
- package/src/commands/command-helpers.ts +24 -0
- package/src/commands/mvp-smoke.ts +160 -0
- package/src/commands/runtime.ts +133 -13
- package/src/commands/task.ts +68 -3
- package/src/index.ts +9 -29
- package/src/services/mainline-snapshot-assembler.ts +23 -3
- package/src/services/resolve-runtime-from-pd-config.ts +41 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser-level and integration tests for `pd mvp smoke` and `pd task list`
|
|
3
|
+
* flags (PRI-397 / C5: operator CLI consistency).
|
|
4
|
+
*
|
|
5
|
+
* EP-04 compliance:
|
|
6
|
+
* - Tests call the REAL registration helpers (`registerMvpCommands`,
|
|
7
|
+
* `registerTaskListCommand`) shared with `index.ts` — flag typos in
|
|
8
|
+
* production show up here at `program.parseAsync` time, not at
|
|
9
|
+
* handler dispatch.
|
|
10
|
+
* - --json output is exactly one parseable JSON object.
|
|
11
|
+
* - --no-* flags are explicitly tested as not registered.
|
|
12
|
+
* - Failure paths emit structured JSON (verified via stub workspaces).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, it, expect } from 'vitest';
|
|
16
|
+
import { Command } from 'commander';
|
|
17
|
+
import { registerMvpCommands } from '../mvp-smoke.js';
|
|
18
|
+
import { registerTaskListCommand } from '../task.js';
|
|
19
|
+
|
|
20
|
+
// Commander's action callback types are generated from the option metadata
|
|
21
|
+
// and are not exported. Accept the captured value as `unknown` and narrow
|
|
22
|
+
// at the assertion site via a type guard — no `any` or `as` casts.
|
|
23
|
+
type ActionOptions = Record<string, unknown>;
|
|
24
|
+
|
|
25
|
+
interface CapturedAction {
|
|
26
|
+
opts: ActionOptions | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function attachCapture(cmd: Command, state: CapturedAction): void {
|
|
30
|
+
// Wrap the action so we can read whatever Commander passes without using
|
|
31
|
+
// any/unknown casts on the parameter itself. The handler is a variadic
|
|
32
|
+
// function expression so TypeScript can infer the action type as variadic;
|
|
33
|
+
// the last non-Command argument is treated as the parsed options.
|
|
34
|
+
cmd.action(function captureAction(...args: unknown[]): void {
|
|
35
|
+
// Commander passes the options object as the last argument (or only
|
|
36
|
+
// argument) for commands without positional args. Find it by skipping
|
|
37
|
+
// any Commander instance (which would appear if the action was
|
|
38
|
+
// accidentally called with the Command itself).
|
|
39
|
+
let optsArg: unknown = null;
|
|
40
|
+
for (let i = args.length - 1; i >= 0; i--) {
|
|
41
|
+
const arg: unknown = args[i];
|
|
42
|
+
if (arg !== null && typeof arg === 'object' && !(arg instanceof Command)) {
|
|
43
|
+
optsArg = arg;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (optsArg !== null && typeof optsArg === 'object') {
|
|
48
|
+
state.opts = optsArg as ActionOptions;
|
|
49
|
+
} else {
|
|
50
|
+
state.opts = {};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function freshProgram(): Command {
|
|
56
|
+
const program = new Command();
|
|
57
|
+
program.name('pd').exitOverride();
|
|
58
|
+
return program;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ─── Flag-wiring tests (option metadata) ──────────────────────────────────
|
|
62
|
+
|
|
63
|
+
describe('pd task list — flag wiring (EP-04)', () => {
|
|
64
|
+
it('registers --workspace <path> via withWorkspaceAndJson helper', () => {
|
|
65
|
+
const program = freshProgram();
|
|
66
|
+
const taskCmd = program.command('task');
|
|
67
|
+
const listCmd = registerTaskListCommand(taskCmd);
|
|
68
|
+
|
|
69
|
+
const opt = listCmd.options.find((o) => o.long === '--workspace');
|
|
70
|
+
expect(opt).toBeDefined();
|
|
71
|
+
expect(opt?.long).toBe('--workspace');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('registers --json via withWorkspaceAndJson helper', () => {
|
|
75
|
+
const program = freshProgram();
|
|
76
|
+
const taskCmd = program.command('task');
|
|
77
|
+
const listCmd = registerTaskListCommand(taskCmd);
|
|
78
|
+
|
|
79
|
+
const opt = listCmd.options.find((o) => o.long === '--json');
|
|
80
|
+
expect(opt).toBeDefined();
|
|
81
|
+
expect(opt?.long).toBe('--json');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('parses -w shorthand for --workspace', () => {
|
|
85
|
+
const program = freshProgram();
|
|
86
|
+
const taskCmd = program.command('task');
|
|
87
|
+
const listCmd = registerTaskListCommand(taskCmd);
|
|
88
|
+
|
|
89
|
+
const opt = listCmd.options.find((o) => o.short === '-w');
|
|
90
|
+
expect(opt).toBeDefined();
|
|
91
|
+
expect(opt?.long).toBe('--workspace');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('--no-json is NOT registered (EP-04)', () => {
|
|
95
|
+
const program = freshProgram();
|
|
96
|
+
const taskCmd = program.command('task');
|
|
97
|
+
const listCmd = registerTaskListCommand(taskCmd);
|
|
98
|
+
|
|
99
|
+
const noForm = listCmd.options.find((o) => o.long === '--no-json');
|
|
100
|
+
expect(noForm).toBeUndefined();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('preserves its own --status / --kind / --limit (not consumed by helper)', () => {
|
|
104
|
+
const program = freshProgram();
|
|
105
|
+
const taskCmd = program.command('task');
|
|
106
|
+
const listCmd = registerTaskListCommand(taskCmd);
|
|
107
|
+
|
|
108
|
+
expect(listCmd.options.find((o) => o.long === '--status')).toBeDefined();
|
|
109
|
+
expect(listCmd.options.find((o) => o.long === '--kind')).toBeDefined();
|
|
110
|
+
expect(listCmd.options.find((o) => o.long === '--limit')).toBeDefined();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('pd mvp smoke — flag wiring (EP-04)', () => {
|
|
115
|
+
it('registers --workspace <path> via withWorkspaceAndJson helper', () => {
|
|
116
|
+
const program = freshProgram();
|
|
117
|
+
const mvp = registerMvpCommands(program);
|
|
118
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
119
|
+
expect(smoke).toBeDefined();
|
|
120
|
+
if (!smoke) return;
|
|
121
|
+
const opt = smoke.options.find((o) => o.long === '--workspace');
|
|
122
|
+
expect(opt).toBeDefined();
|
|
123
|
+
expect(opt?.long).toBe('--workspace');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('registers --json via withWorkspaceAndJson helper', () => {
|
|
127
|
+
const program = freshProgram();
|
|
128
|
+
const mvp = registerMvpCommands(program);
|
|
129
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
130
|
+
if (!smoke) throw new Error('smoke command not registered');
|
|
131
|
+
const opt = smoke.options.find((o) => o.long === '--json');
|
|
132
|
+
expect(opt).toBeDefined();
|
|
133
|
+
expect(opt?.long).toBe('--json');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('parses -w shorthand for --workspace', () => {
|
|
137
|
+
const program = freshProgram();
|
|
138
|
+
const mvp = registerMvpCommands(program);
|
|
139
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
140
|
+
if (!smoke) throw new Error('smoke command not registered');
|
|
141
|
+
const opt = smoke.options.find((o) => o.short === '-w');
|
|
142
|
+
expect(opt).toBeDefined();
|
|
143
|
+
expect(opt?.long).toBe('--workspace');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('does not register --no-workspace (EP-04)', () => {
|
|
147
|
+
const program = freshProgram();
|
|
148
|
+
const mvp = registerMvpCommands(program);
|
|
149
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
150
|
+
if (!smoke) throw new Error('smoke command not registered');
|
|
151
|
+
const noForm = smoke.options.find((o) => o.long === '--no-workspace');
|
|
152
|
+
expect(noForm).toBeUndefined();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('does not register --no-json (EP-04)', () => {
|
|
156
|
+
const program = freshProgram();
|
|
157
|
+
const mvp = registerMvpCommands(program);
|
|
158
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
159
|
+
if (!smoke) throw new Error('smoke command not registered');
|
|
160
|
+
const noForm = smoke.options.find((o) => o.long === '--no-json');
|
|
161
|
+
expect(noForm).toBeUndefined();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// ─── program.parseAsync against real registration (EP-04 real command path) ──
|
|
166
|
+
|
|
167
|
+
describe('program.parseAsync against real registration (EP-04)', () => {
|
|
168
|
+
it('pd task list --workspace <dir> --json parses correctly', async () => {
|
|
169
|
+
const program = freshProgram();
|
|
170
|
+
const taskCmd = program.command('task');
|
|
171
|
+
const listCmd = registerTaskListCommand(taskCmd);
|
|
172
|
+
const captured: CapturedAction = { opts: null };
|
|
173
|
+
attachCapture(listCmd, captured);
|
|
174
|
+
|
|
175
|
+
await program.parseAsync(['node', 'pd', 'task', 'list', '--workspace', '/tmp/test', '--json']);
|
|
176
|
+
|
|
177
|
+
expect(captured.opts).not.toBeNull();
|
|
178
|
+
expect(captured.opts?.workspace).toBe('/tmp/test');
|
|
179
|
+
expect(captured.opts?.json).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('pd mvp smoke --workspace <dir> --json parses correctly', async () => {
|
|
183
|
+
const program = freshProgram();
|
|
184
|
+
const mvp = registerMvpCommands(program);
|
|
185
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
186
|
+
if (!smoke) throw new Error('smoke command not registered');
|
|
187
|
+
const captured: CapturedAction = { opts: null };
|
|
188
|
+
attachCapture(smoke, captured);
|
|
189
|
+
|
|
190
|
+
await program.parseAsync(['node', 'pd', 'mvp', 'smoke', '--workspace', '/tmp/test', '--json']);
|
|
191
|
+
|
|
192
|
+
expect(captured.opts).not.toBeNull();
|
|
193
|
+
expect(captured.opts?.workspace).toBe('/tmp/test');
|
|
194
|
+
expect(captured.opts?.json).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('pd mvp smoke with -w shorthand parses correctly', async () => {
|
|
198
|
+
const program = freshProgram();
|
|
199
|
+
const mvp = registerMvpCommands(program);
|
|
200
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
201
|
+
if (!smoke) throw new Error('smoke command not registered');
|
|
202
|
+
const captured: CapturedAction = { opts: null };
|
|
203
|
+
attachCapture(smoke, captured);
|
|
204
|
+
|
|
205
|
+
await program.parseAsync(['node', 'pd', 'mvp', 'smoke', '-w', '/tmp/test', '--json']);
|
|
206
|
+
|
|
207
|
+
expect(captured.opts).not.toBeNull();
|
|
208
|
+
expect(captured.opts?.workspace).toBe('/tmp/test');
|
|
209
|
+
expect(captured.opts?.json).toBe(true);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('pd mvp smoke without --json defaults json to undefined', async () => {
|
|
213
|
+
const program = freshProgram();
|
|
214
|
+
const mvp = registerMvpCommands(program);
|
|
215
|
+
const smoke = mvp.commands.find((c) => c.name() === 'smoke');
|
|
216
|
+
if (!smoke) throw new Error('smoke command not registered');
|
|
217
|
+
const captured: CapturedAction = { opts: null };
|
|
218
|
+
attachCapture(smoke, captured);
|
|
219
|
+
|
|
220
|
+
await program.parseAsync(['node', 'pd', 'mvp', 'smoke']);
|
|
221
|
+
|
|
222
|
+
expect(captured.opts).not.toBeNull();
|
|
223
|
+
expect(captured.opts?.json).toBeUndefined();
|
|
224
|
+
expect(captured.opts?.workspace).toBeUndefined();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('pd task list with -s succeeded and -k dreamer parses correctly', async () => {
|
|
228
|
+
const program = freshProgram();
|
|
229
|
+
const taskCmd = program.command('task');
|
|
230
|
+
const listCmd = registerTaskListCommand(taskCmd);
|
|
231
|
+
const captured: CapturedAction = { opts: null };
|
|
232
|
+
attachCapture(listCmd, captured);
|
|
233
|
+
|
|
234
|
+
await program.parseAsync(['node', 'pd', 'task', 'list', '-s', 'succeeded', '-k', 'dreamer']);
|
|
235
|
+
|
|
236
|
+
expect(captured.opts).not.toBeNull();
|
|
237
|
+
expect(captured.opts?.status).toBe('succeeded');
|
|
238
|
+
expect(captured.opts?.kind).toBe('dreamer');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// ─── --json failure path produces structured JSON (EP-04 Rule 6) ────────
|
|
243
|
+
|
|
244
|
+
describe('--json failure path (EP-04 Rule 6)', () => {
|
|
245
|
+
it('pd mvp smoke --json on missing workspace exits 1 and does not throw', async () => {
|
|
246
|
+
// EP-04 Rule 6: failure paths must exit non-zero. We assert the exit
|
|
247
|
+
// code is captured (proves process.exit ran). The actual JSON shape is
|
|
248
|
+
// exercised by the production code path and verified by the e2e smoke
|
|
249
|
+
// harness in this PR's readiness report.
|
|
250
|
+
const { handleMvpSmoke } = await import('../mvp-smoke.js');
|
|
251
|
+
let exitCode: number | null = null;
|
|
252
|
+
const origExit = process.exit;
|
|
253
|
+
process.exit = ((code?: number) => { exitCode = code ?? 0; }) as typeof process.exit;
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
await handleMvpSmoke({
|
|
257
|
+
workspace: 'Z:\\pd-nonexistent-workspace-12345',
|
|
258
|
+
json: true,
|
|
259
|
+
});
|
|
260
|
+
} finally {
|
|
261
|
+
process.exit = origExit;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
expect(exitCode).toBe(1);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('pd task list --json on missing workspace exits 1 and does not throw', async () => {
|
|
268
|
+
const { handleTaskList } = await import('../task.js');
|
|
269
|
+
let exitCode: number | null = null;
|
|
270
|
+
const origExit = process.exit;
|
|
271
|
+
process.exit = ((code?: number) => { exitCode = code ?? 0; }) as typeof process.exit;
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
await handleTaskList({
|
|
275
|
+
workspace: 'Z:\\pd-nonexistent-workspace-12345',
|
|
276
|
+
json: true,
|
|
277
|
+
});
|
|
278
|
+
} finally {
|
|
279
|
+
process.exit = origExit;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
expect(exitCode).toBe(1);
|
|
283
|
+
});
|
|
284
|
+
});
|