The tests set MESH_LAB_INCUS in their body, which runs after the client module has read it, so they asked the real incus: green where none is installed, red on the workstation that runs the lab.
45 lines
2.1 KiB
TypeScript
45 lines
2.1 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { instanceExists, taggedInstances, taggedNetworks, useIncusCommand } from "../src/incus/client.ts";
|
|
|
|
// `false` is a real program that exits non-zero and prints nothing — which is also the worst
|
|
// case, because an empty stderr is how a failure arrives with no explanation.
|
|
//
|
|
// **Injected, never set in the environment here.** This file used to set MESH_LAB_INCUS in its body,
|
|
// which runs after the imports above — so the client had already read the variable, and these tests
|
|
// asked the real incus: green on a machine without one, red on the workstation that runs the lab.
|
|
useIncusCommand(["false"]);
|
|
|
|
/**
|
|
* "I cannot see" must never be answered as "there is nothing there."
|
|
*
|
|
* This is the fault the comment on `incusOk` warns about, committed by three of its own callers
|
|
* writing `?? "[]"`. It cost a session: `mesh-lab list` printed *no scenario instances standing*
|
|
* while two were standing, because the shell had no permission to reach the daemon. Nothing was
|
|
* wrong with the lab's knowledge of the instances — it had never managed to ask.
|
|
*
|
|
* The same shape as the fault the node host exists to prevent, in the tool that tests the host:
|
|
* a service that does not exist reported as `stopped`.
|
|
*/
|
|
|
|
test("listing instances fails rather than reporting none", async () => {
|
|
await assert.rejects(
|
|
() => taggedInstances(),
|
|
"a failed `incus list` came back as an empty list; every caller would report nothing running",
|
|
);
|
|
});
|
|
|
|
test("listing networks fails rather than reporting none", async () => {
|
|
await assert.rejects(
|
|
() => taggedNetworks(),
|
|
"a failed `incus network list` came back as an empty list",
|
|
);
|
|
});
|
|
|
|
test("but a question whose failure genuinely means no still answers no", async () => {
|
|
// The distinction worth keeping. `instanceExists` asks about one named thing, and a daemon
|
|
// that will not answer is not evidence the instance exists — so false is honest here, and
|
|
// making this throw too would be over-correcting until nothing can be asked at all.
|
|
assert.equal(await instanceExists("anything"), false);
|
|
});
|