72 lines
2.7 KiB
JavaScript
72 lines
2.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import test from "node:test";
|
|
import { calculateEnvIdentity, createPlan } from "./ci-plan.mjs";
|
|
|
|
test("plan reuses a present env image without expanding build scope", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "agentrun-ci-plan-"));
|
|
await mkdir(join(root, "src"));
|
|
await writeFile(join(root, "src", "index.ts"), "export const ok = true;\n");
|
|
const envIdentity = calculateEnvIdentity({
|
|
root,
|
|
envIdentityFiles: ["src"],
|
|
buildArgs: ["BUN_IMAGE=oven/bun:1-alpine"],
|
|
containerHttpProxy: "",
|
|
containerHttpsProxy: "",
|
|
containerNoProxy: "localhost",
|
|
});
|
|
await mkdir(join(root, "scripts", "ci"), { recursive: true });
|
|
await writeFile(join(root, "scripts", "ci-plan.mjs"), "planner-only\n");
|
|
await writeFile(join(root, "scripts", "ci-plan.test.mjs"), "planner-test-only\n");
|
|
await writeFile(join(root, "scripts", "ci", "verify-reviewed-plan.mjs"), "admission-only\n");
|
|
await writeFile(join(root, "scripts", "ci", "verify-reviewed-plan.test.mjs"), "admission-test-only\n");
|
|
assert.equal(calculateEnvIdentity({
|
|
root,
|
|
envIdentityFiles: ["src", "scripts"],
|
|
buildArgs: ["BUN_IMAGE=oven/bun:1-alpine"],
|
|
containerHttpProxy: "",
|
|
containerHttpsProxy: "",
|
|
containerNoProxy: "localhost",
|
|
}), calculateEnvIdentity({
|
|
root,
|
|
envIdentityFiles: ["src"],
|
|
buildArgs: ["BUN_IMAGE=oven/bun:1-alpine"],
|
|
containerHttpProxy: "",
|
|
containerHttpsProxy: "",
|
|
containerNoProxy: "localhost",
|
|
}));
|
|
const plan = createPlan({
|
|
sourceCommitId: "a".repeat(40),
|
|
baseCommitId: "b".repeat(40),
|
|
target: "NC01",
|
|
consumer: "agentrun-nc01-v02",
|
|
lane: "nc01-v02",
|
|
changedPaths: ["src/index.ts"],
|
|
envIdentity,
|
|
imageRepository: "127.0.0.1:5000/agentrun/agentrun-mgr-env",
|
|
registryProbe: { status: "present", digest: `sha256:${"c".repeat(64)}` },
|
|
});
|
|
assert.deepEqual(plan.buildServices, []);
|
|
assert.deepEqual(plan.rolloutServices, ["agentrun-mgr"]);
|
|
assert.deepEqual(plan.affectedServices, ["agentrun-mgr"]);
|
|
assert.deepEqual(plan.reusedServices, ["agentrun-mgr"]);
|
|
assert.match(plan.planIdentity.value, /^sha256:[0-9a-f]{64}$/u);
|
|
});
|
|
|
|
test("plan exposes a missing env image as one build", () => {
|
|
const plan = createPlan({
|
|
sourceCommitId: "a".repeat(40),
|
|
baseCommitId: "b".repeat(40),
|
|
target: "NC01",
|
|
consumer: "agentrun-nc01-v02",
|
|
lane: "nc01-v02",
|
|
changedPaths: ["src/index.ts"],
|
|
envIdentity: "env-id",
|
|
imageRepository: "127.0.0.1:5000/agentrun/agentrun-mgr-env",
|
|
registryProbe: { status: "missing", digest: null },
|
|
});
|
|
assert.deepEqual(plan.buildServices, ["agentrun-mgr"]);
|
|
});
|