rightsize 0.1.2 → 0.2.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 +28 -4
- package/dist/backend-docker/backend.d.ts +53 -1
- package/dist/backend-docker/backend.d.ts.map +1 -1
- package/dist/backend-docker/backend.js +106 -13
- package/dist/backend-docker/backend.js.map +1 -1
- package/dist/backend-docker/labels.d.ts +27 -5
- package/dist/backend-docker/labels.d.ts.map +1 -1
- package/dist/backend-docker/labels.js +33 -5
- package/dist/backend-docker/labels.js.map +1 -1
- package/dist/backend-msb/backend.d.ts +35 -6
- package/dist/backend-msb/backend.d.ts.map +1 -1
- package/dist/backend-msb/backend.js +69 -14
- package/dist/backend-msb/backend.js.map +1 -1
- package/dist/backend-msb/provider.d.ts.map +1 -1
- package/dist/backend-msb/provider.js +7 -11
- package/dist/backend-msb/provider.js.map +1 -1
- package/dist/backend-msb/provisioner.d.ts.map +1 -1
- package/dist/backend-msb/provisioner.js +1 -20
- package/dist/backend-msb/provisioner.js.map +1 -1
- package/dist/core/backend.d.ts +73 -0
- package/dist/core/backend.d.ts.map +1 -1
- package/dist/core/backends.d.ts +16 -2
- package/dist/core/backends.d.ts.map +1 -1
- package/dist/core/backends.js +39 -5
- package/dist/core/backends.js.map +1 -1
- package/dist/core/cache-dir.d.ts +17 -0
- package/dist/core/cache-dir.d.ts.map +1 -0
- package/dist/core/cache-dir.js +29 -0
- package/dist/core/cache-dir.js.map +1 -0
- package/dist/core/cleanup.d.ts +19 -4
- package/dist/core/cleanup.d.ts.map +1 -1
- package/dist/core/cleanup.js +14 -27
- package/dist/core/cleanup.js.map +1 -1
- package/dist/core/diagnostics.d.ts +33 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +76 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/errors.d.ts +41 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +56 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/generic-container.d.ts +107 -1
- package/dist/core/generic-container.d.ts.map +1 -1
- package/dist/core/generic-container.js +417 -3
- package/dist/core/generic-container.js.map +1 -1
- package/dist/core/model.d.ts +22 -0
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/network.d.ts.map +1 -1
- package/dist/core/network.js +2 -0
- package/dist/core/network.js.map +1 -1
- package/dist/core/reaper/env.d.ts +14 -0
- package/dist/core/reaper/env.d.ts.map +1 -0
- package/dist/core/reaper/env.js +22 -0
- package/dist/core/reaper/env.js.map +1 -0
- package/dist/core/reaper/init.d.ts +39 -0
- package/dist/core/reaper/init.d.ts.map +1 -0
- package/dist/core/reaper/init.js +140 -0
- package/dist/core/reaper/init.js.map +1 -0
- package/dist/core/reaper/ledger.d.ts +32 -0
- package/dist/core/reaper/ledger.d.ts.map +1 -0
- package/dist/core/reaper/ledger.js +160 -0
- package/dist/core/reaper/ledger.js.map +1 -0
- package/dist/core/reaper/process-liveness.d.ts +39 -0
- package/dist/core/reaper/process-liveness.d.ts.map +1 -0
- package/dist/core/reaper/process-liveness.js +117 -0
- package/dist/core/reaper/process-liveness.js.map +1 -0
- package/dist/core/reaper/run-record.d.ts +48 -0
- package/dist/core/reaper/run-record.d.ts.map +1 -0
- package/dist/core/reaper/run-record.js +58 -0
- package/dist/core/reaper/run-record.js.map +1 -0
- package/dist/core/reaper/sweep.d.ts +23 -0
- package/dist/core/reaper/sweep.d.ts.map +1 -0
- package/dist/core/reaper/sweep.js +76 -0
- package/dist/core/reaper/sweep.js.map +1 -0
- package/dist/core/reaper/watchdog.d.ts +100 -0
- package/dist/core/reaper/watchdog.d.ts.map +1 -0
- package/dist/core/reaper/watchdog.js +412 -0
- package/dist/core/reaper/watchdog.js.map +1 -0
- package/dist/core/reuse/env.d.ts +12 -0
- package/dist/core/reuse/env.d.ts.map +1 -0
- package/dist/core/reuse/env.js +15 -0
- package/dist/core/reuse/env.js.map +1 -0
- package/dist/core/reuse/hash.d.ts +34 -0
- package/dist/core/reuse/hash.d.ts.map +1 -0
- package/dist/core/reuse/hash.js +52 -0
- package/dist/core/reuse/hash.js.map +1 -0
- package/dist/core/reuse/registry.d.ts +50 -0
- package/dist/core/reuse/registry.d.ts.map +1 -0
- package/dist/core/reuse/registry.js +75 -0
- package/dist/core/reuse/registry.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/backend-msb/reaper.d.ts +0 -10
- package/dist/backend-msb/reaper.d.ts.map +0 -1
- package/dist/backend-msb/reaper.js +0 -73
- package/dist/backend-msb/reaper.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backends.js","sourceRoot":"","sources":["../../src/core/backends.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"backends.js","sourceRoot":"","sources":["../../src/core/backends.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEtG,sEAAsE;AACtE,wEAAwE;AACxE,oEAAoE;AACpE,kDAAkD;AAClD,MAAM,UAAU,GAAsB,EAAE,CAAC;AAEzC,yHAAyH;AACzH,MAAM,UAAU,eAAe,CAAC,QAAyB;IACvD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,sBAAsB;IACpC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,UAAU,CAAC,SAAqC;IACvD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,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UAAU,GAAG,GAAS,EAAE;oBAC5B,mBAAmB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBACxC,CAAC,CAAC;gBACF,oEAAoE;gBACpE,oEAAoE;gBACpE,kEAAkE;gBAClE,iEAAiE;gBACjE,IAAI,CAAC;oBACH,aAAa,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;gBACtD,CAAC;gBAAC,MAAM,CAAC;oBACP,uDAAuD;oBACvD,UAAU,EAAE,CAAC;gBACf,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,IAAI,kBAA6C,CAAC;AAElD;;;;;;;;;;GAUG;AACH,SAAS,WAAW;IAClB,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;IACzB,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;QACrC,kBAAkB,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,0IAA0I;AAC1I,SAAS,oBAAoB;IAC3B,aAAa,GAAG,SAAS,CAAC;IAC1B,iBAAiB,GAAG,KAAK,CAAC;IAC1B,kBAAkB,GAAG,SAAS,CAAC;IAC/B,oBAAoB,EAAE,CAAC;AACzB,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,+EAA+E;IAC/E,OAAO;IACP,+GAA+G;IAC/G,MAAM;IACN,4FAA4F;IAC5F,WAAW;IACX,4HAA4H;IAC5H,oBAAoB;CACrB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one rightsize runtime cache directory, shared by every part of the
|
|
3
|
+
* library that needs a place on disk: the msb toolchain provisioner
|
|
4
|
+
* (`<cacheDir>/msb/<version>/...`), the reaping ledger (`<cacheDir>/runs/...`),
|
|
5
|
+
* and the watchdog scripts (`<cacheDir>/reaper/...`). Lives in core rather
|
|
6
|
+
* than the msb provisioner because the ledger needs it even in a
|
|
7
|
+
* docker-only process, which never touches `backend-msb` at all.
|
|
8
|
+
*
|
|
9
|
+
* `%LOCALAPPDATA%` is the Windows-idiomatic location for a machine-local,
|
|
10
|
+
* non-roaming native toolchain cache (as opposed to `%USERPROFILE%`, which a
|
|
11
|
+
* roaming-profile setup can sync, or a Unix-style dotfile under the home
|
|
12
|
+
* dir). Falls back to `%USERPROFILE%\AppData\Local` if the env var is unset,
|
|
13
|
+
* matching what `os.homedir()` resolves to on a normal Windows install when
|
|
14
|
+
* `LOCALAPPDATA` isn't populated (rare, but seen on some minimal/CI images).
|
|
15
|
+
*/
|
|
16
|
+
export declare function cacheDir(): string;
|
|
17
|
+
//# sourceMappingURL=cache-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-dir.d.ts","sourceRoot":"","sources":["../../src/core/cache-dir.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,IAAI,MAAM,CAUjC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
/**
|
|
4
|
+
* The one rightsize runtime cache directory, shared by every part of the
|
|
5
|
+
* library that needs a place on disk: the msb toolchain provisioner
|
|
6
|
+
* (`<cacheDir>/msb/<version>/...`), the reaping ledger (`<cacheDir>/runs/...`),
|
|
7
|
+
* and the watchdog scripts (`<cacheDir>/reaper/...`). Lives in core rather
|
|
8
|
+
* than the msb provisioner because the ledger needs it even in a
|
|
9
|
+
* docker-only process, which never touches `backend-msb` at all.
|
|
10
|
+
*
|
|
11
|
+
* `%LOCALAPPDATA%` is the Windows-idiomatic location for a machine-local,
|
|
12
|
+
* non-roaming native toolchain cache (as opposed to `%USERPROFILE%`, which a
|
|
13
|
+
* roaming-profile setup can sync, or a Unix-style dotfile under the home
|
|
14
|
+
* dir). Falls back to `%USERPROFILE%\AppData\Local` if the env var is unset,
|
|
15
|
+
* matching what `os.homedir()` resolves to on a normal Windows install when
|
|
16
|
+
* `LOCALAPPDATA` isn't populated (rare, but seen on some minimal/CI images).
|
|
17
|
+
*/
|
|
18
|
+
export function cacheDir() {
|
|
19
|
+
const override = process.env["RIGHTSIZE_CACHE_DIR"];
|
|
20
|
+
if (override !== undefined) {
|
|
21
|
+
return override;
|
|
22
|
+
}
|
|
23
|
+
if (process.platform === "win32") {
|
|
24
|
+
const localAppData = process.env["LOCALAPPDATA"] ?? path.join(os.homedir(), "AppData", "Local");
|
|
25
|
+
return path.join(localAppData, "rightsize");
|
|
26
|
+
}
|
|
27
|
+
return path.join(os.homedir(), ".cache", "rightsize");
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=cache-dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-dir.js","sourceRoot":"","sources":["../../src/core/cache-dir.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ;IACtB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/core/cleanup.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Best-effort exit-path cleanup — the JVM-shutdown-hook / Rust-cleanup-
|
|
3
3
|
* thread analog for a process that dies (or is asked to die) before its
|
|
4
|
-
* `await using` scopes unwind normally.
|
|
4
|
+
* `await using` scopes unwind normally. Doubles as the process-local
|
|
5
|
+
* registry of currently running containers the failure-diagnostics report
|
|
6
|
+
* (`diagnostics.ts`) reads from — one live-container registry, not two: a
|
|
7
|
+
* container is registered here the instant `GenericContainer.start()`
|
|
8
|
+
* confirms it booted, and deregistered the instant `stop()` tears it down,
|
|
9
|
+
* which is exactly the "currently running" window diagnostics needs too.
|
|
5
10
|
*
|
|
6
11
|
* Node's `process.on("exit", ...)` handler runs SYNCHRONOUSLY and cannot
|
|
7
12
|
* `await` — by the time it fires, the event loop is already being torn
|
|
@@ -19,11 +24,21 @@
|
|
|
19
24
|
* case, sweeping up `rz-<other-runid>-*` leftovers from a crashed prior
|
|
20
25
|
* run.
|
|
21
26
|
*/
|
|
27
|
+
import type { SandboxBackend, SandboxHandle } from "./backend.js";
|
|
22
28
|
export type SyncCleanup = () => void;
|
|
23
|
-
/** Registers a synchronous teardown for a live container, keyed by handle id. */
|
|
24
|
-
export declare function registerSyncCleanup(
|
|
25
|
-
/** Unregisters a container's teardown once it has been stopped/removed normally. */
|
|
29
|
+
/** Registers a synchronous teardown for a live container, keyed by handle id — and, by the same call, adds it to the live-container registry `liveContainers()` exposes. */
|
|
30
|
+
export declare function registerSyncCleanup(handle: SandboxHandle, backend: SandboxBackend, cleanupFn: SyncCleanup): void;
|
|
31
|
+
/** Unregisters a container's teardown once it has been stopped/removed normally — and removes it from the live-container registry. */
|
|
26
32
|
export declare function unregisterSyncCleanup(handleId: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* The process-local registry of currently running containers — every
|
|
35
|
+
* container `registerSyncCleanup` currently holds, in start order. This is
|
|
36
|
+
* `diagnostics.ts`'s data source; nothing else needs a second registry.
|
|
37
|
+
*/
|
|
38
|
+
export declare function liveContainers(): ReadonlyArray<{
|
|
39
|
+
readonly handle: SandboxHandle;
|
|
40
|
+
readonly backend: SandboxBackend;
|
|
41
|
+
}>;
|
|
27
42
|
/** Test seam: clears registered cleanups without running them. */
|
|
28
43
|
export declare function _resetForTests(): void;
|
|
29
44
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/core/cleanup.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/core/cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElE,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAqDrC,4KAA4K;AAC5K,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAGhH;AAED,sIAAsI;AACtI,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,aAAa,CAAC;IAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC,CAEpH;AAED,kEAAkE;AAClE,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
|
package/dist/core/cleanup.js
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Best-effort exit-path cleanup — the JVM-shutdown-hook / Rust-cleanup-
|
|
3
|
-
* thread analog for a process that dies (or is asked to die) before its
|
|
4
|
-
* `await using` scopes unwind normally.
|
|
5
|
-
*
|
|
6
|
-
* Node's `process.on("exit", ...)` handler runs SYNCHRONOUSLY and cannot
|
|
7
|
-
* `await` — by the time it fires, the event loop is already being torn
|
|
8
|
-
* down, so a backend's real async `stop()`/`remove()` cannot run there.
|
|
9
|
-
* Each backend therefore registers a synchronous, blocking teardown
|
|
10
|
-
* function per live container (`child_process.spawnSync` for msb, a
|
|
11
|
-
* blocking unix-socket DELETE for docker) instead of its normal async
|
|
12
|
-
* path. This module only owns the REGISTRY and the process hooks; it has
|
|
13
|
-
* no opinion on how any one backend tears a container down.
|
|
14
|
-
*
|
|
15
|
-
* This is a last-resort backstop, not the primary cleanup path — the
|
|
16
|
-
* primary path is `GenericContainer.stop()` / `[Symbol.asyncDispose]`.
|
|
17
|
-
* SIGKILL bypasses even this (no handler runs at all); the orphan reaper
|
|
18
|
-
* each backend runs at startup (`sweepOrphans`) is the backstop for that
|
|
19
|
-
* case, sweeping up `rz-<other-runid>-*` leftovers from a crashed prior
|
|
20
|
-
* run.
|
|
21
|
-
*/
|
|
22
1
|
const registered = new Map();
|
|
23
2
|
let hooksInstalled = false;
|
|
24
3
|
function runAll() {
|
|
25
|
-
for (const
|
|
4
|
+
for (const entry of registered.values()) {
|
|
26
5
|
try {
|
|
27
|
-
|
|
6
|
+
entry.cleanup();
|
|
28
7
|
}
|
|
29
8
|
catch {
|
|
30
9
|
// Best-effort: a failure to clean up one container must not block
|
|
@@ -60,15 +39,23 @@ function installHooksOnce() {
|
|
|
60
39
|
});
|
|
61
40
|
}
|
|
62
41
|
}
|
|
63
|
-
/** Registers a synchronous teardown for a live container, keyed by handle id. */
|
|
64
|
-
export function registerSyncCleanup(
|
|
42
|
+
/** Registers a synchronous teardown for a live container, keyed by handle id — and, by the same call, adds it to the live-container registry `liveContainers()` exposes. */
|
|
43
|
+
export function registerSyncCleanup(handle, backend, cleanupFn) {
|
|
65
44
|
installHooksOnce();
|
|
66
|
-
registered.set(
|
|
45
|
+
registered.set(handle.id, { handle, backend, cleanup: cleanupFn });
|
|
67
46
|
}
|
|
68
|
-
/** Unregisters a container's teardown once it has been stopped/removed normally. */
|
|
47
|
+
/** Unregisters a container's teardown once it has been stopped/removed normally — and removes it from the live-container registry. */
|
|
69
48
|
export function unregisterSyncCleanup(handleId) {
|
|
70
49
|
registered.delete(handleId);
|
|
71
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The process-local registry of currently running containers — every
|
|
53
|
+
* container `registerSyncCleanup` currently holds, in start order. This is
|
|
54
|
+
* `diagnostics.ts`'s data source; nothing else needs a second registry.
|
|
55
|
+
*/
|
|
56
|
+
export function liveContainers() {
|
|
57
|
+
return Array.from(registered.values(), ({ handle, backend }) => ({ handle, backend }));
|
|
58
|
+
}
|
|
72
59
|
/** Test seam: clears registered cleanups without running them. */
|
|
73
60
|
export function _resetForTests() {
|
|
74
61
|
registered.clear();
|
package/dist/core/cleanup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/core/cleanup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/core/cleanup.ts"],"names":[],"mappings":"AAoCA,MAAM,UAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;AAC1D,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B,SAAS,MAAM;IACb,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;QACxC,IAAI,CAAC;YACH,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;YAClE,gEAAgE;QAClE,CAAC;IACH,CAAC;IACD,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC;AAED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C;AACzF,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,cAAc;IAC5B,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,EAAE,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failure-diagnostics report: every container this process currently has
|
|
3
|
+
* running (`cleanup.ts`'s live-container registry — populated on a
|
|
4
|
+
* successful `start()`, cleared on `stop()`), in start order — its image,
|
|
5
|
+
* state, host, mapped ports, and a bounded tail of its logs. Identical
|
|
6
|
+
* FORMAT to the Kotlin and Rust implementations (contract-tested against a
|
|
7
|
+
* golden fixture). A failing `logs()` call degrades to a one-line
|
|
8
|
+
* `logs: unavailable (<reason>)` instead of throwing, so one broken
|
|
9
|
+
* container's log fetch never hides the rest of the report. Every
|
|
10
|
+
* container's `logs()` call runs concurrently.
|
|
11
|
+
*
|
|
12
|
+
* A `keepAlive` (reuse) container is never in this registry — see
|
|
13
|
+
* `cleanup.ts`'s `registerSyncCleanup` call site — so it never appears in
|
|
14
|
+
* this report; it isn't torn down by this process anyway.
|
|
15
|
+
*/
|
|
16
|
+
export declare function diagnostics(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* The shape of a test framework's own failure-registration function —
|
|
19
|
+
* matches vitest's `onTestFailed` closely enough that passing the real
|
|
20
|
+
* thing typechecks (a callback accepting fewer parameters than the
|
|
21
|
+
* framework's own handler type is always assignable to it). No dependency
|
|
22
|
+
* on any particular test framework.
|
|
23
|
+
*/
|
|
24
|
+
export type FailureHook = (callback: () => void | Promise<void>) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Framework-neutral wiring for "print the full diagnostics report, once, to
|
|
27
|
+
* stderr, when a test fails." Pass a test framework's own failure-
|
|
28
|
+
* registration function — e.g. vitest's `onTestFailed` — and this registers
|
|
29
|
+
* a callback with it that runs `diagnostics()` and writes the result. See
|
|
30
|
+
* the [diagnostics guide](/guide/diagnostics) for the vitest wiring example.
|
|
31
|
+
*/
|
|
32
|
+
export declare function registerDiagnostics(onTestFailed: FailureHook, write?: (text: string) => void): void;
|
|
33
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/core/diagnostics.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAOnD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,WAAW,EACzB,KAAK,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAExB,GACA,IAAI,CAEN"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { liveContainers } from "./cleanup.js";
|
|
2
|
+
/** Bounded log tail: matches the cross-language contract (Kotlin/Rust `diagnostics` report the same tail length). */
|
|
3
|
+
const LOG_TAIL_LINES = 50;
|
|
4
|
+
function formatPorts(spec) {
|
|
5
|
+
if (spec.ports.length === 0) {
|
|
6
|
+
return "(none)";
|
|
7
|
+
}
|
|
8
|
+
return spec.ports.map((p) => `${p.guestPort}->${p.hostPort}`).join(", ");
|
|
9
|
+
}
|
|
10
|
+
/** The last `n` lines of `raw`, dropping one trailing empty element from a final newline (never a real blank log line otherwise). */
|
|
11
|
+
function tailLines(raw, n) {
|
|
12
|
+
const lines = raw.split("\n");
|
|
13
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
14
|
+
lines.pop();
|
|
15
|
+
}
|
|
16
|
+
return lines.slice(-n);
|
|
17
|
+
}
|
|
18
|
+
function reasonOf(err) {
|
|
19
|
+
return err instanceof Error ? err.message : String(err);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Every entry in the live-container registry is, by construction, currently
|
|
23
|
+
* running (see `cleanup.ts`'s doc) — `state:` is therefore always
|
|
24
|
+
* `running`, never queried from the backend. `host` is always `127.0.0.1`
|
|
25
|
+
* per `GenericContainer.host`'s own invariant.
|
|
26
|
+
*/
|
|
27
|
+
async function renderContainer(handle, backend) {
|
|
28
|
+
const lines = [`-- ${handle.spec.name} (${handle.spec.image}) --`, `state: running host: 127.0.0.1 ports: ${formatPorts(handle.spec)}`];
|
|
29
|
+
try {
|
|
30
|
+
const raw = await backend.logs(handle);
|
|
31
|
+
lines.push(`last ${LOG_TAIL_LINES} log lines:`);
|
|
32
|
+
for (const line of tailLines(raw, LOG_TAIL_LINES)) {
|
|
33
|
+
lines.push(` ${line}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
lines.push(`logs: unavailable (${reasonOf(err)})`);
|
|
38
|
+
}
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The failure-diagnostics report: every container this process currently has
|
|
43
|
+
* running (`cleanup.ts`'s live-container registry — populated on a
|
|
44
|
+
* successful `start()`, cleared on `stop()`), in start order — its image,
|
|
45
|
+
* state, host, mapped ports, and a bounded tail of its logs. Identical
|
|
46
|
+
* FORMAT to the Kotlin and Rust implementations (contract-tested against a
|
|
47
|
+
* golden fixture). A failing `logs()` call degrades to a one-line
|
|
48
|
+
* `logs: unavailable (<reason>)` instead of throwing, so one broken
|
|
49
|
+
* container's log fetch never hides the rest of the report. Every
|
|
50
|
+
* container's `logs()` call runs concurrently.
|
|
51
|
+
*
|
|
52
|
+
* A `keepAlive` (reuse) container is never in this registry — see
|
|
53
|
+
* `cleanup.ts`'s `registerSyncCleanup` call site — so it never appears in
|
|
54
|
+
* this report; it isn't torn down by this process anyway.
|
|
55
|
+
*/
|
|
56
|
+
export async function diagnostics() {
|
|
57
|
+
const entries = liveContainers();
|
|
58
|
+
if (entries.length === 0) {
|
|
59
|
+
return "== rightsize diagnostics: no running containers ==";
|
|
60
|
+
}
|
|
61
|
+
const blocks = await Promise.all(entries.map(({ handle, backend }) => renderContainer(handle, backend)));
|
|
62
|
+
return `== rightsize diagnostics: ${entries.length} running container(s) ==\n${blocks.join("\n")}`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Framework-neutral wiring for "print the full diagnostics report, once, to
|
|
66
|
+
* stderr, when a test fails." Pass a test framework's own failure-
|
|
67
|
+
* registration function — e.g. vitest's `onTestFailed` — and this registers
|
|
68
|
+
* a callback with it that runs `diagnostics()` and writes the result. See
|
|
69
|
+
* the [diagnostics guide](/guide/diagnostics) for the vitest wiring example.
|
|
70
|
+
*/
|
|
71
|
+
export function registerDiagnostics(onTestFailed, write = (text) => {
|
|
72
|
+
process.stderr.write(text);
|
|
73
|
+
}) {
|
|
74
|
+
onTestFailed(() => diagnostics().then((text) => write(`${text}\n`)));
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/core/diagnostics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,qHAAqH;AACrH,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,SAAS,WAAW,CAAC,IAA2B;IAC9C,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,qIAAqI;AACrI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C;AAC1B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,oDAAoD,CAAC;IAC9D,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACzG,OAAO,6BAA6B,OAAO,CAAC,MAAM,6BAA6B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AACrG,CAAC;AAWD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAyB,EACzB,QAAgC,CAAC,IAAY,EAAE,EAAE;IAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;IAED,YAAY,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -48,4 +48,45 @@ export declare class BackendError extends Error {
|
|
|
48
48
|
export declare class ProvisionError extends Error {
|
|
49
49
|
constructor(message: string);
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Thrown at `start()` when a container is both marked `withReuse()` and
|
|
53
|
+
* joined to a `Network` via `withNetwork()` — reuse's identity hash covers
|
|
54
|
+
* only the container's own spec, never cross-container network topology, so
|
|
55
|
+
* an adopted sandbox from an earlier process could never be correctly
|
|
56
|
+
* re-linked to today's siblings. Thrown only once reuse is actually double
|
|
57
|
+
* opt-in active (API marker AND `RIGHTSIZE_REUSE`); an API-marked-but-env-
|
|
58
|
+
* disabled container never reaches this check; the whole start() attempt is
|
|
59
|
+
* still aborted before any port allocation, ledger tracking, or backend call.
|
|
60
|
+
*/
|
|
61
|
+
export declare class ReuseWithNetworkError extends Error {
|
|
62
|
+
constructor();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Thrown at `start()` when a container is marked `withRequireIsolation()`
|
|
66
|
+
* but the active backend's `capabilities.hardwareIsolated` is `false` — the
|
|
67
|
+
* docker fallback shares the host kernel and cannot provide the
|
|
68
|
+
* hardware-virtualized isolation the caller demanded. Thrown before any
|
|
69
|
+
* create/network work: no sandbox is created.
|
|
70
|
+
*/
|
|
71
|
+
export declare class IsolationRequiredError extends Error {
|
|
72
|
+
/** The active backend's name (e.g. `"docker"`). */
|
|
73
|
+
readonly backend: string;
|
|
74
|
+
constructor(
|
|
75
|
+
/** The active backend's name (e.g. `"docker"`). */
|
|
76
|
+
backend: string);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Thrown by `checkpoint()` when the active backend's
|
|
80
|
+
* `capabilities.checkpoint` is `false` — microsandbox has no upstream
|
|
81
|
+
* microVM snapshot support today. Thrown before any backend call: the
|
|
82
|
+
* generic layer gates on the capability itself rather than letting the
|
|
83
|
+
* backend's own `commitToImage` reject.
|
|
84
|
+
*/
|
|
85
|
+
export declare class CheckpointUnsupportedError extends Error {
|
|
86
|
+
/** The active backend's name (e.g. `"microsandbox"`). */
|
|
87
|
+
readonly backend: string;
|
|
88
|
+
constructor(
|
|
89
|
+
/** The active backend's name (e.g. `"microsandbox"`). */
|
|
90
|
+
backend: string);
|
|
91
|
+
}
|
|
51
92
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAEh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AC5F,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;gBAFxB,OAAO,EAAE,MAAM;IACf,4FAA4F;IACnF,KAAK,CAAC,EAAE,OAAO,YAAA;CAK3B;AAED,gFAAgF;AAChF,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED,8EAA8E;AAC9E,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,kIAAkI;AAClI,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;GASG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;;CAS/C;AAED;;;;;;GAMG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAE7C,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM;;IADxB,mDAAmD;IAC1C,OAAO,EAAE,MAAM;CAS3B;AAED;;;;;;GAMG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM;;IADxB,yDAAyD;IAChD,OAAO,EAAE,MAAM;CAS3B"}
|
package/dist/core/errors.js
CHANGED
|
@@ -63,4 +63,60 @@ export class ProvisionError extends Error {
|
|
|
63
63
|
this.name = "ProvisionError";
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Thrown at `start()` when a container is both marked `withReuse()` and
|
|
68
|
+
* joined to a `Network` via `withNetwork()` — reuse's identity hash covers
|
|
69
|
+
* only the container's own spec, never cross-container network topology, so
|
|
70
|
+
* an adopted sandbox from an earlier process could never be correctly
|
|
71
|
+
* re-linked to today's siblings. Thrown only once reuse is actually double
|
|
72
|
+
* opt-in active (API marker AND `RIGHTSIZE_REUSE`); an API-marked-but-env-
|
|
73
|
+
* disabled container never reaches this check; the whole start() attempt is
|
|
74
|
+
* still aborted before any port allocation, ledger tracking, or backend call.
|
|
75
|
+
*/
|
|
76
|
+
export class ReuseWithNetworkError extends Error {
|
|
77
|
+
constructor() {
|
|
78
|
+
super("withReuse() cannot be combined with withNetwork() — reuse's identity hash does not cover network " +
|
|
79
|
+
"topology, so an adopted sandbox could not be correctly re-linked to today's siblings. Drop either " +
|
|
80
|
+
"withReuse() or withNetwork() on this container.");
|
|
81
|
+
this.name = "ReuseWithNetworkError";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Thrown at `start()` when a container is marked `withRequireIsolation()`
|
|
86
|
+
* but the active backend's `capabilities.hardwareIsolated` is `false` — the
|
|
87
|
+
* docker fallback shares the host kernel and cannot provide the
|
|
88
|
+
* hardware-virtualized isolation the caller demanded. Thrown before any
|
|
89
|
+
* create/network work: no sandbox is created.
|
|
90
|
+
*/
|
|
91
|
+
export class IsolationRequiredError extends Error {
|
|
92
|
+
backend;
|
|
93
|
+
constructor(
|
|
94
|
+
/** The active backend's name (e.g. `"docker"`). */
|
|
95
|
+
backend) {
|
|
96
|
+
super(`withRequireIsolation() demands hardware-virtualized isolation, but the active backend ('${backend}') ` +
|
|
97
|
+
"does not provide it — set RIGHTSIZE_BACKEND=microsandbox to use the microsandbox backend, or drop " +
|
|
98
|
+
"withRequireIsolation() to accept the docker fallback's shared-kernel isolation.");
|
|
99
|
+
this.backend = backend;
|
|
100
|
+
this.name = "IsolationRequiredError";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Thrown by `checkpoint()` when the active backend's
|
|
105
|
+
* `capabilities.checkpoint` is `false` — microsandbox has no upstream
|
|
106
|
+
* microVM snapshot support today. Thrown before any backend call: the
|
|
107
|
+
* generic layer gates on the capability itself rather than letting the
|
|
108
|
+
* backend's own `commitToImage` reject.
|
|
109
|
+
*/
|
|
110
|
+
export class CheckpointUnsupportedError extends Error {
|
|
111
|
+
backend;
|
|
112
|
+
constructor(
|
|
113
|
+
/** The active backend's name (e.g. `"microsandbox"`). */
|
|
114
|
+
backend) {
|
|
115
|
+
super(`checkpoint() is not supported by the '${backend}' backend — checkpoint/restore is implemented via image ` +
|
|
116
|
+
"commit on the docker backend today; native microVM memory snapshots for microsandbox are on the " +
|
|
117
|
+
"roadmap. Set RIGHTSIZE_BACKEND=docker to use checkpoint/restore.");
|
|
118
|
+
this.backend = backend;
|
|
119
|
+
this.name = "CheckpointUnsupportedError";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
66
122
|
//# sourceMappingURL=errors.js.map
|
package/dist/core/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAGvC;IAEA;IAEA;IANX;IACE,uDAAuD;IAC9C,OAAe;IACxB,yDAAyD;IAChD,OAAe;IACxB,qFAAqF;IAC5E,MAAe;QAExB,KAAK,CAAC,YAAY,OAAO,8BAA8B,OAAO,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QANjG,YAAO,GAAP,OAAO,CAAQ;QAEf,YAAO,GAAP,OAAO,CAAQ;QAEf,WAAM,GAAN,MAAM,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAInC;IAHX,YACE,OAAe;IACf,4FAA4F;IACnF,KAAe;QAExB,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAFnD,UAAK,GAAL,KAAK,CAAU;QAGxB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,OAAO,oBA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O,CAAQ;QAOxB,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -2,7 +2,7 @@ import { Network } from "./network.js";
|
|
|
2
2
|
import type { NetworkMember } from "./network.js";
|
|
3
3
|
import type { WaitStrategy } from "./wait.js";
|
|
4
4
|
import type { SandboxBackend, FollowHandle } from "./backend.js";
|
|
5
|
-
import type { ContainerSpec, ExecResult } from "./model.js";
|
|
5
|
+
import type { ContainerSpec, ExecResult, Checkpoint } from "./model.js";
|
|
6
6
|
import type { MountableFile } from "./mountable-file.js";
|
|
7
7
|
/**
|
|
8
8
|
* The builder, launcher, and lifecycle guard for a single container — the
|
|
@@ -33,6 +33,8 @@ export declare class GenericContainer implements AsyncDisposable, NetworkMember
|
|
|
33
33
|
private waitStrategy;
|
|
34
34
|
private memoryLimitMb;
|
|
35
35
|
private backendOverride;
|
|
36
|
+
private reuseRequested;
|
|
37
|
+
private requireIsolationRequested;
|
|
36
38
|
private handle;
|
|
37
39
|
private backend;
|
|
38
40
|
private mappedPorts;
|
|
@@ -41,6 +43,19 @@ export declare class GenericContainer implements AsyncDisposable, NetworkMember
|
|
|
41
43
|
constructor(image: string);
|
|
42
44
|
/** Convenience: `new GenericContainer(image).start()`. */
|
|
43
45
|
static start(image: string): Promise<GenericContainer>;
|
|
46
|
+
/**
|
|
47
|
+
* Builds a normal, ephemeral `GenericContainer` from a `Checkpoint`
|
|
48
|
+
* (`checkpoint()`'s return value): image is `cp.imageRef`, and
|
|
49
|
+
* env/command/exposed ports/memory limit default to `cp.spec` — chain
|
|
50
|
+
* further builder calls (a different `waitingFor`, `withBackend`, …)
|
|
51
|
+
* before `start()`, the same as any other container. Never carries over
|
|
52
|
+
* `cp.spec`'s network/aliases/mounts — the committed image already has
|
|
53
|
+
* the filesystem baked in, and (as with `withReuse()`'s own network
|
|
54
|
+
* restriction) network topology is never part of what a checkpoint
|
|
55
|
+
* captures. Once started, a restored container is ordinary in every
|
|
56
|
+
* respect: fresh host ports, normal reaping-ledger tracking, normal stop.
|
|
57
|
+
*/
|
|
58
|
+
static fromCheckpoint(cp: Checkpoint): GenericContainer;
|
|
44
59
|
/** Sets an environment variable visible to the workload. Last-write-wins if called again with the same key; insertion order is otherwise preserved. */
|
|
45
60
|
withEnv(key: string, value: string): this;
|
|
46
61
|
/** Publishes these guest ports to pre-allocated host ports (see `FreePorts`); read back with `getMappedPort`. */
|
|
@@ -59,6 +74,26 @@ export declare class GenericContainer implements AsyncDisposable, NetworkMember
|
|
|
59
74
|
withMemoryLimit(megabytes: number): this;
|
|
60
75
|
/** Test/advanced seam: pin the backend instead of resolving `Backends.active()`. */
|
|
61
76
|
withBackend(backend: SandboxBackend): this;
|
|
77
|
+
/**
|
|
78
|
+
* Marks this container for reuse: survive process exit and be ADOPTED —
|
|
79
|
+
* not re-created — by the next equivalent container's `start()`, in this
|
|
80
|
+
* process or a later one. Double opt-in: this API marker alone does
|
|
81
|
+
* nothing unless `RIGHTSIZE_REUSE` is also `"true"` or `"1"` at `start()`
|
|
82
|
+
* time. Marked-but-not-enabled starts as an ordinary ephemeral container
|
|
83
|
+
* (Testcontainers semantics), with a one-time stderr note. See the
|
|
84
|
+
* [reuse guide](/guide/reuse) for identity rules, the network
|
|
85
|
+
* restriction, and manual cleanup.
|
|
86
|
+
*/
|
|
87
|
+
withReuse(): this;
|
|
88
|
+
/**
|
|
89
|
+
* Demands hardware-virtualized isolation: `start()` throws
|
|
90
|
+
* `IsolationRequiredError` before any create/network work if the active
|
|
91
|
+
* backend's `capabilities.hardwareIsolated` is `false` (the docker
|
|
92
|
+
* fallback, which shares the host kernel), instead of silently degrading.
|
|
93
|
+
* Use for tests that run untrusted code. See the
|
|
94
|
+
* [isolation guide](/guide/isolation).
|
|
95
|
+
*/
|
|
96
|
+
withRequireIsolation(): this;
|
|
62
97
|
/** Module hook: override to adjust the spec once mapped host ports are known (e.g. advertised listeners). */
|
|
63
98
|
protected customizeSpec(spec: ContainerSpec, _mapped: (guest: number) => number): ContainerSpec;
|
|
64
99
|
/** Module hook: runs after the container is ready (e.g. `rs.initiate` for a Mongo replica set). */
|
|
@@ -84,6 +119,10 @@ export declare class GenericContainer implements AsyncDisposable, NetworkMember
|
|
|
84
119
|
protected currentBackend(): SandboxBackend;
|
|
85
120
|
private resolveBackend;
|
|
86
121
|
private buildSpec;
|
|
122
|
+
/** The reuse-active counterpart of `buildSpec`: always `keepAlive: true`, named `rz-reuse-<hash12>` rather than the run-scoped `rz-<runId>-<seq>`, and never joined to a `Network` (rejected earlier in `start()`). */
|
|
123
|
+
private buildReuseSpec;
|
|
124
|
+
/** This container's reuse identity hash — the reuse-relevant subset of its builder state, hashed per `reuseHash`'s canonical form. Reads every `withCopyFileToContainer` source file's CURRENT content, so a mutated source file between two `start()` calls changes identity. */
|
|
125
|
+
private computeReuseHash;
|
|
87
126
|
private allocatePorts;
|
|
88
127
|
private releasePorts;
|
|
89
128
|
/**
|
|
@@ -101,6 +140,59 @@ export declare class GenericContainer implements AsyncDisposable, NetworkMember
|
|
|
101
140
|
* allocate-then-bind race to an unrelated process.
|
|
102
141
|
*/
|
|
103
142
|
start(): Promise<this>;
|
|
143
|
+
/**
|
|
144
|
+
* The reuse-active start path — an entirely separate flow from the
|
|
145
|
+
* ephemeral one above, never joining `MAX_START_ATTEMPTS`'s port-conflict
|
|
146
|
+
* retry loop, the ledger, or the sync-cleanup registry (all deliberate:
|
|
147
|
+
* see `withReuse()`'s own doc and the reaping addendum). Computes this
|
|
148
|
+
* container's identity hash, then adopts an existing sandbox or creates a
|
|
149
|
+
* fresh one under the deterministic `rz-reuse-<hash12>` name.
|
|
150
|
+
*/
|
|
151
|
+
private startReuse;
|
|
152
|
+
/**
|
|
153
|
+
* Reads the registry once and either adopts (registry hit, running,
|
|
154
|
+
* wait ok) or falls through to a fresh create — see the reuse spec's own
|
|
155
|
+
* "Start flow when reuse is active" for the full state table this
|
|
156
|
+
* implements. `isRetry` caps the name-collision recursion at one retry
|
|
157
|
+
* (`adoptOrCreate` re-enters itself exactly once, from the create/start
|
|
158
|
+
* failure branch below): "another process won the race" is expected to
|
|
159
|
+
* resolve within one retry (by then its own registry write has very
|
|
160
|
+
* likely landed); anything still colliding after that is a genuine
|
|
161
|
+
* failure, not a race, and propagates.
|
|
162
|
+
*/
|
|
163
|
+
private adoptOrCreate;
|
|
164
|
+
/**
|
|
165
|
+
* Registry hit → verify: confirm the name is actually running (backend
|
|
166
|
+
* query, never trusted from the file alone), then re-run this
|
|
167
|
+
* container's OWN wait strategy against the recorded ports — a running
|
|
168
|
+
* sandbox that never became ready for THIS workload is exactly as
|
|
169
|
+
* unadoptable as one that isn't running at all. `undefined` means adopt
|
|
170
|
+
* failed for any reason (not running, or the wait failed); the caller's
|
|
171
|
+
* best-effort cleanup already ran by the time this returns.
|
|
172
|
+
*/
|
|
173
|
+
private tryAdopt;
|
|
174
|
+
/** Best-effort: remove whatever's running under `name` (by name — this call never held a handle for it) and delete the registry file. Never throws. */
|
|
175
|
+
private cleanupStaleReuse;
|
|
176
|
+
/**
|
|
177
|
+
* The crash-mid-boot-orphan guard for the "no registry entry at all"
|
|
178
|
+
* fresh-create path: confirms with the backend whether `name` is actually
|
|
179
|
+
* running BEFORE this container's own create() attempt, and only then
|
|
180
|
+
* best-effort-removes it — never a blind `removeByName` the way
|
|
181
|
+
* `cleanupStaleReuse` above does for the corrupt/failed-verification
|
|
182
|
+
* cases, where a registry entry (however stale) already proved something
|
|
183
|
+
* about this identity once existed. Here nothing has ever proved that, so
|
|
184
|
+
* the common empty-cache case (nothing running) pays no removal call at
|
|
185
|
+
* all, and a concurrent creator that's already past ITS OWN create()-and-
|
|
186
|
+
* register cycle by the time this runs is instead caught by the
|
|
187
|
+
* name-collision-retry-into-adopt path below (a registry entry appearing
|
|
188
|
+
* for it means that process won the race — adopt, don't remove). The spec
|
|
189
|
+
* handed to `findRunning` here is a throwaway: any exposed ports serve
|
|
190
|
+
* only to satisfy `ContainerSpec`'s shape, since every backend's
|
|
191
|
+
* `findRunning` matches on `spec.name` alone.
|
|
192
|
+
*/
|
|
193
|
+
private removeOrphanedRunningReuse;
|
|
194
|
+
/** The `WaitTarget` for a specific (backend, handle, ports) triple, independent of this instance's own `this.handle`/`this.backend`/`this.mappedPorts` — needed because reuse's adopt-verification wait runs BEFORE those fields are ever assigned. */
|
|
195
|
+
private waitTargetFor;
|
|
104
196
|
/**
|
|
105
197
|
* Stops and removes the backend-native resource, releases its host ports,
|
|
106
198
|
* and clears the port map. Idempotent — stopping a container that never
|
|
@@ -129,6 +221,20 @@ export declare class GenericContainer implements AsyncDisposable, NetworkMember
|
|
|
129
221
|
/** Alias for `getMappedPort`, satisfying the `NetworkMember`/`WaitTarget` shape (which name this method `mappedPort`). */
|
|
130
222
|
mappedPort(guestPort: number): number;
|
|
131
223
|
private requireHandle;
|
|
224
|
+
/**
|
|
225
|
+
* Commits this running container's filesystem to a new image and returns
|
|
226
|
+
* a `Checkpoint` — a FILESYSTEM capture, not a memory snapshot:
|
|
227
|
+
* `fromCheckpoint()` boots a fresh container from the committed image
|
|
228
|
+
* with processes restarting from scratch, not resuming. Requires the
|
|
229
|
+
* active backend's `capabilities.checkpoint` (docker: `true`, via image
|
|
230
|
+
* commit; microsandbox: `false`, no upstream microVM snapshot support
|
|
231
|
+
* yet) — checked BEFORE any backend call, so an unsupported backend never
|
|
232
|
+
* attempts one. Throws a state error (same shape as `exec`/`logs`) if
|
|
233
|
+
* this container isn't currently running. Checkpoint images are never
|
|
234
|
+
* auto-reaped (they're images, not containers) — see the checkpoints
|
|
235
|
+
* guide for the manual cleanup one-liner.
|
|
236
|
+
*/
|
|
237
|
+
checkpoint(): Promise<Checkpoint>;
|
|
132
238
|
/** Runs a one-shot command inside the running container and waits for it to exit. Throws if the container is not running. */
|
|
133
239
|
exec(...cmd: string[]): Promise<ExecResult>;
|
|
134
240
|
/** Fetches the workload's logs so far (a bounded tail), as a single string. Throws if the container is not running. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic-container.d.ts","sourceRoot":"","sources":["../../src/core/generic-container.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generic-container.d.ts","sourceRoot":"","sources":["../../src/core/generic-container.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,WAAW,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAiB,YAAY,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAa,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAiEzD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,YAAW,eAAe,EAAE,aAAa;IACrE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,YAAY,CAAyC;IAC7D,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,yBAAyB,CAAS;IAE1C,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,OAAO,CAAS;IAExB,0FAA0F;gBAC9E,KAAK,EAAE,MAAM;IAIzB,0DAA0D;WAC7C,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,C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