test(codex): add coverage for native auth detection in environment probe
Add tests for codex_native_auth_present and codex_openai_api_key_missing code paths. Also pass adapter-configured CODEX_HOME through to readCodexAuthInfo so the probe respects per-adapter home directories. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a9dcea023b
commit
06b85d62b2
3 changed files with 65 additions and 3 deletions
|
|
@ -107,8 +107,8 @@ function parsePlanAndEmailFromToken(idToken: string | null, accessToken: string
|
||||||
return { email: null, planType: null };
|
return { email: null, planType: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function readCodexAuthInfo(): Promise<CodexAuthInfo | null> {
|
export async function readCodexAuthInfo(codexHome?: string): Promise<CodexAuthInfo | null> {
|
||||||
const authPath = path.join(codexHomeDir(), "auth.json");
|
const authPath = path.join(codexHome ?? codexHomeDir(), "auth.json");
|
||||||
let raw: string;
|
let raw: string;
|
||||||
try {
|
try {
|
||||||
raw = await fs.readFile(authPath, "utf8");
|
raw = await fs.readFile(authPath, "utf8");
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,8 @@ export async function testEnvironment(
|
||||||
detail: `Detected in ${source}.`,
|
detail: `Detected in ${source}.`,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const codexAuth = await readCodexAuthInfo().catch(() => null);
|
const codexHome = isNonEmpty(env.CODEX_HOME) ? env.CODEX_HOME : undefined;
|
||||||
|
const codexAuth = await readCodexAuthInfo(codexHome).catch(() => null);
|
||||||
if (codexAuth) {
|
if (codexAuth) {
|
||||||
checks.push({
|
checks.push({
|
||||||
code: "codex_native_auth_present",
|
code: "codex_native_auth_present",
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,67 @@ describe("codex_local environment diagnostics", () => {
|
||||||
await fs.rm(path.dirname(cwd), { recursive: true, force: true });
|
await fs.rm(path.dirname(cwd), { recursive: true, force: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits codex_native_auth_present when ~/.codex/auth.json exists and OPENAI_API_KEY is unset", async () => {
|
||||||
|
const root = path.join(
|
||||||
|
os.tmpdir(),
|
||||||
|
`paperclip-codex-auth-${Date.now()}-${Math.random().toString(16).slice(2)}`,
|
||||||
|
);
|
||||||
|
const codexHome = path.join(root, ".codex");
|
||||||
|
const cwd = path.join(root, "workspace");
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.mkdir(codexHome, { recursive: true });
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(codexHome, "auth.json"),
|
||||||
|
JSON.stringify({ accessToken: "fake-token", accountId: "acct-1" }),
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await testEnvironment({
|
||||||
|
companyId: "company-1",
|
||||||
|
adapterType: "codex_local",
|
||||||
|
config: {
|
||||||
|
command: process.execPath,
|
||||||
|
cwd,
|
||||||
|
env: { CODEX_HOME: codexHome },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.checks.some((check) => check.code === "codex_native_auth_present")).toBe(true);
|
||||||
|
expect(result.checks.some((check) => check.code === "codex_openai_api_key_missing")).toBe(false);
|
||||||
|
} finally {
|
||||||
|
await fs.rm(root, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("emits codex_openai_api_key_missing when neither env var nor native auth exists", async () => {
|
||||||
|
const root = path.join(
|
||||||
|
os.tmpdir(),
|
||||||
|
`paperclip-codex-noauth-${Date.now()}-${Math.random().toString(16).slice(2)}`,
|
||||||
|
);
|
||||||
|
const codexHome = path.join(root, ".codex");
|
||||||
|
const cwd = path.join(root, "workspace");
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.mkdir(codexHome, { recursive: true });
|
||||||
|
// No auth.json written
|
||||||
|
|
||||||
|
const result = await testEnvironment({
|
||||||
|
companyId: "company-1",
|
||||||
|
adapterType: "codex_local",
|
||||||
|
config: {
|
||||||
|
command: process.execPath,
|
||||||
|
cwd,
|
||||||
|
env: { CODEX_HOME: codexHome },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.checks.some((check) => check.code === "codex_openai_api_key_missing")).toBe(true);
|
||||||
|
expect(result.checks.some((check) => check.code === "codex_native_auth_present")).toBe(false);
|
||||||
|
} finally {
|
||||||
|
await fs.rm(root, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
itWindows("runs the hello probe when Codex is available via a Windows .cmd wrapper", async () => {
|
itWindows("runs the hello probe when Codex is available via a Windows .cmd wrapper", async () => {
|
||||||
const root = path.join(
|
const root = path.join(
|
||||||
os.tmpdir(),
|
os.tmpdir(),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue