|
11 | 11 | // host-installed codex can never shadow it, #694.) |
12 | 12 | // partial output. |
13 | 13 | import assert from 'node:assert/strict'; |
14 | | -import { spawn, execFileSync } from 'node:child_process'; |
| 14 | +import { spawn, execFile, execFileSync } from 'node:child_process'; |
15 | 15 | import crypto from 'node:crypto'; |
16 | 16 | import fs from 'node:fs'; |
17 | 17 | import net from 'node:net'; |
@@ -23,6 +23,13 @@ import { fileURLToPath } from 'node:url'; |
23 | 23 | const binDir = path.dirname(fileURLToPath(import.meta.url)); |
24 | 24 |
|
25 | 25 | const STUB = `#!/bin/sh |
| 26 | +# The proxy runs this through execFile before accepting chat turns. Handle it |
| 27 | +# before reading stdin: execFile leaves the child's stdin open, so cat would |
| 28 | +# otherwise wait for the 30-second command timeout on every request. |
| 29 | +if [ "$1" = "debug" ] && [ "$2" = "models" ]; then |
| 30 | + printf '%s\\n' '{"models":[{"slug":"gpt-6.1-sol","display_name":"GPT-6.1 Sol","supported_reasoning_levels":[{"effort":"low"},{"effort":"medium"},{"effort":"high"}],"default_reasoning_level":"medium"},{"slug":"gpt-6-luna","display_name":"GPT-6 Luna","supported_reasoning_levels":[{"effort":"low"},{"effort":"medium"}],"default_reasoning_level":"low"},{"slug":"gpt-5.6-luna","display_name":"GPT-5.6 Luna","supported_reasoning_levels":[{"effort":"low"},{"effort":"medium"}],"default_reasoning_level":"low"}]}' |
| 31 | + exit 0 |
| 32 | +fi |
26 | 33 | prompt="$(cat)" |
27 | 34 | resume=0 |
28 | 35 | for a in "$@"; do [ "$a" = "resume" ] && resume=1; done |
@@ -78,6 +85,27 @@ case "$prompt" in |
78 | 85 | esac |
79 | 86 | `; |
80 | 87 |
|
| 88 | +test('Codex stub answers live model lookup without blocking on stdin', async (t) => { |
| 89 | + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'codex-proxy-stub-test-')); |
| 90 | + t.after(() => fs.rmSync(tmp, { recursive: true, force: true })); |
| 91 | + const stubPath = path.join(tmp, 'codex'); |
| 92 | + fs.writeFileSync(stubPath, STUB, { mode: 0o755 }); |
| 93 | + |
| 94 | + const stdout = await new Promise((resolve, reject) => { |
| 95 | + execFile(stubPath, ['debug', 'models'], { timeout: 1000 }, (err, out, stderr) => { |
| 96 | + if (err) { |
| 97 | + reject(new Error(`codex debug models stub failed: ${err.message}; stderr=${stderr}`)); |
| 98 | + } else { |
| 99 | + resolve(out); |
| 100 | + } |
| 101 | + }); |
| 102 | + }); |
| 103 | + const catalog = JSON.parse(stdout); |
| 104 | + assert.ok(Array.isArray(catalog.models)); |
| 105 | + assert.ok(catalog.models.length >= 3); |
| 106 | + assert.ok(catalog.models.some((model) => model.slug === 'gpt-6.1-sol')); |
| 107 | +}); |
| 108 | + |
81 | 109 |
|
82 | 110 | // --------------------------------------------------------------------------- |
83 | 111 | // Fake app-server daemon (#480): a real WebSocket-over-Unix-socket server |
|