| 71 | } |
| 72 | |
| 73 | export function spawnReplPtyFixture(options?: { |
| 74 | readonly prefix?: string |
| 75 | readonly columns?: number |
| 76 | readonly lines?: number |
| 77 | readonly scenario?: ReplPtyFixtureScenario |
| 78 | }): ReplPtyFixture { |
| 79 | const tmpDir = mkdtempSync( |
| 80 | join(tmpdir(), options?.prefix ?? 'code-repl-pty-fixture-'), |
| 81 | ) |
| 82 | const readyPath = join(tmpDir, 'ready') |
| 83 | const frameLogPath = join(tmpDir, 'frames.jsonl') |
| 84 | const rawOutputPath = join(tmpDir, 'raw-output.log') |
| 85 | const scenarioPath = options?.scenario |
| 86 | ? join(tmpDir, 'scenario.json') |
| 87 | : undefined |
| 88 | |
| 89 | if (scenarioPath) { |
| 90 | writeFileSync( |
| 91 | scenarioPath, |
| 92 | JSON.stringify(options.scenario, null, 2), |
| 93 | 'utf8', |
| 94 | ) |
| 95 | } |
| 96 | |
| 97 | const session = spawnPtyContractSession( |
| 98 | buildFixtureArgs({ |
| 99 | readyPath, |
| 100 | frameLogPath, |
| 101 | rawOutputPath, |
| 102 | scenarioPath, |
| 103 | }), |
| 104 | { |
| 105 | cwd: TEST_CODE_DIR, |
| 106 | env: { |
| 107 | TMPDIR: TEST_TMPDIR, |
| 108 | }, |
| 109 | columns: options?.columns ?? 120, |
| 110 | lines: options?.lines ?? 40, |
| 111 | }, |
| 112 | ) |
| 113 | |
| 114 | return { |
| 115 | tmpDir, |
| 116 | readyPath, |
| 117 | frameLogPath, |
| 118 | rawOutputPath, |
| 119 | scenarioPath, |
| 120 | session, |
| 121 | cleanup() { |
| 122 | rmSync(tmpDir, { recursive: true, force: true }) |
| 123 | }, |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | export async function waitForReplPtyPrompt( |
| 128 | session: PtyContractSession, |