Compare commits
5
Commits
fix/r4e-k2
...
fix/r4e-r2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
896bd88380 | ||
|
|
24f50c7c86 | ||
|
|
e3db481491 | ||
|
|
21b4925892 | ||
|
|
8d3f81c2c0 |
@@ -0,0 +1,188 @@
|
|||||||
|
// **mesh/check is written from the checker's owed state, read by a watch** (ADR 0521; R4e round 2 finding R2-1; finding K1
|
||||||
|
// before it; novox/hq issue 1301; ADR 0447 §1, ADR 0503 §3: main requires mesh/check alone).
|
||||||
|
//
|
||||||
|
// No tool writes mesh/check: a tool is told no caller, and the console every agent session speaks through (node-tools)
|
||||||
|
// invokes every tool, so a tool that wrote it could be called by any session to merge past the checker (the fault issue
|
||||||
|
// 293 closed for the two statuses before it). Nor does an event: nothing in the delivery plan orders this module before the
|
||||||
|
// forge bridge, and a durable consumer whose filters change keeps its deliver policy, so an event said before this module
|
||||||
|
// consumed it was lost. The checker keeps what it owes the forge in its state `owed` (ADR 0484 §2), which it announces
|
||||||
|
// readable (ADR 0495 §2-§3), and only the checker writes it. This module watches it: the watch hands over the latest value of
|
||||||
|
// every key when it starts, whenever that is, and then every change. Each key whose act is the status mesh/check is
|
||||||
|
// written on its head, once per revision; a revision older than one already written on the key is dropped.
|
||||||
|
//
|
||||||
|
// A read refused (the grant not yet composed) is said once and asked again on a bound until it holds. A forge that refuses
|
||||||
|
// a status is asked again on a bound, until it writes or a newer revision of the key comes.
|
||||||
|
|
||||||
|
import type { CommitStatus } from "./client.js";
|
||||||
|
import { bindUntilHeld, bindWait } from "./bind.js";
|
||||||
|
import { checkName } from "./guard.js";
|
||||||
|
import { CHECK_STATUS } from "./pulls.js";
|
||||||
|
|
||||||
|
/** The checker's state this module reads, and the act of its keys this module writes. */
|
||||||
|
export const CHECKER_OWED = "mesh-delivery-checker.owed";
|
||||||
|
export const CHECK_ACT = `status=${CHECK_STATUS}`;
|
||||||
|
|
||||||
|
const states = new Set(["pending", "success", "error", "failure", "warning"]);
|
||||||
|
|
||||||
|
/** What writing the check needs of the forge. */
|
||||||
|
export interface CheckForge {
|
||||||
|
setCommitStatus(owner: string, repo: string, sha: string, status: CommitStatus): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One change of the checker's owed, as the SDK's state watch hands it. */
|
||||||
|
export interface OwedChange {
|
||||||
|
key: string;
|
||||||
|
op: "put" | "delete";
|
||||||
|
value?: unknown;
|
||||||
|
revision: number;
|
||||||
|
current?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A key part as mesh-sdk go/delivery EscapeName writes it, read back: `=` and two lowercase hex digits per byte. */
|
||||||
|
function unescapeName(part: string): string {
|
||||||
|
if (!/^([-/_a-zA-Z0-9]|=[0-9a-f]{2})+$/.test(part)) throw new Error(`${JSON.stringify(part)} is not an escaped name`);
|
||||||
|
return Buffer.from(part.replace(/=([0-9a-f]{2})/g, (_, h) => String.fromCharCode(parseInt(h, 16))), "latin1").toString("utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The pull request and head of the checker's owed key (mesh-sdk go/delivery CheckerOwedKey):
|
||||||
|
* `<owner>/<name>.<number>.<head>.status=mesh/check`, owner and name escaped. */
|
||||||
|
export function owedKeyOf(key: string): { owner: string; repo: string; number: number; sha: string } {
|
||||||
|
const parts = String(key ?? "").split(".");
|
||||||
|
if (parts.length !== 4) throw new Error(`${JSON.stringify(key)} is not an owed key, <repository>.<number>.<head>.<act>`);
|
||||||
|
const [repository, number, sha, act] = parts;
|
||||||
|
if (act !== CHECK_ACT) throw new Error(`${JSON.stringify(key)} owes ${JSON.stringify(act)}, not ${CHECK_ACT}`);
|
||||||
|
const m = /^([^/]+)\/([^/]+)$/.exec(repository);
|
||||||
|
if (!m) throw new Error(`${JSON.stringify(key)} names no <owner>/<name>`);
|
||||||
|
if (!/^(0|[1-9][0-9]*)$/.test(number)) throw new Error(`${JSON.stringify(key)} names no pull request number`);
|
||||||
|
if (!/^([0-9a-f]{40}|[0-9a-f]{64})$/i.test(sha)) throw new Error(`${JSON.stringify(key)} names no head's whole sha`);
|
||||||
|
return { owner: checkName("owner", unescapeName(m[1])), repo: checkName("name", unescapeName(m[2])), number: Number(number), sha };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The status an owed change asks for, checked as mesh-sdk go/delivery DecodeCheckerOwed checks it; or why it is not one. */
|
||||||
|
export function checkStatusOf(change: OwedChange): { owner: string; repo: string; sha: string; revision: number; status: CommitStatus } {
|
||||||
|
if (change.op !== "put") throw new Error(`a ${change.op} owes nothing`);
|
||||||
|
const { owner, repo, sha } = owedKeyOf(change.key);
|
||||||
|
const revision = change.revision;
|
||||||
|
if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 0) {
|
||||||
|
throw new Error(`${JSON.stringify(revision)} is not a revision`);
|
||||||
|
}
|
||||||
|
const v = change.value;
|
||||||
|
if (!v || typeof v !== "object") throw new Error("the value is no owed act");
|
||||||
|
const o = v as Record<string, unknown>;
|
||||||
|
if (o.v !== 1) throw new Error(`the owed act's version ${JSON.stringify(o.v)} is not one this module reads`);
|
||||||
|
if (o.act !== "status" || o.context !== CHECK_STATUS) {
|
||||||
|
throw new Error(`the owed act is ${JSON.stringify(o.act)} ${JSON.stringify(o.context)}, not the status ${CHECK_STATUS}`);
|
||||||
|
}
|
||||||
|
const state = String(o.state ?? "");
|
||||||
|
if (!states.has(state)) throw new Error(`${JSON.stringify(o.state)} is not a status the forge keeps`);
|
||||||
|
let description = String(o.text ?? "").replace(/\s+/g, " ").trim();
|
||||||
|
if (description.length > 140) description = description.slice(0, 139) + "…";
|
||||||
|
const target = typeof o.target === "string" && /^https?:\/\//.test(o.target) ? o.target : undefined;
|
||||||
|
const status: CommitStatus = { state: state as CommitStatus["state"], context: CHECK_STATUS, description,
|
||||||
|
...(target ? { target_url: target } : {}) };
|
||||||
|
return { owner, repo, sha, revision, status };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The one writer of mesh/check: each owed revision of the checker's, in revision order per key. */
|
||||||
|
export class CheckStatuses {
|
||||||
|
/** The newest revision written of each key, and the newest seen; the oldest keys go past what any forge holds open. */
|
||||||
|
private written = new Map<string, number>();
|
||||||
|
private seen = new Map<string, number>();
|
||||||
|
/** The turn each key's writes wait on, and the asks again still running. */
|
||||||
|
private turns = new Map<string, Promise<unknown>>();
|
||||||
|
private again = new Set<Promise<void>>();
|
||||||
|
private forge: CheckForge;
|
||||||
|
private say: (line: string) => void;
|
||||||
|
private sleep: (ms: number) => Promise<void>;
|
||||||
|
|
||||||
|
constructor(forge: CheckForge, say: (line: string) => void = (l) => console.error(l),
|
||||||
|
sleep: (ms: number) => Promise<void> = (ms) => new Promise((r) => setTimeout(r, ms))) {
|
||||||
|
this.forge = forge;
|
||||||
|
this.say = say;
|
||||||
|
this.sleep = sleep;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Write the change's status: "written", or "dropped" for one that owes no mesh/check or is older than one written. A
|
||||||
|
* forge that refuses throws. */
|
||||||
|
async apply(change: OwedChange): Promise<"written" | "dropped"> {
|
||||||
|
let asked;
|
||||||
|
try {
|
||||||
|
asked = checkStatusOf(change);
|
||||||
|
} catch (err) {
|
||||||
|
this.say(`[gitea] ${CHECKER_OWED} ${change?.key} at revision ${change?.revision} writes nothing: ${err instanceof Error ? err.message : err}`);
|
||||||
|
return "dropped";
|
||||||
|
}
|
||||||
|
const key = change.key;
|
||||||
|
const seen = this.seen.get(key);
|
||||||
|
if (seen === undefined || asked.revision > seen) this.remember(this.seen, key, asked.revision);
|
||||||
|
// One key's writes take turns, so two at once are weighed one after the other.
|
||||||
|
const before = this.turns.get(key) ?? Promise.resolve();
|
||||||
|
const turn = before.then(async (): Promise<"written" | "dropped"> => {
|
||||||
|
const newest = this.written.get(key);
|
||||||
|
if (newest !== undefined && asked.revision < newest) {
|
||||||
|
this.say(`[gitea] ${asked.owner}/${asked.repo}@${asked.sha.slice(0, 12)}: mesh/check at revision ${asked.revision} is older than ${newest}, already written, and is dropped`);
|
||||||
|
return "dropped";
|
||||||
|
}
|
||||||
|
await this.forge.setCommitStatus(asked.owner, asked.repo, asked.sha, asked.status);
|
||||||
|
this.remember(this.written, key, asked.revision);
|
||||||
|
return "written";
|
||||||
|
});
|
||||||
|
const settled = turn.catch(() => {});
|
||||||
|
this.turns.set(key, settled);
|
||||||
|
void settled.then(() => { if (this.turns.get(key) === settled) this.turns.delete(key); });
|
||||||
|
return turn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What the watch hands over: written, or when the forge refuses, asked again on a bound in the background until it is
|
||||||
|
* written or a newer revision of the key was seen. Never throws: a watch's handler that throws loses the change. */
|
||||||
|
async take(change: OwedChange): Promise<void> {
|
||||||
|
try {
|
||||||
|
await this.apply(change);
|
||||||
|
} catch (err) {
|
||||||
|
const run = this.askAgain(change, err);
|
||||||
|
this.again.add(run);
|
||||||
|
void run.finally(() => this.again.delete(run));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolves when no ask again is running. */
|
||||||
|
async settled(): Promise<void> {
|
||||||
|
while (this.again.size) await Promise.all([...this.again]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async askAgain(change: OwedChange, first: unknown): Promise<void> {
|
||||||
|
let err = first;
|
||||||
|
for (let attempt = 1; ; attempt++) {
|
||||||
|
const wait = bindWait(attempt);
|
||||||
|
this.say(`[gitea] ${change.key}: mesh/check at revision ${change.revision} could not be written (${err instanceof Error ? err.message : err}); asked again in ${wait / 1000}s`);
|
||||||
|
await this.sleep(wait);
|
||||||
|
const newest = this.seen.get(change.key);
|
||||||
|
if (newest !== undefined && newest > change.revision) return;
|
||||||
|
try {
|
||||||
|
await this.apply(change);
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private remember(map: Map<string, number>, key: string, revision: number): void {
|
||||||
|
map.delete(key);
|
||||||
|
map.set(key, revision);
|
||||||
|
if (map.size > 4000) map.delete(map.keys().next().value as string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch the checker's owed with `watch` (the SDK's `state(CHECKER_OWED).watch`), handing each change to `checks`. A watch
|
||||||
|
* refused — the read not granted yet — is said once and asked again on a bound until it holds (bind.ts). Never rejects.
|
||||||
|
*/
|
||||||
|
export async function watchOwed(watch: (handler: (change: OwedChange) => Promise<void>) => Promise<void>, checks: CheckStatuses,
|
||||||
|
sleep?: (ms: number) => Promise<void>, say: (line: string) => void = (l) => console.error(l)): Promise<void> {
|
||||||
|
let refusals = 0;
|
||||||
|
await bindUntilHeld(CHECKER_OWED, () => watch((change) => checks.take(change)), sleep, (line) => {
|
||||||
|
if (/could not be bound/.test(line) && refusals++ > 0) return;
|
||||||
|
say(line);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -101,10 +101,10 @@ export function deliveryStatus(context: string, state: string, description: stri
|
|||||||
if (!/^mesh\/[a-z-]+$/.test(context)) throw new Error(`${context} is not a status of the mesh's own`);
|
if (!/^mesh\/[a-z-]+$/.test(context)) throw new Error(`${context} is not a status of the mesh's own`);
|
||||||
if (!states.has(state)) throw new Error(`${state} is not a status the forge keeps`);
|
if (!states.has(state)) throw new Error(`${state} is not a status the forge keeps`);
|
||||||
// mesh/check is the checker's verdict and the one status main requires (ADR 0447 §1): no hand sets it in any
|
// mesh/check is the checker's verdict and the one status main requires (ADR 0447 §1): no hand sets it in any
|
||||||
// state, as issue 293 closed for the two before it. The forge bridge writes it through gitea_check_status, a tool
|
// state, as issue 293 closed for the two before it. No tool writes it, since a tool is told no caller (R4e finding K1):
|
||||||
// only its account may call (issue 1301).
|
// check.ts writes it from the checker's owed state (ADR 0521).
|
||||||
if (context === CHECK_STATUS) {
|
if (context === CHECK_STATUS) {
|
||||||
throw new Error(`${CHECK_STATUS} is the checker's status: the forge bridge writes it through gitea_check_status, never this tool`);
|
throw new Error(`${CHECK_STATUS} is the checker's status: it is written from mesh-delivery-checker.owed alone, never by a tool`);
|
||||||
}
|
}
|
||||||
// The merge check's statuses are its verdict's, set when the controller says it, and a branch may require
|
// The merge check's statuses are its verdict's, set when the controller says it, and a branch may require
|
||||||
// them: never set to a verdict by hand, so nothing passes — or fails — a merge past the check (novox/hq
|
// them: never set to a verdict by hand, so nothing passes — or fails — a merge past the check (novox/hq
|
||||||
@@ -136,7 +136,7 @@ export interface StatusWriters {
|
|||||||
export function commitStatusTool(writers: StatusWriters): ToolDefinition {
|
export function commitStatusTool(writers: StatusWriters): ToolDefinition {
|
||||||
return {
|
return {
|
||||||
name: "gitea_commit_status",
|
name: "gitea_commit_status",
|
||||||
description: "Set one of the mesh's statuses on a commit (mesh/delivery, mesh/delivery-group): pending, success, error, failure or warning, a short description, and the page it links to. mesh/check, the status main requires, is refused: the checker's forge bridge writes it through gitea_check_status. hq's mesh/repo-check (and mesh/merge-gate, kept for a revert) take pending only — a recheck putting them back until the fresh verdict sets them — on the head's whole sha, in their turn after the check's earlier writes.",
|
description: "Set one of the mesh's statuses on a commit (mesh/delivery, mesh/delivery-group): pending, success, error, failure or warning, a short description, and the page it links to. mesh/check, the status main requires, is refused: no tool writes it: it is written from the checker's own state. hq's mesh/repo-check (and mesh/merge-gate, kept for a revert) take pending only — a recheck putting them back until the fresh verdict sets them — on the head's whole sha, in their turn after the check's earlier writes.",
|
||||||
input: {
|
input: {
|
||||||
owner: { type: "string", description: "the repository owner" },
|
owner: { type: "string", description: "the repository owner" },
|
||||||
repo: { type: "string", description: "the repository name" },
|
repo: { type: "string", description: "the repository name" },
|
||||||
@@ -163,48 +163,3 @@ export function commitStatusTool(writers: StatusWriters): ToolDefinition {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** What the check's status tool writes with: the forge. */
|
|
||||||
export interface CheckStatusWriter {
|
|
||||||
setCommitStatus(owner: string, repo: string, sha: string, status: CommitStatus): Promise<void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The `gitea_check_status` tool (novox/hq issue 1301, ADR 0447 §1): the one way `mesh/check` is written. Its arguments
|
|
||||||
* are gitea_commit_status's, so the forge bridge sends an owed status's arguments unchanged to it: owner, repo, sha
|
|
||||||
* (the head's whole sha), state, description, target_url, and context, which may be left out and is mesh/check when
|
|
||||||
* given. **Who may write it is the bus's grant**: the runtime tells a tool no caller, so only a module that lists
|
|
||||||
* `gitea.gitea_check_status` in its manifest's `invokes` may call it, and the forge bridge alone does. Served beside
|
|
||||||
* gitea_commit_status, from the watcher's bundle.
|
|
||||||
*/
|
|
||||||
export function checkStatusTool(writer: CheckStatusWriter): ToolDefinition {
|
|
||||||
return {
|
|
||||||
name: "gitea_check_status",
|
|
||||||
description: "Set mesh/check, the checker's verdict and the one status main requires, on a pull request's head: pending, success, error, failure or warning, a short description, and the page it links to. The checker's forge bridge alone may call it (its manifest's invokes); no other status is written here, and no other tool writes this one.",
|
|
||||||
input: {
|
|
||||||
owner: { type: "string", description: "the repository owner" },
|
|
||||||
repo: { type: "string", description: "the repository name" },
|
|
||||||
sha: { type: "string", description: "the head's whole sha" },
|
|
||||||
context: { type: "string", description: "mesh/check, or left out" },
|
|
||||||
state: { type: "string", description: "pending | success | error | failure | warning" },
|
|
||||||
description: { type: "string", description: "one line" },
|
|
||||||
target_url: { type: "string", description: "the page it links to (the check's report)" },
|
|
||||||
},
|
|
||||||
run: async (args) => {
|
|
||||||
const owner = checkName("owner", args.owner), repo = checkName("name", args.repo), sha = String(args.sha ?? "");
|
|
||||||
if (args.context !== undefined && args.context !== null && String(args.context) !== CHECK_STATUS) {
|
|
||||||
throw new Error(`${JSON.stringify(args.context)}: this tool writes ${CHECK_STATUS} alone. Nothing was sent`);
|
|
||||||
}
|
|
||||||
if (!/^([0-9a-f]{40}|[0-9a-f]{64})$/i.test(sha)) {
|
|
||||||
throw new Error(`${JSON.stringify(args.sha)} is not a head's whole sha: ${CHECK_STATUS} names the head whole. Nothing was sent`);
|
|
||||||
}
|
|
||||||
// deliveryStatus checks the state and cuts the description; it refuses mesh/check, so it is asked for a
|
|
||||||
// context of the mesh's own and the status is named mesh/check after.
|
|
||||||
const checked = deliveryStatus("mesh/delivery", String(args.state), String(args.description ?? ""),
|
|
||||||
args.target_url ? String(args.target_url) : undefined);
|
|
||||||
const status = { ...checked, context: CHECK_STATUS };
|
|
||||||
await writer.setCommitStatus(owner, repo, sha, status);
|
|
||||||
return { set: status };
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
+17
-5
@@ -13,8 +13,12 @@
|
|||||||
// commit's statuses: `mesh/merge-gate`, the modules of the mesh's graph the change touches, and
|
// commit's statuses: `mesh/merge-gate`, the modules of the mesh's graph the change touches, and
|
||||||
// `mesh/repo-check`, the repository's own merge-check.sh (novox/hq ADR 0237 as amended); with a comment
|
// `mesh/repo-check`, the repository's own merge-check.sh (novox/hq ADR 0237 as amended); with a comment
|
||||||
// saying why when the gate is not a pass or the repository's own check failed. Of the two, only those the base
|
// saying why when the gate is not a pass or the repository's own check failed. Of the two, only those the base
|
||||||
// still requires are written (issue 1301): main requires `mesh/check` — the checker's, written by its forge bridge
|
// still requires are written (issue 1301): main requires `mesh/check` — the checker's — everywhere but hq, whose main
|
||||||
// through gitea_check_status — everywhere but hq, whose main requires `mesh/repo-check` alone (ADR 0503 §5).
|
// requires `mesh/repo-check` alone (ADR 0503 §5).
|
||||||
|
//
|
||||||
|
// Reads mesh-delivery-checker.owed — what the checker owes the forge, mesh/check on each head it judged — by a watch, and
|
||||||
|
// writes it (check.ts; ADR 0521, R4e finding R2-1). No tool writes mesh/check (finding K1), and no event: the watch hands
|
||||||
|
// over the latest value of every key whenever this module starts.
|
||||||
//
|
//
|
||||||
// Consumes node-build-agent.started — a build machine took an ask — and says, on the head a pending check is of,
|
// Consumes node-build-agent.started — a build machine took an ask — and says, on the head a pending check is of,
|
||||||
// which machine builds it since when (novox/hq issue 446). This module is the one writer of mesh/merge-gate.
|
// which machine builds it since when (novox/hq issue 446). This module is the one writer of mesh/merge-gate.
|
||||||
@@ -41,7 +45,9 @@
|
|||||||
import { emit, on } from "@novox/mesh-sdk/events";
|
import { emit, on } from "@novox/mesh-sdk/events";
|
||||||
import { registerModuleTools } from "@novox/mesh-sdk/tools";
|
import { registerModuleTools } from "@novox/mesh-sdk/tools";
|
||||||
import { statesAnnouncement } from "./kept.js";
|
import { statesAnnouncement } from "./kept.js";
|
||||||
import { checkStatusTool, commitStatusTool } from "./delivery.js";
|
import { commitStatusTool } from "./delivery.js";
|
||||||
|
import { CHECKER_OWED, CheckStatuses, watchOwed, type OwedChange } from "./check.js";
|
||||||
|
import { state } from "@novox/mesh-sdk/state";
|
||||||
import { announce, keepWatermark, readWatermark } from "./announce.js";
|
import { announce, keepWatermark, readWatermark } from "./announce.js";
|
||||||
import { mergeTool } from "./merge.js";
|
import { mergeTool } from "./merge.js";
|
||||||
import { GiteaAdmin, GiteaClient, movedSince } from "./client.js";
|
import { GiteaAdmin, GiteaClient, movedSince } from "./client.js";
|
||||||
@@ -475,6 +481,11 @@ const gates = new GateWriter({
|
|||||||
headChecks: (owner, repo, sha) => (gitea as GiteaClient).headChecks(owner, repo, sha),
|
headChecks: (owner, repo, sha) => (gitea as GiteaClient).headChecks(owner, repo, sha),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The one writer of mesh/check, from the checker's owed (check.ts; ADR 0521).
|
||||||
|
const checks = new CheckStatuses({
|
||||||
|
setCommitStatus: (owner, repo, sha, status) => (gitea as GiteaClient).setCommitStatus(owner, repo, sha, status),
|
||||||
|
});
|
||||||
|
|
||||||
// **The status tool is served here, beside the writer** (novox/hq issue 456): the runtime starts each bundle as its own
|
// **The status tool is served here, beside the writer** (novox/hq issue 456): the runtime starts each bundle as its own
|
||||||
// process, so a recheck's pending written from the tools' bundle bypassed this writer's chain. Without a forge to
|
// process, so a recheck's pending written from the tools' bundle bypassed this writer's chain. Without a forge to
|
||||||
// reach, nothing is served, as the tools' bundle serves nothing then.
|
// reach, nothing is served, as the tools' bundle serves nothing then.
|
||||||
@@ -491,8 +502,6 @@ await emit("states", statesAnnouncement(process.env.MESH_MODULE || "gitea", proc
|
|||||||
registerModuleTools("gitea", () => [eventsTool(pace), ...(gitea ? [commitStatusTool({
|
registerModuleTools("gitea", () => [eventsTool(pace), ...(gitea ? [commitStatusTool({
|
||||||
setCommitStatus: (owner, repo, sha, status) => (gitea as GiteaClient).setCommitStatus(owner, repo, sha, status),
|
setCommitStatus: (owner, repo, sha, status) => (gitea as GiteaClient).setCommitStatus(owner, repo, sha, status),
|
||||||
gates,
|
gates,
|
||||||
}), checkStatusTool({
|
|
||||||
setCommitStatus: (owner, repo, sha, status) => (gitea as GiteaClient).setCommitStatus(owner, repo, sha, status),
|
|
||||||
}), mergeTool(gitea, { gates })] : [])]);
|
}), mergeTool(gitea, { gates })] : [])]);
|
||||||
|
|
||||||
// **A build machine took an ask** (the build seat's `started`, novox/hq ADR 0157): said on the head it checks, when
|
// **A build machine took an ask** (the build seat's `started`, novox/hq ADR 0157): said on the head it checks, when
|
||||||
@@ -621,4 +630,7 @@ if (gitea) {
|
|||||||
})],
|
})],
|
||||||
["node-build-agent.started", () => on("node-build-agent.started", buildStarted)],
|
["node-build-agent.started", () => on("node-build-agent.started", buildStarted)],
|
||||||
], () => console.log("[gitea] watching for new repositories and merged pull requests"));
|
], () => console.log("[gitea] watching for new repositories and merged pull requests"));
|
||||||
|
// The checker's mesh/check, from its owed state (check.ts; ADR 0521): a read not granted yet is said once and asked again,
|
||||||
|
// apart from the binds above, so neither waits for the other.
|
||||||
|
void watchOwed((handler) => state<OwedChange["value"]>(CHECKER_OWED).watch((change) => handler(change)), checks);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -543,6 +543,7 @@
|
|||||||
"ssh-client.keys",
|
"ssh-client.keys",
|
||||||
"mesh-build-go.keys",
|
"mesh-build-go.keys",
|
||||||
"mesh-build-node.keys",
|
"mesh-build-node.keys",
|
||||||
"mesh-build-image.keys"
|
"mesh-build-image.keys",
|
||||||
|
"mesh-delivery-checker.owed"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export const CHECK_CONTEXT = "mesh/merge-gate";
|
|||||||
/** The status context of the repository's own merge-check.sh, the check's second layer (novox/hq ADR 0237). */
|
/** The status context of the repository's own merge-check.sh, the check's second layer (novox/hq ADR 0237). */
|
||||||
export const REPO_CHECK_CONTEXT = "mesh/repo-check";
|
export const REPO_CHECK_CONTEXT = "mesh/repo-check";
|
||||||
|
|
||||||
/** The one status main requires (novox/hq ADR 0447 §1, issue 1301): the checker's verdict, written by its forge bridge
|
/** The one status main requires (novox/hq ADR 0447 §1, issue 1301): the checker's verdict, written by this module from the
|
||||||
* through gitea_check_status. Its line names the head and the trunk commit it judged: "pass <head12> on <trunk12> …". */
|
* checker's owed state (check.ts, ADR 0521). Its line names the head and the trunk commit it judged: "pass <head12> on <trunk12> …". */
|
||||||
export const CHECK_STATUS = "mesh/check";
|
export const CHECK_STATUS = "mesh/check";
|
||||||
|
|
||||||
/** The statuses a branch's rule requires, from the rule the forge applies to it: none when it is unprotected or checks
|
/** The statuses a branch's rule requires, from the rule the forge applies to it: none when it is unprotected or checks
|
||||||
|
|||||||
@@ -36,3 +36,76 @@ test("importing the bundle resolves while the broker keeps refusing the binds",
|
|||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
assert.match(out, /imported/, `the import did not resolve within 3 s while a bind was refused; stderr: ${err.slice(0, 600)}`);
|
assert.match(out, /imported/, `the import did not resolve within 3 s while a bind was refused; stderr: ${err.slice(0, 600)}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// **The bundle writes mesh/check from the checker's owed state, and serves no tool that writes it** (ADR 0521; R4e round 2
|
||||||
|
// finding R2-1; finding K1). The bundle is imported whole, as the runtime imports it, while its read of the checker's owed
|
||||||
|
// is refused (the grant not yet composed): the watch is asked again, and once granted it is handed the bucket as the bus
|
||||||
|
// keeps it, the latest revision of each key, then an older revision delivered late. The forge stand-in sees the latest
|
||||||
|
// written, and nothing after it.
|
||||||
|
test("a bundle whose read of the checker's owed is granted late writes the latest mesh/check, and serves no gitea_check_status", async () => {
|
||||||
|
const index = pathToFileURL(join(here, "..", "dist", "index.js")).href;
|
||||||
|
const sha = "0123456789abcdef0123456789abcdef01234567";
|
||||||
|
const script = `
|
||||||
|
const http = await import("node:http");
|
||||||
|
const statuses = [];
|
||||||
|
const forge = http.createServer((req, res) => {
|
||||||
|
let b = ""; req.on("data", (d) => (b += d)); req.on("end", () => {
|
||||||
|
if (req.method === "POST" && /\\/statuses\\//.test(req.url)) statuses.push(req.url + " " + b);
|
||||||
|
res.setHeader("content-type", "application/json"); res.end(req.method === "GET" ? "[]" : "{}");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
await new Promise((r) => forge.listen(0, "127.0.0.1", r));
|
||||||
|
process.env.MESH_GITEA_URL = "http://127.0.0.1:" + forge.address().port;
|
||||||
|
const bound = [];
|
||||||
|
const { useBroker } = await import("@novox/mesh-sdk/messaging");
|
||||||
|
useBroker(() => ({
|
||||||
|
subscribe: async (pattern) => { bound.push(pattern); return () => {}; },
|
||||||
|
publish: async () => {}, request: async () => { throw new Error("no responders"); },
|
||||||
|
handle: async () => () => {}, close: async () => {},
|
||||||
|
}));
|
||||||
|
const key = "novox/mesh-sdk.12.${sha}.status=mesh/check";
|
||||||
|
const owed = (state, text) => ({ v: 1, act: "status", context: "mesh/check", state, text, target: "https://view.example/c" });
|
||||||
|
const watched = [];
|
||||||
|
let granted = 0;
|
||||||
|
const { useStateChannel } = await import("@novox/mesh-sdk/state");
|
||||||
|
useStateChannel({
|
||||||
|
ask: async () => null,
|
||||||
|
watch: async (params, deliver) => {
|
||||||
|
watched.push(params.state);
|
||||||
|
if (watched.length === 1) throw new Error('gitea keeps and reads no state called "mesh-delivery-checker.owed"');
|
||||||
|
granted++;
|
||||||
|
// Two revisions were written while the read was refused; the bucket hands the latest, then a late older one.
|
||||||
|
await deliver({ state: params.state, key, op: "put", value: owed("success", "pass at 4"), revision: 4, current: true });
|
||||||
|
await deliver({ state: params.state, key, op: "put", value: owed("pending", "pending at 3"), revision: 3, current: false });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await import(${JSON.stringify(index)});
|
||||||
|
const { collectTools } = await import("@novox/mesh-sdk/tools");
|
||||||
|
const tools = collectTools().flatMap((r) => r.tools.map((t) => t.name));
|
||||||
|
for (let i = 0; i < 300 && !(granted && statuses.length); i++) await new Promise((r) => setTimeout(r, 20));
|
||||||
|
await new Promise((r) => setTimeout(r, 200));
|
||||||
|
console.log(JSON.stringify({ tools, bound, watched, statuses }));
|
||||||
|
process.exit(0);`;
|
||||||
|
const env = { ...process.env, MESH_GITEA_TOKEN: "x" };
|
||||||
|
for (const k of ["MESH_GITEA_STATE_DIR", "MESH_GITEA_ADMIN_USER", "MESH_GITEA_ADMIN_PASSWORD", "MESH_SERVED_MODULE", "MESH_GITEA_URL"]) delete env[k];
|
||||||
|
const child = spawn(process.execPath, ["--input-type=module", "-e", script], { cwd: join(here, ".."), env, stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
let out = "";
|
||||||
|
let err = "";
|
||||||
|
child.stdout.on("data", (d) => (out += d));
|
||||||
|
child.stderr.on("data", (d) => (err += d));
|
||||||
|
const ended = new Promise<void>((r) => child.on("exit", () => r()));
|
||||||
|
const timer = setTimeout(() => child.kill("SIGKILL"), 15000);
|
||||||
|
await ended;
|
||||||
|
clearTimeout(timer);
|
||||||
|
const line = out.split("\n").find((l) => l.startsWith("{"));
|
||||||
|
assert.ok(line, `the bundle said nothing; stdout: ${out.slice(0, 400)} stderr: ${err.slice(0, 600)}`);
|
||||||
|
const got = JSON.parse(line!) as { tools: string[]; bound: string[]; watched: string[]; statuses: string[] };
|
||||||
|
assert.ok(got.tools.includes("gitea_commit_status"), `the bundle's tools: ${got.tools}`);
|
||||||
|
assert.ok(!got.tools.includes("gitea_check_status"), "no tool writes mesh/check");
|
||||||
|
assert.ok(!got.bound.some((p) => p.includes("check.status")), `bound: ${got.bound}`);
|
||||||
|
assert.deepEqual(got.watched, ["mesh-delivery-checker.owed", "mesh-delivery-checker.owed"], "refused, then asked again");
|
||||||
|
assert.equal(got.statuses.length, 1, `statuses written: ${got.statuses}`);
|
||||||
|
assert.match(got.statuses[0], new RegExp(`/repos/novox/mesh-sdk/statuses/${sha} .*"context":"mesh/check"`));
|
||||||
|
assert.match(got.statuses[0], /"state":"success".*pass at 4/);
|
||||||
|
assert.match(err, /mesh-delivery-checker\.owed could not be bound/, "the refusal is said");
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
// **mesh/check is written from the checker's owed state, read by a watch** (ADR 0521; R4e round 2 finding R2-1; finding K1
|
||||||
|
// before it). No tool writes mesh/check, since a tool is told no caller and node-tools invokes every tool. Nor does an event:
|
||||||
|
// nothing in the delivery plan orders this module before the forge bridge, and a durable consumer whose filters change keeps
|
||||||
|
// its deliver policy, so an event said before this module consumed it was lost. A watch of the checker's state hands over
|
||||||
|
// the latest value of every key when it starts, whenever that is.
|
||||||
|
|
||||||
|
import { test } from "node:test";
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
|
||||||
|
const sha = "0123456789abcdef0123456789abcdef01234567";
|
||||||
|
const key = (s = sha, repo = "novox/mesh-sdk", n = 12) => `${repo}.${n}.${s}.status=mesh/check`;
|
||||||
|
const owed = (over: Record<string, unknown> = {}) => ({ v: 1, act: "status", context: "mesh/check", state: "success",
|
||||||
|
text: "pass 0123456789ab on aaaaaaaaaaaa", target: "https://view.example/checks/g.1", ...over });
|
||||||
|
const put = (k: string, value: unknown, revision: number, current = false) =>
|
||||||
|
({ state: "mesh-delivery-checker.owed", key: k, op: "put" as const, value, revision, current });
|
||||||
|
|
||||||
|
function forge() {
|
||||||
|
const sent: string[] = [];
|
||||||
|
let failing = 0;
|
||||||
|
return {
|
||||||
|
sent,
|
||||||
|
fail: (n: number) => { failing = n; },
|
||||||
|
setCommitStatus: async (o: string, r: string, s: string, st: any) => {
|
||||||
|
if (failing > 0) { failing--; throw new Error("Gitea API /repos/x/statuses: 502 bad gateway"); }
|
||||||
|
sent.push(`${o}/${r}@${s.slice(0, 8)} ${st.context} ${st.state} ${st.description}${st.target_url ? " " + st.target_url : ""}`);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const noSleep = async () => {};
|
||||||
|
|
||||||
|
test("the checker's owed is what this module reads, and it consumes no check.status", async () => {
|
||||||
|
const { CHECKER_OWED } = await import("../check.ts");
|
||||||
|
assert.equal(CHECKER_OWED, "mesh-delivery-checker.owed");
|
||||||
|
const manifest = JSON.parse(readFileSync(new URL("../module.json", import.meta.url), "utf8"));
|
||||||
|
assert.ok(manifest.reads.includes(CHECKER_OWED), "gitea's manifest reads the checker's owed");
|
||||||
|
assert.ok(!manifest.consumes.some((c: string) => c.includes("check.status")), "no check.status is consumed");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("an owed mesh/check writes the status on its head: its state, its line cut and its link", async () => {
|
||||||
|
const { CheckStatuses } = await import("../check.ts");
|
||||||
|
const f = forge();
|
||||||
|
const checks = new CheckStatuses(f, () => {}, noSleep);
|
||||||
|
assert.equal(await checks.apply(put(key(), owed(), 7, true)), "written");
|
||||||
|
const other = sha.replace(/0/g, "f");
|
||||||
|
assert.equal(await checks.apply(put(key(other, "novox/my=2erepo"), owed({ state: "pending", text: "y".repeat(300), target: "javascript:x" }), 8)), "written");
|
||||||
|
assert.equal(f.sent[0], "novox/mesh-sdk@01234567 mesh/check success pass 0123456789ab on aaaaaaaaaaaa https://view.example/checks/g.1");
|
||||||
|
assert.ok(f.sent[1].startsWith("novox/my.repo@f1234567 mesh/check pending yyyy"), f.sent[1]);
|
||||||
|
assert.ok(f.sent[1].length < 200, "the line is cut as every status's is");
|
||||||
|
assert.ok(!f.sent[1].includes("javascript"), "a link that is no web page is not written");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a key or value that is no owed mesh/check, and a delete, write nothing", async () => {
|
||||||
|
const { CheckStatuses } = await import("../check.ts");
|
||||||
|
const f = forge();
|
||||||
|
const checks = new CheckStatuses(f, () => {}, noSleep);
|
||||||
|
const cases = [
|
||||||
|
put(key(sha.slice(0, 12)), owed(), 1), put(`novox/mesh-sdk.12.${sha}.status=mesh/merge-gate`, owed(), 1),
|
||||||
|
put(`novox/mesh-sdk.12.${sha}.view`, owed(), 1), put(`nokey`, owed(), 1), put(`../x/y.12.${sha}.status=mesh/check`, owed(), 1),
|
||||||
|
put(key(), owed({ context: "mesh/delivery" }), 1), put(key(), owed({ act: "view" }), 1), put(key(), owed({ state: "green" }), 1),
|
||||||
|
put(key(), owed({ v: 2 }), 1), put(key(), null, 1), put(key(), "text", 1), put(key(), owed(), -1),
|
||||||
|
{ state: "mesh-delivery-checker.owed", key: key(), op: "delete" as const, revision: 2, current: false },
|
||||||
|
];
|
||||||
|
for (const c of cases) assert.equal(await checks.apply(c as any), "dropped", JSON.stringify(c));
|
||||||
|
assert.deepEqual(f.sent, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a revision older than one written on the key is dropped; the same one is written again", async () => {
|
||||||
|
const { CheckStatuses } = await import("../check.ts");
|
||||||
|
const f = forge();
|
||||||
|
const checks = new CheckStatuses(f, () => {}, noSleep);
|
||||||
|
await checks.apply(put(key(), owed({ state: "success" }), 10));
|
||||||
|
assert.equal(await checks.apply(put(key(), owed({ state: "pending" }), 9)), "dropped", "a stale pending never hides the verdict");
|
||||||
|
assert.equal(await checks.apply(put(key(), owed({ state: "success" }), 10)), "written");
|
||||||
|
assert.equal(await checks.apply(put(key(sha.replace(/1/g, "2")), owed({ state: "pending" }), 3)), "written", "another key is its own");
|
||||||
|
assert.equal(await checks.apply(put(key(), owed({ state: "pending" }), 11)), "written");
|
||||||
|
assert.deepEqual(f.sent.map((s) => s.split(" ").slice(0, 3).join(" ")), ["novox/mesh-sdk@01234567 mesh/check success",
|
||||||
|
"novox/mesh-sdk@01234567 mesh/check success", "novox/mesh-sdk@02234567 mesh/check pending", "novox/mesh-sdk@01234567 mesh/check pending"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a forge that refuses is asked again until it writes, unless a newer revision of the key came meanwhile", async () => {
|
||||||
|
const { CheckStatuses } = await import("../check.ts");
|
||||||
|
const f = forge();
|
||||||
|
const said: string[] = [];
|
||||||
|
const waits: number[] = [];
|
||||||
|
const checks = new CheckStatuses(f, (l) => said.push(l), async (ms) => { waits.push(ms); });
|
||||||
|
f.fail(2);
|
||||||
|
await checks.take(put(key(), owed({ state: "success" }), 5));
|
||||||
|
await checks.settled();
|
||||||
|
assert.deepEqual(f.sent.map((s) => s.split(" ")[2]), ["success"], "written on the third ask");
|
||||||
|
assert.deepEqual(waits, [2_000, 5_000]);
|
||||||
|
assert.match(said[0], /502.*asked again/);
|
||||||
|
// A refusal whose key moved on meanwhile is not asked again: the newer revision is written, the older never after it.
|
||||||
|
const g = forge();
|
||||||
|
let release: () => void = () => {};
|
||||||
|
const gate = new Promise<void>((r) => { release = r; });
|
||||||
|
const later = new CheckStatuses(g, () => {}, () => gate);
|
||||||
|
g.fail(1);
|
||||||
|
await later.take(put(key(), owed({ state: "pending" }), 6));
|
||||||
|
await later.take(put(key(), owed({ state: "success" }), 7));
|
||||||
|
release();
|
||||||
|
await later.settled();
|
||||||
|
assert.deepEqual(g.sent.map((s) => s.split(" ")[2]), ["success"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a watch refused at first is asked again, said once, and once granted writes the latest revision of each key", async () => {
|
||||||
|
const { CheckStatuses, watchOwed } = await import("../check.ts");
|
||||||
|
const f = forge();
|
||||||
|
const said: string[] = [];
|
||||||
|
const checks = new CheckStatuses(f, () => {}, noSleep);
|
||||||
|
// The checker's bucket as the bus keeps it: two revisions of one key written while the read was refused.
|
||||||
|
const kept = new Map<string, { value: unknown; revision: number }>();
|
||||||
|
kept.set(key(), { value: owed({ state: "pending" }), revision: 3 });
|
||||||
|
kept.set(key(), { value: owed({ state: "success" }), revision: 4 });
|
||||||
|
let asked = 0;
|
||||||
|
const watch = async (handler: (c: any) => Promise<void>) => {
|
||||||
|
asked++;
|
||||||
|
if (asked < 3) throw new Error("gitea keeps and reads no state called \"mesh-delivery-checker.owed\"");
|
||||||
|
for (const [k, e] of kept) await handler(put(k, e.value, e.revision, true));
|
||||||
|
};
|
||||||
|
await watchOwed(watch, checks, noSleep, (l) => said.push(l));
|
||||||
|
await checks.settled();
|
||||||
|
assert.equal(asked, 3);
|
||||||
|
assert.deepEqual(f.sent.map((s) => s.split(" ")[2]), ["success"], "only the latest revision is written");
|
||||||
|
assert.equal(said.filter((l) => /could not be bound/.test(l)).length, 1, `said once: ${said.join(" | ")}`);
|
||||||
|
assert.ok(said.some((l) => /bound after 3 attempts/.test(l)), said.join(" | "));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("no tool writes mesh/check: gitea_check_status is gone and gitea_commit_status refuses it", async () => {
|
||||||
|
const delivery = await import("../delivery.ts");
|
||||||
|
assert.equal((delivery as Record<string, unknown>).checkStatusTool, undefined, "delivery.ts serves no gitea_check_status");
|
||||||
|
assert.throws(() => delivery.deliveryStatus("mesh/check", "success", "x"), /mesh-delivery-checker\.owed/);
|
||||||
|
const index = readFileSync(new URL("../index.ts", import.meta.url), "utf8");
|
||||||
|
assert.ok(!/gitea_check_status|checkStatusTool/.test(index), "index.ts serves no gitea_check_status");
|
||||||
|
});
|
||||||
@@ -62,37 +62,20 @@ test("one view per pull request, found by its marker; only the mesh's statuses",
|
|||||||
assert.equal(deliveryStatus("mesh/delivery", "success", "x", "javascript:alert(1)").target_url, undefined);
|
assert.equal(deliveryStatus("mesh/delivery", "success", "x", "javascript:alert(1)").target_url, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Issue 1301-S4 (ADR 0447 §1; the lead's choice A): main requires mesh/check, so no hand may set it. The status tool
|
// Issue 1301-S4 (ADR 0447 §1; R4e findings K1 and R2-1): main requires mesh/check, so no hand may set it. The status tool
|
||||||
// every caller may use refuses it in every state; it is written only by gitea_check_status, which the forge bridge
|
// every caller may use refuses it in every state; no tool writes it at all: it is written from the checker's owed state
|
||||||
// alone lists in its manifest's `invokes`, so only its account may call it.
|
// (check.ts, test/check-owed.test.ts; ADR 0521).
|
||||||
test("mesh/check is refused by the status tool and written by the check's own tool alone", async () => {
|
test("mesh/check is refused by the status tool in every state", async () => {
|
||||||
const { commitStatusTool, checkStatusTool, deliveryStatus, CHECK_STATUS } = await import("../delivery.ts");
|
const { commitStatusTool, deliveryStatus, CHECK_STATUS } = await import("../delivery.ts");
|
||||||
assert.equal(CHECK_STATUS, "mesh/check");
|
assert.equal(CHECK_STATUS, "mesh/check");
|
||||||
const sha = "0123456789abcdef0123456789abcdef01234567";
|
const sha = "0123456789abcdef0123456789abcdef01234567";
|
||||||
const sent: string[] = [];
|
const sent: string[] = [];
|
||||||
const setCommitStatus = async (o: string, r: string, s: string, st: any) =>
|
const setCommitStatus = async (o: string, r: string, s: string, st: any) => void sent.push(`${o}/${r}@${s} ${st.context}`);
|
||||||
void sent.push(`${o}/${r}@${s.slice(0, 8)} ${st.context} ${st.state} ${st.description}${st.target_url ? " " + st.target_url : ""}`);
|
|
||||||
const gates = { rechecked: async () => { throw new Error("not the gate writer's"); } };
|
const gates = { rechecked: async () => { throw new Error("not the gate writer's"); } };
|
||||||
for (const state of ["pending", "success", "failure", "error", "warning"]) {
|
for (const state of ["pending", "success", "failure", "error", "warning"]) {
|
||||||
assert.throws(() => deliveryStatus("mesh/check", state, "x"), /mesh\/check is the checker's status/);
|
assert.throws(() => deliveryStatus("mesh/check", state, "x"), /mesh\/check is the checker's status/);
|
||||||
await assert.rejects(commitStatusTool({ setCommitStatus, gates } as any).run({ owner: "novox", repo: "mesh-sdk", sha,
|
await assert.rejects(commitStatusTool({ setCommitStatus, gates } as any).run({ owner: "novox", repo: "mesh-sdk", sha,
|
||||||
context: "mesh/check", state, description: "by hand" }), /gitea_check_status/);
|
context: "mesh/check", state, description: "by hand" }), /mesh-delivery-checker\.owed/);
|
||||||
}
|
}
|
||||||
assert.deepEqual(sent, [], "nothing was sent for a hand-set mesh/check");
|
assert.deepEqual(sent, [], "nothing was sent for a hand-set mesh/check");
|
||||||
|
|
||||||
const tool = checkStatusTool({ setCommitStatus });
|
|
||||||
assert.equal(tool.name, "gitea_check_status");
|
|
||||||
for (const k of ["owner", "repo", "sha", "state", "description", "target_url", "context"]) assert.ok(k in tool.input, k);
|
|
||||||
// The bridge's arguments as it sends them for gitea_commit_status: the context may be given, and is mesh/check.
|
|
||||||
await tool.run({ owner: "novox", repo: "mesh-sdk", sha, context: "mesh/check", state: "success", description: "pass",
|
|
||||||
target_url: "https://forge.invalid/novox/mesh-sdk/pulls/1" });
|
|
||||||
await tool.run({ owner: "novox", repo: "mesh-sdk", sha, state: "pending", description: "y".repeat(300) });
|
|
||||||
assert.equal(sent[0], "novox/mesh-sdk@01234567 mesh/check success pass https://forge.invalid/novox/mesh-sdk/pulls/1");
|
|
||||||
assert.ok(sent[1].startsWith("novox/mesh-sdk@01234567 mesh/check pending yyyy"), sent[1]);
|
|
||||||
assert.ok(sent[1].length < 200, "the description is cut as every status's is");
|
|
||||||
await assert.rejects(tool.run({ owner: "novox", repo: "mesh-sdk", sha, context: "mesh/delivery", state: "success" }), /mesh\/check alone/);
|
|
||||||
await assert.rejects(tool.run({ owner: "novox", repo: "mesh-sdk", sha: sha.slice(0, 12), state: "success" }), /whole sha/);
|
|
||||||
await assert.rejects(tool.run({ owner: "novox", repo: "mesh-sdk", sha, state: "green" }), /not a status/);
|
|
||||||
await assert.rejects(tool.run({ owner: "../x", repo: "mesh-sdk", sha, state: "success" }));
|
|
||||||
assert.equal(sent.length, 2, "nothing more was sent");
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { GiteaClient } from "../dist/client.js";
|
|||||||
import { ConfiguredToken } from "../dist/token.js";
|
import { ConfiguredToken } from "../dist/token.js";
|
||||||
import { getGiteaTools } from "../dist/tools/index.js";
|
import { getGiteaTools } from "../dist/tools/index.js";
|
||||||
import { mergeTool } from "../dist/merge.js";
|
import { mergeTool } from "../dist/merge.js";
|
||||||
import { checkStatusTool, commitStatusTool } from "../dist/delivery.js";
|
import { commitStatusTool } from "../dist/delivery.js";
|
||||||
import { GateWriter } from "../dist/gate.js";
|
import { GateWriter } from "../dist/gate.js";
|
||||||
import { judgeApiCall, judgeProtectionChange, ruleCovers, routedPath } from "../dist/guard.js";
|
import { judgeApiCall, judgeProtectionChange, ruleCovers, routedPath } from "../dist/guard.js";
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ const gates = { rechecked: (o: string, r: string, sha: string, s: any) => {
|
|||||||
} };
|
} };
|
||||||
const tools = [...getGiteaTools(client), commitStatusTool({
|
const tools = [...getGiteaTools(client), commitStatusTool({
|
||||||
setCommitStatus: (o, r, sha, s) => client.setCommitStatus(o, r, sha, s), gates: writer,
|
setCommitStatus: (o, r, sha, s) => client.setCommitStatus(o, r, sha, s), gates: writer,
|
||||||
}), checkStatusTool({ setCommitStatus: (o, r, sha, s) => client.setCommitStatus(o, r, sha, s) }), mergeTool(client, { gates, stateDir, emit: async (type, body) => { state.emitted.push({ type, body }); },
|
}), mergeTool(client, { gates, stateDir, emit: async (type, body) => { state.emitted.push({ type, body }); },
|
||||||
now: () => new Date(2026, 9, 12, 15, 1) })];
|
now: () => new Date(2026, 9, 12, 15, 1) })];
|
||||||
const tool = (name: string) => tools.find((t) => t.name === name)!;
|
const tool = (name: string) => tools.find((t) => t.name === name)!;
|
||||||
const writes = () => state.sent.map((s) => `${s.method} ${s.path}`);
|
const writes = () => state.sent.map((s) => `${s.method} ${s.path}`);
|
||||||
@@ -568,9 +568,6 @@ test("no tool's caller text becomes another path or another user: `..` and `?sud
|
|||||||
["gitea_get_file", { ...repo, path: "README.md?sudo=jschoubben" }],
|
["gitea_get_file", { ...repo, path: "README.md?sudo=jschoubben" }],
|
||||||
["gitea_commit_status", { ...repo, sha: "abc1234?sudo=jschoubben", context: "mesh/delivery", state: "success" }],
|
["gitea_commit_status", { ...repo, sha: "abc1234?sudo=jschoubben", context: "mesh/delivery", state: "success" }],
|
||||||
["gitea_commit_status", { ...repo, sha: "../../../admin/users", context: "mesh/delivery", state: "success" }],
|
["gitea_commit_status", { ...repo, sha: "../../../admin/users", context: "mesh/delivery", state: "success" }],
|
||||||
["gitea_check_status", { ...repo, sha: "abc1234?sudo=jschoubben", state: "success" }],
|
|
||||||
["gitea_check_status", { ...repo, sha: "../../../admin/users", state: "success" }],
|
|
||||||
["gitea_check_status", { owner: "novox", repo: "..", sha: "0123456789abcdef0123456789abcdef01234567", state: "success" }],
|
|
||||||
["gitea_commit_status", { ...repo, sha: "0123456789abcdef0123456789abcdef01234567", context: "mesh/check", state: "success" }],
|
["gitea_commit_status", { ...repo, sha: "0123456789abcdef0123456789abcdef01234567", context: "mesh/check", state: "success" }],
|
||||||
["gitea_commit_statuses", { ...repo, sha: ".." }],
|
["gitea_commit_statuses", { ...repo, sha: ".." }],
|
||||||
["gitea_commit_statuses", { ...repo, sha: "main?sudo=jschoubben" }],
|
["gitea_commit_statuses", { ...repo, sha: "main?sudo=jschoubben" }],
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ import (
|
|||||||
|
|
||||||
// ADR 0499 §4 (issue 1758): a fetch asked with the module's directory and its named paths leaves the workspace holding
|
// ADR 0499 §4 (issue 1758): a fetch asked with the module's directory and its named paths leaves the workspace holding
|
||||||
// only those, the manifest and the lock files; the rest of the commit is gone before any run step; a request naming
|
// only those, the manifest and the lock files; the rest of the commit is gone before any run step; a request naming
|
||||||
// paths without a directory is refused before anything is fetched.
|
// paths without a directory is refused before anything is fetched. go.mod is kept only when named among the paths
|
||||||
|
// (mesh-sdk's narrowKept is the manifest and the lock files, review finding S1), as a Go build that names its paths does.
|
||||||
func TestAFetchWithNamedPathsNarrowsTheWorkspace(t *testing.T) {
|
func TestAFetchWithNamedPathsNarrowsTheWorkspace(t *testing.T) {
|
||||||
f := newForge(t)
|
f := newForge(t)
|
||||||
_, head := f.repo("novox/narrow", map[string]string{
|
_, head := f.repo("novox/narrow", map[string]string{
|
||||||
@@ -26,7 +27,7 @@ func TestAFetchWithNamedPathsNarrowsTheWorkspace(t *testing.T) {
|
|||||||
"other/o.go": "package other\n",
|
"other/o.go": "package other\n",
|
||||||
})
|
})
|
||||||
m, states := f.module(t)
|
m, states := f.module(t)
|
||||||
res, st := fetched(t, m, states, map[string]any{"repository": "novox/narrow", "commit": head, "dir": "lib", "paths": []any{"cmd"}})
|
res, st := fetched(t, m, states, map[string]any{"repository": "novox/narrow", "commit": head, "dir": "lib", "paths": []any{"cmd", "go.mod"}})
|
||||||
if st.State != delivery.StepPassed {
|
if st.State != delivery.StepPassed {
|
||||||
t.Fatalf("the fetch ended %s: %s", st.State, st.Reason)
|
t.Fatalf("the fetch ended %s: %s", st.State, st.Reason)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module meshbuildgo
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9
|
||||||
github.com/distribution/distribution/v3 v3.1.2
|
github.com/distribution/distribution/v3 v3.1.2
|
||||||
github.com/nats-io/nats-server/v2 v2.11.17
|
github.com/nats-io/nats-server/v2 v2.11.17
|
||||||
github.com/nats-io/nats.go v1.54.0
|
github.com/nats-io/nats.go v1.54.0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876 h1:dtiIJzrX7ey1wmsdzapiFgCKDllCph7/vxfUp1ib/t8=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9 h1:Ufmd2cYEXICQ817IGflccP9bexABE4WhIO49HPbaoSo=
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
||||||
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
|
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
|
||||||
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
|
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module meshbuildimage
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9
|
||||||
github.com/nats-io/nats-server/v2 v2.11.17
|
github.com/nats-io/nats-server/v2 v2.11.17
|
||||||
github.com/nats-io/nats.go v1.54.0
|
github.com/nats-io/nats.go v1.54.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876 h1:dtiIJzrX7ey1wmsdzapiFgCKDllCph7/vxfUp1ib/t8=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9 h1:Ufmd2cYEXICQ817IGflccP9bexABE4WhIO49HPbaoSo=
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
||||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module meshbuildnode
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9
|
||||||
github.com/distribution/distribution/v3 v3.1.2
|
github.com/distribution/distribution/v3 v3.1.2
|
||||||
github.com/nats-io/nats.go v1.54.0
|
github.com/nats-io/nats.go v1.54.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876 h1:dtiIJzrX7ey1wmsdzapiFgCKDllCph7/vxfUp1ib/t8=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9 h1:Ufmd2cYEXICQ817IGflccP9bexABE4WhIO49HPbaoSo=
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
||||||
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
|
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
|
||||||
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
|
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module mesh-delivery-gate
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9
|
||||||
github.com/nats-io/nats-server/v2 v2.11.17
|
github.com/nats-io/nats-server/v2 v2.11.17
|
||||||
github.com/nats-io/nats.go v1.54.0
|
github.com/nats-io/nats.go v1.54.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876 h1:dtiIJzrX7ey1wmsdzapiFgCKDllCph7/vxfUp1ib/t8=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9 h1:Ufmd2cYEXICQ817IGflccP9bexABE4WhIO49HPbaoSo=
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
||||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module pacman
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9
|
||||||
github.com/nats-io/nats-server/v2 v2.11.17
|
github.com/nats-io/nats-server/v2 v2.11.17
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876 h1:dtiIJzrX7ey1wmsdzapiFgCKDllCph7/vxfUp1ib/t8=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9 h1:Ufmd2cYEXICQ817IGflccP9bexABE4WhIO49HPbaoSo=
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022183749-875c680d9876/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261022190740-104533e8c0c9/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
||||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||||
|
|||||||
Reference in New Issue
Block a user