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
7 changes: 7 additions & 0 deletions src/plugins/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
// The acknowledged bundle is read back from the JSONL stream when codex
// echoes its configuration (session_configured / turn context events).
//
// Service tier: `-c service_tier=default`, always. "default" is codex's
// sentinel for standard routing: the model catalog can name a faster,
// pricier tier as a model's default, and the sentinel keeps it from
// applying. The caller can't pick a tier; a turn never spends more quota
// than it would on the standard tier.
//
// Posture: `--dangerously-bypass-approvals-and-sandbox` — codex's own
// validated non-interactive full-access mode; no approval prompt exists in
// exec mode with it. `--skip-git-repo-check` keeps non-repo cwds working.
Expand Down Expand Up @@ -121,6 +127,7 @@ export const codexPlugin: Plugin = {
"--json",
"-m", ctx.model,
"-c", `model_reasoning_effort=${ctx.effort}`,
"-c", "service_tier=default",
"--dangerously-bypass-approvals-and-sandbox",
"--skip-git-repo-check",
"--output-last-message", lastMessageFile,
Expand Down
48 changes: 48 additions & 0 deletions test/codex.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// test/codex.test.ts — codex launch argv, offline. The "harness" is a
// stand-in binary that exits at once; only the recorded spawn argv matters.

import test from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";

import { codexPlugin } from "../src/plugins/codex.ts";
import type { LaunchContext } from "../src/plugins/types.ts";

const sessionDir = mkdtempSync(path.join(tmpdir(), "subturn-codex-session-"));

test.after(() => rmSync(sessionDir, { recursive: true, force: true }));

async function launchArgv(nativeSessionId?: string): Promise<string[]> {
let argv: string[] = [];
const ctx: LaunchContext = {
binPath: process.execPath,
model: "some-model",
effort: "low",
prompt: "hi",
cwd: sessionDir,
sessionDir,
turn: nativeSessionId === undefined ? 1 : 2,
nativeSessionId,
deadlineMs: Date.now() + 30_000,
env: {},
emit: (event) => {
if (event["type"] === "spawn") argv = event["argv"] as string[];
},
writeEvidence: () => {},
onChildPid: () => {},
onNativeSessionId: () => {},
};
await codexPlugin.launch(ctx);
return argv;
}

const hasPair = (argv: string[], flag: string, value: string): boolean =>
argv.some((a, i) => a === flag && argv[i + 1] === value);

test("every codex turn pins the standard service tier", async () => {
for (const argv of [await launchArgv(), await launchArgv("some-session")]) {
assert.ok(hasPair(argv, "-c", "service_tier=default"), `argv: ${JSON.stringify(argv)}`);
}
});
Loading