























@@ -1,4 +1,4 @@
1-import { beforeAll, beforeEach, describe, expect, it } from "vitest";
1+import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22import {
33makeAttemptResult,
44makeCompactionSuccess,
@@ -8,12 +8,14 @@ import {
88} from "./run.overflow-compaction.fixture.js";
99import {
1010loadRunOverflowCompactionHarness,
11+mockedBuildEmbeddedRunPayloads,
1112mockedCoerceToFailoverError,
1213mockedCompactDirect,
1314mockedContextEngine,
1415mockedDescribeFailoverError,
1516mockedEvaluateContextWindowGuard,
1617mockedGlobalHookRunner,
18+mockedGetApiKeyForModel,
1719mockedPickFallbackThinkingLevel,
1820mockedResolveContextWindowInfo,
1921mockedResolveFailoverStatus,
@@ -34,6 +36,7 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
34363537beforeEach(() => {
3638resetRunOverflowCompactionHarnessMocks();
39+mockedBuildEmbeddedRunPayloads.mockReturnValue([{ text: "ok" }]);
3740});
38413942it("passes precomputed legacy before_agent_start result into the attempt", async () => {
@@ -72,7 +75,6 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
7275 ...overflowBaseRunParams,
7376runId: "run-auth-profile-passthrough",
7477});
75-7678expect(mockedRunEmbeddedAttempt).toHaveBeenCalledWith(
7779expect.objectContaining({
7880authProfileId: "test-profile",
@@ -81,6 +83,91 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
8183);
8284});
838586+it("forwards explicit OpenAI Codex auth profiles to codex plugin harnesses", async () => {
87+const { clearAgentHarnesses, registerAgentHarness } = await import("../harness/registry.js");
88+const pluginRunAttempt = vi.fn(async () => makeAttemptResult({ assistantTexts: ["ok"] }));
89+clearAgentHarnesses();
90+registerAgentHarness({
91+id: "codex",
92+label: "Codex",
93+supports: (ctx) =>
94+ctx.provider === "codex" ? { supported: true, priority: 100 } : { supported: false },
95+runAttempt: pluginRunAttempt,
96+});
97+mockedGetApiKeyForModel.mockRejectedValueOnce(new Error("generic auth should be skipped"));
98+99+try {
100+await runEmbeddedPiAgent({
101+ ...overflowBaseRunParams,
102+provider: "codex",
103+model: "gpt-5.4",
104+config: {
105+agents: {
106+defaults: {
107+embeddedHarness: { runtime: "codex", fallback: "none" },
108+},
109+},
110+},
111+authProfileId: "openai-codex:work",
112+authProfileIdSource: "user",
113+runId: "plugin-harness-forwards-openai-codex-auth",
114+});
115+} finally {
116+clearAgentHarnesses();
117+}
118+119+expect(mockedGetApiKeyForModel).not.toHaveBeenCalled();
120+expect(pluginRunAttempt).toHaveBeenCalledWith(
121+expect.objectContaining({
122+provider: "codex",
123+authProfileId: "openai-codex:work",
124+authProfileIdSource: "user",
125+}),
126+);
127+});
128+129+it("forwards OpenAI Codex auth profiles when openai/* is forced through codex", async () => {
130+const { clearAgentHarnesses, registerAgentHarness } = await import("../harness/registry.js");
131+const pluginRunAttempt = vi.fn(async () => makeAttemptResult({ assistantTexts: ["ok"] }));
132+clearAgentHarnesses();
133+registerAgentHarness({
134+id: "codex",
135+label: "Codex",
136+supports: () => ({ supported: false }),
137+runAttempt: pluginRunAttempt,
138+});
139+mockedGetApiKeyForModel.mockRejectedValueOnce(new Error("generic auth should be skipped"));
140+141+try {
142+await runEmbeddedPiAgent({
143+ ...overflowBaseRunParams,
144+provider: "openai",
145+model: "gpt-5.4",
146+config: {
147+agents: {
148+defaults: {
149+embeddedHarness: { runtime: "codex", fallback: "none" },
150+},
151+},
152+},
153+authProfileId: "openai-codex:work",
154+authProfileIdSource: "user",
155+runId: "forced-codex-harness-forwards-openai-codex-auth",
156+});
157+} finally {
158+clearAgentHarnesses();
159+}
160+161+expect(mockedGetApiKeyForModel).not.toHaveBeenCalled();
162+expect(pluginRunAttempt).toHaveBeenCalledWith(
163+expect.objectContaining({
164+provider: "openai",
165+authProfileId: "openai-codex:work",
166+authProfileIdSource: "user",
167+}),
168+);
169+});
170+84171it("blocks undersized models before dispatching a provider attempt", async () => {
85172mockedResolveContextWindowInfo.mockReturnValue({
86173tokens: 800,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。