Skip to content

[Hackathon] fix(http): on a corporate network the CLI fails every command, then blames the wrong thing (fetch failed, invalid key, no credits) #433

Closed

Description

@Andy00L

Verified against (commit SHA or released version)

commit 988c035 (v0.14.0)

Discord Username / User ID

interferon0

What does this improvement do?

The CLI assumes nothing sits between it and api.testsprite.com. On a company laptop, in a hotel, or on a self-hosted CI runner, something usually does: a proxy that re-signs HTTPS, a firewall that serves a block page, a captive portal. Three things go wrong there, and each one sends the user (or the coding agent driving the CLI) to fix the wrong thing.

1. Behind a TLS-inspecting proxy, every command fails, even when IT set the machine up correctly. Zscaler, Netskope and antivirus HTTPS scanning re-sign traffic with a root that IT installs in the operating system's certificate store. curl, git and the browser trust it. Node only trusts its bundled Mozilla roots, so every testsprite command fails:

$ SSL_CERT_FILE=corp-ca.pem testsprite --endpoint-url https://127.0.0.1:18203 auth status
Error: fetch failed
Service is temporarily unavailable. The CLI retries with exponential backoff; if this persists, report it.
(exit 10, after 4 attempts)

(SSL_CERT_FILE=corp-ca.pem curl https://127.0.0.1:18203/me answers 200 on the same machine.) Nothing mentions a certificate or NODE_EXTRA_CA_CERTS. The shortcut people reach for, NODE_TLS_REJECT_UNAUTHORIZED=0, turns off certificate checks for the requests that carry the API key.

2. A proxy's block page is read as TestSprite's verdict. When a firewall, captive portal or WAF answers with an HTML page, the CLI maps its status code to an API error code as if TestSprite had said it. Measured with test get test_abc against a server that answers every request with an HTML "Access Denied" page:

page status what v0.14.0 tells the user exit
403 Server returned 403 without an error envelope. (code AUTH_FORBIDDEN) 3 (auth)
402 Top up credits on the portal Billing page ... Run testsprite usage to check your current balance 12 (credits)
404 Server returned 404 without an error envelope. (code NOT_FOUND) 4 (not found)
426 Server returned 426 without an error envelope. (code CLIENT_TOO_OLD) 14 (upgrade)

Scripts and coding agents act on the exit code and the error text, so they rotate a working API key, tell the user to buy credits, recreate a test that exists, or upgrade the CLI, for a request TestSprite never received. The page's title, which usually says exactly what happened ("Website blocked by your organization"), is thrown away. testsprite doctor on the same 403 page prints API key rejected (AUTH_FORBIDDEN) and tells the user to mint a new API key with the run:tunnel scope.

3. Every other network failure reads the same. A typo in --endpoint-url, a closed port and a proxy asking for credentials (407) all print fetch failed plus "if this persists, report it", after 4 attempts. testsprite doctor says GET /me failed (UNAVAILABLE) and then blames the endpoint for not supporting tunnels.

Details / implementation notes

Proposed fix, in the shared HTTP layer so every command gets it:

  • OS certificate store fallback. When Node rejects the API's chain as untrusted, add the roots that only the OS store has to Node's default CA list (tls.getCACertificates('system') + tls.setDefaultCACertificates, Node 22.19+ / 24.5+), once per process, and retry at once. Verification stays on. On Node 20 nothing changes.
  • Pages that are not the API. The API answers errors with JSON: its envelope, or its framework's JSON for an unknown route ({"message":"Cannot GET ...","error":"Not Found","statusCode":404}) or a body it cannot parse. It also echoes the request's x-request-id. I checked both against api.testsprite.com. So a 4xx whose body is not JSON at all (HTML, plain text, empty) and that does not echo the request id did not come from the API. Report it as exit 10 with details.reason: "not_testsprite", the status, the content type and the page title, and do not retry it. JSON answers, 408/429 and 5xx keep today's handling.
  • Named causes. Walk the fetch failed cause chain and name the failure (untrusted, expired or wrong-host certificate, DNS, refused, timeout, reset, proxy refusal), with the fix in nextAction and details.reason / details.cause for --output json. Certificate failures and a 407 fail on the first attempt. doctor prints the same cause and stops blaming tunnels.
  • Exit codes for real API answers do not change.

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

  1. added
    needs-triage
    hackathon
    on Oct 16, 2026
  2. fyZhang66 commented on Oct 20, 2026

    @fyZhang66
    Contributor

    Confirmed in part, thanks @Andy00L. The non-JSON 2xx copy is already fixed on dev (it names a proxy, captive portal or login page). Still open: TLS chain errors are reported as a generic transport failure and retried four times, and non-JSON error statuses still map 402/403 to credits/auth. Accepted at low priority, scope:

    • Short-circuit UNABLE_TO_VERIFY_LEAF_SIGNATURE / SELF_SIGNED_CERT_IN_CHAIN / CERT_HAS_EXPIRED into a typed error with no retries, whose message names NODE_EXTRA_CA_CERTS.
    • Classify a non-JSON error status as "something between you and the API" rather than by status code.
    • Out of scope: reading the OS certificate store (tls.getCACertificates('system') is not available across our supported Node range).
    • Tests (must fail before the fix): each TLS code → exit 10, single attempt, message names the env var; an HTML 403 is not reported as AUTH_FORBIDDEN.

    No new dependency. Comment /assign to claim it.

  3. added
    accepted
    and removed
    needs-triage
    on Oct 20, 2026
  4. OkeyAmy commented on Oct 20, 2026

    @OkeyAmy
    Contributor

    /assign

  5. added
    in-progress
    on Oct 20, 2026
  6. testsprite-hob commented on Oct 20, 2026

    @testsprite-hob

    Assigned to @OkeyAmy. Thanks for taking this on. (0 more slots available.)

    Your open assigned issues (3/3):

  7. removed
    in-progress
    on Nov 19, 2026
  8. added a commit that references this issue on Nov 19, 2026
    cf65d4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acceptedhackathon

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions