Return applied swarm command receipts
This commit is contained in:
parent
cf526a7c78
commit
523f64b5d0
2 changed files with 40 additions and 3 deletions
|
|
@ -18,14 +18,19 @@ const controlDefinition = defineDocumentType({
|
|||
type: "voidbot.swarm_control_state", schemaName: "voidbot.swarm_control_state", schemaId: "voidbot.swarm_control_state.v1", schemaVersion: "voidbot.swarm_control_state.v1",
|
||||
global: false, name: () => "voidbot-swarm", schema: objectSchema,
|
||||
});
|
||||
const receiptDefinition = defineDocumentType({
|
||||
type: "gamecult.eve.command_receipt", schemaName: "gamecult.eve.command_receipt", schemaId: "gamecult.eve.command_receipt.v1", schemaVersion: "gamecult.eve.command_receipt.v1",
|
||||
global: false, name: input => input?.commandId || "smoke-receipt", schema: objectSchema,
|
||||
});
|
||||
const commandId = `smoke:swarm-heat:${Date.now()}`;
|
||||
await CultMesh.publishRudpDocumentOnce("voidbot-swarm-heat-smoke", 0x43554c54, "rudp://127.0.0.1:17873", { definition: commandDefinition }, commandId, {
|
||||
const receipt = await CultMesh.publishRudpDocumentAndWaitForReceipt("voidbot-swarm-heat-smoke", 0x43554c54, "rudp://127.0.0.1:17873", { definition: commandDefinition }, commandId, {
|
||||
schema: "gamecult.eve.command.v1", commandId, providerId: "voidbot.swarm", surfaceId: "voidbot.swarm.surface",
|
||||
command: "swarm.set_heat", payload: { value, transport: "cultmesh-binding" }, clientId: "voidbot.smoke", issuedAt: new Date().toISOString(),
|
||||
}, { sourceRuntimeId: "voidbot-swarm-heat-smoke", sourceRole: "verification", tags: ["smoke", "command"] });
|
||||
}, { definition: receiptDefinition }, { sourceRuntimeId: "voidbot-swarm-heat-smoke", sourceRole: "verification", tags: ["smoke", "command"], receiptTimeoutMs: 5_000 });
|
||||
if (receipt.commandId !== commandId || receipt.state !== "reconciled") throw new Error(`Receipt did not confirm application: ${JSON.stringify(receipt)}`);
|
||||
|
||||
await new Promise(resolvePromise => setTimeout(resolvePromise, 500));
|
||||
const node = await CultMesh.createNode(resolve(repoRoot, ".voidbot", "private", "swarm-controls.cc"), { documents: [controlDefinition] });
|
||||
const control = node.get(controlDefinition, "voidbot-swarm");
|
||||
if (Number(control?.globalHeat) !== value || control?.commandId !== commandId) throw new Error(`Applied control did not match command: ${JSON.stringify(control)}`);
|
||||
console.log(JSON.stringify({ ok: true, commandId, globalHeat: control.globalHeat, controlStore: resolve(repoRoot, ".voidbot", "private", "swarm-controls.cc") }));
|
||||
console.log(JSON.stringify({ ok: true, commandId, globalHeat: control.globalHeat, receipt, controlStore: resolve(repoRoot, ".voidbot", "private", "swarm-controls.cc") }));
|
||||
|
|
|
|||
Loading…
Reference in a new issue