-
Notifications
You must be signed in to change notification settings - Fork 276
fix request timeout for openai-compatible providers #1423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2c19148
cefb1c0
92f5bea
37a5954
12d88f2
fca1fa1
6b37227
7e640b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,3 +7,6 @@ export const DEFAULT_HEADERS = { | |||||||||
| } | ||||||||||
|
|
||||||||||
| export const NOT_PROVIDED = "not-provided" | ||||||||||
|
|
||||||||||
| // 50 min default request timeout | ||||||||||
| export const DEFAULT_TIMEOUT_MS = 60 * 60 * 1000 | ||||||||||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Align the timeout comment with
Suggested correction-// 50 min default request timeout
+// 60 min default request timeout📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 12410
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 33059
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 25442
🌐 Web query:
Nock 14 disableNetConnect Node fetch undici support official documentation💡 Result:
Nock version 14 introduces support for native Node.js fetch and includes basic support for Undici, allowing you to use Nock's mocking capabilities with these modern HTTP clients [1][2][3]. Regarding the specific components of your query: 1. disableNetConnect Support: Nock's
disableNetConnect()function is the standard method for forbidding unmocked HTTP requests [4][5]. In Nock v14, this functionality is designed to work with the updated interception logic that supports native fetch [6]. WhendisableNetConnect()is active, any request made to a host that is not explicitly mocked will trigger aNetConnectNotAllowedError[4][5]. 2. Undici Support: While Nock traditionally intercepted requests at the Node.js built-inhttpmodule level—which Undici bypasses by using thenetmodule directly [7]—Nock v14 added basic support for Undici [3]. This is achieved by allowing Nock to act as a dispatcher within the Undici ecosystem [3]. 3. Official Documentation: Official guidance on these features is primarily found in the Nock repository's pull request descriptions, release notes, and source code [1][2][3]. Because Undici and native fetch operate differently than traditionalhttprequests, Nock's integration with them is documented through these repository updates rather than a static, separate documentation page [1][8][3]. For users requiring advanced Undici mocking, the recommended approach remains using Undici's nativeMockAgentwhen possible, as it is purpose-built for that library [8][9][7]. If you are using Nock to support legacy and modern fetch/undici requests simultaneously, ensure you are on a recent v14 release [2][10].Citations:
🌐 Web query:
Nock v14 Undici custom dispatcher Agent disableNetConnect native fetch interception💡 Result:
Nock v14 introduced support for native fetch [1] by migrating to
@mswjs/interceptorsfor its interception logic [2]. While Nock v14 has added basic, experimental support for intercepting Undici requests [3], it does not fully replace Undici's native mocking capabilities or handle all custom dispatcher scenarios [4][5]. Regarding your specific requirements: 1. Undici Custom Dispatcher/Agent Interception: Nock v14 provides a NockAgent that attempts to intercept Undici requests by setting the global dispatcher [3]. However, this mechanism can be bypassed if an explicit custom dispatcher or agent is provided to the fetch or Undici request call [4]. In such cases, Nock's global interceptor is ignored because the request bypasses the global dispatcher that Nock has wrapped [4]. 2. disableNetConnect: Nock's nock.disableNetConnect is primarily designed for the standard Node.js http/https modules [6]. Because Undici operates differently—often by design ignoring global monkey-patching in favor of its own dispatcher-based model—nock.disableNetConnect does not reliably block outgoing network requests made through Undici [6][7]. Recommended Approach: For Undici-based code, particularly when using custom dispatchers or agents, it is best practice to use Undici's built-in MockAgent [6][5]. This provides native, reliable mocking and network control without the limitations of Nock's interception layer: const { MockAgent, setGlobalDispatcher } = require('undici'); const mockAgent = new MockAgent; mockAgent.disableNetConnect; // Reliably disables network for Undici requests [8] setGlobalDispatcher(mockAgent); // To handle custom clients/pools, use the mock agent to get an interceptor const mockPool = mockAgent.get('http://example.com'); mockPool.intercept({ path: '/test', method: 'GET' }).reply(200, { data: 'ok' }); If you must use Nock, be aware that it currently supports interception primarily at the global level [3]. If your application architecture requires passing explicit custom dispatchers, you may need to use a manual stubbing workaround (such as using Reflect to force the use of the Nock-managed dispatcher) [4], though this is not officially supported and may be brittle.Citations:
Block real network access in KimiCode tests.
OpenAiHandler.customFetchpasses an explicitundici.Agent, which bypasses Nock's global dispatcher. Therefore,nock.disableNetConnect()does not protect the request-consuming tests that rely on the forwarding mock. Install a default rejectingglobalThis.fetchstub and override it only in tests that need responses, or use an UndiciMockAgent.🤖 Prompt for AI Agents