Title: clef-proxy: the upstream half of PR #691's fix has no regression test — and the hardcoded gateway URL makes it untestable · Issue #692 · developing-today/code · GitHub
Open Graph Title: clef-proxy: the upstream half of PR #691's fix has no regression test — and the hardcoded gateway URL makes it untestable · Issue #692 · developing-today/code
X Title: clef-proxy: the upstream half of PR #691's fix has no regression test — and the hardcoded gateway URL makes it untestable · Issue #692 · developing-today/code
Description: Finding PR #691 fixed both halves of #690 in bin/clef-proxy.mjs, but only the client-body half got a regression test. The upstream half — a non-JSON or null/scalar gateway response is reported as an upstream failure preserving the upstre...
Open Graph Description: Finding PR #691 fixed both halves of #690 in bin/clef-proxy.mjs, but only the client-body half got a regression test. The upstream half — a non-JSON or null/scalar gateway response is reported as a...
X Description: Finding PR #691 fixed both halves of #690 in bin/clef-proxy.mjs, but only the client-body half got a regression test. The upstream half — a non-JSON or null/scalar gateway response is reported as a...
Opengraph URL: https://github.com/developing-today/code/issues/692
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"clef-proxy: the upstream half of PR #691's fix has no regression test — and the hardcoded gateway URL makes it untestable","articleBody":"## Finding\n\nPR #691 fixed both halves of #690 in `bin/clef-proxy.mjs`, but only the client-body half got a regression test. The upstream half — a non-JSON or `null`/scalar gateway response is reported as an upstream failure preserving the upstream status instead of throwing into a 500 — has no test that can fail if it regresses, and as written it cannot be tested at all: the gateway URL is hardcoded, so no stub upstream can be injected.\n\n## Evidence\n\n- PR: https://github.com/developing-today/code/pull/691 (merged 2026-10-23T21:39:55Z, merge commit `8e05af24341b321779851bc824177b14cfd57b9f`, commit `02183adb78c00e20fab4bebb2e7100a6f4e58bcc`, fixes #690, now CLOSED)\n- Upstream guard on current main `8e05af24` (`bin/clef-proxy.mjs:157-165`, blob `b61de077` cross-checked via `gh api`): `cfData` starts `null`, `await cfRes.json()` is in its own `try {} catch {}`, and the success check is `cfRes.ok && cfData?.success && cfData.result?.answers`; the failure branch answers `cfRes.status >= 400 ? cfRes.status : 502`.\n- The new test file's own header says the upstream is out of scope (`bin/clef-proxy.test.mjs:4-6`): \"The proxy forwards valid requests to the Cloudflare AI gateway, which these tests never reach: they cover the paths that answer locally\". Its four subtests are health 200, invalid JSON 400, non-object JSON 400, missing token 401 — none reaches the fetch. Verified this run (pr-diff-review): `node --test bin/clef-proxy.test.mjs` passes 5/5 on current main, and reverting only the upstream guard (unguarded `cfRes.json()` / `cfData.success`) would fail none of them.\n- The gateway base is not overridable (`bin/clef-proxy.mjs:141`): `const cfUrl = \\`https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/workers-ai/run/${model}\\``. Account, gateway and token all come from env/config (`getCredentials`, :56-73), but the host does not, so a test cannot point the proxy at a local stub gateway without a code change first.\n- #690's acceptance criteria required tests only for the local paths (health / invalid JSON 400 / missing token 401), so the issue closed with the upstream behaviour — two of its own acceptance bullets — unpinned. Same pattern as #688 (the untested streaming half of PR #685's design-code-proxy fix).\n\n## Why it matters\n\nThe upstream guard is the half that fires exactly when Cloudflare is misbehaving — an HTML 502/429 page or a malformed gateway body is when clients most need the real upstream status instead of a misleading JSON-parse 500. Today the code is correct; what is missing is the pin that keeps it correct, and the hardcoded gateway host means a future contributor cannot add that pin without first refactoring the URL construction.\n\nSingle-repo: `clef-proxy` and the `gateway.ai.cloudflare.com` URL exist only in this repo (git grep across the local clones of developing-today/opencode, developing-today/openchamber and dezren39/nix finds neither).\n\n## Acceptance criteria\n\n- [ ] The gateway base URL is overridable for tests (e.g. an env var such as `CLEF_PROXY_GATEWAY_BASE_URL` / `CLOUDFLARE_GATEWAY_BASE_URL` defaulting to `https://gateway.ai.cloudflare.com/v1`), or an equivalent fetch/stub injection exists; production behaviour with the override unset is byte-identical.\n- [ ] New tests in `bin/clef-proxy.test.mjs` run the proxy against a stub gateway and cover at least: a non-JSON upstream body with an error status (client gets that status / 502 upstream failure, not a JSON-parse 500), and a `null` (or scalar) upstream JSON body (no throw on `cfData.success`, reported as an upstream failure).\n- [ ] Ablation: with the upstream guard reverted (unguarded `await cfRes.json()` and `cfData.success`), the new tests fail; with the guard in place, the full clef-proxy suite passes (`node --test bin/clef-proxy.test.mjs`).\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-23T21:41:20Z","url":"https://github.com/developing-today/code/issues/692"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b9fad223-8735-cab1-fa3b-d7eeedf33149 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98E8:572F9:A7CC22:E08C74:6B06412B |
| html-safe-nonce | c768584c0e92c4e7bfdadd6b992229c0e89bf2cecfee8b63367c7a738c712118 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEU4OjU3MkY5OkE3Q0MyMjpFMDhDNzQ6NkIwNjQxMkIiLCJ2aXNpdG9yX2lkIjoiNjcwMjA3NDI1ODQ4MDU3ODg1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4d52a54c40e62e63ef9e5baaaf3abb2bdb188cc328d6a1be5ce11e4739d91db |
| hovercard-subject-tag | issue:6005866388 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/692/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b999a2221f66273ff11d91286ee177ff6620679c2d94267a6715be69a5a9d89/developing-today/code/issues/692 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b999a2221f66273ff11d91286ee177ff6620679c2d94267a6715be69a5a9d89/developing-today/code/issues/692 |
| og:image:alt | Finding PR #691 fixed both halves of #690 in bin/clef-proxy.mjs, but only the client-body half got a regression test. The upstream half — a non-JSON or null/scalar gateway response is reported as a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1bff4f6bfaa96dc9c42cacf315424c24ebb548b06142ced5e3aaccb2a42dd652 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ac613d3698d3d8565651455086e1f74da07bf277 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width