A fake model server, so the failures are ours
Every AI customization request follows the same order: authenticate, validate the prompt, check quota, hold a credit, call the model, filter the returned tool ids against the registry, then save. Any failure after the hold has to refund it, and the refund has to be idempotent because retries and overlapping requests are real.
Testing that against a real provider is unreliable. When a request fails you cannot tell whether the model misbehaved, our parser misread it, the whitelist dropped everything, or the refund path never ran. So there is a local substitute: scripts/mock-llm-server.mjs, an OpenAI-compatible chat completions endpoint that needs no key.
It is not a canned string. In its default mode it parses the tool list out of the system prompt and answers with real ids, so the whitelist is genuinely exercised. Other modes return half real and half invented ids, only invented ids, non-JSON prose, or an upstream 500. Each mode maps to one branch that must end in a refund.
Two things this buys us. Switching to the real provider is a matter of changing AI_API_BASE, AI_API_KEY and AI_MODEL: the fake and the real service speak the same shape, so the switch does not become a rewrite. And credit accounting can be tested deterministically. Deduct, fail, refund, then check the balance and the usage row; no credits spent, no dependence on a vendor's error format.