Skip to content

Commit 8790758

Browse files
committed
fix(codex): close final integration gate gaps
1 parent 368a1ee commit 8790758

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ jobs:
452452
steps:
453453
- name: Checkout
454454
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
455+
with:
456+
persist-credentials: false
455457

456458
- name: Setup Bun
457459
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2

‎tests/claude-messages-endpoint.test.ts‎

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { waitForNativeMainStartupGate } from "../src/codex/native-profile-startup";
21
import { afterEach, beforeEach, expect, test } from "bun:test";
32
import { managementFetch as fetch } from "./helpers/management-auth";
43
import { logsFromApiBody } from "./helpers/logs-api";
@@ -12,6 +11,7 @@ import type { RequestLogContext } from "../src/server/request-log";
1211
import { startServer } from "../src/server";
1312
import {
1413
fetchWithHeaderDeadline,
14+
handleClaudeMessages,
1515
readBoundedPassthroughBody,
1616
resolvePassthroughBodyGuard,
1717
tapAnthropicSseForLog,
@@ -24,6 +24,7 @@ import {
2424
acquireNativeMainProfileDrain,
2525
getNativeMainProfileRequestCount,
2626
resetLifecycleDrainStateForTests,
27+
tryAdmitTurn,
2728
} from "../src/server/lifecycle";
2829
import {
2930
blockNativeMainRecovery,
@@ -820,8 +821,7 @@ test("routed Claude requests give OpenAI sidecars main auth without leaking it t
820821
writeFileSync(join(isolatedCodexHome!.path, "auth.json"), JSON.stringify({
821822
tokens: { access_token: mainAccessToken, account_id: mainAccountId },
822823
}));
823-
const server = startServer(0);
824-
await waitForNativeMainStartupGate();
824+
let requestSequence = 0;
825825
const requestBody = {
826826
model: "routed/text-model",
827827
max_tokens: 128,
@@ -835,11 +835,33 @@ test("routed Claude requests give OpenAI sidecars main auth without leaking it t
835835
],
836836
}],
837837
};
838+
const invokeMessages = async (): Promise<number> => {
839+
const turnAdmissionLease = tryAdmitTurn();
840+
if (!turnAdmissionLease) throw new Error("test turn admission unavailable");
841+
const start = Date.now();
842+
try {
843+
const response = await handleClaudeMessages(
844+
new Request("http://localhost/v1/messages", {
845+
method: "POST",
846+
headers: {
847+
"content-type": "application/json",
848+
"x-api-key": "placeholder",
849+
"anthropic-version": "2023-06-01",
850+
},
851+
body: JSON.stringify(requestBody),
852+
}),
853+
config,
854+
{ model: "unknown", provider: "unknown", inboundProtocol: "messages" } as RequestLogContext,
855+
{ requestId: `claude-sidecar-test-${++requestSequence}`, start, turnAdmissionLease },
856+
);
857+
await response.text();
858+
return response.status;
859+
} finally {
860+
turnAdmissionLease.release();
861+
}
862+
};
838863
try {
839-
await waitForNativeMainStartupGate();
840-
const authenticated = await postMessages(server.url.toString(), requestBody);
841-
expect(authenticated.status).toBe(200);
842-
await authenticated.text();
864+
expect(await invokeMessages()).toBe(200);
843865

844866
expect(sidecarCalls.map(call => call.kind).sort()).toEqual(["vision", "web-search"]);
845867
for (const call of sidecarCalls) {
@@ -857,19 +879,16 @@ test("routed Claude requests give OpenAI sidecars main auth without leaking it t
857879

858880
rmSync(join(isolatedCodexHome!.path, "auth.json"));
859881
const sidecarCountBeforeNoLogin = sidecarCalls.length;
860-
const noLogin = await postMessages(server.url.toString(), requestBody);
861-
expect(noLogin.status).toBe(200);
862-
await noLogin.text();
882+
expect(await invokeMessages()).toBe(200);
863883

864884
expect(sidecarCalls.length).toBe(sidecarCountBeforeNoLogin);
865885
expect(routedCalls.at(-1)?.authorization).toBe("Bearer routed-provider-key");
866886
const noLoginBody = JSON.stringify(routedCalls.at(-1)?.body);
867887
expect(noLoginBody).toContain("[image omitted: this model is text-only and the vision sidecar is unavailable (no ChatGPT login)]");
868888
expect(noLoginBody).not.toContain(imageBytes);
869889
} finally {
870-
await server.stop(true);
871-
forward.stop(true);
872-
routed.stop(true);
890+
await forward.stop(true);
891+
await routed.stop(true);
873892
}
874893
});
875894

‎tests/native-profile-drain-server.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ describe("native main profile scoped server admission", () => {
400400
return upstream as unknown as WebSocket;
401401
},
402402
});
403+
await waitForNativeMainStartupGate();
403404
const url = new URL("/v1/live/uncooperative", server.url);
404405
url.protocol = "ws:";
405406
const client = new WebSocket(url);

0 commit comments

Comments
 (0)