Add TUI capture request contract
This commit is contained in:
parent
0f701cab8e
commit
01521a8d2f
12 changed files with 337 additions and 13 deletions
122
tools/evetui/evetui-capture-contract.mjs
Normal file
122
tools/evetui/evetui-capture-contract.mjs
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
export function buildTuiCaptureRequest({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
advertisementPath = "",
|
||||
capabilityManifestPath = "",
|
||||
stamp = new Date().toISOString().replace(/[:.]/g, "-"),
|
||||
} = {}) {
|
||||
if (!advertisement || typeof advertisement !== "object") {
|
||||
throw new Error("advertisement is required");
|
||||
}
|
||||
if (!capabilityManifest || typeof capabilityManifest !== "object") {
|
||||
throw new Error("capabilityManifest is required");
|
||||
}
|
||||
|
||||
const captureContract = capabilityManifest.lifecycle?.capture?.captureContract;
|
||||
if (!captureContract) {
|
||||
throw new Error("capability manifest is missing lifecycle.capture.captureContract");
|
||||
}
|
||||
|
||||
if (advertisement.providerId !== captureContract.requiredProvider) {
|
||||
throw new Error(
|
||||
`capture provider mismatch: expected ${captureContract.requiredProvider} got ${advertisement.providerId || "missing"}`,
|
||||
);
|
||||
}
|
||||
|
||||
const targetId = captureContract.targetId || captureContract.runtimeId;
|
||||
const surface = (advertisement.surfaces || []).find(candidate => candidate.surfaceId === captureContract.requiredSurface);
|
||||
if (!surface) {
|
||||
throw new Error(`capture surface not advertised: ${captureContract.requiredSurface}`);
|
||||
}
|
||||
|
||||
const loweringTargets = surface.worldInteraction?.loweringTargets || [];
|
||||
if (!loweringTargets.includes(targetId)) {
|
||||
throw new Error(`surface ${surface.surfaceId} does not advertise lowering target ${targetId}`);
|
||||
}
|
||||
|
||||
const artifactPath = replaceStamp(captureContract.artifactPattern, stamp);
|
||||
|
||||
return {
|
||||
schema: captureContract.requestSchema || "gamecult.eve.runtime_capture_request.v1",
|
||||
runtimeId: capabilityManifest.runtimeId,
|
||||
ownerRepo: captureContract.ownerRepo,
|
||||
providerId: advertisement.providerId,
|
||||
surfaceId: surface.surfaceId,
|
||||
surfaceKind: surface.surfaceKind || "",
|
||||
targetId,
|
||||
projectionKind: surface.worldInteraction?.projectionKind || "",
|
||||
commandBoundary: surface.worldInteraction?.commandBoundary || "",
|
||||
receiptSchema: surface.worldInteraction?.receiptSchema || "",
|
||||
captureKind: captureContract.captureKind,
|
||||
artifactKind: captureContract.artifactKind,
|
||||
artifactPath,
|
||||
conformanceAttachment: captureContract.conformanceAttachment,
|
||||
authority: captureContract.authority,
|
||||
sourceAdvertisementPath: advertisementPath,
|
||||
sourceCapabilityManifestPath: capabilityManifestPath,
|
||||
issuedAtUtc: stamp,
|
||||
};
|
||||
}
|
||||
|
||||
export function loadJsonFile(filePath) {
|
||||
return JSON.parse(readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
export function writeCaptureRequest(request, outputPath) {
|
||||
mkdirSync(path.dirname(outputPath), { recursive: true });
|
||||
writeFileSync(outputPath, `${JSON.stringify(request, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
function replaceStamp(pattern, stamp) {
|
||||
if (!pattern || !pattern.includes("{stamp}")) {
|
||||
throw new Error(`capture artifact pattern must include {stamp}: ${pattern || "missing"}`);
|
||||
}
|
||||
return pattern.replace("{stamp}", stamp);
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = {};
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const value = argv[index];
|
||||
if (!value.startsWith("--")) continue;
|
||||
const key = value.slice(2);
|
||||
const next = argv[index + 1];
|
||||
if (!next || next.startsWith("--")) {
|
||||
args[key] = true;
|
||||
} else {
|
||||
args[key] = next;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function runCli() {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
for (const required of ["advertisement", "capability", "output"]) {
|
||||
if (!args[required]) {
|
||||
throw new Error(`missing required --${required}`);
|
||||
}
|
||||
}
|
||||
|
||||
const stamp = args.stamp || new Date().toISOString().replace(/[:.]/g, "-");
|
||||
const request = buildTuiCaptureRequest({
|
||||
advertisement: loadJsonFile(args.advertisement),
|
||||
capabilityManifest: loadJsonFile(args.capability),
|
||||
advertisementPath: args.advertisement,
|
||||
capabilityManifestPath: args.capability,
|
||||
stamp,
|
||||
});
|
||||
writeCaptureRequest(request, args.output);
|
||||
process.stdout.write(`${args.output}\n`);
|
||||
}
|
||||
|
||||
const invokedPath = process.argv[1] ? path.resolve(process.argv[1]) : "";
|
||||
const modulePath = fileURLToPath(import.meta.url);
|
||||
if (invokedPath === modulePath) {
|
||||
runCli();
|
||||
}
|
||||
42
tools/evetui/evetui-capture-contract.test.mjs
Normal file
42
tools/evetui/evetui-capture-contract.test.mjs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import { buildTuiCaptureRequest } from "./evetui-capture-contract.mjs";
|
||||
|
||||
const advertisement = JSON.parse(readFileSync(new URL("../../web/fixtures/aetheria.provider-advertisement.json", import.meta.url), "utf8"));
|
||||
const capabilityManifest = JSON.parse(readFileSync(new URL("../../runtimes/incubating/eve-tui/eve-runtime-capability.json", import.meta.url), "utf8"));
|
||||
|
||||
test("builds TUI capture request from provider advertisement", () => {
|
||||
const request = buildTuiCaptureRequest({
|
||||
advertisement,
|
||||
capabilityManifest,
|
||||
advertisementPath: "web/fixtures/aetheria.provider-advertisement.json",
|
||||
capabilityManifestPath: "runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
stamp: "smoke",
|
||||
});
|
||||
|
||||
assert.equal(request.schema, "gamecult.eve.runtime_capture_request.v1");
|
||||
assert.equal(request.runtimeId, "tui");
|
||||
assert.equal(request.ownerRepo, "EveTui");
|
||||
assert.equal(request.providerId, "aetheria");
|
||||
assert.equal(request.surfaceId, "aetheria.daemon.game");
|
||||
assert.equal(request.targetId, "tui");
|
||||
assert.equal(request.projectionKind, "provider-authored-world-surface");
|
||||
assert.equal(request.commandBoundary, "aetheria.daemon.commands");
|
||||
assert.equal(request.receiptSchema, "aetheria.eve_command_acceptance_status.v1");
|
||||
assert.equal(request.captureKind, "terminal-transcript-or-cell-grid");
|
||||
assert.equal(request.artifactKind, "ansi-transcript-or-json-grid");
|
||||
assert.equal(request.artifactPath, "artifacts/evetui-capture/smoke/tui-transcript.ansi");
|
||||
assert.match(request.authority, /provider state/);
|
||||
});
|
||||
|
||||
test("rejects capture request when the surface does not advertise TUI", () => {
|
||||
const withoutTarget = structuredClone(advertisement);
|
||||
const surface = withoutTarget.surfaces.find(candidate => candidate.surfaceId === "aetheria.daemon.game");
|
||||
surface.worldInteraction.loweringTargets = surface.worldInteraction.loweringTargets.filter(target => target !== "tui");
|
||||
|
||||
assert.throws(
|
||||
() => buildTuiCaptureRequest({ advertisement: withoutTarget, capabilityManifest, stamp: "smoke" }),
|
||||
/does not advertise lowering target tui/,
|
||||
);
|
||||
});
|
||||
|
|
@ -840,7 +840,10 @@
|
|||
"runtimes/incubating/eve-tui/eve-runtime-capability.json",
|
||||
"scripts/run-evetui-split-handoff-smoke.ps1",
|
||||
"scripts/run-evetui-lifecycle-smoke.ps1",
|
||||
"scripts/run-evetui-provider-shell-smoke.ps1"
|
||||
"scripts/run-evetui-provider-shell-smoke.ps1",
|
||||
"scripts/run-evetui-capture-contract-smoke.ps1",
|
||||
"tools/evetui/evetui-capture-contract.mjs",
|
||||
"tools/evetui/evetui-capture-contract.test.mjs"
|
||||
],
|
||||
"expectedSourceSymbols": [
|
||||
{
|
||||
|
|
@ -850,6 +853,14 @@
|
|||
{
|
||||
"path": "runtimes/incubating/eve-tui/test/eve-tui-shell.test.mjs",
|
||||
"contains": ["selects advertised provider surfaces", "command intents carry provider-advertised boundaries", "summary grid is explicitly lossy", "lowers provider surface trees into a terminal grid", "rejects surface documents that do not match the advertised TUI target", "aetheria.daemon.commands"]
|
||||
},
|
||||
{
|
||||
"path": "tools/evetui/evetui-capture-contract.mjs",
|
||||
"contains": ["buildTuiCaptureRequest", "gamecult.eve.runtime_capture_request.v1", "ansi-transcript-or-json-grid", "loweringTargets", "writeCaptureRequest"]
|
||||
},
|
||||
{
|
||||
"path": "tools/evetui/evetui-capture-contract.test.mjs",
|
||||
"contains": ["builds TUI capture request from provider advertisement", "rejects capture request when the surface does not advertise TUI", "artifacts/evetui-capture/smoke/tui-transcript.ansi"]
|
||||
}
|
||||
],
|
||||
"capture": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue