/** * Integration tests run against a real hypervisor. Mocking it is forbidden — a test that * fakes the system under integration asserts that the fake behaves as expected, which is * the shape of test this project exists to stop shipping (novox/hq ADR 0034). * * Consequence, accepted: these are slow, and they need a machine that can raise scenarios. * They skip rather than fail where it cannot, so that a machine without a hypervisor gets * an honest "not run" instead of a green suite that checked nothing. */ import { isReachable, pools, supportedDrivers } from "../../src/incus/client.ts"; import { destroy, list } from "../../src/lifecycle/operate.ts"; export interface Capability { usable: boolean; why: string; } /** Can this machine run scenarios at all? Checked once, reported honestly. */ export async function labIsUsable(): Promise { if (!(await isReachable())) { return { usable: false, why: "the incus daemon is not reachable as this user (try MESH_LAB_INCUS='sudo -n incus')", }; } const drivers = await supportedDrivers(); if (!drivers.some((d) => d === "btrfs" || d === "zfs")) { return { usable: false, why: "no copy-on-write driver — snapshots would be full copies" }; } if (!(await pools()).some((p) => p.driver === "btrfs" || p.driver === "zfs")) { return { usable: false, why: "no pool uses a copy-on-write driver" }; } return { usable: true, why: "" }; } /** Tear down anything a test left behind, whether it passed or not. */ export async function destroyAll(prefix: string): Promise { for (const instance of await list()) { if (instance.instanceId.startsWith(prefix)) { await destroy(instance.instanceId); } } }