48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { verifyReviewedPlan } from "./verify-reviewed-plan.mjs";
|
|
|
|
const consumer = "agentrun-nc01-v02";
|
|
const actual = {
|
|
sourceCommitId: "a".repeat(40),
|
|
baseCommitId: "b".repeat(40),
|
|
buildServices: [],
|
|
rolloutServices: ["agentrun-mgr"],
|
|
affectedServices: ["agentrun-mgr"],
|
|
planIdentity: {
|
|
value: `sha256:${"c".repeat(64)}`,
|
|
inputs: { target: "NC01", consumer },
|
|
},
|
|
};
|
|
|
|
function envelope(overrides = {}, envelopeConsumer = consumer) {
|
|
const reviewed = {
|
|
version: "v1",
|
|
planIdentity: actual.planIdentity.value,
|
|
target: "NC01",
|
|
consumer,
|
|
sourceCommit: actual.sourceCommitId,
|
|
baseCommit: actual.baseCommitId,
|
|
buildServices: [],
|
|
rolloutServices: ["agentrun-mgr"],
|
|
affectedServices: ["agentrun-mgr"],
|
|
...overrides,
|
|
};
|
|
return `unidesk-release-plan-v1.${envelopeConsumer}.${Buffer.from(JSON.stringify(reviewed)).toString("base64url")}`;
|
|
}
|
|
|
|
test("accepts the consumer-qualified reviewed plan envelope", () => {
|
|
assert.equal(verifyReviewedPlan(actual, envelope()).ok, true);
|
|
});
|
|
|
|
test("rejects an envelope addressed to another consumer", () => {
|
|
assert.throws(() => verifyReviewedPlan(actual, envelope({}, "agentrun-nc01-release")), /another consumer/u);
|
|
});
|
|
|
|
test("rejects actual scope that expands beyond the reviewed plan", () => {
|
|
const expanded = { ...actual, buildServices: ["agentrun-mgr"] };
|
|
const result = verifyReviewedPlan(expanded, envelope());
|
|
assert.equal(result.ok, false);
|
|
assert.deepEqual(result.additions.buildServices, ["agentrun-mgr"]);
|
|
});
|