Files
pikasTech-HWLAB/scripts/dev-m3-hardware-loop-smoke.test.mjs
T
2026-05-22 18:29:55 +00:00

60 lines
2.3 KiB
JavaScript

import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { mkdir, readFile, rm } from "node:fs/promises";
import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const testOutputDir = "tmp/dev-m3-hardware-loop-smoke-test";
function runSmoke(args) {
return execFileSync("node", ["scripts/dev-m3-hardware-loop-smoke.mjs", ...args], {
cwd: repoRoot,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"]
});
}
test("default M3 smoke is source/read-only and never claims DEV-LIVE", async () => {
await mkdir(path.join(repoRoot, testOutputDir), { recursive: true });
const output = path.join(testOutputDir, "default-source-readonly.json");
try {
const stdout = runSmoke(["--output", output]);
assert.match(stdout, /mode=dry-run/u);
const report = JSON.parse(await readFile(path.join(repoRoot, output), "utf8"));
assert.equal(report.dryRunPlan.mode, "plan-only");
assert.equal(report.dryRunPlan.dryRunCallsLiveEndpoints, false);
assert.equal(report.dryRunPlan.liveWriteWillRun, false);
assert.equal(report.liveOperation.status, "not_run");
assert.equal(report.liveOperation.operationId, "not_observed");
assert.equal(report.summary.status, "blocked");
assert.match(report.summary.result, /did not call DEV endpoints/u);
assert.equal(
report.liveChecks.find((check) => check.id === "direct-call-do-write-di-read")?.status,
"not_run"
);
} finally {
await rm(path.join(repoRoot, output), { force: true });
}
});
test("--dry-run aliases the same source/read-only no-write path", async () => {
await mkdir(path.join(repoRoot, testOutputDir), { recursive: true });
const output = path.join(testOutputDir, "dry-run-source-readonly.json");
try {
runSmoke(["--dry-run", "--output", output]);
const report = JSON.parse(await readFile(path.join(repoRoot, output), "utf8"));
assert.equal(report.dryRunPlan.mode, "plan-only");
assert.equal(report.dryRunPlan.liveWriteWillRun, false);
assert.ok(
report.dryRunPlan.failureClassifications.includes("patch_panel_wiring_missing")
);
assert.equal(report.liveOperation.status, "not_run");
} finally {
await rm(path.join(repoRoot, output), { force: true });
}
});