C1: the forge module says away when the forge or its store is away
A 401, 502, 503 or connection fault is judged by the forge's own unauthenticated version read: the read failing, or naming the store unavailable, answers the kind away with part and words, which every caller reads as a transport fault; the read passing, a 401 (the fresh token refused too) is the forge refusing the mesh's admin account, never worded as an account to create. Builds: design 47 H2 §776; H-A-350 DMC-2, H-A-354
This commit is contained in:
@@ -474,6 +474,7 @@ test("every read and act of the seat git answers its contract, and an error is a
|
||||
const SHA = "a".repeat(40), OTHER = "b".repeat(40);
|
||||
const gone = () => { throw new Error("Gitea API GET /repos/novox/app/pulls/9: 404 Not Found"); };
|
||||
const down = () => { throw new Error("Gitea API GET /repos/novox/app/x: 502 Bad Gateway"); };
|
||||
const unauthorized = () => { throw new Error("Gitea API /repos/novox/app/pulls/9: 401 Unauthorized"); };
|
||||
const pr = { number: 9, title: "t", state: "open", merged: false, head: "feat/x", head_sha: SHA, base: "main", user: "jochen", html_url: "http://f/9", mergeable: true };
|
||||
const tagged: string[] = [];
|
||||
let comments: { id: number; body: string }[] = [], noteShown = "", added = 0, noteWritten = 0;
|
||||
@@ -483,6 +484,7 @@ test("every read and act of the seat git answers its contract, and an error is a
|
||||
appliedProtection: async () => ({ rule_name: "main", enable_status_check: true, status_check_contexts: ["mesh/check"] }),
|
||||
getRepo: async () => ({ writes: true }),
|
||||
openPulls: async () => [{ owner: "novox", repo: "app", number: 9, base: "main", head: "feat/x", head_sha: SHA, required: ["mesh/check"], checks: {} }],
|
||||
forgeVersion: async () => ({ ok: true, version: "1.27.3" }),
|
||||
tags: async () => [{ tag: "go/v0.1.1", commit: SHA }, { tag: "go/v0.1.0", commit: OTHER }, { tag: "v1", commit: SHA }],
|
||||
commitTrees: async () => ({ root: SHA, trees: { "": SHA } }),
|
||||
getFile: async (_o: string, _r: string, path: string) => (path === "gone" ? (() => { throw new Error("Gitea API GET /repos/novox/app/contents/gone: 404 Not Found"); })() : path === "down" ? down() : { path, sha: OTHER, size: 3, content: "abc" }),
|
||||
@@ -505,6 +507,12 @@ test("every read and act of the seat git answers its contract, and an error is a
|
||||
["pull", "by merge commit", { repository: "novox/app", "merge-commit": OTHER }, {}, (a) => [a.pull.state, a.pull["merge-commit"], a.merging], ["merged", OTHER, undefined]],
|
||||
["pull", "unknown", { repository: "novox/app", number: 404 }, {}, (a) => [a.pull, a["error-kind"]], [undefined, "not-found"]],
|
||||
["pull", "forge down", { repository: "novox/app", number: 9 }, { getPullRequest: down }, (a) => [a.pull, a["error-kind"]], [undefined, "failed"]],
|
||||
// 47 H2 §776: a 401, 502, 503 or connection fault is away when the forge's version read fails or names its store
|
||||
// unavailable; with the read passing a 401 (the fresh token refused too) is the forge refusing the mesh's admin account.
|
||||
["pull", "502 and the version read failing is away", { repository: "novox/app", number: 9 }, { getPullRequest: down, forgeVersion: async () => ({ ok: false, words: "no answer", store: false }) }, (a) => [a.pull, a["error-kind"], a.part], [undefined, "away", "the forge"]],
|
||||
["pull", "401 and the store named unavailable is away", { repository: "novox/app", number: 9 }, { getPullRequest: unauthorized, forgeVersion: async () => ({ ok: false, words: "database is down", store: true }) }, (a) => [a["error-kind"], a.part, /401/.test(a.words)], ["away", "the forge's store", true]],
|
||||
["pull", "a connection fault and the version read failing is away", { repository: "novox/app", number: 9 }, { getPullRequest: async () => { throw new TypeError("fetch failed"); }, forgeVersion: async () => ({ ok: false, words: "fetch failed", store: false }) }, (a) => [a["error-kind"]], ["away"]],
|
||||
["pull", "401 with the version read passing is refused", { repository: "novox/app", number: 9 }, { getPullRequest: unauthorized }, (a) => [a["error-kind"], /refuses the mesh's admin account/.test(a.error), /[Cc]reate/.test(a.error)], ["refused", true, false]],
|
||||
["branch", "a branch's head, no protection read (ADR 0682 §13)", { repository: "novox/app", branch: "main" }, { branchHead: async () => SHA, appliedProtection: async () => { throw new Error("read"); } }, (a) => [a.head, a.protected, a.error], [SHA, undefined, undefined]],
|
||||
["branch", "no such branch", { repository: "novox/app", branch: "nope" }, { branchHead: gone }, (a) => [a.head, a["error-kind"]], [undefined, "not-found"]],
|
||||
["open-pulls", "one", {}, {}, (a) => [a.pulls.length, a.pulls[0].required], [1, ["mesh/check"]]],
|
||||
|
||||
@@ -125,3 +125,31 @@ test("the forge's tags are read with the commit each names", async () => {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
|
||||
// 47 H2 §776: the forge's own version read, unauthenticated, tells the forge away from its refusal.
|
||||
test("the forge's version read says whether the forge answers and whether its store is away", async () => {
|
||||
const { GiteaClient } = await import("../client.ts");
|
||||
let status = 200, body = `{"version":"1.27.3"}`;
|
||||
const auth: (string | undefined)[] = [];
|
||||
const server = createServer((req, res) => { auth.push(req.headers.authorization); res.statusCode = status; res.end(body); });
|
||||
await new Promise<void>((r) => server.listen(0, r));
|
||||
const port = (server.address() as any).port;
|
||||
try {
|
||||
const client = new GiteaClient(`http://127.0.0.1:${port}`, "t");
|
||||
const rows: [number, string, unknown][] = [
|
||||
[200, `{"version":"1.27.3"}`, { ok: true, version: "1.27.3" }],
|
||||
[500, "database is locked", { ok: false, store: true }],
|
||||
[503, "Service Unavailable", { ok: false, store: false }],
|
||||
];
|
||||
for (const [s, b, want] of rows) {
|
||||
status = s; body = b;
|
||||
const got: any = await client.forgeVersion();
|
||||
assert.deepEqual(got.ok ? got : { ok: got.ok, store: got.store }, want, `${s} ${b}`);
|
||||
}
|
||||
assert.deepEqual(auth.filter(Boolean), [], "the version read is unauthenticated");
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
const gone: any = await new GiteaClient(`http://127.0.0.1:${port}`, "t").forgeVersion();
|
||||
assert.deepEqual([gone.ok, gone.store], [false, false]);
|
||||
});
|
||||
|
||||
@@ -456,9 +456,9 @@ test("the admin account is refused: said plainly, nothing kept, and the next cal
|
||||
|
||||
await assert.rejects(client.listRepos(), (err: unknown) => {
|
||||
assert.ok(err instanceof AdminRefused, String(err));
|
||||
assert.match(err.message, /refused the admin account "mesh-admin" \(401\)/);
|
||||
assert.match(err.message, /admin-bootstrap step creates it/);
|
||||
assert.match(err.message, /came from a predecessor/);
|
||||
// 47 H2 §776: the forge's refusal, never worded as an account to create.
|
||||
assert.match(err.message, /the forge refuses the mesh's admin account "mesh-admin" \(401\)/);
|
||||
assert.doesNotMatch(err.message, /[Cc]reate/);
|
||||
assert.ok(!err.message.includes(PASSWORD));
|
||||
return true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user