Skip to content

test: 开发机代理环境泄漏进「无网络」测试的隔离修复 - #58

Merged
techysy merged 1 commit into
techysy:mainfrom
Lzj37412:fix/test-proxy-isolation
Nov 11, 2026
Merged

techysy merged 1 commit into
techysy:mainfrom
Lzj37412:fix/test-proxy-isolation

Conversation

@Lzj37412

@Lzj37412 Lzj37412 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

问题

两套 fetch-stub 测试在带代理的开发机上必挂,CI(无代理)不暴露:

  • web-session-watch.test.js 3/4 挂
  • robustness-audit.test.js「200 但非 JSON」挂

单测耗时 6-17 秒(真网络往返),失败信息与测试语义完全对不上(「复活后应清标记」失败实际是复活轮的真网响应盖掉了 stub 的 200)。

根因

fetchJsonRace 的 viaProxy 路径走 node:http / node:tls 原生模块直连代理服务器,完全绕过 globalThis.fetch stub。开发机 shell 带代理变量时:

https_proxy=http://localhost:7897 + zcode-net.json proxyFirst=true
→ fetchJsonRace(..., preferProxy: true) 的 order = ['viaProxy', 'direct']
→ viaProxy 用原生 http/tls 发真网络请求
→ 「全部注入 fetch,无网络」的测试承诺失效

effectiveProxy() 的来源:zcode-net.json 的 proxyUrl 或 HTTPS_PROXY 等环境变量——测试的临时 CREDITDADDY_HOME 只隔离了前者,环境变量这条路没堵。

修复(只动测试文件,产品代码零改动)

  1. 两文件头部统一摘除代理环境变量(https_proxy / HTTPS_PROXY / http_proxy / HTTP_PROXY / ALL_PROXY / all_proxy)——「无网络」承诺靠这个兑现
  2. seedQoder 补 id:缺 id 时 find(x.id === acc.id) 退化成「找第一个 undefined id 的账号」,多账号共存时永远命中第一个种子,断言到错的记录上;产品代码 withAccounts 的 list.find((x) => x.id === a.id) 同样受益于精确寻址
  3. store 投影测试改按精确 id 寻址:原模糊 find(x.meta?.qoderWebDead) 会被前面测试留下的死标记账号串位

验证

环境 修复前 修复后
开发机(Windows + https_proxy) 4 fail,单测 6-17s 418/418 全绿,<50ms
CI(无代理) 通过(不暴露) 通过(行为不变)
# 复现(任一带代理的开发机):
# $env:https_proxy='http://localhost:7897'; node --test test/web-session-watch.test.js
# 修复前: 3/4 fail; 修复后: 4/4 pass

两套 fetch-stub 测试在带代理的开发机上必挂(CI 无代理不暴露):
fetchJsonRace 的 viaProxy 路径走 node:http/tls 原生模块直连代理服务器,
完全绕过 globalThis.fetch stub——shell 里的 https_proxy / HTTPS_PROXY /
ALL_PROXY 让真网络请求闯进测试,探测结果被真实响应覆盖。

实测(Windows + https_proxy=http://localhost:7897 + zcode-net.json
proxyFirst=true):
- web-session-watch 3/4 挂,单测耗时 6-8s(真网络往返)
- robustness-audit「200 但非 JSON」挂(同根因)
- 摘掉代理变量后全部 <50ms 通过

修复(只动测试文件,产品代码零改动):
1. 两文件头部统一摘除 https_proxy/HTTPS_PROXY/http_proxy/HTTP_PROXY/
   ALL_PROXY/all_proxy——「全部注入 fetch,无网络」的承诺靠这个兑现
2. seedQoder 补 id:缺 id 时 find(x.id === acc.id) 退化成「找第一个
   undefined id 的账号」,多账号共存时永远命中第一个种子,断言到错的记录
3. store 投影测试改按精确 id 寻址(原模糊 find(x.meta?.qoderWebDead)
   会被前面测试留下的死标记账号串位)
@techysy
techysy merged commit c782819 into techysy:main Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants