Skip to content

[PR] refactor: converge buildXxxEnv family into data-driven client-env presets (#1440) - #1450

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-27_client-env-dedup
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-27_client-env-dedup

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

First item of the #1440 audit's P3 (protocol×client matrix copy-paste): the six buildXxxEnv functions in src/launcher.ts carried four byte-identical bodies (codex/trae/copilot/amp), one NO_PROXY variant (jcode) and one dual-CA variant (aider).

Now: one data table (CLIENT_ENV_PRESETS) + one builder (buildClientEnv, internal) encoding the shared cert-MITM env contract — proxy origin + CA + marker — with per-client deltas as flags (noProxy, requestsCaBundle, plus aider's existing routeHttp). The six public names remain as one-line wrappers, so all call sites and tests are untouched.

Adding a future client = one table row + one wrapper line (previously: copy-paste a whole function body).

Behavior change disclosure

None. The generated env objects are key-for-key identical for every client:

  • codex/trae/copilot/amp: {HTTPS_PROXY, SSL_CERT_FILE, BILLION_CONTEXT_PROXY} over baseEnv
  • jcode: same + NO_PROXY/no_proxy loopback pair
  • aider: same core + REQUESTS_CA_BUNDLE, conditional HTTP_PROXY (routeHttp), loopback pair

Verification

Refs #1440

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_client-env-dedup (e4f83fb)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1450

Each push to this PR publishes a new version under the pr-1450 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1450.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Reviewing this PR now. Initial state: branch 2026-09-27_client-env-dedup is 1 commit (e4f83fb2) ahead of current master 825f1529 (release v0.1.158) — fresh base, no rebase needed. Diff is scoped to src/launcher.ts only (+45/−33). CI: lane e2e checks (pi/dsh/codex/opencode), hermetic registry e2e, build-artifact, version-guard all green; the platform test matrix (ubuntu/windows 22+24) was still running at time of writing. Full review conclusions to follow shortly.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — approved, ready for human merge.

Scope & direction (①): First item of the #1440 audit P3. The root cause is six hand-maintained copies of one cert-MITM env contract in src/launcher.ts; converging them into CLIENT_ENV_PRESETS + a single internal buildClientEnv removes the copy-paste producer (future drift becomes structurally impossible; adding a client = one table row + one wrapper line). Fixes the mechanism, not a symptom.

Regression review (②) — existing behaviors on the touched paths, itemized:

  1. Per-client env objects — verified old vs new key-for-key and insertion-order identical:
    • codex/trae/copilot/amp: {...baseEnv, HTTPS_PROXY, SSL_CERT_FILE, BILLION_CONTEXT_PROXY} (all preset flags false → zero conditional spreads)
    • jcode: same core + NO_PROXY/no_proxy = "localhost,127.0.0.1,::1" appended last
    • aider: core + conditional HTTP_PROXY (routeHttp) + REQUESTS_CA_BUNDLE + loopback pair — exact same key sequence as before
      → confirms the OP's "no behavior change" disclosure.
  2. Public API: all six exports keep byte-identical signatures (aider keeps routeHttp: boolean); buildClientEnv/CLIENT_ENV_PRESETS are module-private — no new public surface. All six call sites (src/launcher.ts:3536/3540/3576/3595/3599/3633) untouched.
  3. Provenance comments: 能否新增对traecli的支持 #655 (Go SSL_CERT_FILE), 新增 bili aider 启动器 #1048 (aider dual-CA / routeHttp / loopback), 新增 bili copilot / bili amp / bili goose 启动器(第三梯队) #1049 (copilot/amp) preserved on the table rows. One cosmetic trim: jcode's inline note no longer spells out "combined bundle" (now implied by the header's "core keys … CA") — meaning intact.
  4. No config-schema / persistence / wire-shape / kernel-pin impact.

Code (③): type-safe dispatch (keyof typeof CLIENT_ENV_PRESETS, as const), no as any/@ts-ignore, conditional-spread idiom matches the file's existing style (cf. buildPiEnv, src/launcher.ts:826-837). Local run on head e4f83fb2: npm run typecheck clean; tests/launcher.test.ts 229/229 pass.

Tests (④): the six per-client goldens (tests/launcher.test.ts:237,4281,4289,4392,4418,4426) assert exact values per key incl. both routeHttp branches — real teeth against dropped or mis-valued keys. One pre-existing strictness gap (these tests are unchanged by this PR): nothing asserts absence of extra keys, so a mis-flagged preset row (e.g. noProxy: true on codex) would slip past the goldens. I closed that risk by direct old-vs-new inspection above. Optional, non-blocking hardening: convert the six goldens to full-object assert.deepEqual(env, {...}).

Diff (⑤): single file, +45/−33, one commit, base = current master (0 behind), every line serves the dedup. Clean.

CI: all 12 check runs green on e4f83fb2 — full test matrix (ubuntu 22/24, windows 22/24), all five real-client e2e lanes (pi/dsh/codex/opencode + CODEX_HOME overlay), hermetic registry e2e, build-artifact, version-guard. mergeable_state: clean.

Verdict: behavior-neutral refactor, pinned by CI + goldens + inspection. Per §7.4 a refactor: sits outside the auto-merge gate regardless — merging is yours.

中文摘要:审核了 #1440 审计 P3 首项(src/launcher.ts 六个 buildXxxEnv 收敛为数据表 + 单一内部构建器),逐客户核对新旧 env 对象键值与插入顺序完全一致、公开 API 与调用点零变化、来源注释保留;本地 typecheck 与定向测试通过,CI 12 项全绿,确认无行为变更,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

孤儿票清理:标题指向的 issue 已关闭,修复已由其他路径落地。关单;误判请 reopen。

@ranxianglei ranxianglei changed the title refactor: converge buildXxxEnv family into data-driven client-env presets (#1440) [PR] refactor: converge buildXxxEnv family into data-driven client-env presets (#1440) Oct 24, 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.

1 participant