feat(shared): backfill gateway + costs API modules#218
Draft
gambtho wants to merge 15 commits into
Draft
Conversation
Adds vitest devDep + minimal node-env config so the shared package can host its first unit tests. No tests added in this commit — subsequent commits add gateway.test.ts and costs.test.ts.
First method of the gateway backfill — matches the shape currently hand-rolled in frontend/src/lib/api.ts's gatewayApi.getStatus. Tested via a mocked RequestFn.
Follow-up to 4e1cddb. Extracts the `vi.fn().mockResolvedValue(...) as unknown as RequestFn` cast into a small `mockRequest` helper so the five sibling test files that Tasks 3-7 will add inherit a cleaner shape. Also types `mockResponse` against `GatewayInfo` so future type drift in the response shape fails the test at compile time instead of silently under-specifying the mock.
Second method of the gateway backfill — matches gatewayApi.getModels in frontend/src/lib/api.ts. Gateway API is now complete.
First of four costs methods — POSTs a CostEstimateRequest and returns a CostEstimateResponse. Matches frontend's costsApi.estimate.
Uses default values (gpuCount=1, replicas=1, computeType=gpu) when called with no args, matching frontend. The response shape is exported as NodePoolCostsResponse so callers can name it if they need to.
Returns the supported GPU model list with memory and generation metadata. Matches frontend.
Final method of the costs backfill. URL-encodes the free-form label argument so any label (including spaces / special chars) is safely passed as a query param. Costs API is now complete.
The two new factories are now exposed via createApiClient's return value, matching the pattern for every other API. Consumers (frontend, headlamp) will start using them in PR 3. Smoke test asserts both properties exist on a configured client instance, so the wiring itself is covered by a runtime test in addition to TypeScript. Note: costs.NormalizeGpuResponse is re-exported under the alias CostsNormalizeGpuResponse to avoid a name clash with the existing aiconfigurator.NormalizeGpuResponse export.
Ensures CI and local `bun run test` catch shared-package regressions. Shared runs first because workspace consumers depend on it.
…ponse at source Eliminates the re-export alias in index.ts by giving the costs type a unique name at its declaration site. The canonical name is now CostsNormalizeGpuResponse everywhere — in costs.ts, in costs.test.ts, and in the public API surface via index.ts. This avoids confusion from having NormalizeGpuResponse mean one thing inside costs.ts and CostsNormalizeGpuResponse outside it. The aiconfigurator module's NormalizeGpuResponse is unchanged.
…ess fields from costs response types
…teway and costs APIs
…est for normalizeGpu
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
gateway.tsandcosts.tsAPI modules to@airunway/shared/api, matching the shapes currently hand-rolled infrontend/src/lib/api.ts(lines 677–734)createApiClient()so consumers can accessclient.gateway.*andclient.costs.*shared/(first test infrastructure for the shared package) with 10 unit tests covering all 6 new methodsPart of: #195 — Shared UI Layer + New-User Onboarding (Phase 1, PR 1 of ~10)
No consumer changes.
frontend/src/lib/api.tsis untouched — PR 3 will flip the frontend to use these shared modules and delete the 734-line duplicate.What's new
shared/api/gateway.tsgetStatus(),getModels()shared/api/costs.tsestimate(),getNodePoolCosts(),getGpuModels(),normalizeGpu()shared/api/index.tsshared/api/test-helpers.tsmockRequest<T>()helperTest plan
cd shared && bun run test— 10/10 passingbun run test(root) — 718 total (shared: 10, frontend: 102, backend: 606)cd shared && bun run build— exit 0, no TypeScript errorsgit diff origin/main -- frontend/— empty (no consumer changes)frontend/src/lib/api.tsexactly (verified side-by-side)getNodePoolCosts(gpuCount=1, replicas=1, computeType='gpu')match frontendnormalizeGpuURL-encodes label viaencodeURIComponent(test verifies%20encoding)