fix(copilot): cap oauth request timeouts · openclaw/openclaw@fb8b9e9
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { MAX_TIMER_TIMEOUT_MS } from "../../../shared/number-coercion.js"; |
2 | 3 | import { refreshGitHubCopilotToken, testing } from "./github-copilot.js"; |
3 | 4 | |
4 | 5 | function stubHangingFetch(timeoutMs: number): void { |
@@ -95,6 +96,16 @@ describe("GitHub Copilot OAuth model policy", () => {
|
95 | 96 | ); |
96 | 97 | }); |
97 | 98 | |
| 99 | +it("caps oversized request timeouts before creating abort signals", async () => { |
| 100 | +stubHangingFetch(MAX_TIMER_TIMEOUT_MS); |
| 101 | + |
| 102 | +await expect( |
| 103 | +testing.startDeviceFlow("github.com", { timeoutMs: Number.MAX_SAFE_INTEGER }), |
| 104 | +).rejects.toThrow( |
| 105 | +`GitHub Copilot device code request timed out after ${MAX_TIMER_TIMEOUT_MS}ms`, |
| 106 | +); |
| 107 | +}); |
| 108 | + |
98 | 109 | it("rejects unsafe device code lifetimes", async () => { |
99 | 110 | vi.stubGlobal( |
100 | 111 | "fetch", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,7 @@ import {
|
8 | 8 | resolveExpiresAtMsFromDurationSeconds, |
9 | 9 | resolveExpiresAtMsFromEpochSeconds, |
10 | 10 | } from "../../../infra/parse-finite-number.js"; |
| 11 | +import { resolveTimerTimeoutMs } from "../../../shared/number-coercion.js"; |
11 | 12 | import type { Model } from "../../types.js"; |
12 | 13 | import type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderInterface } from "./types.js"; |
13 | 14 | |
@@ -145,7 +146,9 @@ function formatCopilotRequestError(
|
145 | 146 | } |
146 | 147 | |
147 | 148 | function buildCopilotRequestSignal(options: CopilotRequestOptions): AbortSignal { |
148 | | -const timeoutSignal = AbortSignal.timeout(options.timeoutMs ?? COPILOT_REQUEST_TIMEOUT_MS); |
| 149 | +const timeoutSignal = AbortSignal.timeout( |
| 150 | +resolveTimerTimeoutMs(options.timeoutMs, COPILOT_REQUEST_TIMEOUT_MS), |
| 151 | +); |
149 | 152 | if (!options.signal) { |
150 | 153 | return timeoutSignal; |
151 | 154 | } |
@@ -158,7 +161,7 @@ async function fetchResponse(
|
158 | 161 | operation: string, |
159 | 162 | options: CopilotRequestOptions = {}, |
160 | 163 | ): Promise<Response> { |
161 | | -const timeoutMs = options.timeoutMs ?? COPILOT_REQUEST_TIMEOUT_MS; |
| 164 | +const timeoutMs = resolveTimerTimeoutMs(options.timeoutMs, COPILOT_REQUEST_TIMEOUT_MS); |
162 | 165 | try { |
163 | 166 | return await fetch(url, { |
164 | 167 | ...init, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。