-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add chaos() API for HTTP-layer fault injection with default-on rules #2119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
17
commits into
main
Choose a base branch
from
copilot/add-chaos-api-for-http-layer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
19e341b
feat: add chaos() API for HTTP-layer fault injection
Copilot 942c6e6
refactor: address code review feedback on chaos API
Copilot 395d262
refactor: share chaos registry across all api runners
Copilot 81e0ece
test: verify repl chaos affects all api groups
Copilot 3b9d87b
test: tidy repl chaos shared-registry coverage
Copilot 20fc1df
fix: block content-type header mutations in chaos rules
Copilot 831a623
test: simplify content-type removal guard case
Copilot 8e7af9d
fix: validate chaos probability range
Copilot 4f2a2d6
refactor: remove chaos timeout API
Copilot cb6318d
docs: add chaos fault simulation pattern
Copilot 08d171b
docs: clarify chaos API in fault pattern section
Copilot 56d46ba
docs: clarify always plus probability chaos pattern
Copilot 08e3556
docs: tighten chaos fault pattern wording
Copilot e24f997
docs: add chaos fault-testing usage pattern
Copilot 15db83a
Merge branch 'main' into copilot/add-chaos-api-for-http-layer
pmcelhaney 47eed03
refactor: remove chaos always method
Copilot 2314de5
Merge branch 'main' into copilot/add-chaos-api-for-http-layer
pmcelhaney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Test Fault Scenarios with Chaos Rules | ||
|
|
||
| You want to test how a client, UI, or integration behaves under upstream failures without editing route handlers or restarting the mock server. | ||
|
|
||
| ## Problem | ||
|
|
||
| Failure behavior is often tested too late because reproducing 5xxs, flaky responses, or temporary outages usually means changing handler code, wiring custom flags, or waiting for real backend incidents. | ||
|
|
||
| ## Solution | ||
|
|
||
| Use Counterfact's `chaos()` API from the Live REPL to inject HTTP-layer faults on demand. Keep the baseline handlers unchanged, then apply temporary rules for the exact paths and failure profiles you want to exercise. | ||
|
|
||
| ## Example | ||
|
|
||
| Start with a healthy service: | ||
|
|
||
| ```text | ||
| ⬣> client.get("/payments/42") | ||
| { status: 200, body: { ... } } | ||
| ``` | ||
|
|
||
| Inject an intermittent upstream failure pattern: | ||
|
|
||
| ```ts | ||
| // Match /payments* requests indefinitely, | ||
| // but fail only about 20% with a retry hint. | ||
| chaos("/payments") | ||
| .probability(0.2) | ||
| .status(503) | ||
| .header("Retry-After", "1"); | ||
| ``` | ||
|
|
||
| You can also target a bounded outage: | ||
|
|
||
| ```ts | ||
| // Fail the next 3 matching requests, then stop automatically. | ||
| chaos("/payments").next(3).status(503); | ||
| ``` | ||
|
|
||
| And remove the rule when your test scenario is complete: | ||
|
|
||
| ```ts | ||
| const fault = chaos("/payments").status(500); | ||
| fault.stop(); | ||
| ``` | ||
|
|
||
| ## Consequences | ||
|
|
||
| - Faults are injected at the HTTP response layer, so you can test resilience behavior without changing route files. | ||
| - Rules are fast to toggle from the REPL, which is useful for exploratory testing and manual acceptance checks. | ||
| - `probability(...)` enables controlled flakiness; `next(count)` enables deterministic burst failures. | ||
| - This pattern does not simulate low-level network disconnects; it focuses on HTTP response behavior. | ||
|
|
||
| ## Related Patterns | ||
|
|
||
| - [Simulate Failures and Edge Cases](./simulate-failures.md) — implement failure behavior directly in handlers/context | ||
| - [Simulate Realistic Latency](./simulate-latency.md) — add delayed responses to complement fault injection | ||
| - [Live Server Inspection with the REPL](./repl-inspection.md) — drive chaos rules and requests interactively |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot, again there should be a single chaosRegistry at the server level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and already wired this way: there is a single server-level
ChaosRegistryshared across all runners and the REPL. Addressed in commit 395d262, with cross-group behavior covered in 81e0ece.