Skip to content
Open
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
17 changes: 17 additions & 0 deletions packages/server/inbox-launch-codex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ function setup(options: { state?: FakeCodexLaunchState; config?: string | null;
}

describe("Codex through the launch engine, against the fake codex", () => {
test("a provider without OpenAI auth stays eligible despite a signed-out CLI status", async () => {
const t = setup({ state: { login: "none", requiresOpenaiAuth: false } });
const block = (await t.launch.composeBlock())!;
expect(block.agents.map((agent) => agent.agent)).toContain("codex");
expect(t.fake.rpc("account/read")).toHaveLength(1);
expect(t.fake.rpc("account/rateLimits/read")).toHaveLength(0);
expect(t.fake.rpc("thread/start")).toHaveLength(0);
});

test("a failed provider account read does not bypass a signed-out CLI status", async () => {
const t = setup({ state: { login: "none", requiresOpenaiAuth: false, failAccountRead: true } });
const block = (await t.launch.composeBlock())!;
expect(block.agents.map((agent) => agent.agent)).not.toContain("codex");
expect(block.not_ready).toContainEqual({ agent: "codex", name: "Codex", code: "signed_out" });
expect(t.fake.rpc("account/read")).toHaveLength(1);
});

test("To offers Codex only once codex is there, signed in and connected to the Inbox", async () => {
const ready = setup();
expect((await ready.launch.composeBlock())!.agents.map((a) => a.agent)).toContain("codex");
Expand Down
16 changes: 14 additions & 2 deletions packages/server/inbox-launch-codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { agentVersionRun, codexHome, createAgentEnvironmentFor, INBOX_MCP_SERVER
import { LAUNCH_CHOICES_RUN_MS, launchChoiceCache, type LaunchChoiceLists } from "./inbox-launch-choice";
import { shellQuote, versionAtLeast } from "./inbox-launch-claude";
import { createCodexPermissions, CODEX_APPROVALS } from "./inbox-launch-codex-permission";
import { createInboxCodexAccount } from "./inbox-codex-account";
import { launchSpawnEnv, type LaunchEnv } from "./inbox-launch-env";
import { launchNoteText, launchTurnErrorNote, writeLaunchNote, type LaunchAvailability, type LaunchDelivery, type LaunchHost, type LaunchHostContext, type LaunchHostResult, type LaunchLive, type LaunchPermissionContext } from "./inbox-launch-host";

Expand Down Expand Up @@ -661,7 +662,7 @@ export function createCodexLaunchHost(ctx: LaunchHostContext, options: { readyMs

/**
* `codex` on the plain env's PATH and new enough, the person's Codex has Plannotator's Inbox MCP entry (it is
* how a Codex session answers in the Inbox), and Codex has a login (`codex login status`, local only).
* how a Codex session answers in the Inbox), and Codex has a login or a provider that requires no OpenAI account.
*/
async available(): Promise<LaunchAvailability> {
const e = await ctx.environment();
Expand All @@ -675,7 +676,18 @@ export function createCodexLaunchHost(ctx: LaunchHostContext, options: { readyMs
choiceKey = `${path}@${shown}`;
const home = homeEnv();
const status = await e.run([path, "login", "status"], { timeoutMs: 10_000, ...(home ? { env: { CODEX_HOME: home } } : {}) });
if (codexLoginStatusSignedOut(status)) return { ok: false, missing: false, reason: "Codex isn't signed in", code: "signed_out" };
if (codexLoginStatusSignedOut(status)) {
const account = createInboxCodexAccount({
environment: () => createAgentEnvironmentFor({ platform: ctx.platform, homeDir: ctx.homeDir, env: { ...e.env, ...(home ? { CODEX_HOME: home } : {}) } }),
dataDir: ctx.dataDir,
extraClis: [],
});
try {
if ((await account.read()).state !== "signed_in") return { ok: false, missing: false, reason: "Codex isn't signed in", code: "signed_out" };
} finally {
account.stop();
}
}
return { ok: true, version: shown };
},

Expand Down
7 changes: 6 additions & 1 deletion tests/helpers/fake-codex-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface FakeCodexLaunchState {
version?: string;
/** `codex login status` and `account/read`: signed in with ChatGPT (the default), an API key, or not at all. */
login?: "chatgpt" | "apikey" | "none";
/** Whether the selected provider requires an OpenAI account. */
requiresOpenaiAuth?: boolean;
/** Reject the account read while leaving the CLI status available. */
failAccountRead?: boolean;
/** `account/read`'s plan. */
plan?: string;
/** `account/rateLimits/read`'s `rateLimits`, or "fail". */
Expand Down Expand Up @@ -151,8 +155,9 @@ function handle(msg) {
return reply({ data: models.map((m, i) => ({ id: m.id, model: m.id, displayName: m.id, hidden: !!m.hidden, isDefault: i === 0, supportedReasoningEfforts: m.efforts.map((e) => ({ reasoningEffort: e, description: e })), defaultReasoningEffort: m.efforts[0] })), nextCursor: null });
}
case "account/read": {
if (now.failAccountRead) return fail("account unavailable");
const login = now.login || "chatgpt";
return reply({ account: login === "none" ? null : login === "apikey" ? { type: "apiKey" } : { type: "chatgpt", email: "someone@example.com", planType: now.plan || "plus" }, requiresOpenaiAuth: true });
return reply({ account: login === "none" ? null : login === "apikey" ? { type: "apiKey" } : { type: "chatgpt", email: "someone@example.com", planType: now.plan || "plus" }, requiresOpenaiAuth: now.requiresOpenaiAuth ?? true });
}
case "account/rateLimits/read": {
if (now.rateLimits === "fail" || (now.login || "chatgpt") !== "chatgpt") return fail("chatgpt authentication required to read rate limits");
Expand Down