GIT7, GIT8: the forge module keeps the runner's failed required steps and refuses a head by them; git_failed_steps and git_failed_steps_drop
merge-pull refuses a head at whose fingerprint a run failed a required step (policy-failed, naming run, module, step), from the module's own state failed-steps kept from step-ended, with the seen keys of every step end and the deletion once no watched branch's head nor open pull request's head names a commit. The two tools read it with its fill and drop a key after the hand act. Builds: design 47 G §39, §83, §84, §85, §135, §475, §487, §548 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
// The forge module judges a head by the failed steps it heard (design 47 §39, §475, §487, §548, §135): what the runner's
|
||||
// step-ended writes, what a passing rerun clears, which head is refused, and what goes once no head names a commit.
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
|
||||
import { FailedSteps, Heads, failedStepKey, seenKey } from "../failedsteps.js";
|
||||
|
||||
const C1 = "1".repeat(40), C2 = "2".repeat(40), C3 = "3".repeat(40);
|
||||
|
||||
function memory() {
|
||||
const kv = new Map<string, unknown>();
|
||||
return { kv, st: {
|
||||
get: async (k: string) => (kv.has(k) ? { key: k, value: kv.get(k), revision: 1 } : null),
|
||||
put: async (k: string, v: unknown) => { kv.set(k, structuredClone(v)); return 1; },
|
||||
delete: async (k: string) => { kv.delete(k); },
|
||||
keys: async () => [...kv.keys()].sort(),
|
||||
watch: async () => {},
|
||||
} };
|
||||
}
|
||||
const ended = (commit: string, outcome: string, extra: Record<string, unknown> = {}, over: Record<string, unknown> = {}) => ({
|
||||
v: 1, pipeline: `main.7.nats-${commit.slice(0, 2)}`, module: "nats", branch: "main", commit, at: "2026-11-11T12:00:00Z",
|
||||
result: { step: "unit", status: "required", outcome, fingerprint: "fp-1", ...extra }, ...over }) as any;
|
||||
|
||||
test("a head is refused by a required step that failed at its fingerprint in any run, until a rerun passes it", async () => {
|
||||
const { kv, st } = memory();
|
||||
const heads = new Heads();
|
||||
const f = new FailedSteps(st as any, () => {}, (c) => heads.has(c));
|
||||
const notes: [string, string | null][] = [];
|
||||
const judged = async (name: string, commit: string, want: string | null) => {
|
||||
const got = await f.judge(commit);
|
||||
assert.equal(got ? `${got.run} ${got.module} ${got.step}` : null, want, name);
|
||||
};
|
||||
await f.stepEnded(ended(C1, "passed"));
|
||||
await judged("a head that passed alone merges", C1, null);
|
||||
await judged("a head no run named merges", C3, null);
|
||||
await f.stepEnded(ended(C2, "failed", {}, { pipeline: "run-on-request" }));
|
||||
await judged("the head that failed", C2, "run-on-request nats unit");
|
||||
await judged("an earlier commit of the same content (passed before, failed after)", C1, "run-on-request nats unit");
|
||||
assert.deepEqual((kv.get(failedStepKey("nats", "fp-1", "unit")) as any).commits, [C1, C2], "the commits it was seen at");
|
||||
// A step-ended of an ask that is no pipeline's step (no commit, no fingerprint) writes nothing (§548).
|
||||
const before = kv.size;
|
||||
await f.stepEnded({ v: 1, asker: "mesh-build-go", ask: "a-1", node: "ace", result: { step: "unit", status: "required", outcome: "failed" } } as any);
|
||||
assert.equal(kv.size, before, "a builder's failed build is no run of a commit");
|
||||
// A later commit at the fingerprint is refused too, and a failed optional step refuses nothing.
|
||||
await f.stepEnded(ended(C3, "passed"));
|
||||
await judged("a later commit of the same content", C3, "run-on-request nats unit");
|
||||
await f.stepEnded(ended(C3, "failed", { step: "lint", status: "optional", fingerprint: "fp-2" }));
|
||||
await judged("a failed optional step", C3, "run-on-request nats unit");
|
||||
assert.equal(kv.has(failedStepKey("nats", "fp-2", "lint")), false);
|
||||
// A plain pass clears nothing; a rerun that passes clears it.
|
||||
await f.stepEnded(ended(C2, "passed"));
|
||||
await judged("a plain pass", C2, "run-on-request nats unit");
|
||||
await f.stepEnded(ended(C2, "passed", { rerun: true, by: "operator" }));
|
||||
await judged("a passing rerun", C2, null);
|
||||
await judged("a passing rerun, for the earlier commit too", C1, null);
|
||||
void notes;
|
||||
});
|
||||
|
||||
test("an entry goes once none of its commits is a watched branch's head or an open pull request's head", async () => {
|
||||
const { kv, st } = memory();
|
||||
const heads = new Heads();
|
||||
const f = new FailedSteps(st as any, () => {}, (c) => heads.has(c));
|
||||
heads.replace(new Set(["novox/app@main"]), new Map([["novox/app@main", C1]]), new Map([["novox/app#4", C2]]));
|
||||
await f.stepEnded(ended(C2, "failed"));
|
||||
await f.stepEnded(ended(C1, "passed"));
|
||||
assert.deepEqual([...kv.keys()].sort(), [failedStepKey("nats", "fp-1", "unit"), seenKey(C1, "nats"), seenKey(C2, "nats")].sort());
|
||||
// The pull request is closed: its commit is no head, its seen key goes; the entry stays for the trunk's head that shares it.
|
||||
await f.lost(heads.pullEnded({ repository: "novox/app", number: 4 } as any));
|
||||
assert.equal(kv.has(seenKey(C2, "nats")), false);
|
||||
assert.deepEqual((kv.get(failedStepKey("nats", "fp-1", "unit")) as any).commits, [C1]);
|
||||
// The branch moves on: nothing names the entry's commits, so it goes. A branch no registration watches moves nothing.
|
||||
assert.deepEqual(heads.branchMoved("novox/app", "feature", C3), []);
|
||||
await f.lost(heads.branchMoved("novox/app", "main", C3));
|
||||
assert.deepEqual([...kv.keys()], [], "the failure and the seen keys are gone");
|
||||
});
|
||||
|
||||
test("git_failed_steps shows what is held and its fill, and git_failed_steps_drop writes the hand act before it drops", async () => {
|
||||
const { failedStepsTools } = await import("../tools/failedsteps.js");
|
||||
const { runAs } = await import("@novox/mesh-sdk/callers");
|
||||
const { st } = memory();
|
||||
const f = new FailedSteps(st as any);
|
||||
await f.stepEnded(ended(C2, "failed"));
|
||||
const acts: any[] = [];
|
||||
let recorded = true;
|
||||
const [read, drop] = failedStepsTools(f, async (a) => { if (!recorded) throw new Error("no hand-act log"); acts.push(a); });
|
||||
const shown: any = await read.run({});
|
||||
assert.deepEqual([shown.failed.map((x: any) => [x.key, x.run]), shown.seen.length, shown.fill.keys, shown.fill.cap],
|
||||
[[["nats.fp-1.unit", "main.7.nats-22"]], 1, 2, 64 * 1024 * 1024]);
|
||||
assert.equal(((await read.run({ commit: C1 })) as any).failed.length, 0, "a commit asked for filters");
|
||||
recorded = false;
|
||||
await assert.rejects(runAs({ "mesh/caller": "operator" }, {}, () => drop.run({ key: "nats.fp-1.unit", why: "stale" })), /hand act was not recorded, so nothing was dropped/);
|
||||
assert.equal((await f.judge(C2))?.step, "unit", "nothing dropped without the hand act");
|
||||
recorded = true;
|
||||
const done: any = await runAs({ "mesh/caller": "operator" }, {}, () => drop.run({ key: "nats.fp-1.unit", why: "stale" }));
|
||||
assert.deepEqual([done.dropped, acts.length, acts[0].verb], [true, 1, "git_failed_steps_drop"]);
|
||||
assert.equal(await f.judge(C2), null);
|
||||
});
|
||||
@@ -434,11 +434,12 @@ test("the two new tools are named for what mesh_search is asked, and gitea_api s
|
||||
// **merge-pull judges the head it is asked at and no check** (design 47 *The seat git*, §314): merge-pull merges the
|
||||
// head it is named into a base that takes no push, whatever its statuses say, and an id said again after the merge is
|
||||
// answered performed.
|
||||
test("merge-pull merges the head the caller names and judges no check", async () => {
|
||||
test("merge-pull merges the head the caller names, and refuses one at whose fingerprint a required step failed", async () => {
|
||||
const { seatTools } = await import("../dist/seat.js");
|
||||
const { runAs } = await import("@novox/mesh-sdk/callers");
|
||||
const bridge = "ace.mesh-delivery-forge-bridge";
|
||||
let registered = true;
|
||||
let failedStep: { run: string; module: string; step: string; fingerprint: string } | null = null;
|
||||
// The head's one writer of its statuses (gate.ts), over a forge whose first write is still in flight when the next is asked.
|
||||
const { GateWriter } = await import("../dist/gate.js");
|
||||
const landed: string[] = [];
|
||||
@@ -452,7 +453,7 @@ test("merge-pull merges the head the caller names and judges no check", async ()
|
||||
};
|
||||
const gates = new GateWriter(slow);
|
||||
const seat = seatTools(Object.assign(Object.create(client), { setCommitStatus: slow.setCommitStatus }),
|
||||
{ run: async () => ({ stdout: "", code: 0 }), container: "gitea", statuses: gates, registered: () => registered });
|
||||
{ run: async () => ({ stdout: "", code: 0 }), container: "gitea", statuses: gates, registered: () => registered, judge: async () => failedStep });
|
||||
const call = (verb: string, args: Record<string, unknown>, caller = bridge) =>
|
||||
runAs({ "mesh/caller": caller }, args, () => seat.find((t: any) => t.name === `git.${verb}`)!.run(args)) as Promise<any>;
|
||||
const merge = (extra: Record<string, unknown> = {}, caller?: string) =>
|
||||
@@ -463,6 +464,8 @@ test("merge-pull merges the head the caller names and judges no check", async ()
|
||||
{ name: "a base no rule guards", set: () => { state.rules = []; }, want: /guarded by no protection rule/, kind: "unprotected" },
|
||||
{ name: "a base whose protection was removed after the last branch-moved", set: () => { state.rules = [protectedMain()]; state.rules = []; }, want: /guarded by no protection rule/, kind: "unprotected" },
|
||||
{ name: "a base that takes a push", set: () => { state.rules = [{ rule_name: "main", enable_push: true }]; }, want: /guarded by no protection rule/, kind: "unprotected" },
|
||||
{ name: "a required step failed at the head's fingerprint", set: () => { failedStep = { run: "main.7.nats", module: "nats", step: "unit", fingerprint: "fp-1" }; },
|
||||
want: /the unit step of nats failed in run main\.7\.nats/, kind: "policy-failed" },
|
||||
{ name: "a failed check", set: () => { state.statuses = [{ context: "mesh/check", state: "failure", description: "fail" }]; }, want: "merged" },
|
||||
{ name: "no status at all", set: () => { state.statuses = []; }, want: "merged" },
|
||||
{ name: "a check of another trunk", set: () => { state.statuses = judgedAt(MOVED); }, want: "merged" },
|
||||
@@ -474,7 +477,7 @@ test("merge-pull merges the head the caller names and judges no check", async ()
|
||||
{ name: "the forge merged another head", set: () => { state.landed = MOVED; }, want: /WAS merged .*the forge merged 3c4d5e6f7a8b, not the abc1234def56/, loud: true },
|
||||
];
|
||||
for (const r of rows) {
|
||||
registered = true; state.merged = false; state.head = REVIEWED; state.statuses = judgedAt(TRUNK); state.sent = [];
|
||||
registered = true; failedStep = null; state.merged = false; state.head = REVIEWED; state.statuses = judgedAt(TRUNK); state.sent = [];
|
||||
state.rules = [protectedMain()]; state.prState = "open"; state.parents = null; state.commitsFail = 0; state.landed = "";
|
||||
r.set();
|
||||
const got = await merge(r.extra, r.caller);
|
||||
@@ -488,6 +491,7 @@ test("merge-pull merges the head the caller names and judges no check", async ()
|
||||
} else {
|
||||
assert.match(String(got.refused ?? got.error), r.want, r.name);
|
||||
if (r.kind) assert.equal(got["refused-kind"], r.kind, r.name);
|
||||
if (r.kind === "policy-failed") assert.deepEqual([got.run, got.module, got.step], ["main.7.nats", "nats", "unit"], r.name);
|
||||
assert.deepEqual(writes(), r.loud ? ["POST /repos/novox/mesh-catalog/pulls/7/merge"] : [], `${r.name}: what was merged`);
|
||||
}
|
||||
}
|
||||
@@ -548,10 +552,10 @@ test("every read and act of the seat git answers its contract, and an error is a
|
||||
};
|
||||
const run = async (_f: string, args: string[]) => args.includes("show") || args.includes("--ref") && !args.includes("append")
|
||||
? { stdout: noteShown, code: noteShown ? 0 : 1 } : (noteWritten++, { stdout: "", code: 0 });
|
||||
const seat = seatTools(forge as any, { run: run as any, container: "gitea", statuses: { status: async () => {} }, registered: () => true });
|
||||
const seat = seatTools(forge as any, { run: run as any, container: "gitea", statuses: { status: async () => {} }, registered: () => true, judge: async () => null });
|
||||
const call = (verb: string, args: Record<string, unknown>, over: Record<string, unknown> = {}) => {
|
||||
const t = seat.find((x: any) => x.name === `git.${verb}`)!;
|
||||
const wrapped = seatTools(Object.assign(Object.create(forge), over) as any, { run: run as any, container: "gitea", statuses: { status: async () => {} }, registered: () => true });
|
||||
const wrapped = seatTools(Object.assign(Object.create(forge), over) as any, { run: run as any, container: "gitea", statuses: { status: async () => {} }, registered: () => true, judge: async () => null });
|
||||
return runAs({ "mesh/caller": "ace.x" }, args, () => wrapped.find((x: any) => x.name === t.name)!.run(args)) as Promise<any>;
|
||||
};
|
||||
const rows: [string, string, Record<string, unknown>, Record<string, unknown>, (a: any) => unknown, unknown][] = [
|
||||
|
||||
Reference in New Issue
Block a user