Implement AXIS parity UI and execution baseline
This commit is contained in:
33
web/worker/test_resource_intro_graphic_s7_06.mjs
Normal file
33
web/worker/test_resource_intro_graphic_s7_06.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { createHash } from "node:crypto";
|
||||
import { WorkspaceRuntime } from "../workspace/runtime.mjs";
|
||||
import { resolveResources } from "../workspace/resource-resolver.mjs";
|
||||
|
||||
const logo = await readFile(new URL("../../linuxcnc/linuxcnc.gif", import.meta.url));
|
||||
const logoSha = createHash("sha256").update(logo).digest("hex");
|
||||
const sourceGeneratorPath = new URL("../../linuxcnc/src/emc/usr_intf/stepconf/build_INI.py", import.meta.url);
|
||||
const sourceGenerator = await readFile(sourceGeneratorPath, "utf8");
|
||||
const sourceGeneratorStatement = 'print("INTRO_GRAPHIC = linuxcnc.gif", file=file)';
|
||||
assert.match(sourceGenerator, new RegExp(sourceGeneratorStatement.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
||||
const sourceGeneratorSha = createHash("sha256").update(sourceGenerator).digest("hex");
|
||||
const fixtureData = "gif-fixture";
|
||||
const files = { "config/main.ini": "[DISPLAY]\nINTRO_GRAPHIC = linuxcnc.gif\n", "linuxcnc/linuxcnc.gif": fixtureData };
|
||||
const workspace = new WorkspaceRuntime({ files });
|
||||
const resolved = resolveResources({ workspace, entrypoint: "config/main.ini" });
|
||||
const repeated = resolveResources({ workspace, entrypoint: "config/main.ini" });
|
||||
assert.equal(resolved.status, "ready");
|
||||
assert.deepEqual(resolved.resources.map((row) => ({ type: row.type, path: row.path, key: row.key })), [{ type: "image", path: "linuxcnc/linuxcnc.gif", key: "INTRO_GRAPHIC" }]);
|
||||
assert.equal(resolved.resources[0].bytes, new TextEncoder().encode(fixtureData).byteLength);
|
||||
assert.match(resolved.state_hash, /^fnv1a64:/);
|
||||
assert.equal(repeated.state_hash, resolved.state_hash);
|
||||
|
||||
const wrongKey = resolveResources({ workspace: new WorkspaceRuntime({ files: { "config/main.ini": "[EMCIO]\nTOOL_TABLE = linuxcnc.gif\n", "linuxcnc/linuxcnc.gif": fixtureData } }), entrypoint: "config/main.ini" });
|
||||
assert.equal(wrongKey.status, "blocked");
|
||||
assert.equal(wrongKey.resources[0].code, "resource_missing");
|
||||
assert.equal(wrongKey.resources[0].type, "tool_table");
|
||||
const wrongSection = resolveResources({ workspace: new WorkspaceRuntime({ files: { "config/main.ini": "[EMCIO]\nINTRO_GRAPHIC = linuxcnc.gif\n", "linuxcnc/linuxcnc.gif": fixtureData } }), entrypoint: "config/main.ini" });
|
||||
assert.equal(wrongSection.status, "blocked");
|
||||
assert.equal(wrongSection.resources[0].code, "resource_missing");
|
||||
|
||||
console.log(JSON.stringify({ schema: "resource-intro-graphic-s7-06-sample.v1", status: "verified", source_generator: { path: "linuxcnc/src/emc/usr_intf/stepconf/build_INI.py", statement: sourceGeneratorStatement, sha256: sourceGeneratorSha }, resource: { type: resolved.resources[0].type, path: resolved.resources[0].path, bytes: resolved.resources[0].bytes, asset_sha256: logoSha, data_hash: resolved.resources[0].data_hash }, resource_graph: { state_hash: resolved.state_hash, repeated_state_hash: repeated.state_hash, deterministic: resolved.state_hash === repeated.state_hash }, wrong_key: { status: wrongKey.status, code: wrongKey.resources[0].code, type: wrongKey.resources[0].type }, wrong_section: { status: wrongSection.status, code: wrongSection.resources[0].code, type: wrongSection.resources[0].type }, boundaries: ["only DISPLAY.INTRO_GRAPHIC linuxcnc.gif uses the canonical shared asset", "generic basename and tool/parameter/HAL/program substitution remains blocked"] }));
|
||||
Reference in New Issue
Block a user