Files
mesh-catalog/modules/gitea/test/mainrules.test.ts
T
jschoubben 77f33d317f Keep main's rules only when the setting keep-main-rules is true (default false)
The operator, 2026-10-23: "disable the gitea branch protection reset thing". The 10-minute tick and the start-time
ensureMainMerges, and the repositories sync's changes to existing repositories' main rules, now run only when the new
setting is true; new repositories are still made. The sync says in its outcome that rules were left.
2026-10-23 15:53:30 +02:00

44 lines
1.8 KiB
TypeScript

// The operator, 2026-10-23: "disable the gitea branch protection reset thing". keep-main-rules false (the default)
// writes nothing at the forge, true puts main's rule right as before.
import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { keepMainRules, mainRulesStep, LEFT_AS_SET } from "../dist/mainrules.js";
function env(body?: string): NodeJS.ProcessEnv {
if (body === undefined) return {};
const f = join(mkdtempSync(join(tmpdir(), "gitea-keep-")), "config.json");
writeFileSync(f, body);
return { MESH_GITEA_CONFIG_FILE: f };
}
test("the setting is false unless the config says true", () => {
assert.equal(keepMainRules(env()), false);
assert.equal(keepMainRules(env("{}")), false);
assert.equal(keepMainRules(env('{"keep-main-rules":false}')), false);
assert.equal(keepMainRules(env("not json")), false);
assert.equal(keepMainRules(env('{"keep-main-rules":true}')), true);
});
test("false: the step never writes and says once that the rules are left", async () => {
let writes = 0;
const said: string[] = [];
const step = mainRulesStep(false, async () => { writes++; return ["a"]; }, (l) => said.push(l));
await step(); await step(); await step();
assert.equal(writes, 0);
assert.deepEqual(said, [LEFT_AS_SET]);
assert.match(LEFT_AS_SET, /main's rules are left as set at the forge \(keep-main-rules is false\)/);
});
test("true: every step puts the rules right", async () => {
let writes = 0;
const said: string[] = [];
const step = mainRulesStep(true, async () => { writes++; return ["a", "b"]; }, (l) => said.push(l));
await step(); await step();
assert.equal(writes, 2);
assert.deepEqual(said, ["[gitea] main's rule is right in 2 repositories"]);
});