|
3 | 3 | CLI_HELP_TEXT, |
4 | 4 | DOCTOR_HELP_TEXT, |
5 | 5 | MODELS_HELP_TEXT, |
| 6 | + PEEK_HELP_TEXT, |
6 | 7 | RESULT_HELP_TEXT, |
7 | 8 | RUN_HELP_TEXT, |
8 | 9 | WAIT_HELP_TEXT, |
@@ -199,6 +200,64 @@ describe('ai-cli app', () => { |
199 | 200 | expect(waitForProcesses).not.toHaveBeenCalled(); |
200 | 201 | }); |
201 | 202 |
|
| 203 | + it('dispatches peek with deduped pid arguments and time', async () => { |
| 204 | + const stdout = vi.fn(); |
| 205 | + const stderr = vi.fn(); |
| 206 | + const peekProcesses = vi.fn().mockResolvedValue({ |
| 207 | + peek_started_at: '2026-04-11T12:34:56.789Z', |
| 208 | + observed_duration_sec: 0.01, |
| 209 | + processes: [], |
| 210 | + }); |
| 211 | + |
| 212 | + const exitCode = await runCli( |
| 213 | + ['peek', '123', '456', '123', '--time', '5'], |
| 214 | + { |
| 215 | + stdout, |
| 216 | + stderr, |
| 217 | + peekProcesses, |
| 218 | + } |
| 219 | + ); |
| 220 | + |
| 221 | + expect(exitCode).toBe(0); |
| 222 | + expect(peekProcesses).toHaveBeenCalledWith([123, 456], 5); |
| 223 | + expect(stdout).toHaveBeenCalledWith(expect.stringContaining('"peek_started_at"')); |
| 224 | + expect(stderr).not.toHaveBeenCalled(); |
| 225 | + }); |
| 226 | + |
| 227 | + it('defaults peek time and rejects --follow', async () => { |
| 228 | + const stdout = vi.fn(); |
| 229 | + const stderr = vi.fn(); |
| 230 | + const peekProcesses = vi.fn().mockResolvedValue({ |
| 231 | + peek_started_at: '2026-04-11T12:34:56.789Z', |
| 232 | + observed_duration_sec: 0.01, |
| 233 | + processes: [], |
| 234 | + }); |
| 235 | + |
| 236 | + const defaultExitCode = await runCli(['peek', '123'], { stdout, stderr, peekProcesses }); |
| 237 | + expect(defaultExitCode).toBe(0); |
| 238 | + expect(peekProcesses).toHaveBeenCalledWith([123], 10); |
| 239 | + |
| 240 | + const followExitCode = await runCli(['peek', '123', '--follow'], { stdout, stderr, peekProcesses }); |
| 241 | + expect(followExitCode).toBe(1); |
| 242 | + expect(stderr).toHaveBeenCalledWith('peek does not support --follow in v1\n'); |
| 243 | + }); |
| 244 | + |
| 245 | + it('rejects invalid peek time values', async () => { |
| 246 | + const stdout = vi.fn(); |
| 247 | + const stderr = vi.fn(); |
| 248 | + const peekProcesses = vi.fn(); |
| 249 | + |
| 250 | + const exitCode = await runCli(['peek', '123', '--time', '1.5'], { |
| 251 | + stdout, |
| 252 | + stderr, |
| 253 | + peekProcesses, |
| 254 | + }); |
| 255 | + |
| 256 | + expect(exitCode).toBe(1); |
| 257 | + expect(stderr).toHaveBeenCalledWith(expect.stringContaining('peek_time_sec must be a positive integer')); |
| 258 | + expect(peekProcesses).not.toHaveBeenCalled(); |
| 259 | + }); |
| 260 | + |
202 | 261 | it('dispatches ps, result, and kill', async () => { |
203 | 262 | const stdout = vi.fn(); |
204 | 263 | const stderr = vi.fn(); |
@@ -354,6 +413,18 @@ describe('ai-cli app', () => { |
354 | 413 | expect(stderr).not.toHaveBeenCalled(); |
355 | 414 | }); |
356 | 415 |
|
| 416 | + it('prints detailed help for peek --help', async () => { |
| 417 | + const stdout = vi.fn(); |
| 418 | + const stderr = vi.fn(); |
| 419 | + |
| 420 | + const exitCode = await runCli(['peek', '--help'], { stdout, stderr }); |
| 421 | + |
| 422 | + expect(exitCode).toBe(0); |
| 423 | + expect(stdout).toHaveBeenCalledWith(PEEK_HELP_TEXT); |
| 424 | + expect(stdout).toHaveBeenCalledWith(expect.stringContaining('No --follow mode')); |
| 425 | + expect(stderr).not.toHaveBeenCalled(); |
| 426 | + }); |
| 427 | + |
357 | 428 | it('prints detailed help for models --help', async () => { |
358 | 429 | const stdout = vi.fn(); |
359 | 430 | const stderr = vi.fn(); |
|
0 commit comments