diff --git a/modules/gitea/index.ts b/modules/gitea/index.ts index cca6f610..aa9550ad 100644 --- a/modules/gitea/index.ts +++ b/modules/gitea/index.ts @@ -38,8 +38,7 @@ import { emit, on } from "@novox/mesh-sdk/events"; import { registerModuleTools } from "@novox/mesh-sdk/tools"; -import { keeps } from "@novox/mesh-sdk/state"; -import { KEPT } from "./kept.js"; +import { statesAnnouncement } from "./kept.js"; import { commitStatusTool } from "./delivery.js"; import { announce, keepWatermark, readWatermark } from "./announce.js"; import { mergeTool } from "./merge.js"; @@ -476,7 +475,8 @@ const pace = new Pace(); if (!gitea) pace.unheard("the forge is not watched: no way to a token", false); // The states this module keeps and which others may read, said on the bus before it serves (novox/hq ADR 0495 clause 2). -await keeps(KEPT); +// Said with `emit`, not the SDK's `keeps`, which the toolchain's SDK does not have yet: switch to `keeps` once that SDK is 0.1.15 or later (issue 1852). +await emit("states", statesAnnouncement(process.env.MESH_MODULE || "gitea", process.env.MESH_NODE)); // gitea_events is served whether or not the forge is watched: it says so (novox/hq issue 729). registerModuleTools("gitea", () => [eventsTool(pace), ...(gitea ? [commitStatusTool({ diff --git a/modules/gitea/kept.ts b/modules/gitea/kept.ts index baa70f84..fccc5514 100644 --- a/modules/gitea/kept.ts +++ b/modules/gitea/kept.ts @@ -6,3 +6,15 @@ export const KEPT: readonly { readonly name: string; readonly readable?: boolean { name: "announced" }, { name: "bound" }, ]; + +/** The announcement of these states, in the layout mesh-sdk's go/announce reads (novox/hq ADR 0495 clause 2): version 1, + * the module, the machine when known, and the states sorted by name, `readable` only where true. It is said as the event + * `states`, which is the subject mesh.mod.gitea.event.states. gitea says it with the SDK's `emit` because the + * toolchain's SDK, which judges R4e's group, predates the SDK's `keeps` (0.1.15); switch to `keeps` once the toolchain's + * SDK is 0.1.15 or later (issue 1852). */ +export function statesAnnouncement(module: string, node: string | undefined) { + const states = [...KEPT] + .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) + .map((k) => (k.readable ? { name: k.name, readable: true } : { name: k.name })); + return { v: 1, module, ...(node ? { node } : {}), states }; +} diff --git a/modules/gitea/package.json b/modules/gitea/package.json index 2a21d1f5..21a6feb5 100644 --- a/modules/gitea/package.json +++ b/modules/gitea/package.json @@ -9,7 +9,7 @@ "test": "npm run build && node --test --experimental-strip-types 'test/*.test.ts'" }, "dependencies": { - "@novox/mesh-sdk": "^0.1.15" + "@novox/mesh-sdk": "^0.1.1" }, "devDependencies": { "@types/node": "^22.0.0", diff --git a/modules/gitea/test/kept.test.ts b/modules/gitea/test/kept.test.ts index 2f942fd5..5702f8e1 100644 --- a/modules/gitea/test/kept.test.ts +++ b/modules/gitea/test/kept.test.ts @@ -12,9 +12,14 @@ test("the states the module announces are the states its manifest declares", asy assert.ok(KEPT.every((k) => !k.readable), "no other module's manifest reads a state of gitea"); }); -test("index.ts announces the list through the SDK before it serves", () => { +test("the announcement has the layout mesh-sdk's go/announce reads: version 1, the module, the node, the states sorted by name", async () => { + const { statesAnnouncement } = await import("../kept.ts"); + assert.deepEqual(statesAnnouncement("gitea", "ace"), { v: 1, module: "gitea", node: "ace", states: [{ name: "announced" }, { name: "bound" }] }); + assert.deepEqual(statesAnnouncement("gitea", undefined), { v: 1, module: "gitea", states: [{ name: "announced" }, { name: "bound" }] }); +}); + +test("index.ts says the announcement as the event `states` before the tools are served", () => { const source = readFileSync(new URL("../index.ts", import.meta.url), "utf8"); - assert.match(source, /import \{ keeps \} from "@novox\/mesh-sdk\/state"/); - assert.match(source, /await keeps\(KEPT\)/); - assert.ok(source.indexOf("await keeps(KEPT)") < source.indexOf("registerModuleTools(\"gitea\""), "keeps comes before the tools are served"); + assert.match(source, /await emit\("states", statesAnnouncement\(/); + assert.ok(source.indexOf('await emit("states"') < source.indexOf('registerModuleTools("gitea"'), "announced before the tools are served"); });