(initial: DaemonRecord[], choices: unknown[])
| 48 | describe('runDaemonPicker', () => { |
| 49 | // A fake registry whose list shrinks as daemons are stopped (like the real one). |
| 50 | function harness(initial: DaemonRecord[], choices: unknown[]) { |
| 51 | let daemons = [...initial]; |
| 52 | const stopped: string[] = []; |
| 53 | const notes: string[] = []; |
| 54 | let doneMsg = ''; |
| 55 | let i = 0; |
| 56 | const CANCEL_SYMBOL = Symbol('cancel'); |
| 57 | const deps: PickerDeps = { |
| 58 | list: () => daemons, |
| 59 | stop: async (root): Promise<StopResult> => { |
| 60 | daemons = daemons.filter((d) => d.root !== root); |
| 61 | stopped.push(root); |
| 62 | return { root, pid: 0, outcome: 'term' }; |
| 63 | }, |
| 64 | stopAll: async (): Promise<StopResult[]> => { |
| 65 | const all = daemons.map((d) => ({ root: d.root, pid: d.pid, outcome: 'term' as const })); |
| 66 | daemons = []; |
| 67 | stopped.push('ALL'); |
| 68 | return all; |
| 69 | }, |
| 70 | cwdRoot: null, |
| 71 | now: () => 5000, |
| 72 | select: async () => choices[i++], |
| 73 | isCancel: (v) => v === CANCEL_SYMBOL, |
| 74 | note: (m) => notes.push(m), |
| 75 | done: (m) => { doneMsg = m; }, |
| 76 | }; |
| 77 | return { deps, stopped, notes, getDone: () => doneMsg, CANCEL_SYMBOL }; |
| 78 | } |
| 79 | |
| 80 | it('stops the chosen daemon, then re-prompts and exits on Cancel', async () => { |
| 81 | const h = harness([rec('/p/a', 1, 1), rec('/p/b', 2, 2)], ['/p/b', CANCEL]); |
no test coverage detected