rightsize 0.1.2 → 0.3.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.
Files changed (131) hide show
  1. package/README.md +36 -4
  2. package/dist/backend-docker/backend.d.ts +76 -1
  3. package/dist/backend-docker/backend.d.ts.map +1 -1
  4. package/dist/backend-docker/backend.js +156 -13
  5. package/dist/backend-docker/backend.js.map +1 -1
  6. package/dist/backend-docker/cli.d.ts +25 -0
  7. package/dist/backend-docker/cli.d.ts.map +1 -0
  8. package/dist/backend-docker/cli.js +64 -0
  9. package/dist/backend-docker/cli.js.map +1 -0
  10. package/dist/backend-docker/labels.d.ts +27 -5
  11. package/dist/backend-docker/labels.d.ts.map +1 -1
  12. package/dist/backend-docker/labels.js +33 -5
  13. package/dist/backend-docker/labels.js.map +1 -1
  14. package/dist/backend-msb/backend.d.ts +89 -6
  15. package/dist/backend-msb/backend.d.ts.map +1 -1
  16. package/dist/backend-msb/backend.js +179 -14
  17. package/dist/backend-msb/backend.js.map +1 -1
  18. package/dist/backend-msb/commands.d.ts +10 -0
  19. package/dist/backend-msb/commands.d.ts.map +1 -1
  20. package/dist/backend-msb/commands.js +29 -1
  21. package/dist/backend-msb/commands.js.map +1 -1
  22. package/dist/backend-msb/provider.d.ts.map +1 -1
  23. package/dist/backend-msb/provider.js +7 -11
  24. package/dist/backend-msb/provider.js.map +1 -1
  25. package/dist/backend-msb/provisioner.d.ts.map +1 -1
  26. package/dist/backend-msb/provisioner.js +1 -20
  27. package/dist/backend-msb/provisioner.js.map +1 -1
  28. package/dist/backend-msb/snapshot-not-found.d.ts +25 -0
  29. package/dist/backend-msb/snapshot-not-found.d.ts.map +1 -0
  30. package/dist/backend-msb/snapshot-not-found.js +27 -0
  31. package/dist/backend-msb/snapshot-not-found.js.map +1 -0
  32. package/dist/core/backend.d.ts +124 -0
  33. package/dist/core/backend.d.ts.map +1 -1
  34. package/dist/core/backends.d.ts +16 -2
  35. package/dist/core/backends.d.ts.map +1 -1
  36. package/dist/core/backends.js +39 -5
  37. package/dist/core/backends.js.map +1 -1
  38. package/dist/core/cache-dir.d.ts +17 -0
  39. package/dist/core/cache-dir.d.ts.map +1 -0
  40. package/dist/core/cache-dir.js +29 -0
  41. package/dist/core/cache-dir.js.map +1 -0
  42. package/dist/core/checkpoint/api.d.ts +80 -0
  43. package/dist/core/checkpoint/api.d.ts.map +1 -0
  44. package/dist/core/checkpoint/api.js +138 -0
  45. package/dist/core/checkpoint/api.js.map +1 -0
  46. package/dist/core/checkpoint/name.d.ts +12 -0
  47. package/dist/core/checkpoint/name.d.ts.map +1 -0
  48. package/dist/core/checkpoint/name.js +17 -0
  49. package/dist/core/checkpoint/name.js.map +1 -0
  50. package/dist/core/checkpoint/ref.d.ts +12 -0
  51. package/dist/core/checkpoint/ref.d.ts.map +1 -0
  52. package/dist/core/checkpoint/ref.js +16 -0
  53. package/dist/core/checkpoint/ref.js.map +1 -0
  54. package/dist/core/checkpoint/registry.d.ts +107 -0
  55. package/dist/core/checkpoint/registry.d.ts.map +1 -0
  56. package/dist/core/checkpoint/registry.js +180 -0
  57. package/dist/core/checkpoint/registry.js.map +1 -0
  58. package/dist/core/cleanup.d.ts +19 -4
  59. package/dist/core/cleanup.d.ts.map +1 -1
  60. package/dist/core/cleanup.js +14 -27
  61. package/dist/core/cleanup.js.map +1 -1
  62. package/dist/core/diagnostics.d.ts +33 -0
  63. package/dist/core/diagnostics.d.ts.map +1 -0
  64. package/dist/core/diagnostics.js +76 -0
  65. package/dist/core/diagnostics.js.map +1 -0
  66. package/dist/core/errors.d.ts +97 -0
  67. package/dist/core/errors.d.ts.map +1 -1
  68. package/dist/core/errors.js +129 -0
  69. package/dist/core/errors.js.map +1 -1
  70. package/dist/core/generic-container.d.ts +176 -1
  71. package/dist/core/generic-container.d.ts.map +1 -1
  72. package/dist/core/generic-container.js +566 -3
  73. package/dist/core/generic-container.js.map +1 -1
  74. package/dist/core/model.d.ts +39 -0
  75. package/dist/core/model.d.ts.map +1 -1
  76. package/dist/core/network.d.ts.map +1 -1
  77. package/dist/core/network.js +2 -0
  78. package/dist/core/network.js.map +1 -1
  79. package/dist/core/reaper/env.d.ts +14 -0
  80. package/dist/core/reaper/env.d.ts.map +1 -0
  81. package/dist/core/reaper/env.js +22 -0
  82. package/dist/core/reaper/env.js.map +1 -0
  83. package/dist/core/reaper/init.d.ts +39 -0
  84. package/dist/core/reaper/init.d.ts.map +1 -0
  85. package/dist/core/reaper/init.js +140 -0
  86. package/dist/core/reaper/init.js.map +1 -0
  87. package/dist/core/reaper/ledger.d.ts +32 -0
  88. package/dist/core/reaper/ledger.d.ts.map +1 -0
  89. package/dist/core/reaper/ledger.js +160 -0
  90. package/dist/core/reaper/ledger.js.map +1 -0
  91. package/dist/core/reaper/process-liveness.d.ts +39 -0
  92. package/dist/core/reaper/process-liveness.d.ts.map +1 -0
  93. package/dist/core/reaper/process-liveness.js +117 -0
  94. package/dist/core/reaper/process-liveness.js.map +1 -0
  95. package/dist/core/reaper/run-record.d.ts +48 -0
  96. package/dist/core/reaper/run-record.d.ts.map +1 -0
  97. package/dist/core/reaper/run-record.js +58 -0
  98. package/dist/core/reaper/run-record.js.map +1 -0
  99. package/dist/core/reaper/sweep.d.ts +23 -0
  100. package/dist/core/reaper/sweep.d.ts.map +1 -0
  101. package/dist/core/reaper/sweep.js +76 -0
  102. package/dist/core/reaper/sweep.js.map +1 -0
  103. package/dist/core/reaper/watchdog.d.ts +100 -0
  104. package/dist/core/reaper/watchdog.d.ts.map +1 -0
  105. package/dist/core/reaper/watchdog.js +412 -0
  106. package/dist/core/reaper/watchdog.js.map +1 -0
  107. package/dist/core/reuse/env.d.ts +12 -0
  108. package/dist/core/reuse/env.d.ts.map +1 -0
  109. package/dist/core/reuse/env.js +15 -0
  110. package/dist/core/reuse/env.js.map +1 -0
  111. package/dist/core/reuse/hash.d.ts +34 -0
  112. package/dist/core/reuse/hash.d.ts.map +1 -0
  113. package/dist/core/reuse/hash.js +52 -0
  114. package/dist/core/reuse/hash.js.map +1 -0
  115. package/dist/core/reuse/registry.d.ts +50 -0
  116. package/dist/core/reuse/registry.d.ts.map +1 -0
  117. package/dist/core/reuse/registry.js +75 -0
  118. package/dist/core/reuse/registry.js.map +1 -0
  119. package/dist/index.d.ts +8 -4
  120. package/dist/index.d.ts.map +1 -1
  121. package/dist/index.js +5 -2
  122. package/dist/index.js.map +1 -1
  123. package/dist/modules/keycloak.js +1 -1
  124. package/dist/modules/mysql.d.ts.map +1 -1
  125. package/dist/modules/mysql.js +4 -3
  126. package/dist/modules/mysql.js.map +1 -1
  127. package/package.json +1 -1
  128. package/dist/backend-msb/reaper.d.ts +0 -10
  129. package/dist/backend-msb/reaper.d.ts.map +0 -1
  130. package/dist/backend-msb/reaper.js +0 -73
  131. package/dist/backend-msb/reaper.js.map +0 -1
