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/SECURITY.md CHANGED
@@ -1,18 +1,26 @@
1
- # Security
2
-
3
- ## Supported versions
4
-
5
- Security fixes are applied to the latest published version of Recovery Probe.
6
-
7
- ## Reporting a vulnerability
8
-
9
- Please do not open a public issue for a suspected vulnerability.
10
-
11
- Use [GitHub's private vulnerability reporting](https://github.com/BojanKovachki/recovery-probe/security/advisories/new) and include:
12
-
13
- - the affected version;
14
- - a minimal reproduction;
15
- - the expected and observed behavior;
16
- - any known impact.
17
-
18
- Reports should not contain real credentials, production request data, or other sensitive application information. I aim to acknowledge reports within seven days.
1
+ # Security
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes are applied to the latest published version of Recovery Probe.
6
+
7
+ ## Preview repair trust boundary
8
+
9
+ Repair operates on a separate local clone, **not an OS/network security sandbox**. Launch scripts, setup/test commands and generated application code execute with your user's filesystem/network privileges. Use trusted configuration and a disposable development container or VM for unreviewed candidates. No production credentials or production mutation targets.
10
+
11
+ Source upload is opt-in and file-allowlisted, but secret detection is not comprehensive: review `repair-request.json` before generation. Provider keys are not passed to child commands; processes can still access credentials on disk outside a sandbox. There is no implicit upload, automatic merge or deployment.
12
+
13
+ Saved browser state, Electron test profiles, source bundles, expected text, command logs and screenshots can contain private data. Output permissions are restrictive on POSIX; verify ACLs yourself on Windows. Never commit these artifacts. Before using an employer's code or services, obtain the required authorization.
14
+
15
+ ## Reporting a vulnerability
16
+
17
+ Please do not open a public issue for a suspected vulnerability.
18
+
19
+ Use [GitHub's private vulnerability reporting](https://github.com/BojanKovachki/recovery-probe/security/advisories/new) and include:
20
+
21
+ - the affected version;
22
+ - a minimal reproduction;
23
+ - the expected and observed behavior;
24
+ - any known impact.
25
+
26
+ Reports should not contain real credentials, production request data, or other sensitive application information. I aim to acknowledge reports within seven days.
package/bin/core-demo.mjs CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env node
2
- import { mkdir, writeFile } from 'node:fs/promises';
3
- import { runCoreDemo } from '../examples/core-demo.mjs';
4
- const report = await runCoreDemo();
5
- await mkdir('artifacts', { recursive: true });
6
- await writeFile('artifacts/core-demo.json', JSON.stringify(report, null, 2) + '\n');
7
- console.log(JSON.stringify(report, null, 2));
8
- process.exitCode = report.expectedDemonstrationVerified ? 0 : 1;
1
+ #!/usr/bin/env node
2
+ import { mkdir, writeFile } from 'node:fs/promises';
3
+ import { runCoreDemo } from '../examples/core-demo.mjs';
4
+ const report = await runCoreDemo();
5
+ await mkdir('artifacts', { recursive: true });
6
+ await writeFile('artifacts/core-demo.json', JSON.stringify(report, null, 2) + '\n');
7
+ console.log(JSON.stringify(report, null, 2));
8
+ process.exitCode = report.expectedDemonstrationVerified ? 0 : 1;
@@ -0,0 +1,82 @@
1
+ import { readFile, writeFile, mkdir } from 'node:fs/promises';
2
+ import { resolve, join } from 'node:path';
3
+ import { connectDesktop, desktopPages, selectDesktopPage, pageIdentity, discoverDesktop, checkDesktop, validateDesktopConfig } from '../src/desktop.mjs';
4
+ import { writeDesktopReport } from '../src/desktop-report.mjs';
5
+
6
+ export async function desktopMain(args) {
7
+ if (!args.length || args.includes('--help')) {
8
+ console.log(`Recovery Probe desktop preview
9
+
10
+ Attach to an Electron DEVELOPMENT renderer through its loopback debugging port.
11
+
12
+ recovery-probe desktop --list [--cdp http://127.0.0.1:9222]
13
+ recovery-probe desktop --discover --page 0 [--duration 5000] [--out .recovery-probe/discovery]
14
+ recovery-probe desktop --config scenario.json [--out .recovery-probe/run] [--screenshots]
15
+
16
+ Discovery reloads the chosen window and lists successful renderer GET JSON endpoints.
17
+ Checks reload it once per baseline/fault, optionally click the configured Retry button,
18
+ and perform a final reload reset. The app stays open. Use a test account/environment.
19
+ The config selects one endpoint and a data-dependent readySelector; see docs/desktop.md.
20
+ Requests made by native SDKs/IPC and untouched app screens are outside this check.
21
+ Reports stay local. Screenshots are opt-in and may contain private on-screen content.`);
22
+ return;
23
+ }
24
+ const options = {};
25
+ const values = new Set(['--cdp', '--page', '--duration', '--out', '--config']);
26
+ for (let i = 0; i < args.length; i++) {
27
+ const arg = args[i];
28
+ const key = arg.slice(2);
29
+ if (['--list', '--discover', '--screenshots'].includes(arg)) options[key] = true;
30
+ else if (values.has(arg)) {
31
+ if (!args[i + 1] || args[i + 1].startsWith('--')) throw new Error(`${arg} needs a value`);
32
+ options[key] = args[++i];
33
+ } else throw new Error(`Unknown desktop option: ${arg}`);
34
+ }
35
+ if ([options.list, options.discover, options.config].filter(Boolean).length !== 1) throw new Error('Choose one of --list, --discover, or --config');
36
+ if (options.page !== undefined) {
37
+ if (!/^\d+$/.test(options.page)) throw new Error('--page must be a non-negative integer');
38
+ options.page = Number(options.page);
39
+ }
40
+ if (options.duration !== undefined && (!/^\d+$/.test(options.duration) || Number(options.duration) < 200 || Number(options.duration) > 30000)) throw new Error('--duration must be 200–30000 ms');
41
+ let config = options.config ? JSON.parse(await readFile(options.config, 'utf8')) : {};
42
+ if (options.page !== undefined) config.page = options.page;
43
+ config.cdp = options.cdp ?? config.cdp ?? 'http://127.0.0.1:9222';
44
+ if (options.config) config = validateDesktopConfig(config);
45
+ const browser = await connectDesktop(config.cdp);
46
+ try {
47
+ if (options.list) {
48
+ const pages = desktopPages(browser);
49
+ if (!pages.length) throw new Error('No renderer pages found');
50
+ pages.forEach((page, index) => console.log(`${index} ${pageIdentity(page.url())}`));
51
+ return;
52
+ }
53
+ const page = selectDesktopPage(browser, config);
54
+ const directory = resolve(options.out ?? `.recovery-probe/${new Date().toISOString().replace(/[:.]/g, '-')}`);
55
+ await mkdir(directory, { recursive: true, mode: 0o700 });
56
+ if (options.discover) {
57
+ const discovery = await discoverDesktop(page, { durationMs: Number(options.duration ?? 5000) });
58
+ await writeFile(join(directory, 'discovery.json'), JSON.stringify(discovery, null, 2) + '\n', { mode: 0o600 });
59
+ const template = { cdp: config.cdp, page: desktopPages(browser).indexOf(page), pageUrl: discovery.pageUrl, endpoint: discovery.endpoints.length === 1 ? discovery.endpoints[0].endpoint : '', readySelector: '', retrySelector: '', recovery: 'retry', timeoutMs: 5000 };
60
+ await writeFile(join(directory, 'scenario.json'), JSON.stringify(template, null, 2) + '\n', { mode: 0o600 });
61
+ discovery.endpoints.forEach((row, index) => console.log(`${index + 1}. GET ${row.endpoint} (${row.observed} response(s), query values omitted)`));
62
+ if (!discovery.endpoints.length) console.log('No matching renderer GET JSON responses observed. The screen may use cached data, native SDK/IPC requests, a service worker, or load after the discovery window. This is not a pass.');
63
+ console.log(`\nDiscovery: ${join(directory, 'discovery.json')}\nFill endpoint (if blank), readySelector and retrySelector in ${join(directory, 'scenario.json')}`);
64
+ return;
65
+ }
66
+ console.log('Checking the current development renderer. It will reload between faults.');
67
+ const report = await checkDesktop(page, config, {
68
+ onFailure: options.screenshots ? async (target, row) => {
69
+ const filename = `${row.kind}.png`;
70
+ await target.screenshot({ path: join(directory, filename), timeout: 5000 });
71
+ row.screenshot = filename;
72
+ } : undefined,
73
+ });
74
+ await writeDesktopReport(directory, report, config);
75
+ for (const row of report.results) console.log(`${row.outcome.toUpperCase().padEnd(12)} ${row.kind}: ${row.code} (injected ${row.applied}, later successful responses ${row.successfulResponsesAfterFault})`);
76
+ console.log(`Final reload reset: ${report.finalReset}\nReport: ${join(directory, 'report.html')}\nReproduce: node ${join(directory, 'reproduce.mjs')}\nFix investigation: ${join(directory, 'fix-brief.md')}`);
77
+ process.exitCode = report.ok ? 0 : report.results.some(row => row.outcome === 'fail') ? 1 : 2;
78
+ } finally {
79
+ // Closing a CDP connection disconnects this client; it does not close the existing app.
80
+ await browser.close();
81
+ }
82
+ }
@@ -1,120 +1,135 @@
1
- #!/usr/bin/env node
2
- import { readFile, writeFile, mkdir } from 'node:fs/promises';
3
- import { dirname } from 'node:path';
4
- import { probeRecovery } from '../src/index.mjs';
5
- import { startDemoServer } from '../examples/demo-server.mjs';
6
-
7
- const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
8
-
9
- function printHelp() {
10
- console.log(`Recovery Probe ${version}
11
-
12
- Usage:
13
- recovery-probe --demo [--out report.json] [--json]
14
- recovery-probe --config scenario.json [--out report.json] [--json]
15
- recovery-probe --version
16
-
17
- Options:
18
- --demo Run the included broken-versus-fixed browser demonstration.
19
- --config <file> Check one JSON-configured recovery scenario.
20
- --out <file> Save the full machine-readable report.
21
- --json Print the full JSON report instead of a terminal summary.
22
- --help Show this help.
23
-
24
- Use only development or test targets you control.`);
25
- }
26
-
27
- function marker(outcome) {
28
- if (outcome === 'pass') return 'PASS';
29
- if (outcome === 'fail') return 'CAUGHT';
30
- return outcome.toUpperCase();
31
- }
32
-
33
- function printSummary(report) {
34
- console.log(`Recovery Probe ${report.version} — ${report.mode}\n`);
35
- for (const app of report.apps) {
36
- console.log(app.name);
37
- for (const row of app.results) {
38
- const injected = row.applied ? `, injected ${row.applied}` : '';
39
- console.log(` ${marker(row.outcome).padEnd(12)} ${row.scenario} (${row.code}${injected})`);
40
- }
41
- console.log('');
42
- }
43
- if (report.mode === 'controlled demonstration') {
44
- console.log(report.expectedDemonstrationVerified
45
- ? 'Demo verified: the happy path passes, the broken recovery is caught, and the fixed app recovers.'
46
- : 'Demo failed: the expected broken-versus-fixed distinction was not observed.');
47
- } else {
48
- console.log(report.apps.every(app => app.ok) ? 'Recovery check passed.' : 'Recovery check did not pass.');
49
- }
50
- }
51
-
52
- async function main() {
53
- const args = process.argv.slice(2);
54
- if (args.includes('--help') || !args.length) {
55
- printHelp();
56
- return;
57
- }
58
- if (args.length === 1 && args[0] === '--version') {
59
- console.log(version);
60
- return;
61
- }
62
- let demo = false;
63
- let json = false;
64
- let configPath;
65
- let output;
66
- for (let i = 0; i < args.length; i++) {
67
- const arg = args[i];
68
- if (arg === '--demo') demo = true;
69
- else if (arg === '--json') json = true;
70
- else if (arg === '--config' || arg === '--out') {
71
- const value = args[++i];
72
- if (!value || value.startsWith('--')) throw new Error(`${arg} needs a value`);
73
- if (arg === '--config') configPath = value; else output = value;
74
- } else throw new Error(`Unknown argument: ${arg}`);
75
- }
76
- if (demo === Boolean(configPath)) throw new Error('Choose exactly one of --demo or --config');
77
-
78
- const config = configPath ? JSON.parse(await readFile(configPath, 'utf8')) : null;
79
- const { chromium } = await import('playwright');
80
- const browser = await chromium.launch({ headless: true });
81
- let server;
82
- let report;
83
- try {
84
- const apps = [];
85
- if (demo) {
86
- server = await startDemoServer();
87
- for (const variant of ['broken', 'fixed']) {
88
- apps.push(await probeRecovery(browser, {
89
- name: `${variant} synthetic fixture`, url: `${server.url}/${variant}`,
90
- requestPattern: '**/api/profile', readySelector: '#profile', retrySelector: '#retry', timeoutMs: 1200,
91
- }));
92
- }
93
- } else apps.push(await probeRecovery(browser, config));
94
- report = {
95
- tool: 'Recovery Probe', version, generatedAt: new Date().toISOString(),
96
- environment: { node: process.version, platform: process.platform, chromium: browser.version() },
97
- mode: demo ? 'controlled demonstration' : 'configured recovery check', apps,
98
- };
99
- if (demo) {
100
- report.expectedDemonstrationVerified = apps[0].results[0].outcome === 'pass'
101
- && apps[0].results.slice(1).every(row => row.outcome === 'fail' && row.applied === 1)
102
- && apps[1].ok;
103
- process.exitCode = report.expectedDemonstrationVerified ? 0 : 1;
104
- } else process.exitCode = apps.every(app => app.ok) ? 0 : 1;
105
- } finally {
106
- await browser.close();
107
- if (server) await server.close();
108
- }
109
- if (json) console.log(JSON.stringify(report, null, 2));
110
- else printSummary(report);
111
- if (output) {
112
- await mkdir(dirname(output), { recursive: true });
113
- await writeFile(output, JSON.stringify(report, null, 2) + '\n');
114
- }
115
- }
116
-
117
- main().catch(error => {
118
- console.error(`Recovery Probe: ${error.message}`);
119
- process.exitCode = 2;
120
- });
1
+ #!/usr/bin/env node
2
+ import { readFile, writeFile, mkdir } from 'node:fs/promises';
3
+ import { dirname } from 'node:path';
4
+ import { probeRecovery } from '../src/index.mjs';
5
+ import { startDemoServer } from '../examples/demo-server.mjs';
6
+
7
+ const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
8
+
9
+ function printHelp() {
10
+ console.log(`Recovery Probe ${version}
11
+
12
+ Usage:
13
+ recovery-probe --demo [--out report.json] [--json]
14
+ recovery-probe --config scenario.json [--out report.json] [--json]
15
+ recovery-probe desktop --help
16
+ recovery-probe web --help
17
+ recovery-probe repair --help
18
+ recovery-probe --version
19
+
20
+ Options:
21
+ --demo Run the included broken-versus-fixed browser demonstration.
22
+ --config <file> Check one JSON-configured recovery scenario.
23
+ --out <file> Save the full machine-readable report.
24
+ --json Print the full JSON report instead of a terminal summary.
25
+ --help Show this help.
26
+
27
+ Use only development or test targets you control.`);
28
+ }
29
+
30
+ function marker(outcome) {
31
+ if (outcome === 'pass') return 'PASS';
32
+ if (outcome === 'fail') return 'CAUGHT';
33
+ return outcome.toUpperCase();
34
+ }
35
+
36
+ function printSummary(report) {
37
+ console.log(`Recovery Probe ${report.version} — ${report.mode}\n`);
38
+ for (const app of report.apps) {
39
+ console.log(app.name);
40
+ for (const row of app.results) {
41
+ const injected = row.applied ? `, injected ${row.applied}` : '';
42
+ console.log(` ${marker(row.outcome).padEnd(12)} ${row.scenario} (${row.code}${injected})`);
43
+ }
44
+ console.log('');
45
+ }
46
+ if (report.mode === 'controlled demonstration') {
47
+ console.log(report.expectedDemonstrationVerified
48
+ ? 'Demo verified: the happy path passes, the broken recovery is caught, and the fixed app recovers.'
49
+ : 'Demo failed: the expected broken-versus-fixed distinction was not observed.');
50
+ } else {
51
+ console.log(report.apps.every(app => app.ok) ? 'Recovery check passed.' : 'Recovery check did not pass.');
52
+ }
53
+ }
54
+
55
+ async function main() {
56
+ const args = process.argv.slice(2);
57
+ if (args[0] === 'web') {
58
+ const { webMain } = await import('./web.mjs');
59
+ return webMain(args.slice(1));
60
+ }
61
+ if (args[0] === 'repair') {
62
+ const { repairMain } = await import('./repair.mjs');
63
+ return repairMain(args.slice(1));
64
+ }
65
+ if (args[0] === 'desktop') {
66
+ const { desktopMain } = await import('./desktop.mjs');
67
+ return desktopMain(args.slice(1));
68
+ }
69
+ if (args.includes('--help') || !args.length) {
70
+ printHelp();
71
+ return;
72
+ }
73
+ if (args.length === 1 && args[0] === '--version') {
74
+ console.log(version);
75
+ return;
76
+ }
77
+ let demo = false;
78
+ let json = false;
79
+ let configPath;
80
+ let output;
81
+ for (let i = 0; i < args.length; i++) {
82
+ const arg = args[i];
83
+ if (arg === '--demo') demo = true;
84
+ else if (arg === '--json') json = true;
85
+ else if (arg === '--config' || arg === '--out') {
86
+ const value = args[++i];
87
+ if (!value || value.startsWith('--')) throw new Error(`${arg} needs a value`);
88
+ if (arg === '--config') configPath = value; else output = value;
89
+ } else throw new Error(`Unknown argument: ${arg}`);
90
+ }
91
+ if (demo === Boolean(configPath)) throw new Error('Choose exactly one of --demo or --config');
92
+
93
+ const config = configPath ? JSON.parse(await readFile(configPath, 'utf8')) : null;
94
+ const { chromium } = await import('playwright');
95
+ const browser = await chromium.launch({ headless: true });
96
+ let server;
97
+ let report;
98
+ try {
99
+ const apps = [];
100
+ if (demo) {
101
+ server = await startDemoServer();
102
+ for (const variant of ['broken', 'fixed']) {
103
+ apps.push(await probeRecovery(browser, {
104
+ name: `${variant} synthetic fixture`, url: `${server.url}/${variant}`,
105
+ requestPattern: '**/api/profile', readySelector: '#profile', retrySelector: '#retry', timeoutMs: 1200,
106
+ }));
107
+ }
108
+ } else apps.push(await probeRecovery(browser, config));
109
+ report = {
110
+ tool: 'Recovery Probe', version, generatedAt: new Date().toISOString(),
111
+ environment: { node: process.version, platform: process.platform, chromium: browser.version() },
112
+ mode: demo ? 'controlled demonstration' : 'configured recovery check', apps,
113
+ };
114
+ if (demo) {
115
+ report.expectedDemonstrationVerified = apps[0].results[0].outcome === 'pass'
116
+ && apps[0].results.slice(1).every(row => row.outcome === 'fail' && row.applied === 1)
117
+ && apps[1].ok;
118
+ process.exitCode = report.expectedDemonstrationVerified ? 0 : 1;
119
+ } else process.exitCode = apps.every(app => app.ok) ? 0 : 1;
120
+ } finally {
121
+ await browser.close();
122
+ if (server) await server.close();
123
+ }
124
+ if (json) console.log(JSON.stringify(report, null, 2));
125
+ else printSummary(report);
126
+ if (output) {
127
+ await mkdir(dirname(output), { recursive: true });
128
+ await writeFile(output, JSON.stringify(report, null, 2) + '\n');
129
+ }
130
+ }
131
+
132
+ main().catch(error => {
133
+ console.error(`Recovery Probe: ${error.message}`);
134
+ process.exitCode = 2;
135
+ });
package/bin/repair.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { resolve, dirname } from 'node:path';
3
+ import { prepareRepair, generateRepair, verifyRepair } from '../src/repair.mjs';
4
+
5
+ export async function repairMain(args) {
6
+ if (!args.length || args.includes('--help')) {
7
+ console.log(`Recovery Probe repair preview — local development only
8
+ recovery-probe repair --config repair.json --out NEW_DIRECTORY --allow-execution
9
+ recovery-probe repair --generate RUN_DIRECTORY --allow-source-upload
10
+ recovery-probe repair --verify RUN_DIRECTORY --allow-execution
11
+
12
+ Optional single run: --config ... --out ... --allow-execution --allow-source-upload --auto-verify
13
+
14
+ Config: target (web/desktop), repo, sourceFiles, scenario, launch, setup, tests, provider.model.
15
+ Paths resolve relative to the config. Output must be outside your clean source repository.
16
+ Step 1 clones the committed source locally, starts that copy and reproduces a failure.
17
+ Step 2 sends only repair-request.json to OpenAI, using your local OPENAI_API_KEY.
18
+ Step 3 applies proposal.json only to the copy and reruns the same scenario and your tests.
19
+ Review proposal.json before verification. --auto-verify explicitly executes unreviewed AI code.
20
+ A checkout is NOT a security sandbox: use a disposable dev container/VM and test accounts.
21
+ There is no implicit source upload, production deployment, commit, merge or original-repo edit.
22
+ See docs/repair.md for complete web and Electron examples and Windows commands.`);
23
+ return;
24
+ }
25
+ const options = {};
26
+ for (let i = 0; i < args.length; i++) {
27
+ const arg = args[i];
28
+ if (['--allow-execution', '--allow-source-upload', '--auto-verify'].includes(arg)) options[arg.slice(2)] = true;
29
+ else if (['--config', '--out', '--generate', '--verify'].includes(arg)) {
30
+ if (!args[i + 1] || args[i + 1].startsWith('--')) throw new Error(`${arg} needs a value`);
31
+ options[arg.slice(2)] = args[++i];
32
+ } else throw new Error(`Unknown repair option: ${arg}`);
33
+ }
34
+ if ([options.config, options.generate, options.verify].filter(Boolean).length !== 1) throw new Error('Choose --config, --generate, or --verify');
35
+ if (options['auto-verify'] && (!options.config || !options['allow-execution'] || !options['allow-source-upload'])) throw new Error('--auto-verify requires --config, --allow-execution and --allow-source-upload');
36
+ let directory = resolve(options.generate ?? options.verify ?? options.out ?? `../recovery-probe-run-${Date.now()}`);
37
+ if (options.verify) {
38
+ const result = await verifyRepair(directory, { allowExecution: options['allow-execution'] });
39
+ console.log(JSON.stringify(result, null, 2));
40
+ console.log(`Review ${directory}/candidate.patch. Your original repository was not modified.`);
41
+ process.exitCode = result.status === 'verified-candidate' ? 0 : 1;
42
+ return;
43
+ }
44
+ if (options.config) {
45
+ const configPath = resolve(options.config);
46
+ const config = JSON.parse(await readFile(configPath, 'utf8'));
47
+ config.repo = resolve(dirname(configPath), config.repo ?? '.');
48
+ if (config.scenario?.storageState) config.scenario.storageState = resolve(dirname(configPath), config.scenario.storageState);
49
+ console.log('Reproducing in a separate checkout; running only the commands you configured.');
50
+ const prepared = await prepareRepair(config, directory, { allowExecution: options['allow-execution'] });
51
+ if (!prepared.reproduced) {
52
+ console.log(`No repairable failure reproduced. Inspect ${directory}/before.json; no model called.`);
53
+ process.exitCode = prepared.before.ok ? 0 : 2;
54
+ return;
55
+ }
56
+ console.log(`Failure reproduced. Inspect ${directory}/repair-request.json before authorizing source upload.`);
57
+ if (!options['allow-source-upload']) return;
58
+ }
59
+ const proposal = await generateRepair(directory, { allowSourceUpload: options['allow-source-upload'] });
60
+ console.log(`Proposal: ${directory}/proposal.json (${proposal.edits.length} edit(s)). No source changes applied yet.`);
61
+ if (options['auto-verify'] && proposal.edits.length) {
62
+ const result = await verifyRepair(directory, { allowExecution: true });
63
+ console.log(JSON.stringify(result, null, 2));
64
+ process.exitCode = result.status === 'verified-candidate' ? 0 : 1;
65
+ } else console.log('Review the proposal, then run repair --verify RUN_DIRECTORY --allow-execution.');
66
+ }
package/bin/web.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import { readFile, writeFile, mkdir } from 'node:fs/promises';
2
+ import { resolve, dirname, join } from 'node:path';
3
+ import { createInterface } from 'node:readline/promises';
4
+ import { openWeb, checkWeb, discoverWeb } from '../src/web.mjs';
5
+ import { writeDesktopReport } from '../src/desktop-report.mjs';
6
+
7
+ export async function webMain(args) {
8
+ if (!args.length || args.includes('--help')) {
9
+ console.log(`Recovery Probe web preview
10
+ recovery-probe web --login --url http://localhost:3000 --state /private/portal-state.json
11
+ recovery-probe web --discover --url http://localhost:3000/users [--state /private/portal-state.json] [--out NEW_DIRECTORY]
12
+ recovery-probe web --config scenario.json [--state /private/portal-state.json] [--headed] [--out NEW_DIRECTORY]
13
+
14
+ Use an authorized development/test account. Checks reload the page and inject GET faults.
15
+ Login opens a visible Chromium window. Sign in yourself, then press Enter in the terminal.
16
+ State contains credentials: never commit/share it. Automatic recovery needs no Retry UI.
17
+ Discovery writes a scenario template; fill its endpoint and data-dependent readySelector.`);
18
+ return;
19
+ }
20
+ const options = {};
21
+ for (let i = 0; i < args.length; i++) {
22
+ const arg = args[i];
23
+ if (['--login', '--discover', '--headed'].includes(arg)) options[arg.slice(2)] = true;
24
+ else if (['--url', '--state', '--config', '--out'].includes(arg)) {
25
+ if (!args[i + 1] || args[i + 1].startsWith('--')) throw new Error(`${arg} needs a value`);
26
+ options[arg.slice(2)] = args[++i];
27
+ } else throw new Error(`Unknown web option: ${arg}`);
28
+ }
29
+ if ([options.login, options.discover, options.config].filter(Boolean).length !== 1) throw new Error('Choose --login, --discover, or --config');
30
+ const configPath = options.config && resolve(options.config);
31
+ const config = configPath ? JSON.parse(await readFile(configPath, 'utf8')) : { pageUrl: options.url };
32
+ if (config.storageState) config.storageState = resolve(dirname(configPath), config.storageState);
33
+ if (options.state && !options.login) config.storageState = resolve(options.state);
34
+ if (options.headed || options.login) config.headless = false;
35
+ if (options.login) {
36
+ if (!options.state || !process.stdin.isTTY) throw new Error('--login requires --state and an interactive terminal');
37
+ const state = resolve(options.state);
38
+ await mkdir(dirname(state), { recursive: true, mode: 0o700 });
39
+ const session = await openWeb(config);
40
+ const terminal = createInterface({ input: process.stdin, output: process.stdout });
41
+ try {
42
+ await terminal.question('Sign in using the browser, return to your app, then press Enter to save login state. ');
43
+ const saved = await session.context.storageState({ indexedDB: true });
44
+ await writeFile(state, JSON.stringify(saved), { mode: 0o600, flag: 'wx' });
45
+ console.log(`Saved ${state}. Keep it private. Session-storage-only authentication needs your existing Playwright login fixture.`);
46
+ } finally { terminal.close(); await session.browser.close(); }
47
+ return;
48
+ }
49
+ const directory = resolve(options.out ?? `.recovery-probe/web-${Date.now()}`);
50
+ await mkdir(dirname(directory), { recursive: true, mode: 0o700 });
51
+ await mkdir(directory, { mode: 0o700 });
52
+ if (options.discover) {
53
+ const report = await discoverWeb(config);
54
+ const scenario = { ...config, pageUrl: report.pageUrl, endpoint: report.endpoints.length === 1 ? report.endpoints[0].endpoint : '', readySelector: '', recovery: 'automatic', timeoutMs: 5000 };
55
+ await writeFile(join(directory, 'discovery.json'), JSON.stringify(report, null, 2), { mode: 0o600 });
56
+ await writeFile(join(directory, 'scenario.json'), JSON.stringify(scenario, null, 2), { mode: 0o600 });
57
+ console.log(JSON.stringify(report, null, 2));
58
+ console.log(`Fill in ${join(directory, 'scenario.json')}`);
59
+ return;
60
+ }
61
+ const scenario = { recovery: 'automatic', ...config, target: 'web' };
62
+ const report = await checkWeb(scenario);
63
+ await writeDesktopReport(directory, report, scenario);
64
+ console.log(`${report.ok ? 'PASS' : 'NOT PASSED'}: ${join(directory, 'report.html')}`);
65
+ process.exitCode = report.ok ? 0 : report.results.some(row => row.outcome === 'fail') ? 1 : 2;
66
+ }