unsloth/studio/frontend
Daniel Han a2ab0dda30 studio/frontend: add Vitest suite for auth + 422 helper
Pins the behavioural invariants that landed in PR #5490 (the frontend
half of the #5375-regression fix-up backlog) so a future hardening
pass cannot quietly undo them. Today these surfaces have only typecheck
+ bundle-build coverage; this lifts the floor.

What's pinned (35 tests across 3 files, ~360 ms):

- src/lib/__tests__/format-fastapi-error.test.ts (17)
  formatFastApiDetail + readFastApiError: string passthrough, array
  detail joined as "field: msg" / "; ", nested loc joined by ".",
  missing msg / missing loc / empty array / mixed valid+junk, plus
  Response shapes for 422 / 400 / 500 / 503 / non-JSON / object-detail
  + message fallback. Regression target: rendering `[object Object]`
  or `Request failed (422)` instead of "field: msg".

- src/features/auth/__tests__/session.test.ts (10)
  storeAuthTokens writes only the two JWT keys (never the must-change
  key -- the CodeQL data-flow pin); clearAuthTokens removes all three;
  setMustChangePassword writes the literal "1" / removes the key
  (presence-encoded so the stored value stays a constant, not a
  derived boolean); isOnboardingDone treats only the literal "true"
  as done.

- src/features/auth/__tests__/api.test.ts (8)
  refreshSession singleflight (5 racing callers -> 1 /api/auth/refresh
  request); in-flight slot clears so subsequent calls refetch;
  non-OK response clears tokens; no refresh token -> no fetch;
  logoutGeneration drops the new token pair when logout() lands
  mid-refresh; logout() clears local state on 204; logout() retries
  with a rotated access token on 401; logout() still clears state on
  network failure.

Wiring:
- vitest 4 + happy-dom 18 as devDependencies.
- vitest.config.ts mirrors the @/ alias from tsconfig.app.json.
- New `test` / `test:watch` scripts.

Workflow step (CI gating) is intentionally NOT included in this PR
because the publishing token lacks `workflow` scope. After merge, add
this between the Typecheck and Build steps in
.github/workflows/studio-frontend-ci.yml:

  - name: Unit tests (Vitest)
    run: npm run test

`npm run typecheck` / `test` / `build` all clean locally.
2026-05-18 08:07:45 +00:00
..
public Polish/cloud to providers (#5450) 2026-05-15 19:29:21 +04:00
src studio/frontend: add Vitest suite for auth + 422 helper 2026-05-18 08:07:45 +00:00
.gitignore perf(studio): upgrade to Vite 8 + auto-install bun for faster frontend builds (#4522) 2026-03-25 04:27:41 -07:00
.gitkeep add studio root folder 2026-02-02 09:14:35 +00:00
.npmrc security: NOT affected by Mini Shai-Hulud (May-12 wave) -- forward-looking hardening only (#5397) 2026-05-13 04:58:12 -07:00
biome.json feat: add seed dataset support with configuration, preview, and builder utilities 2026-02-14 18:44:38 +01:00
components.json add studio root folder 2026-02-02 09:14:35 +00:00
data-designer.openapi (1).yaml save and import, and fixes 2026-02-04 14:32:49 +01:00
eslint.config.js Final cleanup 2026-03-12 18:28:04 +00:00
index.html Final cleanup 2026-03-12 18:28:04 +00:00
package-lock.json studio/frontend: add Vitest suite for auth + 422 helper 2026-05-18 08:07:45 +00:00
package.json studio/frontend: add Vitest suite for auth + 422 helper 2026-05-18 08:07:45 +00:00
tsconfig.app.json Relax frontend unused local check (#4388) 2026-03-17 16:04:11 -07:00
tsconfig.json cleanup 2026-02-04 13:28:39 +01:00
tsconfig.node.json cleanup 2026-02-04 13:28:39 +01:00
vite.config.ts Fix Install commands for Windows + 1 line installs (#4447) 2026-03-19 02:09:09 -07:00
vitest.config.ts studio/frontend: add Vitest suite for auth + 422 helper 2026-05-18 08:07:45 +00:00