|
1 | 1 | import path from "path"; |
2 | 2 |
|
| 3 | +import { codexExecSpy } from "./codexExecSpy"; |
3 | 4 | import { describe, expect, it } from "@jest/globals"; |
4 | 5 |
|
5 | 6 | import { Codex } from "../src/codex"; |
@@ -130,4 +131,56 @@ describe("Codex", () => { |
130 | 131 | await close(); |
131 | 132 | } |
132 | 133 | }); |
| 134 | + |
| 135 | + it("passes turn options to exec", async () => { |
| 136 | + const { url, close, requests } = await startResponsesTestProxy({ |
| 137 | + statusCode: 200, |
| 138 | + responseBodies: [ |
| 139 | + sse( |
| 140 | + responseStarted("response_1"), |
| 141 | + assistantMessage("Turn options applied", "item_1"), |
| 142 | + responseCompleted("response_1"), |
| 143 | + ), |
| 144 | + ], |
| 145 | + }); |
| 146 | + |
| 147 | + const { args: spawnArgs, restore } = codexExecSpy(); |
| 148 | + |
| 149 | + try { |
| 150 | + const client = new Codex({ executablePath: codexExecPath, baseUrl: url, apiKey: "test" }); |
| 151 | + |
| 152 | + const thread = client.startThread(); |
| 153 | + await thread.run("apply options", { |
| 154 | + model: "gpt-test-1", |
| 155 | + sandboxMode: "workspace-write", |
| 156 | + }); |
| 157 | + |
| 158 | + const payload = requests[0]; |
| 159 | + expect(payload).toBeDefined(); |
| 160 | + const json = payload!.json as { model?: string } | undefined; |
| 161 | + |
| 162 | + expect(json?.model).toBe("gpt-test-1"); |
| 163 | + expect(spawnArgs.length).toBeGreaterThan(0); |
| 164 | + const commandArgs = spawnArgs[0]; |
| 165 | + |
| 166 | + expectPair(commandArgs, ["--sandbox", "workspace-write"]); |
| 167 | + expectPair(commandArgs, ["--model", "gpt-test-1"]); |
| 168 | + |
| 169 | + } finally { |
| 170 | + restore(); |
| 171 | + await close(); |
| 172 | + } |
| 173 | + }); |
133 | 174 | }); |
| 175 | + |
| 176 | + |
| 177 | +function expectPair(args: string[] | undefined, pair: [string, string]) { |
| 178 | + if (!args) { |
| 179 | + throw new Error("Args is undefined"); |
| 180 | + } |
| 181 | + const index = args.indexOf(pair[0]); |
| 182 | + if (index === -1) { |
| 183 | + throw new Error(`Pair ${pair[0]} not found in args`); |
| 184 | + } |
| 185 | + expect(args[index + 1]).toBe(pair[1]); |
| 186 | +} |
0 commit comments