Skip to content

clef-proxy: the upstream half of PR #691's fix has no regression test — and the hardcoded gateway URL makes it untestable #692

Closed

Description

@dezren39

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 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.

Evidence

Why it matters

The 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.

Single-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).

Acceptance criteria

  • 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.
  • 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).
  • 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).

Activity

  1. added
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Oct 25, 2026
  2. dezren39 commented on Oct 26, 2026

    @dezren39
    MemberAuthor

    Intake review

    Still live (verified this run, fleet monitor): bin/clef-proxy.mjs on current main still hardcodes the gateway URL at line 160 (https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/workers-ai/run/${model}) with no env override, and the upstream guard (cfRes.ok && cfData?.success && cfData.result?.answers, line ~184) is present but still has no test that can reach it — the test file's local-paths-only scope is unchanged.

    Related: PR #691 / closed #690 (the fix whose upstream half this pins), #688 (the same untested-streaming-half pattern in design-code-proxy).

    Notes / risks: the prerequisite refactor (gateway base URL from env/config, defaulting to the current hardcoded value) is the only production change needed; keep the default byte-identical so deployment behaviour does not move.

    Suggested approach: add a CLEF_GATEWAY_BASE-style override in getCredentials/config, point the test suite at a local stub gateway, and add subtests for non-JSON upstream body, null/scalar JSON, and upstream 4xx/5xx status preservation.

    Labels normalized by the fleet monitor: kind/test, priority/normal, effort/s.

  3. added
    kind/testTest coverage, test infrastructure, or test-only fixes
    priority/normalOrdinary priority (the default)
    effort/sSmall: expected under 2 hours of work
    meta/enrichedIntake review done: acceptance criteria, links, and normalized labels added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Oct 26, 2026
  4. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  5. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triage findings (queue task 1068, lane D)

    Verdict: CONFIRMED on current main 47214f1c — verified by direct read of bin/clef-proxy.mjs this run (line numbers moved since filing; the code is byte-equivalent):

    • Guard behaviour (as filed): :246-255 — cfData starts null, await cfRes.json() sits in its own try {} catch {}, success requires cfRes.ok && cfData?.success && cfData.result?.answers, and the failure branch answers cfRes.status >= 400 ? cfRes.status : 502. A non-JSON or null/scalar gateway body is reported as an upstream failure preserving the upstream status — the fix(clef-proxy): malformed client JSON is a 400, not a 500 (#690) #691 upstream half is present and correct.
    • Untestability (as filed): :227 — cfUrl is built from a hardcoded https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/workers-ai/run/${model}. Account/gateway/token all resolve env-first (getCredentials, :75/:79/:88), and even the listen host is env-overridable (CLEF_PROXY_HOST, :9) — but the gateway host/base is not, so no stub upstream can be injected. bin/clef-proxy.test.mjs's own header still states the tests "never reach" the upstream; its subtests cover only the local paths (health / 400 / 401), so reverting the guard would fail none of them.
    • No open PR references clef-proxy: the upstream half of PR #691's fix has no regression test — and the hardcoded gateway URL makes it untestable #692 (searched this run).

    Seam proposal (pinned for the follow-up task — not implemented here): follow the file's own env-first convention: const gatewayBase = process.env.CLEF_PROXY_GATEWAY_BASE || 'https://gateway.ai.cloudflare.com' and build cfUrl as ${gatewayBase}/v1/${accountId}/${gatewayId}/workers-ai/run/${model}. Default behaviour is byte-identical. The existing test harness already spawns the proxy as a subprocess with a controlled env/HOME, so with this seam the upstream tests need no export refactor: stand up a stub HTTP server on 127.0.0.1, point CLEF_PROXY_GATEWAY_BASE at it, POST a valid body, and pin: (1) upstream 502 with an HTML/non-JSON body → proxy answers 502 (not 500); (2) upstream 200 with JSON null → 502; (3) upstream 200 with a scalar body → 502; (4) upstream 200 with {success:true,result:{answers}} → 200 with the answers (happy path pinned too).

    A small_fix follow-up task (seam + the four upstream regression tests) is being enqueued from this triage.

  6. 7 remaining items

  7. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Oct 31, 2026
  8. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — task 4596 implemented by Lane A. PR opened @af1424238: CLEF_PROXY_GATEWAY_BASE seam (Cloudflare default, cfUrl shape unchanged) + stub-upstream regression tests (non-JSON 502 / null 200 / scalar 200 / happy path); node --test bin/clef-proxy.test.mjs 10/10 on the laptop. Parking on CI + Codex review.

  9. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Oct 31, 2026
  10. added a commit that references this issue on Oct 31, 2026
  11. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Oct 31, 2026
  12. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

effort/sSmall: expected under 2 hours of workkind/testTest coverage, test infrastructure, or test-only fixesmeta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/normalOrdinary priority (the default)source/pr-diff-reviewFiled by the pr-diff-review jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions