50 lines
3.0 KiB
TypeScript
50 lines
3.0 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
|
|
// A branch's protection (novox/hq ADR 0237): what the operator's agent sets so a pull request waits for the
|
|
// mesh's merge check before it merges.
|
|
|
|
test("the statuses asked for replace the rule's, and an empty list requires none", async () => {
|
|
const { protectionBody } = await import("../dist/protection.js");
|
|
assert.deepEqual(protectionBody({ statusChecks: ["mesh/merge-gate", " mesh/repo-check", "", "mesh/merge-gate"] }, false),
|
|
{ enable_status_check: true, status_check_contexts: ["mesh/merge-gate", "mesh/repo-check"] },
|
|
"an edited rule keeps its pushes as they are, and each status once");
|
|
assert.deepEqual(protectionBody({ statusChecks: [] }, false), { enable_status_check: false, status_check_contexts: [] });
|
|
});
|
|
|
|
test("a new rule refuses direct pushes unless asked; an administrator's override only when said", async () => {
|
|
const { protectionBody } = await import("../dist/protection.js");
|
|
assert.equal(protectionBody({ statusChecks: ["mesh/merge-gate"] }, true).enable_push, false);
|
|
assert.equal(protectionBody({ statusChecks: ["mesh/merge-gate"], push: true }, true).enable_push, true);
|
|
assert.equal(protectionBody({ statusChecks: ["mesh/merge-gate"] }, true).block_admin_merge_override, undefined);
|
|
assert.equal(protectionBody({ statusChecks: ["mesh/merge-gate"], blockAdminOverride: true }, false).block_admin_merge_override, true);
|
|
});
|
|
|
|
// Issue 948 (novox/hq ADR 0398 §2): main takes no push, and only the tools' account merges.
|
|
test("main's body always refuses pushes and lets only the tools' account merge, whatever is asked", async () => {
|
|
const { protectionBody } = await import("../dist/protection.js");
|
|
const { TOOLS_ACCOUNT } = await import("../dist/tools-account.js");
|
|
for (const creating of [true, false]) {
|
|
for (const want of [{ statusChecks: ["mesh/merge-gate"] }, { statusChecks: [], push: true }, { statusChecks: [], push: false }]) {
|
|
const body = protectionBody(want, creating, "main");
|
|
assert.equal(body.enable_push, false, "main takes no push, an edit and a push=true included");
|
|
assert.equal(body.enable_merge_whitelist, true);
|
|
assert.deepEqual(body.merge_whitelist_usernames, [TOOLS_ACCOUNT]);
|
|
}
|
|
}
|
|
assert.deepEqual(TOOLS_ACCOUNT, "mesh-tools");
|
|
});
|
|
|
|
test("another branch's body carries no merge whitelist", async () => {
|
|
const { protectionBody } = await import("../dist/protection.js");
|
|
const body = protectionBody({ statusChecks: ["mesh/merge-gate"] }, false, "release/1");
|
|
assert.equal(body.enable_merge_whitelist, undefined);
|
|
assert.equal(body.merge_whitelist_usernames, undefined);
|
|
assert.equal(protectionBody({ statusChecks: [] }, false).enable_merge_whitelist, undefined);
|
|
});
|
|
|
|
test("the rule main is put right in the forge's own words: the body a setup sends carries no status checks of its own", async () => {
|
|
const { mainRuleBody } = await import("../dist/protection.js");
|
|
assert.deepEqual(mainRuleBody(), { enable_push: false, enable_merge_whitelist: true, merge_whitelist_usernames: ["mesh-tools"] });
|
|
});
|