Skip to Content
LoremLLM

Testing failures

Prove your retries, timeouts and fallbacks work before production finds out.

Retries on rate limits

test("retries after a 429", async () => {
  await using llm = await mockLLM();
  llm.on({ turn: 1 }).reply(sequence(error(429, { retryAfter: 1 }), text("OK")));

  const answer = await agent.run("Hello", { baseURL: `${llm.url}/v1` });

  expect(answer).toBe("OK");
  expect(llm).toHaveBeenRequestedTimes(2);
});

Streams that die halfway

llm
  .on(/report/)
  .reply([text("Here is part one of the report and"), fault("abort", { afterChunks: 4 })]);

Check that the UI shows a retry action and doesn't save a half answer as final.

Timeouts

llm.on(/slow/).reply(fault("timeout", { afterMs: 30_000 }));

Run with fake timers to keep the test fast.

Bad tool calls

Models sometimes call a tool that doesn't exist, or with arguments that don't fit its schema:

llm.on(/refund/).reply(toolCall("refundd", { id: 42 }));

Your agent should return a tool error to the model rather than crash.

Refusals and length limits

finish("content-filter") and finish("length") cover the two finish reasons UIs most often forget. Each maps to the provider's own value: content_filter and length on OpenAI, refusal and max_tokens on Anthropic.

llm.on(/essay/).reply(text("The history of"), finish("length"));

On this page