🐛 fix(desktop): use Electron net.fetch for remote server requests#13400
Conversation
|
@djthread is attempting to deploy a commit to the LobeHub OSS Team on Vercel. A member of the Team first needs to authorize it. |
|
@ONLY-yours @tjx666 - This is a desktop platform fix switching from Node.js |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48c9357707
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
48c9357 to
d0f5a75
Compare
|
The tests stub global.fetch but the electron mock has no net object. The last commit makes net-fetch.ts fall back to globalThis.fetch when net is unavailable (tests). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## canary #13400 +/- ##
=========================================
Coverage 66.56% 66.56%
=========================================
Files 2022 2022
Lines 171262 171262
Branches 19915 16654 -3261
=========================================
+ Hits 113996 113998 +2
+ Misses 57141 57139 -2
Partials 125 125
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@djthread Test failed, plz take a look |
d0f5a75 to
44ab3f8
Compare
|
Thanks, @Innei ! Two categories of test breakage patched in this commit: E2E selectors ( Unit test mocks ( |
|
E2E selectors: This is a common error that often occurs; retrying might resolve it. Here, there is no need for any changes; you just need to fix the unit test you are involved with. Thx.
|
Both LocalFileCtr and RemoteServerConfigCtr tests were patching
global.fetch / stubGlobal, which no longer intercepts calls now that
the controllers route through Electron's net.fetch via @/utils/net-fetch.
Hoist the fetch mock and point vi.mock('@/utils/net-fetch') at it directly.
44ab3f8 to
2492c24
Compare
|
@Innei Ty again. Done. |
|
@codex Will this modification cause issues with exception handling for requests? |
|
To use Codex here, create an environment for this repo. |
|
❤️ Great PR @djthread ❤️ The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world. |
Summary
fetch()to Electron'snet.fetch()for all HTTP requests from the desktop app to user-configured remote serversfetchuses a bundled Mozilla CA list and ignores the OS certificate store, so self-hosted instances behind a reverse proxy with a private CA (e.g. Caddy, mkcert, corporate PKI) silently fail every request — TLS errors are swallowed and the user sees only a timeoutnet.fetchuses Chromium's networking stack, which respects the macOS Keychain, Windows Certificate Store, and system CA bundles on LinuxThese changes allowed me to connect (from macos) to my self-hosted lobehub server with a self-signed cert.
I did think the app would pop up and take focus, but it did not. It did log in and appear to work, however. Without these changes, the browser says
Authentication Successfulbut the desktop app just times out.Affected code paths
AuthCtr.tsRemoteServerConfigCtr.tsLocalFileCtr.tsBackendProxyProtocolManager.tsThe network proxy tester (
tester.ts) intentionally stays on undici'sfetchbecause it requires thedispatcheroption for proxy agent testing.Root cause
Self-hosted desktop auth (Connect → enter server URL → browser login) never completes: the handoff record is created server-side but the desktop app's polling requests fail at the TLS handshake because Node.js doesn't trust the host's CA certificate. The error is caught and discarded in a
logger.debug()call, so the app silently spins until the 2-minute timeout.Fixes #9684, fixes #13128
Test plan