Skip to content

test(e2e-live): preflight gate via @unicitylabs/infra-probe - #11

Open
vrogojin wants to merge 2 commits into
fix/e2e-live-real-issuesfrom
feat/e2e-preflight-infra-probe
Open

test(e2e-live): preflight gate via @unicitylabs/infra-probe#11
vrogojin wants to merge 2 commits into
fix/e2e-live-real-issuesfrom
feat/e2e-preflight-infra-probe

Conversation

@vrogojin

@vrogojin vrogojin commented May 3, 2026

Copy link
Copy Markdown
Owner

Summary

Add a vitest `globalSetup` that runs `@unicitylabs/infra-probe` against testnet (or mainnet/dev via env override) before any test file is loaded. If any service is unreachable the suite aborts up-front instead of burning a 10-15-minute container spawn cycle to surface the same failure as an opaque timeout downstream.

Knobs

Env var Effect
`TRADER_E2E_SKIP_PREFLIGHT=1` bypass entirely (escape hatch)
`TRADER_E2E_PREFLIGHT_STRICT=1` also fail on `degraded` (default warns)
`TRADER_E2E_PREFLIGHT_NETWORK` override network (default: testnet)
`TRADER_E2E_PREFLIGHT_TIMEOUT_MS` per-probe ceiling (default: 30000)

Default policy

Fail-fast on `unreachable`, warn-and-proceed on `degraded`. The e2e suite has generous timeouts that absorb mild slowness, but a fully-down service guarantees a multi-minute hang. Strict mode is available for CI runs that prefer to surface degradation as failure.

Adds two npm scripts (`preflight`, `preflight:json`) for ad-hoc probing without invoking vitest. Pulls in `@unicitylabs/infra-probe@^0.3.0` from npm; ships a tiny .d.ts shim for the upstream pure-ESM module.

Test plan

  • Helper unit-test file runs preflight then proceeds (default policy)
  • `TRADER_E2E_SKIP_PREFLIGHT=1` disables the gate (verified: 171ms total)
  • `TRADER_E2E_PREFLIGHT_STRICT=1` elevates degraded to hard failure
  • Caught a real signal: testnet market API was 12s degraded on first run — preflight surfaced it cleanly with a warning, exactly the scenario this gate exists for
  • Full e2e-live suite passing 11/11 in 23 min with preflight active (caught market degradation as warning)

vrogojin added 2 commits May 3, 2026 10:46
Add a vitest globalSetup that runs the infra-probe against testnet (or
mainnet/dev via env override) before any test file is loaded. If any
service is unreachable the suite aborts up-front instead of burning a
10-15-minute container spawn cycle to surface the same failure as an
opaque timeout downstream.

Knobs:
  TRADER_E2E_SKIP_PREFLIGHT=1     — bypass entirely (escape hatch)
  TRADER_E2E_PREFLIGHT_STRICT=1   — also fail on degraded (default warns)
  TRADER_E2E_PREFLIGHT_NETWORK    — override network (default: testnet)
  TRADER_E2E_PREFLIGHT_TIMEOUT_MS — per-probe ceiling (default: 30000)

Default policy: fail-fast on `unreachable`, warn-and-proceed on
`degraded`. The e2e suite has generous timeouts that absorb mild
slowness, but a fully-down service guarantees a multi-minute hang. The
strict mode is available for CI runs that prefer to surface degradation
as failure rather than risk flaky test output.

Adds two npm scripts (preflight, preflight:json) for ad-hoc probing
without invoking vitest. Pulls in @unicitylabs/infra-probe@^0.3.0 from
npm; ships a tiny .d.ts shim for the upstream pure-ESM module.

Smoke-tested locally: helper unit-test file runs preflight then
proceeds; SKIP env disables the gate; STRICT env elevates degraded to
hard failure (probe currently caught a real 12s search degradation on
the testnet market API).
…Dependencies + README

Three review-feedback items from #11:

## W1+W2: validate env-var inputs at preflight startup

`Number('abc')` returns NaN; `Number('-1')` returns -1; `Number('0')`
returns 0. All of these would propagate to the upstream probe's
`setTimeout` and either fire immediately (NaN coerces to 1ms in Node)
or never fire — producing misleading "preflight failed" results from a
typo. Validate `TRADER_E2E_PREFLIGHT_TIMEOUT_MS` with
`Number.isFinite() && > 0` and throw a clean error otherwise.

Same hardening for `TRADER_E2E_PREFLIGHT_NETWORK`: was a blind cast to
`'testnet' | 'mainnet' | 'dev'`. The upstream `runProbes` would also
throw on unknown networks, but tightening locally makes the contract
visible at trader-service startup and immune to upstream silent enum
extensions.

## W5: move @unicitylabs/infra-probe to devDependencies

The probe is only used from `test/e2e-live/` and the `preflight` /
`preflight:json` npm scripts. End-users `npm install`ing trader-service
as a binary (the `bin: trader-ctl` entrypoint) shouldn't pull in the
probe + its transitive deps (@noble/curves, ws). Move to
devDependencies; lockfile updated.

## W3: document the four env vars in README

A developer hitting "preflight failed" needs to know about
`TRADER_E2E_SKIP_PREFLIGHT=1` without grepping the source. README now
has an "E2E live tests — preflight gate" section with a table of all
four env vars + their defaults + ad-hoc probing instructions.

## Not addressed (deliberately deferred)

- C1 (cosmetic): "N service(s) unreachable" log message can over-count
  when `error` and `unreachable` mix. The gate still fires correctly;
  the message phrasing is a separate cleanup.
- W4 (per-file opt-out): no opt-out mechanism for vitest globalSetup
  per-file. The `TRADER_E2E_SKIP_PREFLIGHT` escape hatch is the
  documented workaround.

## Test plan

- typecheck clean for the test/ tree (the pre-existing src/trader/main.ts
  errors belong to PR #12 and are fixed there)
- helper unit tests pass; preflight runs and validates env vars correctly
- `npm install` re-resolves dep graph after move; no breakage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant