Skip to content

Commit b8d800f

Browse files
committed
test(qa): prove Codex auth product migration
1 parent a70d583 commit b8d800f

15 files changed

Lines changed: 828 additions & 229 deletions

‎extensions/codex/src/app-server/auth-bridge.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,44 @@ describe("bridgeCodexAppServerStartOptions", () => {
16351635
}
16361636
});
16371637

1638+
it("selects ordered Codex OAuth before an OpenAI API-key backup", async () => {
1639+
const request = vi.fn(async () => ({ type: "chatgptAuthTokens" }));
1640+
const accessToken = "test-access-token";
1641+
const authProfileStore: AuthProfileStore = {
1642+
version: 1,
1643+
profiles: {
1644+
"openai:media-api": {
1645+
type: "api_key",
1646+
provider: "openai",
1647+
key: "test-api-key",
1648+
},
1649+
"openai:qa-oauth": {
1650+
type: "oauth",
1651+
provider: "openai",
1652+
access: accessToken,
1653+
refresh: "test-refresh",
1654+
expires: Date.UTC(2036, 0, 1),
1655+
accountId: "qa-codex-account",
1656+
},
1657+
},
1658+
order: { openai: ["openai:qa-oauth", "openai:media-api"] },
1659+
};
1660+
1661+
expect(resolveCodexAppServerAuthProfileId({ store: authProfileStore })).toBe("openai:qa-oauth");
1662+
await applyCodexAppServerAuthProfile({
1663+
client: { request } as never,
1664+
agentDir: "/tmp/openclaw-codex-auth-product-proof",
1665+
authProfileStore,
1666+
});
1667+
1668+
expect(request).toHaveBeenCalledWith("account/login/start", {
1669+
type: "chatgptAuthTokens",
1670+
accessToken,
1671+
chatgptAccountId: "qa-codex-account",
1672+
chatgptPlanType: null,
1673+
});
1674+
});
1675+
16381676
it("does not select Codex profiles without inline OAuth credential material", () => {
16391677
expect(
16401678
resolveCodexAppServerAuthProfileId({

‎extensions/qa-lab/src/scenario-catalog.test.ts‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ describe("qa scenario catalog", () => {
315315

316316
expect(notApplicable).toStrictEqual(
317317
[
318-
"auth-profile-codex-mixed-profiles",
319-
"auth-profile-doctor-migration-safety",
320318
"codex-plugin-cold-install",
321319
"codex-plugin-pinned-new",
322320
"codex-plugin-pinned-old",
@@ -560,12 +558,7 @@ describe("qa scenario catalog", () => {
560558
expect(coldInstall.coverage?.secondary).toBeUndefined();
561559
expect(coldInstall.execution.kind).toBe("script");
562560

563-
const fixtureScenarioIds = [
564-
"codex-plugin-pinned-old",
565-
"codex-plugin-pinned-new",
566-
"auth-profile-codex-mixed-profiles",
567-
"auth-profile-doctor-migration-safety",
568-
];
561+
const fixtureScenarioIds = ["codex-plugin-pinned-old", "codex-plugin-pinned-new"];
569562

570563
for (const scenarioId of fixtureScenarioIds) {
571564
const scenario = readQaScenarioById(scenarioId);
@@ -578,9 +571,32 @@ describe("qa scenario catalog", () => {
578571
hostVersion: "2026.5.21",
579572
pluginRelation: "older",
580573
});
581-
expect(readQaScenarioExecutionConfig("auth-profile-doctor-migration-safety")).toMatchObject({
582-
matrixCells: ["oauth-only", "mixed-no-pin"],
574+
});
575+
576+
it("routes the Codex doctor migration row through the product-backed Vitest", () => {
577+
const scenario = readQaScenarioById("auth-profile-doctor-migration-safety");
578+
579+
expect(scenario.runtimeParityTier).toBeUndefined();
580+
expect(scenario.runtimeParityUsage).toBeUndefined();
581+
expect(scenario.execution).toMatchObject({
582+
kind: "vitest",
583+
path: "test/e2e/qa-lab/runtime/codex-auth-doctor-migration-product-proof.e2e.test.ts",
584+
});
585+
expect(scenario.coverage?.primary).toContain("runtime.doctor-repair");
586+
expect(scenario.coverage?.secondary).toContain("runtime.codex-plugin.auth");
587+
});
588+
589+
it("routes the Codex mixed-profile row through the product-backed Vitest", () => {
590+
const scenario = readQaScenarioById("auth-profile-codex-mixed-profiles");
591+
592+
expect(scenario.runtimeParityTier).toBeUndefined();
593+
expect(scenario.runtimeParityUsage).toBeUndefined();
594+
expect(scenario.execution).toMatchObject({
595+
kind: "vitest",
596+
path: "test/e2e/qa-lab/runtime/codex-auth-product-proof.e2e.test.ts",
583597
});
598+
expect(scenario.coverage?.primary).toContain("runtime.codex-plugin.auth");
599+
expect(scenario.coverage?.secondary).toContain("runtime.doctor-repair");
584600
});
585601

586602
it("keeps the character eval scenario natural and task-shaped", () => {

‎qa/scenarios/runtime/auth-profile-codex-mixed-profiles.yaml‎

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,27 @@ title: Codex auth profile mixed profiles
33
scenario:
44
id: auth-profile-codex-mixed-profiles
55
surface: runtime
6-
runtimeParityTier: standard
7-
runtimeParityUsage:
8-
expectation: not-applicable
9-
reason: Local auth-selection fixture only; no assistant turn runs.
106
coverage:
117
primary:
128
- runtime.codex-plugin.auth
139
secondary:
1410
- auth-profiles.provider-selection
15-
objective: Verify mixed openai OAuth and openai API-key profile stores select the Codex OAuth profile for Codex app-server turns.
11+
- runtime.doctor-repair
12+
objective: Verify doctor repairs mixed legacy Codex OAuth and OpenAI API-key profiles into canonical SQLite state and the Codex auth bridge sends the selected OAuth profile to App Server.
1613
successCriteria:
1714
- The selected auth profile id is openai:qa-oauth.
1815
- The openai:media-api API-key profile is present but not selected.
19-
- The fixture rejects the residual provider mismatch covered by issue #78499.
16+
- Doctor removes the legacy JSON store after verifying its canonical per-agent SQLite import.
17+
- The Gateway-backed Codex turn emits account/login/start with chatgptAuthTokens; evidence redacts token material.
2018
docsRefs:
2119
- docs/cli/doctor.md
20+
- docs/plugins/codex-harness.md
2221
codeRefs:
23-
- extensions/qa-lab/src/auth-profile.fixture.ts
24-
- extensions/qa-lab/src/codex-plugin-lifecycle.test.ts
22+
- src/commands/doctor-auth-flat-profiles.ts
23+
- src/agents/auth-profiles/sqlite.ts
24+
- extensions/codex/src/app-server/auth-bridge.ts
25+
- test/e2e/qa-lab/runtime/codex-auth-product-proof.e2e.test.ts
2526
execution:
26-
kind: flow
27-
summary: Exercise the auth-profile fixture for mixed OpenAI API-key and Codex OAuth stores.
28-
config:
29-
selectedProfileId: openai:qa-oauth
30-
rejectedProfileId: openai:media-api
31-
32-
flow:
33-
steps:
34-
- name: validates mixed-profile Codex auth selection
35-
actions:
36-
- set: auth
37-
value:
38-
expr: await qaImport("./auth-profile.fixture.js")
39-
- set: tmpRoot
40-
value:
41-
expr: await fs.mkdtemp(path.join(env.gateway?.workspaceDir ?? "/tmp", "qa-codex-auth-"))
42-
- try:
43-
actions:
44-
- call: auth.seedAuthProfiles
45-
args:
46-
- mixed
47-
- ref: tmpRoot
48-
- set: selection
49-
value:
50-
expr: auth.resolveCodexAuthProfile(await auth.snapshotAuthProfiles(tmpRoot))
51-
- assert:
52-
expr: "selection.status === 'ready'"
53-
message:
54-
expr: "`expected ready Codex auth selection, got ${JSON.stringify(selection)}`"
55-
- assert:
56-
expr: "selection.profileId === config.selectedProfileId"
57-
message: mixed profiles must select openai OAuth
58-
- assert:
59-
expr: "selection.profileId !== config.rejectedProfileId"
60-
message: codex profile must not equal openai api-key profile
61-
finally:
62-
- call: fs.rm
63-
args:
64-
- ref: tmpRoot
65-
- recursive: true
66-
force: true
67-
- assert:
68-
expr: "config.selectedProfileId !== config.rejectedProfileId"
69-
message: "codex profile must not equal openai api-key profile"
70-
detailsExpr: "`selected=${selection.profileId} rejected=${config.rejectedProfileId}`"
27+
kind: vitest
28+
path: test/e2e/qa-lab/runtime/codex-auth-product-proof.e2e.test.ts
29+
summary: Run the isolated doctor-to-SQLite-to-Gateway-to-Codex-App-Server auth product path.

‎qa/scenarios/runtime/auth-profile-doctor-migration-safety.yaml‎

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,23 @@ title: Codex doctor migration safety matrix
33
scenario:
44
id: auth-profile-doctor-migration-safety
55
surface: runtime
6-
runtimeParityTier: standard
7-
runtimeParityUsage:
8-
expectation: not-applicable
9-
reason: Local doctor-migration fixture only; no assistant turn runs.
106
coverage:
117
primary:
128
- runtime.doctor-repair
139
secondary:
1410
- runtime.codex-plugin.auth
15-
objective: Reproduce the doctor-migration auth cells as an automated fixture matrix for Codex OAuth selection.
11+
objective: Prove that the real doctor command migrates legacy Codex OAuth stores into canonical per-agent SQLite state.
1612
successCriteria:
17-
- OAuth-only hosts select the openai OAuth profile and use the Codex harness.
18-
- Mixed-profile hosts still select openai OAuth when an openai API-key profile exists.
13+
- OAuth-only legacy stores become canonical openai OAuth profiles in per-agent SQLite.
14+
- Mixed legacy stores keep the migrated OAuth profile ahead of an existing openai API-key profile.
15+
- The obsolete JSON auth store is removed after each successful migration.
1916
docsRefs:
2017
- docs/cli/doctor.md
2118
codeRefs:
22-
- extensions/qa-lab/src/auth-profile.fixture.ts
23-
- extensions/qa-lab/src/codex-plugin.fixture.ts
24-
- extensions/qa-lab/src/codex-plugin-lifecycle.test.ts
19+
- src/commands/doctor-auth-flat-profiles.ts
20+
- src/agents/auth-profiles/persisted.ts
21+
- test/e2e/qa-lab/runtime/codex-auth-doctor-migration-product-proof.e2e.test.ts
2522
execution:
26-
kind: flow
27-
summary: Exercise the doctor migration matrix against Codex auth routing.
28-
config:
29-
matrixCells:
30-
- oauth-only
31-
- mixed-no-pin
32-
33-
flow:
34-
steps:
35-
- name: validates doctor migration safety matrix
36-
actions:
37-
- set: auth
38-
value:
39-
expr: await qaImport("./auth-profile.fixture.js")
40-
- set: plugin
41-
value:
42-
expr: await qaImport("./codex-plugin.fixture.js")
43-
- forEach:
44-
items:
45-
ref: config.matrixCells
46-
item: cell
47-
actions:
48-
- set: tmpRoot
49-
value:
50-
expr: await fs.mkdtemp(path.join(env.gateway?.workspaceDir ?? "/tmp", `qa-codex-doctor-${cell}-`))
51-
- set: profileShape
52-
value:
53-
expr: "cell === 'oauth-only' ? 'oauth-only' : 'mixed'"
54-
- try:
55-
actions:
56-
- call: plugin.seedCodexPluginAt
57-
args:
58-
- current
59-
- ref: tmpRoot
60-
- call: auth.seedAuthProfiles
61-
args:
62-
- ref: profileShape
63-
- ref: tmpRoot
64-
- set: result
65-
value:
66-
expr: "plugin.evaluateCodexPluginLifecycle({ plugin: await plugin.snapshotCodexPluginState(tmpRoot), auth: await auth.snapshotAuthProfiles(tmpRoot), hostVersion: plugin.CODEX_PLUGIN_CURRENT_VERSION, doctorFix: true })"
67-
- assert:
68-
expr: "result.status === 'ready' && result.selectedAuthProfileId === auth.QA_CODEX_OAUTH_PROFILE_ID && result.tokenRoute === 'codex-oauth'"
69-
message:
70-
expr: "`doctor matrix cell ${cell} failed Codex auth routing: ${JSON.stringify(result)}`"
71-
finally:
72-
- call: fs.rm
73-
args:
74-
- ref: tmpRoot
75-
- recursive: true
76-
force: true
77-
- assert:
78-
expr: "config.matrixCells.length === 2"
79-
message: "expected two doctor migration cells"
80-
detailsExpr: "`cells=${config.matrixCells.join(',')}`"
23+
kind: vitest
24+
path: test/e2e/qa-lab/runtime/codex-auth-doctor-migration-product-proof.e2e.test.ts
25+
summary: Run the real doctor migration over OAuth-only and mixed legacy stores, then inspect canonical SQLite state.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Shared stdio transport and response builders for fake Codex App Server E2E processes.
2+
import fs from "node:fs";
3+
import readline from "node:readline";
4+
5+
function writeMessage(message) {
6+
process.stdout.write(`${JSON.stringify(message)}\n`);
7+
}
8+
9+
export function createFakeInitializeResponse({ name, userAgent, version }) {
10+
return {
11+
protocolVersion: "2",
12+
serverInfo: { name, version },
13+
userAgent,
14+
};
15+
}
16+
17+
export function createFakeThreadStartResponse({ params, sessionId, threadId, version }) {
18+
const now = Date.now();
19+
const cwd = params?.cwd ?? process.cwd();
20+
return {
21+
thread: {
22+
id: threadId,
23+
sessionId,
24+
forkedFromId: null,
25+
preview: "",
26+
ephemeral: false,
27+
modelProvider: "openai",
28+
createdAt: now,
29+
updatedAt: now,
30+
status: { type: "idle" },
31+
path: null,
32+
cwd,
33+
cliVersion: version,
34+
source: "unknown",
35+
agentNickname: null,
36+
agentRole: null,
37+
gitInfo: null,
38+
name: null,
39+
turns: [],
40+
},
41+
model: params?.model ?? "gpt-5.6-luna",
42+
modelProvider: "openai",
43+
serviceTier: null,
44+
cwd,
45+
runtimeWorkspaceRoots: [],
46+
instructionSources: [],
47+
approvalPolicy: params?.approvalPolicy ?? "never",
48+
approvalsReviewer: params?.approvalsReviewer ?? "user",
49+
sandbox: { type: "dangerFullAccess" },
50+
activePermissionProfile: null,
51+
reasoningEffort: null,
52+
multiAgentMode: "explicitRequestOnly",
53+
};
54+
}
55+
56+
export function runFakeCodexAppServer({ handlers, logMode = "requests", requestLog }) {
57+
function appendLog(message) {
58+
try {
59+
fs.appendFileSync(requestLog, `${JSON.stringify(message)}\n`);
60+
return true;
61+
} catch (error) {
62+
const detail = error instanceof Error ? error.message : String(error);
63+
process.stderr.write(`fake Codex app-server request log write failed: ${detail}\n`);
64+
return false;
65+
}
66+
}
67+
68+
function emit(message) {
69+
if (logMode === "messages") {
70+
appendLog(message);
71+
}
72+
writeMessage(message);
73+
}
74+
75+
const input = readline.createInterface({ input: process.stdin });
76+
input.on("line", (line) => {
77+
if (!line.trim()) {
78+
return;
79+
}
80+
const request = JSON.parse(line);
81+
if (!appendLog(request)) {
82+
if (request?.id !== undefined) {
83+
writeMessage({
84+
error: { message: "fake Codex app-server request log write failed" },
85+
id: request.id,
86+
});
87+
}
88+
return;
89+
}
90+
91+
const { id, method, params } = request;
92+
if (id === undefined) {
93+
return;
94+
}
95+
const sendResult = (result) => emit({ id, result });
96+
const notify = (notificationMethod, notificationParams) =>
97+
emit({ method: notificationMethod, params: notificationParams });
98+
const handler =
99+
typeof method === "string" && Object.hasOwn(handlers, method) ? handlers[method] : undefined;
100+
if (handler) {
101+
handler({ id, notify, params, sendResult });
102+
return;
103+
}
104+
sendResult({});
105+
});
106+
}

0 commit comments

Comments
 (0)