@chaos-maker/core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -8
- package/dist/chaos-maker.cjs +12 -5
- package/dist/chaos-maker.js +1394 -1178
- package/dist/chaos-maker.umd.js +11 -4
- package/dist/sw.js +1 -1
- package/dist/sw.mjs +457 -401
- package/dist/types/ChaosMaker.d.ts +5 -0
- package/dist/types/format-event.d.ts +13 -0
- package/dist/types/index.d.ts +4 -1
- package/dist/types/runtime-state.d.ts +6 -0
- package/dist/types/seed-reporting.d.ts +1 -0
- package/dist/types/session-errors.d.ts +18 -0
- package/dist/types/sw-bridge-source.d.ts +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ chaos.start();
|
|
|
75
75
|
| `unreliableWebSocket` | | 10% drops, 500ms inbound delay, 5% inbound truncation |
|
|
76
76
|
| `unreliableEventStream` | | 5% drops, 200ms delay, 2% close after 2000ms |
|
|
77
77
|
|
|
78
|
-
Kebab-case aliases (`slow-api`, `flaky-api`, `offline-mode`, `high-latency`) are registry-only. They resolve via `presets: ['slow-api']` and `new PresetRegistry().get('slow-api')`. They are NOT keys on the legacy `presets` record export
|
|
78
|
+
Kebab-case aliases (`slow-api`, `flaky-api`, `offline-mode`, `high-latency`) are registry-only. They resolve via `presets: ['slow-api']` and `new PresetRegistry().get('slow-api')`. They are NOT keys on the legacy `presets` record export - `presets['slow-api']` is `undefined` by design. Use the camelCase key (`presets.slowNetwork`) when reading from the record.
|
|
79
79
|
|
|
80
80
|
**Custom presets**
|
|
81
81
|
|
|
@@ -94,7 +94,7 @@ new ChaosMaker({
|
|
|
94
94
|
});
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
Custom preset values may carry only rule arrays plus the optional `groups` field
|
|
97
|
+
Custom preset values may carry only rule arrays plus the optional `groups` field - `presets`, `customPresets`, `seed`, and `debug` are rejected at validation. Dependency chains are out of scope.
|
|
98
98
|
|
|
99
99
|
**Builder helper**
|
|
100
100
|
|
|
@@ -113,7 +113,7 @@ Unknown preset names, chain attempts, forbidden subfields, duplicate registratio
|
|
|
113
113
|
|
|
114
114
|
**Mutability**
|
|
115
115
|
|
|
116
|
-
Built-in preset configs are deep-frozen
|
|
116
|
+
Built-in preset configs are deep-frozen - `presets.slowNetwork.network!.latencies![0].delayMs = 1` throws. Your own custom presets passed via `customPresets` are NOT frozen - keep treating them as your data. The engine takes a deep clone at expansion, so any tweaks you make after construction are not observed.
|
|
117
117
|
|
|
118
118
|
**Legacy spread**
|
|
119
119
|
|
|
@@ -281,14 +281,53 @@ try {
|
|
|
281
281
|
|
|
282
282
|
`validateChaosConfig(input, opts?)` accepts:
|
|
283
283
|
|
|
284
|
-
- `unknownFields: 'reject' | 'warn' | 'ignore'`
|
|
285
|
-
- `customValidators: Partial<Record<RuleType, (rule, ctx) => ValidationIssue[] | void>>`
|
|
286
|
-
- `onDeprecation: (issue) => void`
|
|
284
|
+
- `unknownFields: 'reject' | 'warn' | 'ignore'` - strict by default. `'warn'` and `'ignore'` strip unknowns from the returned config; `'warn'` emits exactly one aggregated `console.warn` per call.
|
|
285
|
+
- `customValidators: Partial<Record<RuleType, (rule, ctx) => ValidationIssue[] | void>>` - run extra checks per rule type.
|
|
286
|
+
- `onDeprecation: (issue) => void` - receive `ValidationIssue` events for deprecated fields. The registry is empty for this release.
|
|
287
287
|
|
|
288
|
-
A JSON Schema artifact ships at `node_modules/@chaos-maker/core/dist/chaos-config.schema.json` for IDE / `"$schema"` autocomplete plus a sidecar `chaos-config.schema.notes.md` listing parity caveats. The artifact is a tooling approximation
|
|
288
|
+
A JSON Schema artifact ships at `node_modules/@chaos-maker/core/dist/chaos-config.schema.json` for IDE / `"$schema"` autocomplete plus a sidecar `chaos-config.schema.notes.md` listing parity caveats. The artifact is a tooling approximation - runtime canonical validation is always Zod via `validateChaosConfig`.
|
|
289
289
|
|
|
290
290
|
See the [Rule Validation concept page](https://chaos-maker-dev.github.io/chaos-maker/concepts/validation/) for the full pipeline, brand semantics, and migration notes.
|
|
291
291
|
|
|
292
|
+
## Lifecycle and isolation
|
|
293
|
+
|
|
294
|
+
`start()` and `stop()` are the only entry points to the patched runtime. On `stop()` each restore step - `fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource`, and the DOM observer - runs inside its own `try` / `catch`, so one failing step does not block the others from running. The failing step is reported via a `cleanup-step-failed:<step>` debug event and a `console.warn`. Some edge cases (frozen prototypes, third-party code that re-wraps a global between `start()` and `stop()`, host objects that reject property writes) may still leave a global patched; treat the diagnostics surface as the source of truth rather than assuming an absolute restore guarantee.
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
const chaos = new ChaosMaker(config);
|
|
298
|
+
chaos.start();
|
|
299
|
+
try {
|
|
300
|
+
// ... drive the page ...
|
|
301
|
+
} finally {
|
|
302
|
+
chaos.stop(); // safe to call twice; idempotent.
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Concurrent instances against the same target are rejected. A second `start()` on a target that already has an active instance throws `[chaos-maker] target already has an active runtime instance` so the first instance keeps owning the patched globals. Use one `ChaosMaker` per realm (page, worker, jsdom) and call `stop()` before constructing a replacement.
|
|
307
|
+
|
|
308
|
+
## Leak diagnostics
|
|
309
|
+
|
|
310
|
+
When debug mode is enabled, the engine emits structured invariant events whenever it sees signs of a leaked runtime - patched globals on start, stale wrapper handles, or another instance owning the target.
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
const chaos = new ChaosMaker(config, { debug: true });
|
|
314
|
+
chaos.start();
|
|
315
|
+
// ...
|
|
316
|
+
chaos.stop();
|
|
317
|
+
|
|
318
|
+
const issues = chaos.getLog().filter((event) =>
|
|
319
|
+
event.type === 'debug' &&
|
|
320
|
+
(event.detail.reason?.includes('already-patched') ||
|
|
321
|
+
event.detail.reason?.includes('stale') ||
|
|
322
|
+
event.detail.reason?.includes('orphaned') ||
|
|
323
|
+
event.detail.reason === 'active-instance-conflict'),
|
|
324
|
+
);
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Reasons emitted include `target-fetch-already-patched`, `target-xhr-open-already-patched`, `target-xhr-send-already-patched`, `target-websocket-already-patched`, `target-eventsource-already-patched`, `stale-websocket-handle`, `stale-eventsource-handle`, `orphaned-dom-observer`, `active-instance-conflict`, and `cleanup-step-failed:<step>`. The same reasons appear with `phase: 'engine:stop'` when a global stays patched after `stop()` runs.
|
|
328
|
+
|
|
329
|
+
Diagnostics are surfaced through `getLog()` only when `debug: true`; the runtime never throws on these conditions (the active-instance check is the one exception). They are intended for CI noise reduction and bug reports, not control flow.
|
|
330
|
+
|
|
292
331
|
## Service Worker chaos
|
|
293
332
|
|
|
294
333
|
Chaos applies to SW-originated fetches via the `@chaos-maker/core/sw` subpath. Zod + UI + builder are excluded from this bundle so it stays small enough for production SW deploys.
|
|
@@ -309,7 +348,7 @@ installChaosSW({ source: 'message' });
|
|
|
309
348
|
|
|
310
349
|
Page-side config is delivered via `postMessage` + `MessageChannel` ack. Use the adapter helpers (`injectSWChaos` / `removeSWChaos` / `getSWChaosLog`) in `@chaos-maker/{playwright,cypress,webdriverio,puppeteer}`.
|
|
311
350
|
|
|
312
|
-
Limitations: `caches.match` hits bypass chaos
|
|
351
|
+
Limitations: `caches.match` hits bypass chaos; push/sync events not covered; cross-origin SWs not supported.
|
|
313
352
|
|
|
314
353
|
## License
|
|
315
354
|
|