Skip to content

refactor(gui): consume the API client for compute operations (#193) - #208

Merged
CameronBrooks11 merged 4 commits into
mainfrom
refactor/gui-consume-client-193
Jun 26, 2026
Merged

CameronBrooks11 merged 4 commits into
mainfrom
refactor/gui-consume-client-193

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Closes #193. Finishes #191 (retires the hand-maintained compute response types). Builds on the merged sidecar (#192).

⚠️ Needs a smoke-test of the built app before merge

This is the first change that flips the GUI's runtime path onto the sidecar (export / preview / validate now POST to the local API instead of shelling out to the CLI). It's green in CI (tsc + vitest), but only a built-app run can confirm the webview actually round-trips to the sidecar. The review assessed the fetch/CSP risk as LOW (Tauri 2 with no csp key imposes no connect-src limit, and the already-merged /health poll uses the same fetch-to-127.0.0.1 mechanism) — but please confirm export/preview/validate work end-to-end. I won't auto-merge this one.

What

  • lib/commands.ts: validateWindDefinition → POST /validate (4xx → {valid:false, errors}); plotDefinition → POST /plan then POST /plot (PNG → base64); planWind → POST /plan then writes the gcode to the chosen path (content-based; no temp .wind). Dead simulateProgram/previewPlot removed. streamProgram + file I/O stay on the Tauri bridge.
  • Retired PlanSummary/SimulationSummary/PlotPreviewPayload/ValidationResult schemas+types — the generated client types supersede them (build: OpenAPI-generated TS client + CI drift gate #191 acceptance).
  • commands.test.ts rewritten against a mocked client. Net −188 lines.

Review

Independent adversarial review: SHIP-WITH-NITS, no blocking — verified openapi-fetch usage against its source, the 422 loc.slice(1) mapping, bytesToBase64, and retirement completeness. Nits addressed: CHANGELOG now notes the warnings caveat; validate hardened against a hypothetical 200 {valid:false}.

Known caveat + follow-ups

  • Preview warnings (previously scraped from CLI stderr) have no structured API equivalent → preview shows none. Noted in CHANGELOG; a structured /plan warnings field is the fix.
  • Off-spec 400: /validate and /plan return a custom 400 not declared in the OpenAPI spec. Handled at runtime; declaring it in the FastAPI responses would make the contract explicit (backend follow-up).

Verification

  • tsc clean · vitest 612 passed · stylelint clean · OpenAPI client drift gate clean (no API change).

@CameronBrooks11

Copy link
Copy Markdown
Member Author

CI is fully green (GUI tsc+vitest, Freeze API ×3, Build Installers ×3). Ready to merge — awaiting a smoke-test of the built app to confirm export/preview/validate round-trip through the sidecar (per the PR description, I'm not auto-merging this one).

@CameronBrooks11

Copy link
Copy Markdown
Member Author

Smoke-test found a real bug (and fixed it): the bundled CLI + sidecar weren't being found on Linux/macOS. Tauri places resources from the ../bundled-*/* globs under a _up_/ subdir on all platforms, but cli_path.rs/api_path.rs only checked _up_ on Windows → 'CLI Backend Unavailable' + the sidecar never spawned. Fixed in 3cb3119 (check _up_ first on all platforms; verified the extracted AppImage binaries live there and run). Rebuilding installers.

Swap the compute wrappers in lib/commands.ts from Tauri `invoke` to the
generated OpenAPI client (via getApiClient):

- validateWindDefinition -> POST /validate (4xx mapped to {valid:false,errors}).
- plotDefinition -> POST /plan then POST /plot (PNG bytes -> base64).
- planWind -> POST /plan, then writes the returned gcode to the chosen path
  (content-based; handleExportGcode no longer writes a temp .wind).
- Delete the dead simulateProgram/previewPlot wrappers (no callers).
- streamProgram + save/load file I/O stay on the Tauri bridge.

Retire the hand-maintained compute response schemas/types (PlanSummary,
SimulationSummary, PlotPreviewPayload, ValidationResult) — the generated
client types supersede them (completes #191's acceptance).

Marlin streaming and its event apparatus are unchanged here; that REST
swap + /jobs polling lands with #190/#199.

Closes #193. Finishes #191.

Known caveat: the preview's planner warnings (previously captured CLI
stderr) have no structured API equivalent yet, so they render empty.
Resources bundled from the `../bundled-cli/*` and `../bundled-api/*` globs
land under a `_up_/` subdirectory on every platform (Tauri encodes the
parent-dir `../`), not just Windows. cli_path.rs and api_path.rs only
checked `_up_` on Windows, so on Linux/macOS the bundled `fiberpath` CLI
and `fiberpath-api` sidecar were never found: the GUI showed "CLI Backend
Unavailable" and the sidecar never spawned (compute paths would fail).

Check `_up_/bundled-*/` first on all platforms, falling back to a flat
`bundled-*/` for dev layouts. Verified against the extracted Linux
AppImage: the binaries live at `<resource_dir>/_up_/bundled-{cli,api}/`
and run correctly (CLI --help, sidecar handshake + /health) — the only
bug was the path lookup.

Surfaced by the #193 smoke-test; also fixes the pre-existing CLI-path bug.
The Tauri webview fetches the sidecar cross-origin (its tauri:// origin →
127.0.0.1:<port>), so the browser enforces CORS. Without these headers the
webview can't read responses ("TypeError: Load failed") and POST preflights
fail, breaking preview/validate/export. Add permissive CORSMiddleware — the
sidecar binds loopback only and is never network-exposed, so allowing any
origin is safe.

Surfaced by the #193 smoke-test.
@CameronBrooks11
CameronBrooks11 force-pushed the refactor/gui-consume-client-193 branch from 3cb3119 to 1b1c2f7 Compare June 26, 2026 15:52
@CameronBrooks11
CameronBrooks11 merged commit e080e6a into main Jun 26, 2026
21 checks passed
@CameronBrooks11
CameronBrooks11 deleted the refactor/gui-consume-client-193 branch June 26, 2026 16:02
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.

refactor(gui): consume the API client; replace event streaming with polling

1 participant