Serve Sai plugin ABI over CultNet
This commit is contained in:
parent
a5c2a65b0e
commit
2e7be7e9f9
9 changed files with 219 additions and 44 deletions
91
scripts/run-eve-cultnet-witness.mjs
Normal file
91
scripts/run-eve-cultnet-witness.mjs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import readline from "node:readline";
|
||||
import { Buffer } from "node:buffer";
|
||||
import { decode, encode } from "@msgpack/msgpack";
|
||||
import { invokeCultNetOperation } from "cultnet-ts";
|
||||
|
||||
const root = path.resolve(import.meta.dirname, "..");
|
||||
const fixturePath = path.join(root, "plugins/sai-vn.plugin-abi-fixture.json");
|
||||
const fixture = JSON.parse(fs.readFileSync(fixturePath, "utf8"));
|
||||
const sidecarPath = path.join(root, "src/eve-cultnet-sidecar.cjs");
|
||||
const child = spawn(process.execPath, [sidecarPath], { cwd: root, stdio: ["ignore", "pipe", "inherit"] });
|
||||
const lines = readline.createInterface({ input: child.stdout })[Symbol.asyncIterator]();
|
||||
const endpointLine = await lines.next();
|
||||
assert.equal(endpointLine.done, false);
|
||||
const endpointAdvertisement = JSON.parse(endpointLine.value);
|
||||
assert.equal(endpointAdvertisement.pluginId, fixture.pluginId);
|
||||
const startedAt = performance.now();
|
||||
const operations = [];
|
||||
|
||||
try {
|
||||
for (let index = 0; index < fixture.operations.length; index += 1) {
|
||||
const fixtureOperation = fixture.operations[index];
|
||||
const requestId = `sai-witness-${index}`;
|
||||
const operationStartedAt = performance.now();
|
||||
const abiRequest = {
|
||||
schema: fixture.requestSchema,
|
||||
pluginId: fixture.pluginId,
|
||||
operation: fixtureOperation.operation,
|
||||
requestId,
|
||||
input: fixtureOperation.input,
|
||||
};
|
||||
const envelope = await invokeCultNetOperation(endpointAdvertisement.endpoint, {
|
||||
schemaVersion: "cultnet.operation_request.v0",
|
||||
messageId: requestId,
|
||||
serviceId: fixture.pluginId,
|
||||
operation: fixtureOperation.operation,
|
||||
payloadSchema: fixture.requestSchema,
|
||||
payloadEncoding: "messagepack-base64",
|
||||
payload: Buffer.from(encode(abiRequest)).toString("base64"),
|
||||
sourceRuntimeId: "eve-conformance",
|
||||
}, { runtimeId: "eve-conformance" });
|
||||
const response = decode(Buffer.from(envelope.payload, "base64"));
|
||||
assert.equal(response.schema, fixture.responseSchema);
|
||||
assert.equal(response.pluginId, fixture.pluginId);
|
||||
assert.equal(response.operation, fixtureOperation.operation);
|
||||
assert.equal(response.requestId, requestId);
|
||||
assert.equal(response.status, "accepted");
|
||||
assertSubset(response.output, fixtureOperation.expect, fixtureOperation.operation);
|
||||
operations.push({
|
||||
operation: fixtureOperation.operation,
|
||||
requestId,
|
||||
status: response.status,
|
||||
durationMs: Number((performance.now() - operationStartedAt).toFixed(3)),
|
||||
expectationCount: Object.keys(fixtureOperation.expect).length,
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
child.kill();
|
||||
}
|
||||
|
||||
const outputPath = path.join(root, "artifacts/eve-plugin/runtime-witness.json");
|
||||
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
||||
fs.writeFileSync(outputPath, `${JSON.stringify({
|
||||
schema: "gamecult.eve.plugin_witness.v1",
|
||||
witnessId: "sai.vn.owner-sidecar",
|
||||
pluginId: fixture.pluginId,
|
||||
ownerRepo: "Sai",
|
||||
status: "pass",
|
||||
transport: "cultnet-operation-v0+rudp",
|
||||
generatedAtUtc: new Date().toISOString(),
|
||||
durationMs: Number((performance.now() - startedAt).toFixed(3)),
|
||||
operations,
|
||||
advertisementPath: "plugins/sai-vn.plugin-advertisement.json",
|
||||
fixturePath: "plugins/sai-vn.plugin-abi-fixture.json",
|
||||
executable: { artifact: "src/eve-cultnet-sidecar.cjs", command: "node" },
|
||||
diagnostics: [],
|
||||
authority: "sai-sidecar-owns-story-session-provider-retains-command-acceptance",
|
||||
}, null, 2)}\n`);
|
||||
console.log(outputPath);
|
||||
|
||||
function assertSubset(actual, expected, label) {
|
||||
if (Array.isArray(expected)) return assert.deepEqual(actual, expected, label);
|
||||
if (expected && typeof expected === "object") {
|
||||
for (const [key, value] of Object.entries(expected)) assertSubset(actual?.[key], value, `${label}.${key}`);
|
||||
return;
|
||||
}
|
||||
assert.equal(actual, expected, label);
|
||||
}
|
||||
|
|
@ -1,22 +1,6 @@
|
|||
param(
|
||||
[string] $EveRoot = "E:\Projects\Eve",
|
||||
[string] $OutputPath = "artifacts\eve-plugin\runtime-witness.json",
|
||||
[string] $NodePath = "node"
|
||||
)
|
||||
param([string] $NodePath = "node")
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$output = if ([IO.Path]::IsPathRooted($OutputPath)) { $OutputPath } else { Join-Path $repoRoot $OutputPath }
|
||||
$launcher = Join-Path $EveRoot "tools\plugins\run-sidecar-witness.mjs"
|
||||
|
||||
& $NodePath $launcher `
|
||||
--advertisement (Join-Path $repoRoot "plugins\sai-vn.plugin-advertisement.json") `
|
||||
--fixture (Join-Path $repoRoot "plugins\sai-vn.plugin-abi-fixture.json") `
|
||||
--output $output `
|
||||
--witness-id "sai.vn.owner-sidecar" `
|
||||
--cwd $repoRoot `
|
||||
--command $NodePath `
|
||||
-- "src/eve-sidecar.cjs"
|
||||
& $NodePath (Join-Path $PSScriptRoot "run-eve-cultnet-witness.mjs")
|
||||
if ($LASTEXITCODE -ne 0) { throw "Sai Eve plugin witness failed with exit code $LASTEXITCODE" }
|
||||
|
||||
Write-Host "Sai Eve plugin witness: $output"
|
||||
|
|
|
|||
Loading…
Reference in a new issue