|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { OAuthRefreshFailureError } from "../../agents/auth-profiles/oauth-refresh-failure.js"; |
| 3 | +import { createCliOutputFailoverError } from "../../agents/cli-runner/output-error.js"; |
3 | 4 | import { FailoverError } from "../../agents/failover-error.js"; |
4 | 5 | import { MissingProviderAuthError, ProviderAuthError } from "../../agents/model-auth.js"; |
5 | 6 | import type { TemplateContext } from "../templating.js"; |
@@ -315,27 +316,31 @@ describe("executeAgentTurn: authentication failures", () => { |
315 | 316 | } |
316 | 317 | }); |
317 | 318 |
|
318 | | - it("surfaces claude-cli re-auth hint over generic provider auth copy for 401 OAuth expiry", async () => { |
319 | | - // When the claude subprocess emits a 401 "Failed to authenticate" because |
320 | | - // its OAuth token has expired, the error is wrapped as a FailoverError with |
321 | | - // reason:"auth" and status:401. Without the ordering fix, this would be |
322 | | - // caught by generic provider-auth mapping before the typed refresh cause, |
323 | | - // producing generic provider copy instead of the |
324 | | - // targeted claude-cli re-auth command. |
325 | | - state.runEmbeddedAgentMock.mockRejectedValueOnce( |
326 | | - new FailoverError( |
327 | | - "Provider claude-cli failed: Failed to authenticate. API Error: 401 Invalid authentication credentials", |
328 | | - { |
329 | | - reason: "auth", |
330 | | - provider: "claude-cli", |
331 | | - model: "claude-sonnet-4-20250514", |
332 | | - status: 401, |
333 | | - }, |
334 | | - ), |
335 | | - ); |
| 319 | + it("surfaces Agent SDK OAuth session expiry in Discord channels", async () => { |
| 320 | + const error = createCliOutputFailoverError({ |
| 321 | + output: { |
| 322 | + text: "", |
| 323 | + errorText: "Failed to authenticate: OAuth session expired and could not be refreshed", |
| 324 | + }, |
| 325 | + provider: "claude-cli", |
| 326 | + model: "claude-opus-5", |
| 327 | + }); |
| 328 | + if (!error) { |
| 329 | + throw new Error("expected CLI output failure"); |
| 330 | + } |
| 331 | + state.runEmbeddedAgentMock.mockRejectedValueOnce(error); |
336 | 332 |
|
337 | 333 | const executeAgentTurn = await getExecuteAgentTurnForTest(); |
338 | | - const result = await executeAgentTurn(createMinimalRunAgentTurnParams()); |
| 334 | + const result = await executeAgentTurn( |
| 335 | + createMinimalRunAgentTurnParams({ |
| 336 | + sessionCtx: { |
| 337 | + Provider: "discord", |
| 338 | + Surface: "discord", |
| 339 | + ChatType: "channel", |
| 340 | + MessageSid: "msg", |
| 341 | + } as unknown as TemplateContext, |
| 342 | + }), |
| 343 | + ); |
339 | 344 |
|
340 | 345 | expect(result.kind).toBe("final"); |
341 | 346 | if (result.kind === "final") { |
|
0 commit comments