(name: string)
| 5 | /** Copy a fixture session into a temp dir, rewriting state.json.agents.*.homedir |
| 6 | * to the real path so wire-reader / agent-tree can resolve them. */ |
| 7 | export async function buildSessionFixture(name: string): Promise<{ |
| 8 | home: string; |
| 9 | sessionDir: string; |
| 10 | cleanup: () => Promise<void>; |
| 11 | }> { |
| 12 | const src = new URL(`./sessions/${name}`, import.meta.url).pathname; |
| 13 | const home = await mkdtemp(); |
| 14 | const sessionsDir = join(home, 'sessions', 'wd_test_000000000000'); |
| 15 | const sessionDir = join(sessionsDir, 'session_fixture'); |
| 16 | await mkdir(sessionsDir, { recursive: true }); |
| 17 | await cp(src, sessionDir, { recursive: true }); |
| 18 | |
| 19 | // Rewrite homedir placeholders. |
| 20 | const statePath = join(sessionDir, 'state.json'); |
| 21 | const state = JSON.parse(await readFile(statePath, 'utf8')); |
| 22 | for (const id of Object.keys(state.agents)) { |
| 23 | state.agents[id].homedir = join(sessionDir, 'agents', id); |
| 24 | } |
| 25 | await writeFile(statePath, JSON.stringify(state, null, 2)); |
| 26 | |
| 27 | // Write session_index.jsonl. |
| 28 | await writeFile( |
| 29 | join(home, 'session_index.jsonl'), |
| 30 | JSON.stringify({ |
| 31 | sessionId: 'session_fixture', |
| 32 | sessionDir, |
| 33 | workDir: '/tmp/work', |
| 34 | }) + '\n', |
| 35 | ); |
| 36 | |
| 37 | return { |
| 38 | home, |
| 39 | sessionDir, |
| 40 | cleanup: () => rm(home, { recursive: true, force: true }), |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | async function mkdtemp(): Promise<string> { |
| 45 | const base = join(tmpdir(), `vis-fixture-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`); |
no test coverage detected