| 169 | // --- Group 2: Version check ------------------------------------------------- |
| 170 | // Stub `codex --version` by putting a fake `codex` executable on PATH. |
| 171 | function tempStubCodex(versionOutput: string, bool_command_fails = false): { |
| 172 | dir: string; |
| 173 | pathEntry: string; |
| 174 | } { |
| 175 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-codex-stub-')); |
| 176 | const bin = path.join(dir, 'codex'); |
| 177 | const script = bool_command_fails |
| 178 | ? '#!/bin/bash\nexit 1\n' |
| 179 | : `#!/bin/bash\nif [ "$1" = "--version" ]; then printf '%s' ${JSON.stringify(versionOutput)}; fi\n`; |
| 180 | fs.writeFileSync(bin, script); |
| 181 | fs.chmodSync(bin, 0o755); |
| 182 | return { dir, pathEntry: dir }; |
| 183 | } |
| 184 | |
| 185 | function runVersionCheck(versionOutput: string): string { |
| 186 | const stub = tempStubCodex(versionOutput); |