@principles/pd-cli 1.112.0 → 1.113.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.
Files changed (26) hide show
  1. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +24 -0
  2. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +1 -0
  3. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +223 -0
  4. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +1 -0
  5. package/dist/commands/runtime-internalization-run-rulehost.d.ts +23 -0
  6. package/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -0
  7. package/dist/commands/runtime-internalization-run-rulehost.js +364 -0
  8. package/dist/commands/runtime-internalization-run-rulehost.js.map +1 -0
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/services/demo-rule-compiler.d.ts +24 -0
  12. package/dist/services/demo-rule-compiler.d.ts.map +1 -0
  13. package/dist/services/demo-rule-compiler.js +53 -0
  14. package/dist/services/demo-rule-compiler.js.map +1 -0
  15. package/dist/services/rulehost-pipeline-runner.d.ts +124 -0
  16. package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -0
  17. package/dist/services/rulehost-pipeline-runner.js +334 -0
  18. package/dist/services/rulehost-pipeline-runner.js.map +1 -0
  19. package/package.json +1 -1
  20. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +280 -0
  21. package/src/commands/runtime-internalization-run-rulehost.ts +417 -0
  22. package/src/index.ts +3 -0
  23. package/src/services/demo-rule-compiler.ts +71 -0
  24. package/src/services/rulehost-pipeline-runner.ts +585 -0
  25. package/tests/services/rulehost-pipeline-e2e.test.ts +477 -0
  26. package/tests/services/rulehost-pipeline-runner.test.ts +519 -0
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Parser-level tests for `pd runtime internalization run-rulehost` flags (PRI-429).
3
+ *
4
+ * CLI gate rule 7: "Test the real command wiring — when behavior depends on
5
+ * Commander options, add a command-registration or parser test that exercises
6
+ * the actual flags."
7
+ *
8
+ * Tests the real `registerRunRuleHostCommand` helper (single source of truth
9
+ * shared with `index.ts`). Flag typos in production surface here at
10
+ * parseAsync time, not at handler dispatch.
11
+ *
12
+ * Covers:
13
+ * - --dry-run and --confirm are registered
14
+ * - --dry-run and --confirm can both be parsed
15
+ * - --json is registered
16
+ * - --pain-id is required (Commander rejects missing required option)
17
+ * - --workspace / -w shorthand is registered
18
+ * - --no-dry-run / --no-confirm are NOT registered (no accidental negation)
19
+ * - mutual exclusivity is enforced at handler level (not parser level —
20
+ * Commander doesn't natively support .conflicts() for boolean flags
21
+ * without explicit registration; the handler validates this)
22
+ */
23
+
24
+ import { describe, it, expect } from 'vitest';
25
+ import { Command } from 'commander';
26
+ import { registerRunRuleHostCommand } from '../runtime-internalization-run-rulehost.js';
27
+
28
+ type ActionOptions = Record<string, unknown>;
29
+
30
+ interface CapturedAction {
31
+ opts: ActionOptions | null;
32
+ }
33
+
34
+ function attachCapture(cmd: Command, state: CapturedAction): void {
35
+ cmd.action(function captureAction(...args: unknown[]): void {
36
+ let optsArg: unknown = null;
37
+ for (let i = args.length - 1; i >= 0; i--) {
38
+ const arg: unknown = args[i];
39
+ if (arg !== null && typeof arg === 'object' && !(arg instanceof Command)) {
40
+ optsArg = arg;
41
+ break;
42
+ }
43
+ }
44
+ if (optsArg !== null && typeof optsArg === 'object') {
45
+ state.opts = optsArg as ActionOptions;
46
+ } else {
47
+ state.opts = {};
48
+ }
49
+ });
50
+ }
51
+
52
+ function freshProgram(): Command {
53
+ const program = new Command();
54
+ program.name('pd').exitOverride();
55
+ return program;
56
+ }
57
+
58
+ describe('pd runtime internalization run-rulehost — flag wiring (CLI gate rule 7)', () => {
59
+ // ── Option metadata ──────────────────────────────────────────────────────
60
+
61
+ it('registers --dry-run flag', () => {
62
+ const program = freshProgram();
63
+ const intCmd = program.command('internalization');
64
+ const runCmd = registerRunRuleHostCommand(intCmd);
65
+
66
+ const opt = runCmd.options.find((o) => o.long === '--dry-run');
67
+ expect(opt).toBeDefined();
68
+ expect(opt?.long).toBe('--dry-run');
69
+ });
70
+
71
+ it('registers --confirm flag', () => {
72
+ const program = freshProgram();
73
+ const intCmd = program.command('internalization');
74
+ const runCmd = registerRunRuleHostCommand(intCmd);
75
+
76
+ const opt = runCmd.options.find((o) => o.long === '--confirm');
77
+ expect(opt).toBeDefined();
78
+ expect(opt?.long).toBe('--confirm');
79
+ });
80
+
81
+ it('registers --json flag', () => {
82
+ const program = freshProgram();
83
+ const intCmd = program.command('internalization');
84
+ const runCmd = registerRunRuleHostCommand(intCmd);
85
+
86
+ const opt = runCmd.options.find((o) => o.long === '--json');
87
+ expect(opt).toBeDefined();
88
+ expect(opt?.long).toBe('--json');
89
+ });
90
+
91
+ it('registers --pain-id as required option', () => {
92
+ const program = freshProgram();
93
+ const intCmd = program.command('internalization');
94
+ const runCmd = registerRunRuleHostCommand(intCmd);
95
+
96
+ const opt = runCmd.options.find((o) => o.long === '--pain-id');
97
+ expect(opt).toBeDefined();
98
+ expect(opt?.long).toBe('--pain-id');
99
+ // requiredOption sets .required = true on the Option
100
+ expect(opt?.required).toBe(true);
101
+ });
102
+
103
+ it('registers -w shorthand for --workspace', () => {
104
+ const program = freshProgram();
105
+ const intCmd = program.command('internalization');
106
+ const runCmd = registerRunRuleHostCommand(intCmd);
107
+
108
+ const opt = runCmd.options.find((o) => o.short === '-w');
109
+ expect(opt).toBeDefined();
110
+ expect(opt?.long).toBe('--workspace');
111
+ });
112
+
113
+ it('does NOT register --no-dry-run (no accidental negation)', () => {
114
+ const program = freshProgram();
115
+ const intCmd = program.command('internalization');
116
+ const runCmd = registerRunRuleHostCommand(intCmd);
117
+
118
+ const noForm = runCmd.options.find((o) => o.long === '--no-dry-run');
119
+ expect(noForm).toBeUndefined();
120
+ });
121
+
122
+ it('does NOT register --no-confirm (no accidental negation)', () => {
123
+ const program = freshProgram();
124
+ const intCmd = program.command('internalization');
125
+ const runCmd = registerRunRuleHostCommand(intCmd);
126
+
127
+ const noForm = runCmd.options.find((o) => o.long === '--no-confirm');
128
+ expect(noForm).toBeUndefined();
129
+ });
130
+
131
+ // ── Parser-level tests (program.parseAsync) ───────────────────────────────
132
+
133
+ it('parses --dry-run as true', async () => {
134
+ const program = freshProgram();
135
+ const intCmd = program.command('internalization');
136
+ const runCmd = registerRunRuleHostCommand(intCmd);
137
+ const captured: CapturedAction = { opts: null };
138
+ attachCapture(runCmd, captured);
139
+
140
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '--dry-run']);
141
+
142
+ expect(captured.opts).not.toBeNull();
143
+ expect(captured.opts?.dryRun).toBe(true);
144
+ });
145
+
146
+ it('parses --confirm as true', async () => {
147
+ const program = freshProgram();
148
+ const intCmd = program.command('internalization');
149
+ const runCmd = registerRunRuleHostCommand(intCmd);
150
+ const captured: CapturedAction = { opts: null };
151
+ attachCapture(runCmd, captured);
152
+
153
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '--confirm']);
154
+
155
+ expect(captured.opts).not.toBeNull();
156
+ expect(captured.opts?.confirm).toBe(true);
157
+ });
158
+
159
+ it('parses both --dry-run and --confirm (handler enforces mutual exclusivity)', async () => {
160
+ // Commander parses both flags; the handler validates mutual exclusivity.
161
+ // This test proves the parser accepts both — the handler test in
162
+ // rulehost-pipeline-e2e.test.ts proves the handler rejects the combination.
163
+ const program = freshProgram();
164
+ const intCmd = program.command('internalization');
165
+ const runCmd = registerRunRuleHostCommand(intCmd);
166
+ const captured: CapturedAction = { opts: null };
167
+ attachCapture(runCmd, captured);
168
+
169
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '--dry-run', '--confirm']);
170
+
171
+ expect(captured.opts).not.toBeNull();
172
+ expect(captured.opts?.dryRun).toBe(true);
173
+ expect(captured.opts?.confirm).toBe(true);
174
+ });
175
+
176
+ it('defaults --dry-run and --confirm to undefined when neither is passed', async () => {
177
+ const program = freshProgram();
178
+ const intCmd = program.command('internalization');
179
+ const runCmd = registerRunRuleHostCommand(intCmd);
180
+ const captured: CapturedAction = { opts: null };
181
+ attachCapture(runCmd, captured);
182
+
183
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1']);
184
+
185
+ expect(captured.opts).not.toBeNull();
186
+ expect(captured.opts?.dryRun).toBeUndefined();
187
+ expect(captured.opts?.confirm).toBeUndefined();
188
+ });
189
+
190
+ it('parses --json as true', async () => {
191
+ const program = freshProgram();
192
+ const intCmd = program.command('internalization');
193
+ const runCmd = registerRunRuleHostCommand(intCmd);
194
+ const captured: CapturedAction = { opts: null };
195
+ attachCapture(runCmd, captured);
196
+
197
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '--json']);
198
+
199
+ expect(captured.opts).not.toBeNull();
200
+ expect(captured.opts?.json).toBe(true);
201
+ });
202
+
203
+ it('parses -w shorthand for --workspace', async () => {
204
+ const program = freshProgram();
205
+ const intCmd = program.command('internalization');
206
+ const runCmd = registerRunRuleHostCommand(intCmd);
207
+ const captured: CapturedAction = { opts: null };
208
+ attachCapture(runCmd, captured);
209
+
210
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '-w', '/tmp/test']);
211
+
212
+ expect(captured.opts).not.toBeNull();
213
+ expect(captured.opts?.workspace).toBe('/tmp/test');
214
+ });
215
+
216
+ it('rejects missing --pain-id (required option)', async () => {
217
+ const program = freshProgram();
218
+ const intCmd = program.command('internalization');
219
+ registerRunRuleHostCommand(intCmd);
220
+
221
+ // Commander should throw on missing required option
222
+ await expect(
223
+ program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--dry-run']),
224
+ ).rejects.toThrow(/pain-id/);
225
+ });
226
+
227
+ it('parses --channel with custom value', async () => {
228
+ const program = freshProgram();
229
+ const intCmd = program.command('internalization');
230
+ const runCmd = registerRunRuleHostCommand(intCmd);
231
+ const captured: CapturedAction = { opts: null };
232
+ attachCapture(runCmd, captured);
233
+
234
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '--channel', 'prompt']);
235
+
236
+ expect(captured.opts).not.toBeNull();
237
+ expect(captured.opts?.channel).toBe('prompt');
238
+ });
239
+
240
+ it('defaults --channel to code_tool_hook', async () => {
241
+ const program = freshProgram();
242
+ const intCmd = program.command('internalization');
243
+ const runCmd = registerRunRuleHostCommand(intCmd);
244
+ const captured: CapturedAction = { opts: null };
245
+ attachCapture(runCmd, captured);
246
+
247
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1']);
248
+
249
+ expect(captured.opts).not.toBeNull();
250
+ expect(captured.opts?.channel).toBe('code_tool_hook');
251
+ });
252
+
253
+ it('parses --max-rounds as integer', async () => {
254
+ const program = freshProgram();
255
+ const intCmd = program.command('internalization');
256
+ const runCmd = registerRunRuleHostCommand(intCmd);
257
+ const captured: CapturedAction = { opts: null };
258
+ attachCapture(runCmd, captured);
259
+
260
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '--max-rounds', '2']);
261
+
262
+ expect(captured.opts).not.toBeNull();
263
+ expect(captured.opts?.maxRounds).toBe(2);
264
+ expect(typeof captured.opts?.maxRounds).toBe('number');
265
+ });
266
+
267
+ it('parses --timeout-ms as integer', async () => {
268
+ const program = freshProgram();
269
+ const intCmd = program.command('internalization');
270
+ const runCmd = registerRunRuleHostCommand(intCmd);
271
+ const captured: CapturedAction = { opts: null };
272
+ attachCapture(runCmd, captured);
273
+
274
+ await program.parseAsync(['node', 'pd', 'internalization', 'run-rulehost', '--pain-id', 'pain-1', '--timeout-ms', '600000']);
275
+
276
+ expect(captured.opts).not.toBeNull();
277
+ expect(captured.opts?.timeoutMs).toBe(600000);
278
+ expect(typeof captured.opts?.timeoutMs).toBe('number');
279
+ });
280
+ });