import assert from "node:assert/strict"; import { writeFile } from "node:fs/promises"; import { capabilities, validateLimit } from "./capabilities.mjs"; import { ERROR_DEFINITIONS, mapCoreError, realExcluded } from "./error-map.mjs"; const codes = Object.keys(ERROR_DEFINITIONS).map(Number); assert.equal(codes.length, new Set(codes).size); for (const code of codes) { const mapped = mapCoreError(code, { operation_id: "op", simulation_tick: 7, source: "test" }); assert.equal(mapped.original_code, code); assert.equal(mapped.operation_id, "op"); assert.equal(mapped.simulation_tick, 7); assert.ok(mapped.message_key.includes("." ) || mapped.message_key === "ok"); } const unknown = mapCoreError(-999); assert.equal(unknown.code, "core_unknown_error"); assert.equal(unknown.retryable, false); const caps = capabilities("ctx"); assert.equal(caps.context_id, "ctx"); assert.ok(caps.commands.includes("SIM_STEP")); assert.equal(caps.exclusions.every((item) => item.status === "REAL-EXCLUDED"), true); assert.equal(validateLimit("max_tick_step", 1000000).status, "accepted"); assert.equal(validateLimit("max_tick_step", 1000001).code, "capability_limit_exceeded"); assert.equal(validateLimit("missing", 1).code, "capability_unknown_limit"); assert.equal(realExcluded("pci", "no_device").code, "real_hardware_excluded"); const report = { schema: "runtime-mapping-report.v1", status: "passed", mapped_error_codes: codes.length, commands: caps.commands.length, limits: Object.keys(caps.limits).length, real_exclusions: caps.exclusions.length, }; await writeFile(new URL("../../coverage/runtime-mapping.report.json", import.meta.url), `${JSON.stringify(report, null, 2)}\n`); console.log(`runtime_mapping=passed errors=${codes.length} exclusions=${caps.exclusions.length}`);