recovery-probe 0.2.0 → 0.3.0-preview.2

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/CHANGELOG.md CHANGED
@@ -1,18 +1,36 @@
1
- # Changelog
2
-
3
- All notable changes to Recovery Probe are documented here. The project follows [Semantic Versioning](https://semver.org/).
4
-
5
- Version 0.2.0 is the first npm release. Earlier 0.1.x revisions were repository-only prototypes.
6
-
7
- ## [0.2.0] - 2026-09-22
8
-
9
- ### Added
10
-
11
- - Deterministic HTTP error, connection failure, and invalid JSON injection.
12
- - Playwright `withFault` helper with bounded counts and route cleanup.
13
- - Browser-independent `createFaultFetch` adapter.
14
- - JSON-configured CLI runner with human-readable and machine-readable output.
15
- - Broken-versus-fixed browser demonstration.
16
- - Core, real-browser, package-installation, and TypeScript integration tests.
17
-
18
- [0.2.0]: https://github.com/BojanKovachki/recovery-probe/releases/tag/v0.2.0
1
+ # Changelog
2
+
3
+ All notable changes to Recovery Probe are documented here. The project follows [Semantic Versioning](https://semver.org/).
4
+
5
+ Version 0.2.0 is the first npm release. Earlier 0.1.x revisions were repository-only prototypes.
6
+
7
+ ## [0.3.0-preview.2] - Unreleased
8
+
9
+ - Add Chromium web discovery/checks and explicit private login-state saving.
10
+ - Add opt-in OpenAI source-edit proposals from selected source files and reproduced evidence.
11
+ - Reproduce and verify in a separate local clone; preserve the original repository and never push/deploy a candidate.
12
+ - Reject unsafe paths, ambiguous replacements, dirty baselines, preexisting target ports and setup/test mutations.
13
+ - Separate reviewed verification from explicit opt-in execution of unreviewed generated code.
14
+ - Add authenticated web and Electron before/after integration tests with controlled provider responses.
15
+ - Clarify release stages and source-upload/report privacy boundaries. Live model fix quality is not yet validated.
16
+
17
+ ## [0.3.0-preview.1] - Unreleased
18
+
19
+ - Add Electron renderer discovery and targeted recovery checks through loopback CDP.
20
+ - Require a successful request after fault injection and a configured healthy UI marker.
21
+ - Add local HTML/JSON reports, executable reproductions, and coding-agent investigation briefs.
22
+ - Test real Electron attachment, preload preservation, recovery failures, automatic retry, stale UI markers, and disconnect behavior.
23
+ - Keep source-code fixes manual and reports local; native SDK/IPC traffic is outside this preview.
24
+
25
+ ## [0.2.0] - 2026-09-22
26
+
27
+ ### Added
28
+
29
+ - Deterministic HTTP error, connection failure, and invalid JSON injection.
30
+ - Playwright `withFault` helper with bounded counts and route cleanup.
31
+ - Browser-independent `createFaultFetch` adapter.
32
+ - JSON-configured CLI runner with human-readable and machine-readable output.
33
+ - Broken-versus-fixed browser demonstration.
34
+ - Core, real-browser, package-installation, and TypeScript integration tests.
35
+
36
+ [0.2.0]: https://github.com/BojanKovachki/recovery-probe/releases/tag/v0.2.0
package/CONTRIBUTING.md CHANGED
@@ -1,39 +1,39 @@
1
- # Contributing
2
-
3
- Thanks for helping make recovery checks easier to trust.
4
-
5
- ## Before opening a change
6
-
7
- - Use Node.js 22 or newer.
8
- - Keep changes focused on deterministic request-level recovery testing.
9
- - Open an issue first for new fault models or public API changes.
10
- - Do not include real credentials, production URLs, request bodies, or response bodies in fixtures or reports.
11
-
12
- ## Development setup
13
-
14
- ```bash
15
- npm ci
16
- npm test
17
- npm run test:package
18
- npx playwright install chromium
19
- npm run test:browser
20
- ```
21
-
22
- Run the controlled demonstrations when behavior or output changes:
23
-
24
- ```bash
25
- npm run demo
26
- npm run demo:browser
27
- ```
28
-
29
- ## Pull requests
30
-
31
- A useful pull request:
32
-
33
- - explains the recovery behavior it covers;
34
- - includes a failing test for a bug fix;
35
- - preserves the distinction between failed, inconclusive, and skipped results;
36
- - keeps fault injection bounded and verifies that the fault occurred;
37
- - updates the README and changelog when the public interface changes.
38
-
39
- By submitting a contribution, you agree that it is licensed under the project's MIT license.
1
+ # Contributing
2
+
3
+ Thanks for helping make recovery checks easier to trust.
4
+
5
+ ## Before opening a change
6
+
7
+ - Use Node.js 22 or newer.
8
+ - Keep changes focused on deterministic request-level recovery testing.
9
+ - Open an issue first for new fault models or public API changes.
10
+ - Do not include real credentials, production URLs, request bodies, or response bodies in fixtures or reports.
11
+
12
+ ## Development setup
13
+
14
+ ```bash
15
+ npm ci
16
+ npm test
17
+ npm run test:package
18
+ npx playwright install chromium
19
+ npm run test:browser
20
+ ```
21
+
22
+ Run the controlled demonstrations when behavior or output changes:
23
+
24
+ ```bash
25
+ npm run demo
26
+ npm run demo:browser
27
+ ```
28
+
29
+ ## Pull requests
30
+
31
+ A useful pull request:
32
+
33
+ - explains the recovery behavior it covers;
34
+ - includes a failing test for a bug fix;
35
+ - preserves the distinction between failed, inconclusive, and skipped results;
36
+ - keeps fault injection bounded and verifies that the fault occurred;
37
+ - updates the README and changelog when the public interface changes.
38
+
39
+ By submitting a contribution, you agree that it is licensed under the project's MIT license.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Bojan Kovachki
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bojan Kovachki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,206 +1,233 @@
1
- # Recovery Probe
2
-
3
- [![CI](https://github.com/BojanKovachki/recovery-probe/actions/workflows/validate.yml/badge.svg)](https://github.com/BojanKovachki/recovery-probe/actions/workflows/validate.yml)
4
- [![npm](https://img.shields.io/npm/v/recovery-probe.svg)](https://www.npmjs.com/package/recovery-probe)
5
- [![Node.js](https://img.shields.io/badge/Node.js-22%2B-339933?logo=node.js&logoColor=white)](https://nodejs.org/)
6
- [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
-
8
- **Deterministic fault injection for testing whether web applications actually recover after failed requests.**
9
-
10
- A happy-path test can pass while a Retry button is completely broken. Recovery Probe adds a small, explicit workflow around Playwright routing and `fetch`: inject one controlled failure, exercise the application's recovery path, and prove that the intended fault really occurred.
11
-
12
- ![Recovery Probe catches a broken retry flow and verifies the corrected flow](docs/demo.svg)
13
-
14
- ## What it catches
15
-
16
- Consider an application that loads normally, but forgets to clear its loading state after an error. Its ordinary end-to-end test stays green. After a transient `503`, interrupted request, or malformed response, Retry does nothing.
17
-
18
- Recovery Probe makes that failure deterministic:
19
-
20
- 1. Match one endpoint and request method.
21
- 2. Inject a bounded fault without replacing global `fetch`.
22
- 3. Run the real recovery interaction and assertion.
23
- 4. Fail if the fault was never observed, so a wrong route cannot create a false positive.
24
- 5. Remove only its own route handler and preserve existing mocks.
25
-
26
- ## Install
27
-
28
- Recovery Probe is designed to be added to an existing Playwright project:
29
-
30
- ```bash
31
- npm install --save-dev recovery-probe
32
- ```
33
-
34
- Node.js 22 or newer is required. Playwright is an optional peer dependency: the fetch-only API works without it, while the browser helper and CLI require Playwright 1.62.1 or newer.
35
-
36
- ## Quick start
37
-
38
- Use `withFault` inside an existing Playwright test. The callback contains the real user action and the application-specific recovery assertion.
39
-
40
- ```js
41
- import { test, expect } from '@playwright/test';
42
- import { withFault } from 'recovery-probe';
43
-
44
- test('profile recovers after a transient 503', async ({ page }) => {
45
- const stats = await withFault(page, {
46
- match: '**/api/profile',
47
- kind: 'http-error',
48
- status: 503,
49
- count: 1,
50
- }, async () => {
51
- await page.goto('http://127.0.0.1:3000/profile');
52
- await page.getByRole('button', { name: 'Retry' }).click();
53
- await expect(page.getByTestId('profile-name')).toHaveText('Test User');
54
- });
55
-
56
- expect(stats.applied).toBe(1);
57
- });
58
- ```
59
-
60
- If the endpoint does not match, Recovery Probe throws `FAULT_NOT_TRIGGERED` instead of allowing the test to pass silently. If the fault is applied but the recovery assertion fails, it throws `RECOVERY_ASSERTION_FAILED` and retains the original assertion error as `cause`.
61
-
62
- ## Run the demonstration
63
-
64
- The repository includes deliberately broken and corrected applications. Both pass their normal loading check; only the corrected application recovers from all three faults.
65
-
66
- ```bash
67
- npm install
68
- npx playwright install chromium
69
- npx recovery-probe --demo
70
- ```
71
-
72
- The command prints a concise comparison:
73
-
74
- ```text
75
- broken synthetic fixture
76
- PASS Normal connection (OK)
77
- CAUGHT HTTP 503 once (RECOVERY_ASSERTION_FAILED, injected 1)
78
- CAUGHT Interrupted request once (RECOVERY_ASSERTION_FAILED, injected 1)
79
- CAUGHT Malformed JSON once (RECOVERY_ASSERTION_FAILED, injected 1)
80
-
81
- fixed synthetic fixture
82
- PASS Normal connection (OK)
83
- PASS HTTP 503 once (OK, injected 1)
84
- PASS Interrupted request once (OK, injected 1)
85
- PASS Malformed JSON once (OK, injected 1)
86
- ```
87
-
88
- `--demo` exits successfully only when it observes the expected contrast: the happy path passes, the broken recovery is caught, and the corrected flow passes. Add `--json` to print the full report or `--out report.json` to save it.
89
-
90
- ## Supported faults
91
-
92
- | Kind | Injected behavior |
93
- | --- | --- |
94
- | `http-error` | Fulfils the matched request with an HTTP error status; defaults to `503`. |
95
- | `connection-failure` | Aborts the matched Playwright request with `connectionfailed`, or throws from the fetch adapter. |
96
- | `invalid-json` | Returns status `200` with a deliberately malformed JSON body. |
97
-
98
- Faults are bounded by `count` (default `1`, maximum `20`). The count is reserved synchronously, so concurrent matching requests cannot over-inject.
99
-
100
- ## Fetch-only tests
101
-
102
- The lightweight `recovery-probe/fetch` entry point has no runtime dependencies and does not require Playwright. It matches one exact absolute URL, including its query string, and never patches global `fetch`.
103
-
104
- ```js
105
- import { createFaultFetch } from 'recovery-probe/fetch';
106
-
107
- const probe = createFaultFetch(fetch, {
108
- url: 'http://127.0.0.1:3000/api/profile',
109
- kind: 'connection-failure',
110
- });
111
-
112
- await exerciseApplication(probe.fetch);
113
- probe.assertApplied();
114
- ```
115
-
116
- `exerciseApplication` represents your own test adapter or application controller. Calling `assertApplied()` is essential: it proves that every requested fault was consumed.
117
-
118
- ## JSON-configured runner
119
-
120
- The CLI supports pages that automatically load GET data, expose a visible Retry button after failure, and show a ready element after recovery.
121
-
122
- ```json
123
- {
124
- "name": "Profile recovery",
125
- "url": "http://127.0.0.1:3000/profile",
126
- "requestPattern": "**/api/profile",
127
- "readySelector": "[data-testid=profile-ready]",
128
- "retrySelector": "[data-testid=profile-retry]",
129
- "timeoutMs": 3000
130
- }
131
- ```
132
-
133
- ```bash
134
- npx recovery-probe --config recovery-probe.json --out artifacts/profile-recovery.json
135
- ```
136
-
137
- The runner first checks the normal baseline in a fresh browser context. If that baseline fails, fault comparisons are skipped and reported as inconclusive. Each fault then receives its own fresh context with service workers blocked so Playwright can intercept the request.
138
-
139
- Exit codes:
140
-
141
- - `0`: every configured check passed, or the controlled demo observed its expected broken-versus-fixed result.
142
- - `1`: a recovery check failed, was inconclusive, or was skipped.
143
- - `2`: invalid arguments, configuration, or environment setup.
144
-
145
- ## Result semantics
146
-
147
- | Code | Meaning |
148
- | --- | --- |
149
- | `OK` | The configured assertion completed and the expected fault count was observed. |
150
- | `RECOVERY_ASSERTION_FAILED` | The fault occurred, but the recovery assertion did not pass. |
151
- | `FAULT_NOT_TRIGGERED` | The requested fault count was not observed. Check the route, method, cache, and service worker. |
152
- | `BASELINE_FAILED` | The ordinary flow failed, so the runner could not make a useful fault comparison. |
153
- | `INJECTION_ERROR` | Playwright could not apply or clean up the route reliably. |
154
-
155
- A passing result proves the configured recovery behavior for that test. It is not a certification of overall application resilience.
156
-
157
- ## API
158
-
159
- ### `withFault(page, options, exercise)`
160
-
161
- Installs one temporary Playwright route, runs `exercise`, verifies the requested fault count, and removes only that route handler.
162
-
163
- ```ts
164
- interface FaultOptions {
165
- match: string | RegExp;
166
- kind: 'http-error' | 'connection-failure' | 'invalid-json';
167
- status?: number;
168
- count?: number;
169
- method?: string;
170
- }
171
- ```
172
-
173
- Register the fault after your own route mocks. The helper uses `route.fallback()` for requests it does not inject, allowing earlier handlers to continue processing them.
174
-
175
- ### `createFaultFetch(baseFetch, options)`
176
-
177
- Creates an isolated fetch wrapper for one exact URL and method. It returns `{ fetch, summary, assertApplied }` and leaves the supplied fetch function unchanged.
178
-
179
- ### `probeRecovery(browser, config)`
180
-
181
- Runs the baseline and the three default recovery checks used by the JSON CLI. For custom interactions or stronger assertions, prefer `withFault` inside your own test.
182
-
183
- ## Scope
184
-
185
- Recovery Probe deliberately focuses on deterministic request-level recovery checks. It does not simulate whole-device offline states, WebSocket interruptions, token expiry, browser sleep, slow-network profiles, or duplicate-submission safety.
186
-
187
- Playwright already provides the routing primitives used here. Recovery Probe adds bounded recipes, fault-occurrence verification, cleanup, consistent result codes, a fetch adapter, and a runnable broken-versus-fixed example. If a few direct `page.route()` calls are clearer for your test, use them; this package is most useful when teams want the recovery pattern to be repeatable.
188
-
189
- The runner requires explicit selectors and endpoint matching. It does not discover an application's recovery policy automatically. Reports contain structural outcomes and environment versions, not request bodies, response bodies, headers, or full target URLs. Recovery Probe sends no telemetry.
190
-
191
- ## Development
192
-
193
- ```bash
194
- npm ci
195
- npm test # 9 fetch/core tests
196
- npm run test:package # isolated tarball install + TypeScript + CLI checks
197
- npx playwright install chromium
198
- npm run test:browser # 7 real-browser integration tests
199
- npm run demo:browser
200
- ```
201
-
202
- CI runs package checks on Node.js 22 and 24, then runs the integration suite and controlled demo in Chromium. See [CONTRIBUTING.md](CONTRIBUTING.md) for the contribution workflow and [SECURITY.md](SECURITY.md) for private vulnerability reporting.
203
-
204
- ## License
205
-
206
- [MIT](LICENSE) © 2026 Bojan Kovachki
1
+ # Recovery Probe
2
+
3
+ [![CI](https://github.com/BojanKovachki/recovery-probe/actions/workflows/validate.yml/badge.svg)](https://github.com/BojanKovachki/recovery-probe/actions/workflows/validate.yml)
4
+ [![npm](https://img.shields.io/npm/v/recovery-probe.svg)](https://www.npmjs.com/package/recovery-probe)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-22%2B-339933?logo=node.js&logoColor=white)](https://nodejs.org/)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
+
8
+ **Find reproducible request-recovery bugs in web and Electron apps. Propose a source fix, then test the candidate.**
9
+
10
+ A happy-path test can pass while a transient failed request leaves an app permanently loading. Recovery Probe injects controlled failures and checks what happens next. Recovery may be automatic; a Retry button or special recovery screen is not required.
11
+
12
+ ## Release status
13
+
14
+ | Version | Available functionality |
15
+ | --- | --- |
16
+ | npm `0.2.0` | Playwright/fetch fault helpers and the original configured CLI. No source investigation or automatic fixes. |
17
+ | GitHub `0.3.0-preview.2`, `feat/repair-workflow` | Web and Electron discovery/checks; browser login-state support; opt-in AI source-edit proposals; isolated-checkout before/after verification. Not yet a stable npm release. |
18
+ | Not implemented | General discovery/fixing of arbitrary bugs, production self-healing, autonomous deployment, native/IPC request interception. |
19
+
20
+ The repair preview needs a local source repository, explicit source-file selection, one expected outcome, app launch/test commands, and your own API key/model for generation. It does **not** obtain these from installing an npm dependency. It returns a reviewable candidate, not a guaranteed fix. [Full setup and safety guide](docs/repair.md).
21
+
22
+ ```bash
23
+ # Preview only; pin the commit when sharing a reproducible installation.
24
+ npm install --save-dev github:BojanKovachki/recovery-probe#feat/repair-workflow playwright
25
+ npx playwright install chromium
26
+ npx recovery-probe web --help
27
+ npx recovery-probe repair --help
28
+ ```
29
+
30
+ ![Recovery Probe catches a broken retry flow and verifies the corrected flow](docs/demo.svg)
31
+
32
+ ## What it catches
33
+
34
+ Consider an application that loads normally, but forgets to clear its loading state after an error. Its ordinary end-to-end test stays green. After a transient `503`, interrupted request, or malformed response, Retry does nothing.
35
+
36
+ Recovery Probe makes that failure deterministic:
37
+
38
+ 1. Match one endpoint and request method.
39
+ 2. Inject a bounded fault without replacing global `fetch`.
40
+ 3. Run the real recovery interaction and assertion.
41
+ 4. Fail if the fault was never observed, so a wrong route cannot create a false positive.
42
+ 5. Remove only its own route handler and preserve existing mocks.
43
+
44
+ ## Web and Electron preview
45
+
46
+ Use `web` for a Chromium portal and `desktop` to attach to an existing development Electron renderer. Both use the same Page-level checking engine. Checks discover GET JSON endpoints, inject selected faults, and produce local evidence. Use the separate `repair` command to reproduce in a clean checkout, request an AI proposal with explicit upload consent, and rerun the scenario after applying the candidate only to that copy. See [web/repair setup](docs/repair.md) and [desktop attachment](docs/desktop.md). npm 0.2.0 includes neither workflow.
47
+
48
+ ## Install
49
+
50
+ Recovery Probe is designed to be added to an existing Playwright project:
51
+
52
+ ```bash
53
+ npm install --save-dev recovery-probe
54
+ ```
55
+
56
+ Node.js 22 or newer is required. Playwright is an optional peer dependency: the fetch-only API works without it, while browser/desktop commands require Playwright `^1.62.1` (1.x).
57
+
58
+ ## Quick start
59
+
60
+ Use `withFault` inside an existing Playwright test. The callback contains the real user action and the application-specific recovery assertion.
61
+
62
+ ```js
63
+ import { test, expect } from '@playwright/test';
64
+ import { withFault } from 'recovery-probe';
65
+
66
+ test('profile recovers after a transient 503', async ({ page }) => {
67
+ const stats = await withFault(page, {
68
+ match: '**/api/profile',
69
+ kind: 'http-error',
70
+ status: 503,
71
+ count: 1,
72
+ }, async () => {
73
+ await page.goto('http://127.0.0.1:3000/profile');
74
+ await page.getByRole('button', { name: 'Retry' }).click();
75
+ await expect(page.getByTestId('profile-name')).toHaveText('Test User');
76
+ });
77
+
78
+ expect(stats.applied).toBe(1);
79
+ });
80
+ ```
81
+
82
+ If the endpoint does not match, Recovery Probe throws `FAULT_NOT_TRIGGERED` instead of allowing the test to pass silently. If the fault is applied but the recovery assertion fails, it throws `RECOVERY_ASSERTION_FAILED` and retains the original assertion error as `cause`.
83
+
84
+ ## Run the demonstration
85
+
86
+ The repository includes deliberately broken and corrected applications. Both pass their normal loading check; only the corrected application recovers from all three faults.
87
+
88
+ ```bash
89
+ npm install
90
+ npx playwright install chromium
91
+ npx recovery-probe --demo
92
+ ```
93
+
94
+ The command prints a concise comparison:
95
+
96
+ ```text
97
+ broken synthetic fixture
98
+ PASS Normal connection (OK)
99
+ CAUGHT HTTP 503 once (RECOVERY_ASSERTION_FAILED, injected 1)
100
+ CAUGHT Interrupted request once (RECOVERY_ASSERTION_FAILED, injected 1)
101
+ CAUGHT Malformed JSON once (RECOVERY_ASSERTION_FAILED, injected 1)
102
+
103
+ fixed synthetic fixture
104
+ PASS Normal connection (OK)
105
+ PASS HTTP 503 once (OK, injected 1)
106
+ PASS Interrupted request once (OK, injected 1)
107
+ PASS Malformed JSON once (OK, injected 1)
108
+ ```
109
+
110
+ `--demo` exits successfully only when it observes the expected contrast: the happy path passes, the broken recovery is caught, and the corrected flow passes. Add `--json` to print the full report or `--out report.json` to save it.
111
+
112
+ ## Supported faults
113
+
114
+ | Kind | Injected behavior |
115
+ | --- | --- |
116
+ | `http-error` | Fulfils the matched request with an HTTP error status; defaults to `503`. |
117
+ | `connection-failure` | Aborts the matched Playwright request with `connectionfailed`, or throws from the fetch adapter. |
118
+ | `invalid-json` | Returns status `200` with a deliberately malformed JSON body. |
119
+
120
+ Faults are bounded by `count` (default `1`, maximum `20`). The count is reserved synchronously, so concurrent matching requests cannot over-inject.
121
+
122
+ ## Fetch-only tests
123
+
124
+ The lightweight `recovery-probe/fetch` entry point has no runtime dependencies and does not require Playwright. It matches one exact absolute URL, including its query string, and never patches global `fetch`.
125
+
126
+ ```js
127
+ import { createFaultFetch } from 'recovery-probe/fetch';
128
+
129
+ const probe = createFaultFetch(fetch, {
130
+ url: 'http://127.0.0.1:3000/api/profile',
131
+ kind: 'connection-failure',
132
+ });
133
+
134
+ await exerciseApplication(probe.fetch);
135
+ probe.assertApplied();
136
+ ```
137
+
138
+ `exerciseApplication` represents your own test adapter or application controller. Calling `assertApplied()` is essential: it proves that every requested fault was consumed.
139
+
140
+ ## JSON-configured runner
141
+
142
+ The CLI supports pages that automatically load GET data, expose a visible Retry button after failure, and show a ready element after recovery.
143
+
144
+ ```json
145
+ {
146
+ "name": "Profile recovery",
147
+ "url": "http://127.0.0.1:3000/profile",
148
+ "requestPattern": "**/api/profile",
149
+ "readySelector": "[data-testid=profile-ready]",
150
+ "retrySelector": "[data-testid=profile-retry]",
151
+ "timeoutMs": 3000
152
+ }
153
+ ```
154
+
155
+ ```bash
156
+ npx recovery-probe --config recovery-probe.json --out artifacts/profile-recovery.json
157
+ ```
158
+
159
+ The runner first checks the normal baseline in a fresh browser context. If that baseline fails, fault comparisons are skipped and reported as inconclusive. Each fault then receives its own fresh context with service workers blocked so Playwright can intercept the request.
160
+
161
+ Exit codes:
162
+
163
+ - `0`: every configured check passed, or the controlled demo observed its expected broken-versus-fixed result.
164
+ - `1`: a recovery check failed, was inconclusive, or was skipped.
165
+ - `2`: invalid arguments, configuration, or environment setup.
166
+
167
+ ## Result semantics
168
+
169
+ | Code | Meaning |
170
+ | --- | --- |
171
+ | `OK` | The configured assertion completed and the expected fault count was observed. |
172
+ | `RECOVERY_ASSERTION_FAILED` | The fault occurred, but the recovery assertion did not pass. |
173
+ | `FAULT_NOT_TRIGGERED` | The requested fault count was not observed. Check the route, method, cache, and service worker. |
174
+ | `BASELINE_FAILED` | The ordinary flow failed, so the runner could not make a useful fault comparison. |
175
+ | `INJECTION_ERROR` | Playwright could not apply or clean up the route reliably. |
176
+
177
+ A passing result proves the configured recovery behavior for that test. It is not a certification of overall application resilience.
178
+
179
+ ## API
180
+
181
+ ### `withFault(page, options, exercise)`
182
+
183
+ Installs one temporary Playwright route, runs `exercise`, verifies the requested fault count, and removes only that route handler.
184
+
185
+ ```ts
186
+ interface FaultOptions {
187
+ match: string | RegExp;
188
+ kind: 'http-error' | 'connection-failure' | 'invalid-json';
189
+ status?: number;
190
+ count?: number;
191
+ method?: string;
192
+ }
193
+ ```
194
+
195
+ Register the fault after your own route mocks. The helper uses `route.fallback()` for requests it does not inject, allowing earlier handlers to continue processing them.
196
+
197
+ ### `createFaultFetch(baseFetch, options)`
198
+
199
+ Creates an isolated fetch wrapper for one exact URL and method. It returns `{ fetch, summary, assertApplied }` and leaves the supplied fetch function unchanged.
200
+
201
+ ### `probeRecovery(browser, config)`
202
+
203
+ Runs the baseline and the three default recovery checks used by the JSON CLI. For custom interactions or stronger assertions, prefer `withFault` inside your own test.
204
+
205
+ ## Scope
206
+
207
+ Recovery Probe deliberately focuses on deterministic request-level recovery checks. It does not simulate whole-device offline states, WebSocket interruptions, token expiry, browser sleep, slow-network profiles, or duplicate-submission safety.
208
+
209
+ Playwright already provides the routing primitives used here. Recovery Probe adds bounded recipes, fault-occurrence verification, cleanup, consistent result codes, a fetch adapter, and a runnable broken-versus-fixed example. If a few direct `page.route()` calls are clearer for your test, use them; this package is most useful when teams want the recovery pattern to be repeatable.
210
+
211
+ The runner requires explicit selectors and endpoint matching. It does not discover an application's recovery policy automatically. Request/response bodies and headers are not collected by the checker. Preview reports include endpoint origin/path, selectors, expected text and configuration; optional screenshots, login state and command logs may be sensitive. Do not commit or share these blindly.
212
+
213
+ Recovery Probe sends no telemetry. Tests/discovery do not call an AI service. Only explicit repair generation with `--allow-source-upload` sends the selected source contents and bounded observations to the configured OpenAI model. Login state and command logs are not part of that upload bundle. `store: false` is set on the API request; this is not a promise of zero provider retention. Review employer policy and provider data terms first.
214
+
215
+ ## Development
216
+
217
+ ```bash
218
+ npm ci
219
+ npm test # 9 fetch/core tests
220
+ npm run test:package # isolated tarball install + TypeScript + CLI checks
221
+ npx playwright install chromium
222
+ npm run test:browser # 7 real-browser integration tests
223
+ npm run test:repair # safety, authenticated portal, before/after pipeline
224
+ # After installing the optional Electron test runtime:
225
+ npm run test:repair:electron
226
+ npm run demo:browser
227
+ ```
228
+
229
+ CI runs package checks on Node.js 22 and 24, Chromium integration, and real Electron checks. Repair integration tests use a **controlled mock model response** but real apps, fault injection, source changes and reruns. They validate orchestration, not live AI diagnosis quality. See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
230
+
231
+ ## License
232
+
233
+ [MIT](LICENSE) © 2026 Bojan Kovachki