Advanced
Presets, global mode, scenarios, and fetch interception
Presets
cruel.enable(cruel.presets.development)
cruel.enable(cruel.presets.staging)
cruel.enable(cruel.presets.production)
cruel.enable(cruel.presets.harsh)
cruel.enable(cruel.presets.nightmare)
cruel.enable(cruel.presets.apocalypse)Profiles
cruel.profile("testing", { fail: 0.2, delay: 100 })
cruel.useProfile("testing")Global Mode
cruel.enable({ fail: 0.1, delay: [100, 500] })
cruel.disable()
cruel.toggle()
cruel.isEnabled()Scoped Chaos
await cruel.scope(async () => {
await api("...")
}, { fail: 0.2 })Fluent API
cruel.wrap(fn).fail(0.1)
cruel.wrap(fn).slow(500)
cruel.wrap(fn).timeout(0.05)
cruel.wrap(fn).flaky()
cruel.wrap(fn).nightmare()Factory
import { createCruel } from "cruel"
const myCruel = createCruel({ delay: 100 })Scenarios
cruel.scenario("outage", {
chaos: { fail: 1 },
duration: 5000,
})
await cruel.play("outage")
cruel.stop()
await cruel.play("networkPartition")
await cruel.play("highLatency")
await cruel.play("degraded")
await cruel.play("recovery")Fetch Interception
cruel.patchFetch()
cruel.intercept("api.openai.com", {
rateLimit: { rate: 0.1, retryAfter: 60 },
delay: [100, 500],
})
cruel.intercept(/api\.anthropic\.com/, {
fail: 0.1,
status: [529],
})
cruel.unpatchFetch()Production Rollout Checklist
For production-like chaos drills, keep blast radius controlled:
- Start with low rates (
0.01-0.05) and increase gradually. - Run chaos in a scoped block or dedicated test path first.
- Attach
onChaosand record event types, model IDs, and latency. - Keep retry, fallback, and circuit-breaker logic enabled during tests.
- Run deterministic passes with
cruel.seed(...)before random passes. - Stop chaos immediately if error budget or latency thresholds are exceeded.