Commit Graph
6 Commits
Author SHA1 Message Date
CatoandClaude Opus 5 ebc9dadb24 perf(test): stop building a browser for tests that never touch one (#917)
The suite ran EVERY file in a jsdom environment. Its own numbers:

  Duration 1257s — environment 2285s, setup 465s, import 318s, tests 166s

Actual test execution was 166 seconds. The dominant term was constructing a
fake DOM for API-route, service and domain tests that never use one — 240 of
291 files.

Now node by default; the 51 files that need a DOM declare it per-file with
`// @vitest-environment jsdom`. Full suite after: 291 files, 2719 tests, 0
failures, environment 2285s -> 307s. A controlled A/B on one unchanged
directory (23 files, 177 tests) isolates the effect from machine load:
environment 178s -> 0.03s, wall 120s -> 84s.

This runs on every push (the pre-push hook) and in CI, so it is paid
constantly.

NOT environmentMatchGlobs, which is the obvious one-line version: Vitest 4
ignores it SILENTLY — no warning, no error. It ran every component test under
node and failed 20 of them, and the only reason that was caught is that a .tsx
test was checked afterwards rather than trusting the clean config load. The
config now says so, so the next person does not spend the same hour.

vitest.setup.ts already guarded its DOM access behind IS_JSDOM, which is what
made this safe to do at all.

One file needed jsdom for a non-obvious reason and the full run is what caught
it: rate-failure-cooldown.test.ts pins browser behaviour of rates.ts, which
gates its fetch on `typeof window` — the test never mentions `window`, only
the module under test does. Grepping the tests for DOM usage cannot see that;
running them can.


Claude-Session: https://claude.ai/code/session_019ns25hxd1ExZsmCJz9nNhe

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 05:37:30 -07:00
bae4be1aa3 refactor(test): migrate the unit suite from Jest 30 to Vitest 4 (#859)
Full parity: 282 test files / 2645 tests green before and after.

- vitest.config.ts mirrors the old moduleNameMapper as ordered resolve.alias
  entries; jsdom env, globals, 30s timeout, v8 coverage with the same ratchet.
- vitest.setup.ts ports jest.setup.ts; lucide-react is now a vi.mock Proxy
  (any icon resolves — the old CJS-alias Proxy surfaced no named exports and
  every unlisted icon crashed renders as "Element type is invalid").
- Codemod jest.* -> vi.* across tests; @jest-environment -> @vitest-environment.
- Constructor mocks use function expressions (vitest news the implementation;
  arrows are not constructable).
- Factories returning a bare component now return { default: ... };
  one TDZ factory moved under vi.hoisted; one require() -> await import().
- jest.isolateModulesAsync dropped in the auth smoke test (resetModules +
  doMock per test covers it).
- Scripts ported (positional path filters replace --testPathPatterns);
  verify's --watchAll flag removed; ci.yml comment updated.
- Deleted jest.config.js, jest.setup.ts, __mocks__/vitest.js,
  tsconfig.test.json, tests/jest-dom.d.ts, and the unimported jest-era
  tests/utils.ts; uninstalled jest, ts-jest, jest-environment-jsdom,
  @types/jest; dropped the dead mcp:jest script.
- Snapshot file rewritten in Vitest format (content byte-identical).


Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 16:14:36 +00:00
ba4cf192b6 fix(voice): one mic, inside the AI entry, styled like it belongs (#654)
* feat(voice): say what you want to make, and land in it

Two things, one of which is embarrassing.

FIRST: voice input on create forms and onboarding has never worked in
production, and not by choice. `FEATURES.voiceInput` reads
NEXT_PUBLIC_FEATURE_VOICE_INPUT, which appeared in no build workflow.
NEXT_PUBLIC_* is compiled into the client bundle, so the flag was false
in every production build it ever shipped in — the mic on every create
form was unreachable dead code. Setting it in the box's runtime .env
could never have helped; ci.yml documents that exact trap two lines above
where the flag should have been.

It is now in ci.yml (the build CD actually ships) and cd.yml, with a test
that fails if a FEATURES flag is missing from the build env. Scoped to
FEATURES on purpose: plenty of NEXT_PUBLIC_* vars are legitimately
optional, and a guard that trips over analytics ids teaches people to
delete the guard.

SECOND: the create menu asks a question most people cannot answer yet —
is the bike in your garage a product or an asset? Is the lesson you would
give a service or an event? You have to learn our vocabulary before you
can start. Speaking skips that:

  "sell my old road bike for 200 francs, a Cannondale, decent condition"
    → /api/cat/transcribe   (existed)
    → /api/voice/intent     (new — the only new model call)
    → /dashboard/store/create?description=...
    → AIPrefillBar fills the form (existed)

Only the router is new. Its prompt is built from ENTITY_REGISTRY
descriptions, so a new entity type teaches it for free, and it validates
the model's answer against the registry rather than trusting it — a
hallucinated type would route to a create path that does not exist.

It refuses rather than guesses. Below 0.6 confidence, an invented type, a
real-but-not-prefillable type, a failed call, or no API key all return
null, and the UI shows what it heard and leaves the menu alone. Landing
someone in the wrong form costs them more than asking does: they have to
notice, back out, and start over, which is the exact friction speaking
was meant to remove.

The recorder moves to useDictation(), depending on nothing
OrangeCat-specific — pass an endpoint and it works in another app.
DictationButton refactors onto it, so there is one recorder, not two.

Still dark until NEXT_PUBLIC_FEATURE_VOICE_INPUT=true exists as a repo
variable. The voice-first create entry does not use that flag and ships
live.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(voice): ownership decides asset from product

Probed the router against the real model instead of a mock: 10/11, and the
miss was "rent out my apartment in Basel for 1800 a month" → product.

The model was not wrong given what it was shown. The registry describes
asset as "Valuable assets for collateral" — nothing about renting — so
"Physical or digital products for sale" was the closest thing on the menu.
The distinction that actually separates them, whether ownership changes
hands, is not written down anywhere. (The offer engine hardcodes its own
"a physical thing to rent or sell → asset" mapping for the same reason.)

Stated as a classification rule here rather than by editing the registry
description, which also renders in the UI and is a protected file.

13/13 with the rule, including two cases checking it did not overcorrect:
"rent out my drone" → asset, "selling my old iphone" → product.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(voice): an eval that can actually catch a bad prompt

The router's unit tests mock the model, so they prove the plumbing —
validation, the confidence floor, refusal — and nothing whatsoever about
the prompt. All eight passed while "rent out my apartment in Basel" was
routing to the product form.

Only a real call catches that, and a real call has no business in
`verify`: it costs a model completion per case and needs network plus
credentials. So this follows eval-cat.mjs — an opt-in script against the
deployed endpoint, with the same sign-in, the same 0/1/2 exit codes.

  npm run eval:voice

13 sentences someone would actually say, including the two that separate
asset from product by ownership, and two that must be DECLINED. The
decline cases matter most: routing a greeting into a create form is the
failure that makes voice feel broken.

Run it when the prompt, the model, or an entity registry description
changes — a registry edit can silently move where sentences land, which
is exactly how the asset/product miss happened.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(registry): assets are for renting too, not only collateral

The router sent "rent out my apartment in Basel for 1800 a month" to the
product form. The model was not wrong given what it was shown: the
registry describes asset as "Valuable assets for collateral", which says
nothing about renting, so "Physical or digital products for sale" was the
closest thing on the menu.

The registry had drifted from the project's own definition. CLAUDE.md
says "Assets | asset | Collateral, rental" and "asset — Real estate,
collateral, rentable assets", in two separate places. The code SSOT
disagreed with the documentation, and the code SSOT is what feeds the
public docs page, the OpenAPI descriptions, the permissions UI, and now
voice routing. (It is also why the offer engine hardcodes its own "a
physical thing to rent or sell → asset" mapping — compensating for this
same gap. That mapping is now redundant, but changing its prompt risks
its behaviour and belongs in its own change.)

I first patched the router's prompt with an ownership rule. That was
treating the symptom. With the description fixed, the eval scores 13/13
WITHOUT the rule, so the rule is gone: entity semantics belong in the
registry, which is the whole reason the router builds its prompt from
registry descriptions rather than carrying its own copy.

createActionLabel changes with it — the create menu currently offers only
"List an asset for collateral", which hides half of what the type does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(voice): the form the voice flow lands you in now actually fills

Tested the shipped voice flow in a browser against production. It routes
correctly and the mic is there, but everything after the routing was worse
than the API alone suggested. Four fixes, two of them serious.

1. A Bitcoin price nobody named. "rent out my apartment in Basel for 1800
   a month" produced rental_price_btc: 0.072 — about 3,800 francs at the
   day's rate, more than double what was said — sitting next to
   currency: CHF contradicting it. The model was cornered: an asset has
   rental_price_btc and NO fiat rental field, so the only place the amount
   could go was a Bitcoin one, and it had no rate to get there honestly.
   The prompt already said not to convert; a prompt is a request, so the
   enforcement now lives in sanitizeAiFields, which drops a *_btc number
   when the user's own words never mentioned Bitcoin. Absent beats
   invented — the same rule as the exchange rates.

2. The fill barely filled. The UI's own status line read "Updated: Title,
   Location" — precisely the two fields that start empty. existingData was
   the entire form state including schema defaults, and `fill` treats any
   non-empty value as something the user typed, so type: 'other' and
   rental_period_type: 'daily' beat the AI's correct real_estate and
   monthly. The AI could only ever fill fields that began blank. The form
   now sends only the fields that differ from their initial value, which
   is the part it is actually in a position to know.

3. Voice landed on a button. The description arrived in the AI box with
   "Fill form" still to press — not "say it and land in it". Opt-in
   ?autofill=1, which voice sets and onboarding deliberately does not:
   there the description is a proposal worth reading first.

4. Two truncated labels, one of them mine from yesterday: "Sell my old
   road bike for 200 fra…" and "Rent out or pledge something you o…". The
   menu's budget is ~28 characters.

Also: the router's minimum transcript length now derives from the prefill
floor instead of being picked separately. At 8 vs 10 a very short sentence
could route to a form and then silently fail to fill it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(voice): one mic, inside the AI entry, styled like it belongs

Founder feedback on the shipped version, verbatim where it stings:
"mic logos on all fields? this is crazy. just put it where ai entry is"
and "looks awful, like unrelated elements."

Both were right.

- The per-field mics are gone. A microphone beside every text input and
  textarea put mic icons on half the form and framed voice as a property
  of inputs. Speaking and typing are the same act — describing what you
  want — so the ONE mic now lives in the AI fill panel, bottom-right next
  to its action, the same arrangement as the Cat composer. Two AI
  surfaces, one shape.

- The create-menu voice entry is restyled from a bordered panel (which
  read as bolted on top of the menu) into a menu row: same icon tile,
  same padding, same hover as every row below it. First row, not a
  foreign object.

- One flag governs every voice surface. Onboarding gated its mic on
  FEATURES.voiceInput while the new surfaces didn't, so the product could
  half-have voice. Now the flag is the SSOT for whether voice exists.

- Drive-by the founder's paste surfaced: the quota chip's sr-only text
  repeated the whole visible sentence, so screen readers announced "10 of
  10 free messages left today" twice (and copying the page produced it
  twice). The hidden span now carries only what the visible chip omits.

The old FormField voice test asserted the per-field mic exists — the
exact design being removed — and now pins the new rule instead: NO mic on
fields, ONE mic in the AI panel.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 19:22:50 +00:00
Georgy ButaevandClaude Opus 4.8 0ab5eb625c fix(entities): update-builder coverage guard (F1) + the 2 real drops it caught
Workstream B of the one-week plan.

- Added __tests__/unit/config/entity-update-builder-coverage.test.ts: for every
  entity, asserts each user-editable field (form field ∩ schema key) is covered
  by its update-payload builder. Complements the form↔schema guard — this catches
  "editable field silently dropped on PUT" (the show_on_profile / F2 class). Fails
  CI on the next such drop.

The guard immediately caught two live bugs, now fixed:
- loan: loan_type + refinancing fields (current_lender, current_interest_rate,
  desired_rate) were persisted on create but DROPPED on update — editing a
  refinance loan silently lost them. Added to the loan update builder.
- asset: the entire sale/rental/deposit config (is_for_sale, sale_price_btc,
  is_for_rent, rental_price_btc, rental_period_type, min/max_rental_period,
  requires_deposit, deposit_amount_btc) was dropped on BOTH create and update —
  the "list for sale/rent" form saved nothing despite real DB columns. Persisted
  in createAsset + the asset update builder.

Also (B2): deleted the dead 7,468-line src/types/database.generated.ts (0
importers), and fixed __tests__/create/FormField.voice.test.tsx (mock
FEATURES.voiceInput — the env flip was too late; feature is gated off by default)
→ npm test green again. Type-check + lint clean, 741 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 10:26:35 +02:00
Georgy ButaevandClaude Opus 4.8 43651407a9 feat(cat): working dictation (Groq Whisper) + composer rebuilt as one integrated control
Founder feedback: the Cat mic "doesn't really work" and the composer is a
"frankenstein — model picker pill bolted above the box, trash detached." Both fixed.

MIC — VoiceInputButton used the browser Web Speech API (webkitSpeechRecognition),
which Brave disables by default, so dictation silently no-op'd. Replaced with:
- POST /api/cat/transcribe — records nothing server-side; accepts a MediaRecorder
  blob and forwards to Groq Whisper (whisper-large-v3-turbo), returns {text}.
  Validated against Groq directly (200 + {text}).
- DictationButton (MediaRecorder → that endpoint), a drop-in for VoiceInputButton
  (same props): idle → recording → transcribing. Works in Brave/Chrome/Safari.
- Swapped at all 3 call sites (composer, onboarding, form field); deleted the old
  VoiceInputButton + its test; repointed FormField voice test to the new mock.

COMPOSER — rebuilt ChatInput as ONE rounded control: textarea on top, a single
control row inside the box — model picker + clear on the left, dictation + send on
the right. Model picker is now a subtle in-bar trigger that opens UPWARD (it was a
bordered pill above the box whose menu dropped off the bottom edge); clear is no
longer a detached button floating left of the box. CSS .oc-chat-composer is now a
column; added .oc-chat-composer-controls. ModelSelector gained openUp + subtle props.

tsc + eslint + FormField voice test green. Groq Whisper call verified live.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 21:41:57 +02:00
g-butandClaude Opus 4.5 2df79381f1 feat: streaming AI, canonical rate limiting, cleanup demo pages
Major changes:
- AI streaming: Add unified client for OpenRouter SSE and local (Ollama) providers
- Local AI detection: Auto-detect and configure local model providers
- Rate limiting: Canonical adapters with X-RateLimit-* headers across APIs
- SSE: Add lib/sse.ts for consistent event-stream parsing

Cleanup:
- Remove /demo, /donate, /fund-us, /funding, /fundraising pages
- Simplify ModelSelector component (288 → 80 lines)
- Consolidate timeline queries

New features:
- Voice input component and hook
- Query provider for React Query
- Model registry with status badges
- HTTP headers config

Tests & Docs:
- E2E tests for project creation wizard
- Unit tests for auth, streaming, components
- CHANGELOG.md for version tracking
- Deployment checklist and PR summary docs

Bug fixes:
- Timeline schema and functions migration fixes
- Messaging RLS recursion fix
- Auth callback improvements
- Bitcoin formatting precision
- Lint fixes for unused variables

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 16:02:26 +01:00