From 74488f3e661a7229fc247b7eb163cafb869a94b1 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 02:59:05 +0100 Subject: [PATCH] Design 47 H1: the seat git answers a listing's missing directory not-found (H-A-232) A directory of a trees listing's files the commit does not hold was thrown as a plain error and answered with the kind failed, so the indexer took it for a forge that failed, never ran its one-directory fallback (issue 1585), and published nothing of the repository. commitTrees throws DirectoryNotInTree for it, and the seat's failure answers it with the kind not-found, the error naming the directory. Builds: design 47 H H-A-232 (2), H-A-234; issue 1585 --- modules/gitea/client.ts | 11 ++++++++++- modules/gitea/seat.ts | 5 ++++- modules/gitea/test/commit-trees.test.ts | 18 +++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/modules/gitea/client.ts b/modules/gitea/client.ts index 7720ff58d..1b761a8b3 100644 --- a/modules/gitea/client.ts +++ b/modules/gitea/client.ts @@ -182,6 +182,15 @@ export const FORGE_REQUEST_TIMEOUT_MS = 20_000; /** The most a tool's answer carries of one file: the bus's message bound is 1 MiB and a file travels as text (issue 1577). */ export const MAX_FILE_BYTES = 512 * 1024; +/** A directory of a listing's `files` the commit does not hold: the seat git answers it with the kind not-found, the error + * naming the directory (seat.ts failure; novox/hq design 47 H H-A-232). */ +export class DirectoryNotInTree extends Error { + constructor(message: string) { + super(message); + this.name = "DirectoryNotInTree"; + } +} + /** One request to the forge, cut at the limit and failing loud naming the request. */ async function timedFetch(url: string, init: RequestInit, label: string, timeoutMs: number): Promise { try { @@ -634,7 +643,7 @@ export class GiteaClient { // is whole (a cut one failed above), so a directory absent from it is absent at the commit. filesOf = {}; for (const dir of files) { - if (dir !== "" && dirOf.get(dir) === undefined) throw new Error(`the directory ${dir} is not in ${owner}/${repo} at ${sha}`); + if (dir !== "" && dirOf.get(dir) === undefined) throw new DirectoryNotInTree(`the directory ${dir} is not in ${owner}/${repo} at ${sha}`); const prefix = dir === "" ? "" : `${dir}/`; const blobs: Record = {}; for (const e of entries) { diff --git a/modules/gitea/seat.ts b/modules/gitea/seat.ts index dee5185b3..4af16387d 100644 --- a/modules/gitea/seat.ts +++ b/modules/gitea/seat.ts @@ -21,7 +21,7 @@ import { type TagAnswer, type TagsAnswer, type TreesAnswer, type ViewAnswer, } from "@novox/mesh-delivery-contracts-git"; import type { CommitStatus, GiteaClient, GiteaComment, GiteaPull } from "./client.js"; -import { MAX_FILE_BYTES } from "./client.js"; +import { DirectoryNotInTree, MAX_FILE_BYTES } from "./client.js"; import { containedFrom, newestByContext } from "./checks.js"; import { Refused, checkName } from "./guard.js"; import { appendNote, viewBody, viewComment, type Runner } from "./delivery.js"; @@ -64,6 +64,9 @@ export function failure(err: unknown): { error: string; "error-kind": ErrorKind const text = err instanceof Error ? err.message : String(err); // The forge's 404: what was asked about (a repository, a commit, a pull request, a branch, a tag) does not exist. if (/^Gitea API [^:]*: 404 /.test(text)) return { error: text, "error-kind": "not-found" }; + // A directory of `files` the commit does not hold (client.ts commitTrees): not-found, the error naming the directory, so the + // indexer reads the others alone and leaves the gone one out (novox/hq design 47 H H-A-232). + if (err instanceof DirectoryNotInTree) return { error: text, "error-kind": "not-found" }; const refused = err instanceof Refused || /^Gitea API [^:]*: 4\d\d /.test(text) || /^Gitea API: /.test(text); return { error: text, "error-kind": refused ? "refused" : "failed" }; } diff --git a/modules/gitea/test/commit-trees.test.ts b/modules/gitea/test/commit-trees.test.ts index 2be41705a..2ce6b6dc0 100644 --- a/modules/gitea/test/commit-trees.test.ts +++ b/modules/gitea/test/commit-trees.test.ts @@ -50,8 +50,9 @@ async function serve(pages: any[]) { res.end(JSON.stringify(pages[page - 1] ?? { sha: COMMIT, tree: [], truncated: false, page, total_count: 0 })); }); await new Promise((r) => server.listen(0, r)); - const client = new GiteaClient(`http://127.0.0.1:${(server.address() as any).port}`, "t"); - return { client, server, asked }; + const url = `http://127.0.0.1:${(server.address() as any).port}`; + const client = new GiteaClient(url, "t"); + return { client, server, asked, url }; } test("a commit's trees: the root and the tree of each directory holding a module.json", async () => { @@ -238,12 +239,19 @@ test("files: every blob under each asked directory, recursively, as its path rel }); test("a directory of files the commit lacks, or spelled badly, or a listing the forge cut, fails and answers nothing", async () => { - const { client, server } = await serve([{ sha: COMMIT, url: "u", tree: LISTING, truncated: false, page: 1, total_count: LISTING.length }]); + const { client, server, url } = await serve([{ sha: COMMIT, url: "u", tree: LISTING, truncated: false, page: 1, total_count: LISTING.length }]); try { - await assert.rejects(client.commitTrees("novox", "hq", COMMIT, undefined, ["modules/a", "modules/gone"]), (err: Error) => { - assert.match(err.message, /modules\/gone/); + // The seat answers it with the kind not-found naming the directory (novox/hq design 47 H H-A-232), never failed: the + // holder's own client and failure, as the module runs them. + const { failure } = await import("../dist/seat.js"); + const { GiteaClient } = await import("../dist/client.js"); + await assert.rejects(new GiteaClient(url, "t").commitTrees("novox", "hq", COMMIT, undefined, ["modules/a", "modules/gone"]), (err: Error) => { + const said = failure(err); + assert.equal(said["error-kind"], "not-found", JSON.stringify(said)); + assert.match(said.error, /the directory modules\/gone is not in novox\/hq/); return true; }); + await assert.rejects(client.commitTrees("novox", "hq", COMMIT, undefined, ["modules/a", "modules/gone"]), /modules\/gone/); await assert.rejects(client.commitTrees("novox", "hq", COMMIT, undefined, ["README.md"]), /README\.md/, "a file is no directory"); for (const bad of ["../x", "/abs", "a//b", "modules/a/", "."]) { await assert.rejects(client.commitTrees("novox", "hq", COMMIT, undefined, [bad]), /files/, bad); -- 2.54.0