@@ -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(handleId: string, cleanupFn: SyncCleanup): void;
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;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AA+CrC,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAGlF;AAED,oFAAoF;AACpF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED,kEAAkE;AAClE,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
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"}
@@ -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 cleanupFn of registered.values()) {
4
+ for (const entry of registered.values()) {
26
5
  try {
27
- cleanupFn();
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(handleId, cleanupFn) {
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(handleId, cleanupFn);
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();
@@ -1 +1 @@
1
- {"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/core/cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;AAClD,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B,SAAS,MAAM;IACb,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5C,IAAI,CAAC;YACH,SAAS,EAAE,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;YAClE,gEAAgE;QAClE,CAAC;IACH,CAAC;IACD,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC;AAED,SAAS,gBAAgB;IACvB,IAAI,cAAc,E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B;IACpD,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;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,SAAS,SAAS,CAAC,GAAW,EAAE,CAAS;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACvD,KAAK,CAAC,GAAG,EAAE,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,QAAQ,CAAC,GAAY;IAC5B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,eAAe,CAAC,MAAqB,EAAE,OA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,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"}
@@ -48,4 +48,101 @@ 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` — both real backends (docker, image
81
+ * commit; microsandbox, disk snapshot) support it today, so this only fires
82
+ * against a backend that genuinely lacks the capability (a test double).
83
+ * Thrown before any backend call: the generic layer gates on the capability
84
+ * itself rather than letting the backend's own `createCheckpoint` reject.
85
+ */
86
+ export declare class CheckpointUnsupportedError extends Error {
87
+ /** The active backend's name (e.g. `"microsandbox"`). */
88
+ readonly backend: string;
89
+ constructor(
90
+ /** The active backend's name (e.g. `"microsandbox"`). */
91
+ backend: string);
92
+ }
93
+ /**
94
+ * Thrown by `GenericContainer.fromCheckpoint(cp).start()` when the active
95
+ * backend's name doesn't match the backend that created `cp` — a checkpoint
96
+ * ref is only meaningful to the backend that minted it (a docker image tag
97
+ * means nothing to `msb`, and a msb snapshot name means nothing to docker).
98
+ * Thrown before any backend call.
99
+ */
100
+ export declare class CheckpointBackendMismatchError extends Error {
101
+ /** The backend that created the checkpoint. */
102
+ readonly createdOnBackend: string;
103
+ /** The backend `start()` actually resolved. */
104
+ readonly activeBackend: string;
105
+ constructor(
106
+ /** The backend that created the checkpoint. */
107
+ createdOnBackend: string,
108
+ /** The backend `start()` actually resolved. */
109
+ activeBackend: string);
110
+ }
111
+ /**
112
+ * Thrown at `start()` when a container built via `GenericContainer.fromCheckpoint()`
113
+ * is also marked `withReuse()` — reuse's identity hash never covers
114
+ * `checkpointRef`, so an adopted sandbox from an earlier process could never
115
+ * be verified against the checkpoint this container was meant to restore.
116
+ * Thrown only once reuse is actually double opt-in active, the same
117
+ * placement as `ReuseWithNetworkError`.
118
+ */
119
+ export declare class ReuseFromCheckpointError extends Error {
120
+ constructor();
121
+ }
122
+ /**
123
+ * Thrown by `copyFileToContainer`/`copyContentToContainer`/
124
+ * `copyFileFromContainer` when `containerPath` is not absolute — both
125
+ * backends require an absolute `NAME:/path` shape, so a relative path can
126
+ * never reach either CLI. Thrown before any backend call.
127
+ */
128
+ export declare class RelativeContainerPathError extends Error {
129
+ /** The rejected path, exactly as passed in. */
130
+ readonly containerPath: string;
131
+ constructor(
132
+ /** The rejected path, exactly as passed in. */
133
+ containerPath: string);
134
+ }
135
+ /**
136
+ * Thrown by `checkpoint(name)` when `name` doesn't match
137
+ * `^[a-z0-9][a-z0-9-]{0,40}$` — the same pattern pinned across every
138
+ * rightsize language implementation. Thrown before any backend or
139
+ * filesystem call, so a bad name never mints a ref or touches the registry.
140
+ */
141
+ export declare class InvalidCheckpointNameError extends Error {
142
+ /** The rejected name, exactly as passed in. */
143
+ readonly checkpointName: string;
144
+ constructor(
145
+ /** The rejected name, exactly as passed in. */
146
+ checkpointName: string);
147
+ }
51
148
  //# 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;IAEhD,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,qFAAqF;IACrF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;;IALxB,uDAAuD;IAC9C,OAAO,EAAE,MAAM;IACxB,yDAAyD;IAChD,OAAO,EAAE,MAAM;IACxB,qFAAqF;IAC5E,MAAM,CAAC,EAAE,MAAM,YAAA;CAK3B;AAED;;;;;;GAMG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAG5C,4FAA4F;IAC5F,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"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBA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ACjC,+CAA+C;IAC/C,QAAQ,CAAC,aAAa,EAAE,MAAM;;IAH9B,+CAA+C;IACtC,gBAAgB,EAAE,MAAM;IACjC,+CAA+C;IACtC,aAAa,EAAE,MAAM;CASjC;AAED;;;;;;;GAOG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;;CASlD;AAED;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,+CAA+C;IAC/C,QAAQ,CAAC,aAAa,EAAE,MAAM;;IAD9B,+CAA+C;IACtC,aAAa,EAAE,MAAM;CAKjC;AAED;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,+CAA+C;IAC/C,QAAQ,CAAC,cAAc,EAAE,MAAM;;IAD/B,+CAA+C;IACtC,cAAc,EAAE,MAAM;CASlC"}
@@ -63,4 +63,133 @@ 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` — both real backends (docker, image
106
+ * commit; microsandbox, disk snapshot) support it today, so this only fires
107
+ * against a backend that genuinely lacks the capability (a test double).
108
+ * Thrown before any backend call: the generic layer gates on the capability
109
+ * itself rather than letting the backend's own `createCheckpoint` reject.
110
+ */
111
+ export class CheckpointUnsupportedError extends Error {
112
+ backend;
113
+ constructor(
114
+ /** The active backend's name (e.g. `"microsandbox"`). */
115
+ backend) {
116
+ super(`checkpoint() is not supported by the '${backend}' backend — checkpointing needs a backend whose ` +
117
+ "capabilities.checkpoint is true.");
118
+ this.backend = backend;
119
+ this.name = "CheckpointUnsupportedError";
120
+ }
121
+ }
122
+ /**
123
+ * Thrown by `GenericContainer.fromCheckpoint(cp).start()` when the active
124
+ * backend's name doesn't match the backend that created `cp` — a checkpoint
125
+ * ref is only meaningful to the backend that minted it (a docker image tag
126
+ * means nothing to `msb`, and a msb snapshot name means nothing to docker).
127
+ * Thrown before any backend call.
128
+ */
129
+ export class CheckpointBackendMismatchError extends Error {
130
+ createdOnBackend;
131
+ activeBackend;
132
+ constructor(
133
+ /** The backend that created the checkpoint. */
134
+ createdOnBackend,
135
+ /** The backend `start()` actually resolved. */
136
+ activeBackend) {
137
+ super(`this checkpoint was created on the '${createdOnBackend}' backend but the active backend is ` +
138
+ `'${activeBackend}' — set RIGHTSIZE_BACKEND=${createdOnBackend} to restore it there, or create a fresh ` +
139
+ `checkpoint under the '${activeBackend}' backend instead.`);
140
+ this.createdOnBackend = createdOnBackend;
141
+ this.activeBackend = activeBackend;
142
+ this.name = "CheckpointBackendMismatchError";
143
+ }
144
+ }
145
+ /**
146
+ * Thrown at `start()` when a container built via `GenericContainer.fromCheckpoint()`
147
+ * is also marked `withReuse()` — reuse's identity hash never covers
148
+ * `checkpointRef`, so an adopted sandbox from an earlier process could never
149
+ * be verified against the checkpoint this container was meant to restore.
150
+ * Thrown only once reuse is actually double opt-in active, the same
151
+ * placement as `ReuseWithNetworkError`.
152
+ */
153
+ export class ReuseFromCheckpointError extends Error {
154
+ constructor() {
155
+ super("withReuse() cannot be combined with fromCheckpoint() — reuse's identity hash does not cover " +
156
+ "checkpointRef, so an adopted sandbox could never be verified against the checkpoint it was meant to " +
157
+ "restore. Drop either withReuse() or fromCheckpoint().");
158
+ this.name = "ReuseFromCheckpointError";
159
+ }
160
+ }
161
+ /**
162
+ * Thrown by `copyFileToContainer`/`copyContentToContainer`/
163
+ * `copyFileFromContainer` when `containerPath` is not absolute — both
164
+ * backends require an absolute `NAME:/path` shape, so a relative path can
165
+ * never reach either CLI. Thrown before any backend call.
166
+ */
167
+ export class RelativeContainerPathError extends Error {
168
+ containerPath;
169
+ constructor(
170
+ /** The rejected path, exactly as passed in. */
171
+ containerPath) {
172
+ super(`containerPath must be an absolute path (got '${containerPath}') — both backends require an absolute guest path.`);
173
+ this.containerPath = containerPath;
174
+ this.name = "RelativeContainerPathError";
175
+ }
176
+ }
177
+ /**
178
+ * Thrown by `checkpoint(name)` when `name` doesn't match
179
+ * `^[a-z0-9][a-z0-9-]{0,40}$` — the same pattern pinned across every
180
+ * rightsize language implementation. Thrown before any backend or
181
+ * filesystem call, so a bad name never mints a ref or touches the registry.
182
+ */
183
+ export class InvalidCheckpointNameError extends Error {
184
+ checkpointName;
185
+ constructor(
186
+ /** The rejected name, exactly as passed in. */
187
+ checkpointName) {
188
+ super(`checkpoint name '${checkpointName}' is invalid — a checkpoint name must match ^[a-z0-9][a-z0-9-]{0,40}$ ` +
189
+ "(start with a lowercase letter or digit, contain only lowercase letters, digits, and hyphens after " +
190
+ "that, and be at most 41 characters long).");
191
+ this.checkpointName = checkpointName;
192
+ this.name = "InvalidCheckpointNameError";
193
+ }
194
+ }
66
195
  //# sourceMappingURL=errors.js.map
@@ -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,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;I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