Commit eeb038b
authored
fix(opencode): send x-headroom-project header on all proxied requests (#2868)
## Description
The OpenCode transport plugin set `HEADROOM_PROJECT` as a shell env var
for child processes but never forwarded it as `x-headroom-project` on
the actual proxied HTTP requests. The proxy's `classify_project` only
attributes traffic via `x-headroom-project` header or `/p/<name>` URL
prefix — without the header, every OpenCode request was unattributed and
the Per-Project Savings dashboard showed `0 project(s)` permanently.
Fixes #2847.
## Root cause
`installHeadroomTransport` was called with only `{ proxyUrl, debug }`.
The `project` value was computed and used only in the `shell.env` hook
(for subprocess env injection), never threaded through to
`mergeFetchHeaders` or `headersForNodeRequest`.
## Changes Made
1. Add `project?: string` to `InstallOptions` and `TransportState`.
2. Resolve the project value once at plugin init (`pluginOptions.project
→ input.project.id → input.directory`) and pass it to
`installHeadroomTransport`.
3. Both header-building seams now set `x-headroom-project` when a
project is present:
- `mergeFetchHeaders` (wrapped `fetch` path)
- `headersForNodeRequest` (wrapped `http.request` / `https.request`
path)
4. Reuse the resolved `project` in the `shell.env` hook (removes the
duplicate resolution that was there before).
## Changes
- `plugins/opencode/src/transport.ts` — `InstallOptions.project`,
`TransportState.project`; `mergeFetchHeaders`, `headersForNodeRequest`,
`routedNodeOptions`, `withRoutedFetchInput`, `installHeadroomTransport`
updated
- `plugins/opencode/src/plugin.ts` — resolve `project` once, pass it to
transport; reuse in `shell.env`
- `plugins/opencode/src/transport.test.ts` — 3 new tests: project header
on fetch, project header on https.request, no header when project unset
- `headroom/providers/opencode/_dist/entry.opencode.js` — rebuilt with
`npm run build:standalone` to match source
## Testing
- [x] Unit tests pass
- [x] TypeScript typecheck passes
- [x] New regression tests added
### Test Output
```
cd plugins/opencode && npm test
# 17 passed (14 existing + 3 new)
```
TypeScript build also passes: `npm run typecheck` (no errors).
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring
## Real Behavior Proof
- Environment: OpenCode transport plugin test environment on the current
PR head.
- Exact command / steps: ran the plugin test suite and TypeScript
typecheck after rebuilding the standalone bundle.
- Observed result: all 17 tests passed, including project-header
coverage for fetch and Node HTTPS paths plus the unset-project control;
typechecking passed.
- Not tested: a live OpenCode session against a deployed Headroom proxy.
## Review Readiness
- [x] I have performed a self-review
- [x] This PR is ready for human review
---------
Signed-off-by: Radhakrishnan P <gingeekrishna@gmail.com>
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>1 parent 2cae0f8 commit eeb038b
5 files changed
Lines changed: 114 additions & 27 deletions
File tree
- headroom/providers/opencode
- _dist
- hook-shim
- plugins/opencode/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12487 | 12487 | | |
12488 | 12488 | | |
12489 | 12489 | | |
| 12490 | + | |
12490 | 12491 | | |
12491 | 12492 | | |
12492 | 12493 | | |
| |||
12635 | 12636 | | |
12636 | 12637 | | |
12637 | 12638 | | |
12638 | | - | |
| 12639 | + | |
12639 | 12640 | | |
12640 | 12641 | | |
12641 | 12642 | | |
| |||
12647 | 12648 | | |
12648 | 12649 | | |
12649 | 12650 | | |
| 12651 | + | |
| 12652 | + | |
| 12653 | + | |
12650 | 12654 | | |
12651 | 12655 | | |
12652 | | - | |
| 12656 | + | |
12653 | 12657 | | |
12654 | 12658 | | |
12655 | 12659 | | |
12656 | 12660 | | |
12657 | 12661 | | |
12658 | 12662 | | |
12659 | 12663 | | |
12660 | | - | |
| 12664 | + | |
12661 | 12665 | | |
12662 | 12666 | | |
12663 | 12667 | | |
| |||
12703 | 12707 | | |
12704 | 12708 | | |
12705 | 12709 | | |
12706 | | - | |
| 12710 | + | |
12707 | 12711 | | |
12708 | 12712 | | |
12709 | 12713 | | |
12710 | 12714 | | |
12711 | 12715 | | |
| 12716 | + | |
| 12717 | + | |
| 12718 | + | |
12712 | 12719 | | |
12713 | 12720 | | |
12714 | 12721 | | |
12715 | 12722 | | |
12716 | 12723 | | |
12717 | 12724 | | |
12718 | 12725 | | |
12719 | | - | |
| 12726 | + | |
12720 | 12727 | | |
12721 | 12728 | | |
12722 | 12729 | | |
| |||
12747 | 12754 | | |
12748 | 12755 | | |
12749 | 12756 | | |
12750 | | - | |
| 12757 | + | |
12751 | 12758 | | |
12752 | 12759 | | |
12753 | 12760 | | |
| |||
12758 | 12765 | | |
12759 | 12766 | | |
12760 | 12767 | | |
12761 | | - | |
| 12768 | + | |
12762 | 12769 | | |
12763 | 12770 | | |
12764 | 12771 | | |
| |||
12794 | 12801 | | |
12795 | 12802 | | |
12796 | 12803 | | |
| 12804 | + | |
12797 | 12805 | | |
12798 | 12806 | | |
12799 | 12807 | | |
12800 | 12808 | | |
12801 | 12809 | | |
12802 | 12810 | | |
12803 | 12811 | | |
| 12812 | + | |
12804 | 12813 | | |
12805 | 12814 | | |
12806 | 12815 | | |
| |||
12821 | 12830 | | |
12822 | 12831 | | |
12823 | 12832 | | |
12824 | | - | |
| 12833 | + | |
12825 | 12834 | | |
12826 | 12835 | | |
12827 | 12836 | | |
| |||
12871 | 12880 | | |
12872 | 12881 | | |
12873 | 12882 | | |
| 12883 | + | |
12874 | 12884 | | |
12875 | 12885 | | |
12876 | 12886 | | |
| 12887 | + | |
12877 | 12888 | | |
12878 | 12889 | | |
12879 | 12890 | | |
| |||
12894 | 12905 | | |
12895 | 12906 | | |
12896 | 12907 | | |
12897 | | - | |
| 12908 | + | |
12898 | 12909 | | |
12899 | 12910 | | |
12900 | 12911 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
159 | | - | |
| 160 | + | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| |||
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
171 | 175 | | |
172 | 176 | | |
173 | | - | |
| 177 | + | |
174 | 178 | | |
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
181 | | - | |
| 185 | + | |
182 | 186 | | |
183 | 187 | | |
184 | 188 | | |
| |||
224 | 228 | | |
225 | 229 | | |
226 | 230 | | |
227 | | - | |
| 231 | + | |
228 | 232 | | |
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
232 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
233 | 240 | | |
234 | 241 | | |
235 | 242 | | |
236 | 243 | | |
237 | 244 | | |
238 | 245 | | |
239 | 246 | | |
240 | | - | |
| 247 | + | |
241 | 248 | | |
242 | 249 | | |
243 | 250 | | |
| |||
268 | 275 | | |
269 | 276 | | |
270 | 277 | | |
271 | | - | |
| 278 | + | |
272 | 279 | | |
273 | 280 | | |
274 | 281 | | |
| |||
279 | 286 | | |
280 | 287 | | |
281 | 288 | | |
282 | | - | |
| 289 | + | |
283 | 290 | | |
284 | 291 | | |
285 | 292 | | |
| |||
315 | 322 | | |
316 | 323 | | |
317 | 324 | | |
| 325 | + | |
318 | 326 | | |
319 | 327 | | |
320 | 328 | | |
321 | 329 | | |
322 | 330 | | |
323 | 331 | | |
324 | 332 | | |
| 333 | + | |
325 | 334 | | |
326 | 335 | | |
327 | 336 | | |
| |||
342 | 351 | | |
343 | 352 | | |
344 | 353 | | |
345 | | - | |
| 354 | + | |
346 | 355 | | |
347 | 356 | | |
348 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
389 | 441 | | |
390 | 442 | | |
391 | 443 | | |
| |||
0 commit comments