|
| 1 | +# 031 — #2107 implementation record |
| 2 | + |
| 3 | +Branch: `fix/service-proxy-env` off `origin/dev` @ `18e072c8d`. |
| 4 | +Commit: `eb910776a`. PR: **#2116** → `dev`. |
| 5 | + |
| 6 | +## What the plan said vs what the tree said |
| 7 | + |
| 8 | +`030` was written against a read of the code and held up on every point, with one |
| 9 | +correction worth recording. |
| 10 | + |
| 11 | +**The plan asked for a guard that already exists.** It said "do not emit empty |
| 12 | +`Environment=` lines". All three builders already drop falsy values before |
| 13 | +joining — `systemdEnvironmentAssignment` returns `null`, |
| 14 | +`buildPlist` uses ternaries, `windowsBatchSet` returns `null` — and each list is |
| 15 | +`.filter(Boolean)`ed. So the risk was real in principle and already handled in |
| 16 | +practice; adding a second guard would have been noise. |
| 17 | + |
| 18 | +That is the useful shape of this correction: the plan named a hazard from |
| 19 | +reading a diff, and the tree had already solved it structurally. |
| 20 | + |
| 21 | +## The change |
| 22 | + |
| 23 | +One helper plus three call sites: |
| 24 | + |
| 25 | +``` |
| 26 | +resolvedProxyEnv(env = process.env): { name, value }[] |
| 27 | + for each of PROXY_ENV_KEYS (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) |
| 28 | + value = env[KEY]?.trim() || env[key]?.trim() // either case |
| 29 | + if (value) push({ name: KEY, value }) // canonical name only |
| 30 | +``` |
| 31 | + |
| 32 | +| Builder | Line of insertion | |
| 33 | +|---|---| |
| 34 | +| `buildUnit` | after `opencodexHome`, mapped through `systemdEnvironmentAssignment` | |
| 35 | +| `buildPlist` | after `OPENCODEX_HOME`, mapped to `<key>/<string>` | |
| 36 | +| `buildWindowsServiceScript` | after `OPENCODEX_HOME`, mapped through `windowsBatchSet` | |
| 37 | + |
| 38 | +Reading both letter cases but writing only the upper-case name matters: curl-style |
| 39 | +tooling sets `http_proxy`, and emitting both spellings into one definition would |
| 40 | +leave two sources of truth for one setting. |
| 41 | + |
| 42 | +## Verification |
| 43 | + |
| 44 | +``` |
| 45 | +bun test tests/service.test.ts 126 pass / 0 fail |
| 46 | +bun x tsc --noEmit exit 0 |
| 47 | +``` |
| 48 | + |
| 49 | +**Red-drive, recorded.** With the three `resolvedProxyEnv()` call sites stripped |
| 50 | +out, the primary test fails on exactly the missing line: |
| 51 | + |
| 52 | +``` |
| 53 | +Expected to contain: "Environment=\"HTTP_PROXY=http://127.0.0.1:7890\"" |
| 54 | +(fail) bakes outbound proxy env into the unit ... (#2107) |
| 55 | + 1 pass 1 fail |
| 56 | +``` |
| 57 | + |
| 58 | +and nothing else in the file breaks. Restoring the fix returns 126/0. |
| 59 | + |
| 60 | +The companion test (no proxy in the shell → no proxy keys emitted) passes in both |
| 61 | +states by design. It is not an oracle for the fix; it is a guard that the fix |
| 62 | +cannot start emitting empty assignments later. |
| 63 | + |
| 64 | +## What this deliberately does not do |
| 65 | + |
| 66 | +- **No interactive `ExecStart`.** `bash -ic` would make service startup depend on |
| 67 | + the user's interactive shell — a worse failure mode than the bug. |
| 68 | +- **No `NO_PROXY` synthesis.** The runtime's `applyProxyEnv` already keeps |
| 69 | + loopback off the proxy path; inventing a value here could diverge from it. |
| 70 | +- **No credential handling decision.** A proxy URL can carry credentials, and |
| 71 | + baking it writes that to disk. `config.proxy` already works for that case |
| 72 | + without this change. Raised in the PR body as an open question rather than |
| 73 | + silently resolved. |
| 74 | + |
| 75 | +## CI posture |
| 76 | + |
| 77 | +Not consulted. `dev` is mid-merge-train (30 commits in the window this work |
| 78 | +started) and its checks are noisy by construction. Verification here is local |
| 79 | +and complete for the changed surface; CI becomes the gate once the train |
| 80 | +settles. |
0 commit comments