Files
pikasTech-HWLAB/scripts/dev-cloud-workbench-smoke.test.mjs
T
2026-05-23 00:05:30 +00:00

103 lines
3.4 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import {
classifyLiveDeploymentIdentity,
classifyLiveWebAssetIdentity
} from "./src/dev-cloud-workbench-smoke-lib.mjs";
const sourceIdentity = Object.freeze({
status: "observed",
commitId: "ff4b3f928f76a0b46cd7998a2a865f3e1caf02c8",
shortCommitId: "ff4b3f928f76",
reportCommitId: "ff4b3f928f76",
worktreeState: "clean",
dirty: false
});
const expectedRuntimeIdentity = Object.freeze({
status: "observed",
serviceId: "hwlab-cloud-api",
source: "deploy/artifact-catalog.dev.json+deploy/deploy.json",
commitId: "7de6edd",
imageTag: "7de6edd",
image: "127.0.0.1:5000/hwlab/hwlab-cloud-api:7de6edd"
});
test("live workbench identity passes only when runtime commit or image tag matches current source", () => {
assert.equal(
classifyLiveDeploymentIdentity(sourceIdentity, {
status: "observed",
commitId: "7de6edd2c41f",
imageTag: "c7de474"
}, expectedRuntimeIdentity).status,
"pass"
);
assert.equal(
classifyLiveDeploymentIdentity(sourceIdentity, {
status: "observed",
commitId: "unknown",
imageTag: "7de6edd"
}, expectedRuntimeIdentity).status,
"pass"
);
const stale = classifyLiveDeploymentIdentity(sourceIdentity, {
status: "observed",
commitId: "c7de474",
imageTag: "c7de474"
}, expectedRuntimeIdentity);
assert.equal(stale.status, "blocked");
assert.match(stale.summary, /Deployment drift/u);
assert.match(stale.reason, /does not match current source desired runtime identity/u);
});
test("live workbench identity blocks when source identity is dirty or runtime identity is absent", () => {
const dirty = classifyLiveDeploymentIdentity(
{ ...sourceIdentity, worktreeState: "dirty", dirty: true, reportCommitId: "unknown" },
{ status: "observed", commitId: "7de6edd", imageTag: "7de6edd" },
expectedRuntimeIdentity
);
assert.equal(dirty.status, "blocked");
assert.match(dirty.reason, /not cleanly attributable/u);
const missingRuntime = classifyLiveDeploymentIdentity(sourceIdentity, {
status: "not_observed",
commitId: "not_observed",
imageTag: "not_observed"
}, expectedRuntimeIdentity);
assert.equal(missingRuntime.status, "blocked");
assert.match(missingRuntime.reason, /not observed/u);
});
test("live workbench identity uses deploy desired runtime identity instead of git HEAD", () => {
const deployed = classifyLiveDeploymentIdentity(sourceIdentity, {
status: "observed",
commitId: "7de6edd",
imageTag: "7de6edd"
}, expectedRuntimeIdentity);
assert.equal(deployed.status, "pass");
assert.equal(deployed.expectedCommit, "7de6edd");
assert.equal(deployed.expectedReportCommitId, "ff4b3f928f76");
assert.equal(deployed.expectedSource, "deploy/artifact-catalog.dev.json+deploy/deploy.json");
});
test("live web asset identity blocks stale deployed primary assets", () => {
const pass = classifyLiveWebAssetIdentity([
{ path: "index.html", status: "match" },
{ path: "styles.css", status: "match" },
{ path: "app.mjs", status: "match" }
]);
assert.equal(pass.status, "pass");
const stale = classifyLiveWebAssetIdentity([
{ path: "index.html", status: "match" },
{ path: "styles.css", status: "mismatch" },
{ path: "app.mjs", status: "mismatch" }
]);
assert.equal(stale.status, "blocked");
assert.deepEqual(stale.mismatches, ["styles.css", "app.mjs"]);
assert.match(stale.summary, /Deployment drift/u);
});