Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sdk/typescript/src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ export class CodexExec {
commandArgs.push("--config", `approval_policy="${args.approvalPolicy}"`);
}

if (args.threadId) {
commandArgs.push("resume", args.threadId);
}

if (args.images?.length) {
for (const image of args.images) {
commandArgs.push("--image", image);
}
}

if (args.threadId) {
commandArgs.push("resume", args.threadId);
}

const env: Record<string, string> = {};
if (this.envOverride) {
Object.assign(env, this.envOverride);
Expand Down
26 changes: 26 additions & 0 deletions sdk/typescript/tests/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,30 @@ describe("CodexExec", () => {
expect(result.error.message).toMatch(/Codex Exec exited/);
}
});

it("places resume args before image args", async () => {
const { CodexExec } = await import("../src/exec");
spawnMock.mockClear();
const child = new FakeChildProcess();
spawnMock.mockReturnValue(child as unknown as child_process.ChildProcess);

setImmediate(() => {
child.stdout.end();
child.stderr.end();
child.emit("exit", 0, null);
});

const exec = new CodexExec("codex");
for await (const _ of exec.run({ input: "hi", images: ["img.png"], threadId: "thread-id" })) {
// no-op
}

const commandArgs = spawnMock.mock.calls[0]?.[1] as string[] | undefined;
expect(commandArgs).toBeDefined();
const resumeIndex = commandArgs!.indexOf("resume");
const imageIndex = commandArgs!.indexOf("--image");
expect(resumeIndex).toBeGreaterThan(-1);
expect(imageIndex).toBeGreaterThan(-1);
expect(resumeIndex).toBeLessThan(imageIndex);
});
});
Loading