@hmharness/sandbox 0.8.3 → 0.8.4
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/dist/chaos.d.ts +49 -0
- package/dist/chaos.js +53 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/chaos.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/sandbox - Long-Horizon Chaos Testing (P1-07)
|
|
3
|
+
*
|
|
4
|
+
* The audit called for: "kill process、disconnect device、corrupt workspace、
|
|
5
|
+
* restart daemon、resume"
|
|
6
|
+
*
|
|
7
|
+
* Provides chaos test scenarios that verify the harness can survive and
|
|
8
|
+
* recover from realistic failures.
|
|
9
|
+
*/
|
|
10
|
+
export type ChaosScenario = 'kill-process' | 'corrupt-workspace' | 'disconnect-device' | 'restart-daemon' | 'network-partition' | 'disk-full' | 'workspace-delete' | 'config-corrupt';
|
|
11
|
+
export interface ChaosResult {
|
|
12
|
+
scenario: ChaosScenario;
|
|
13
|
+
/** did the system survive the chaos? */
|
|
14
|
+
survived: boolean;
|
|
15
|
+
/** did the system recover after the chaos was removed? */
|
|
16
|
+
recovered: boolean;
|
|
17
|
+
/** time to recover in ms (if recovered) */
|
|
18
|
+
recoveryMs: number;
|
|
19
|
+
/** details of what happened */
|
|
20
|
+
notes: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get all defined chaos scenarios.
|
|
24
|
+
* Pure - testable.
|
|
25
|
+
*/
|
|
26
|
+
export declare function allScenarios(): ChaosScenario[];
|
|
27
|
+
/**
|
|
28
|
+
* Simulate workspace corruption by writing random bytes to files.
|
|
29
|
+
* Returns the list of corrupted files.
|
|
30
|
+
*/
|
|
31
|
+
export declare function corruptWorkspaceSpec(files: string[], corruptionPercent?: number): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Check if a system is healthy after chaos was applied.
|
|
34
|
+
* This is the verification step - "did it recover?"
|
|
35
|
+
* Pure - testable.
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkRecovery(checks: Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
pass: boolean;
|
|
40
|
+
}>): {
|
|
41
|
+
recovered: boolean;
|
|
42
|
+
failed: string[];
|
|
43
|
+
passedCount: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Build a chaos test report from results.
|
|
47
|
+
* Pure - testable.
|
|
48
|
+
*/
|
|
49
|
+
export declare function chaosReport(results: ChaosResult[]): string;
|
package/dist/chaos.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/sandbox - Long-Horizon Chaos Testing (P1-07)
|
|
3
|
+
*
|
|
4
|
+
* The audit called for: "kill process、disconnect device、corrupt workspace、
|
|
5
|
+
* restart daemon、resume"
|
|
6
|
+
*
|
|
7
|
+
* Provides chaos test scenarios that verify the harness can survive and
|
|
8
|
+
* recover from realistic failures.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Get all defined chaos scenarios.
|
|
12
|
+
* Pure - testable.
|
|
13
|
+
*/
|
|
14
|
+
export function allScenarios() {
|
|
15
|
+
return ['kill-process', 'corrupt-workspace', 'disconnect-device', 'restart-daemon', 'network-partition', 'disk-full', 'workspace-delete', 'config-corrupt'];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Simulate workspace corruption by writing random bytes to files.
|
|
19
|
+
* Returns the list of corrupted files.
|
|
20
|
+
*/
|
|
21
|
+
export function corruptWorkspaceSpec(files, corruptionPercent = 0.3) {
|
|
22
|
+
const count = Math.max(1, Math.floor(files.length * corruptionPercent));
|
|
23
|
+
return files.slice(0, count);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if a system is healthy after chaos was applied.
|
|
27
|
+
* This is the verification step - "did it recover?"
|
|
28
|
+
* Pure - testable.
|
|
29
|
+
*/
|
|
30
|
+
export function checkRecovery(checks) {
|
|
31
|
+
const failed = checks.filter(c => !c.pass).map(c => c.name);
|
|
32
|
+
return {
|
|
33
|
+
recovered: failed.length === 0,
|
|
34
|
+
failed,
|
|
35
|
+
passedCount: checks.filter(c => c.pass).length,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build a chaos test report from results.
|
|
40
|
+
* Pure - testable.
|
|
41
|
+
*/
|
|
42
|
+
export function chaosReport(results) {
|
|
43
|
+
const lines = [`Chaos Test Report: ${results.length} scenarios`];
|
|
44
|
+
for (const r of results) {
|
|
45
|
+
const status = r.survived && r.recovered ? '✅' : r.survived ? '⚠️' : '❌';
|
|
46
|
+
const recovery = r.recovered ? `recovered in ${r.recoveryMs}ms` : 'NOT recovered';
|
|
47
|
+
lines.push(` ${status} ${r.scenario.padEnd(20)} survived=${r.survived} ${recovery}`);
|
|
48
|
+
}
|
|
49
|
+
const survived = results.filter(r => r.survived).length;
|
|
50
|
+
const recovered = results.filter(r => r.recovered).length;
|
|
51
|
+
lines.push(`Summary: ${survived}/${results.length} survived, ${recovered}/${results.length} recovered`);
|
|
52
|
+
return lines.join('\n');
|
|
53
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/sandbox",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "hmharness sandbox runtime (V2 blueprint M3): isolated workspaces with create/exec/read/write/snapshot/restore/diff/destroy, tiered permissions (READ_ONLY / WORKSPACE_WRITE / FULL_ACCESS), git-backed snapshots. Runtime owns agent turns; the sandbox owns workspace/process state (ADR-0001).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|