test(e2e-live): preflight gate via @unicitylabs/infra-probe - #11
Open
vrogojin wants to merge 2 commits into
Open
test(e2e-live): preflight gate via @unicitylabs/infra-probe#11vrogojin wants to merge 2 commits into
vrogojin wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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