Say gitea's states with the SDK's emit, as the toolchain's SDK has no keeps yet (issue 1790, issue 1852)
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user