* Run the built CLI's `prompt-hook` in `dir` with a UserPromptSubmit payload * shaped like the one Claude Code sends, and return what it injects.
(dir: string, prompt: string)
| 40 | * shaped like the one Claude Code sends, and return what it injects. |
| 41 | */ |
| 42 | function runPromptHook(dir: string, prompt: string): string { |
| 43 | const payload = { |
| 44 | session_id: '0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f0', |
| 45 | transcript_path: path.join(dir, 'transcript.jsonl'), |
| 46 | cwd: dir, |
| 47 | permission_mode: 'default', |
| 48 | hook_event_name: 'UserPromptSubmit', |
| 49 | prompt, |
| 50 | }; |
| 51 | const result = spawnSync(process.execPath, [path.resolve(__dirname, '../dist/bin/codegraph.js'), 'prompt-hook'], { |
| 52 | cwd: dir, |
| 53 | input: JSON.stringify(payload), |
| 54 | encoding: 'utf8', |
| 55 | timeout: 15_000, |
| 56 | env: { |
| 57 | ...process.env, |
| 58 | CODEGRAPH_TELEMETRY: '0', DO_NOT_TRACK: '1', CODEGRAPH_NO_DAEMON: '1', |
| 59 | CODEGRAPH_NO_RELAUNCH: '1', CODEGRAPH_WASM_RELAUNCHED: '1', |
| 60 | // Enable only the hook subprocess under test. |
| 61 | CODEGRAPH_NO_PROMPT_HOOK: '0', CODEGRAPH_PROMPT_HOOK: '1', |
| 62 | }, |
| 63 | }); |
| 64 | expect(result.error).toBeUndefined(); |
| 65 | expect(result.status, result.stderr).toBe(0); |
| 66 | return result.stdout; |
| 67 | } |
| 68 | |
| 69 | describe('planFrontload — front-load hook project resolution (#964)', () => { |
| 70 | let tmp: string; |