@specific.dev/spectest 0.71.0 → 0.72.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.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The image cache as the guest sees it (`CONTAINER_STORE.md`).
3
+ *
4
+ * The control plane writes one manifest per VM at start naming the two
5
+ * cache disks it attached: the **root** (containerd's own root,
6
+ * read-write, this VM's clone) and the **layers** disk (read-only, one
7
+ * EROFS file per layer, shared by every VM of a generation). Both paths
8
+ * are fixed by the control plane; the manifest is how a harness learns
9
+ * whether this VM carries a cache at all (the fake backend does not,
10
+ * and neither does a server older than the cache).
11
+ *
12
+ * Read synchronously as well as asynchronously: a component's service
13
+ * definition is built inside `defineEnvironment`, which is synchronous,
14
+ * and `k3s()` decides its mounts there.
15
+ */
16
+
17
+ import { existsSync, readFileSync } from "node:fs";
18
+
19
+ /** Written by `env.rs` before the harness starts. */
20
+ export const IMAGE_CACHE_MANIFEST = "/run/spectest-image-cache.json";
21
+
22
+ /** Where the cache's paths are, when this VM carries one. */
23
+ export interface ImageCachePaths {
24
+ /** containerd's root: read-write, this VM's own clone. */
25
+ root: string;
26
+ /** The layers disk: read-only, shared by every VM of a generation. */
27
+ layers: string;
28
+ }
29
+
30
+ /**
31
+ * Directory under the root disk holding a nested runtime's containerd
32
+ * root, one per service: `<root>/spectest-nested/<service>`. The merge
33
+ * (`image_cache/merge.rs::NESTED_DIR`) reads every store it finds there
34
+ * exactly as it reads the disk's own.
35
+ */
36
+ export const NESTED_STORES_DIR = "spectest-nested";
37
+
38
+ /** The guest's static `mkfs.erofs`, which a nested runtime's EROFS
39
+ * differ needs and no runtime image ships. */
40
+ export const MKFS_EROFS_PATH = "/usr/local/bin/mkfs.erofs";
41
+
42
+ /** The guest's adopt helper (`base.rs::STORE_ADOPT_SH`), POSIX sh so a
43
+ * nested runtime's busybox can run the same file. */
44
+ export const STORE_ADOPT_PATH = "/usr/local/bin/spectest-store-adopt";
45
+
46
+ function parse(raw: string): ImageCachePaths | null {
47
+ const parsed = JSON.parse(raw) as { disks?: { role?: string; path?: string }[] };
48
+ const root = (parsed.disks ?? []).find((d) => d.role === "root" && d.path)?.path;
49
+ const layers = (parsed.disks ?? []).find((d) => d.role === "layers" && d.path)?.path;
50
+ return root && layers ? { root, layers } : null;
51
+ }
52
+
53
+ /** The cache's paths, or `null` when this VM carries none.
54
+ * `SPECTEST_IMAGE_CACHE_MANIFEST` points a test at another file. */
55
+ export function imageCachePathsSync(
56
+ manifest: string = process.env.SPECTEST_IMAGE_CACHE_MANIFEST || IMAGE_CACHE_MANIFEST,
57
+ ): ImageCachePaths | null {
58
+ try {
59
+ if (!existsSync(manifest)) return null;
60
+ return parse(readFileSync(manifest, "utf8"));
61
+ } catch {
62
+ return null;
63
+ }
64
+ }
65
+
66
+ /** The host directory a nested runtime keeps its containerd root in. */
67
+ export function nestedStoreDir(paths: ImageCachePaths, service: string): string {
68
+ return `${paths.root}/${NESTED_STORES_DIR}/${service}`;
69
+ }
70
+
71
+ /**
72
+ * Is a volume's host path on a cache disk? Such a directory is a cache
73
+ * the lineage keeps — like the container store one level up — and the
74
+ * delta-restore teardown must not wipe it.
75
+ */
76
+ export function isOnImageCache(hostPath: string, paths: ImageCachePaths | null): boolean {
77
+ if (!paths) return false;
78
+ return hostPath === paths.root || hostPath.startsWith(`${paths.root}/`) || hostPath === paths.layers || hostPath.startsWith(`${paths.layers}/`);
79
+ }
@@ -63,8 +63,9 @@ export function sanitizeSegment(p: string): string {
63
63
  * `files` does: a component cannot know the map key the user will give it,
64
64
  * and an **absolute** source gets no automatic per-service directory. A
65
65
  * component that needs one — a nested runtime keeping its store under
66
- * {@link NESTED_STORE_ROOT}, where two of them sharing one directory would
67
- * be two daemons on one metadata store — writes the token into the path.
66
+ * the image cache's `spectest-nested/<service>` (`image-cache.ts::nestedStoreDir`),
67
+ * where two of them sharing one directory would be two daemons on one
68
+ * metadata store — writes the token into the path.
68
69
  *
69
70
  * `workspace` is a parameter rather than a module constant so the rule is
70
71
  * testable without touching the filesystem.