372 lines
10 KiB
JavaScript
372 lines
10 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
import { requireFunctionDossierOracle } from "./real-hopper-assertions.mjs";
|
|
|
|
/** Require truthful tri-state permissions from real Hopper memory regions. */
|
|
export const requireTruthfulMemoryRegions = (segments) => {
|
|
if (!Array.isArray(segments) || segments.length === 0) {
|
|
throw new Error("list_segments returned no real memory regions");
|
|
}
|
|
const regions = segments.flatMap((segment) => [
|
|
segment,
|
|
...(Array.isArray(segment.sections) ? segment.sections : []),
|
|
]);
|
|
for (const region of regions) {
|
|
if (
|
|
typeof region?.name !== "string" ||
|
|
region.name.length === 0 ||
|
|
typeof region.start !== "string" ||
|
|
typeof region.end !== "string"
|
|
) {
|
|
throw new Error(
|
|
"list_segments omitted observed region identity or bounds",
|
|
);
|
|
}
|
|
for (const permission of ["readable", "writable", "executable"]) {
|
|
if (region[permission] !== null) {
|
|
throw new Error(
|
|
`list_segments invented or omitted unknown ${permission}`,
|
|
);
|
|
}
|
|
}
|
|
if (
|
|
region.provenance !== "hopper-public-python-api" ||
|
|
region.permissions?.available !== false ||
|
|
typeof region.permissions.reason !== "string" ||
|
|
region.permissions.reason.length === 0
|
|
) {
|
|
throw new Error("list_segments omitted permission provenance");
|
|
}
|
|
}
|
|
};
|
|
|
|
/** Require correlated start and terminal progress from the real bridge. */
|
|
export function requireBridgeProgress(updates) {
|
|
const messages = updates.map(({ message }) => message);
|
|
if (
|
|
!messages.some(
|
|
(message) =>
|
|
message === "Hopper bridge started request" ||
|
|
message.includes("started on Hopper's serial bridge"),
|
|
) ||
|
|
!messages.some(
|
|
(message) =>
|
|
message === "Hopper bridge completed request" ||
|
|
message.includes("Hopper bridge completed request"),
|
|
)
|
|
)
|
|
throw new Error(
|
|
`The MCP client did not observe correlated Hopper bridge progress: ${JSON.stringify(updates)}`,
|
|
);
|
|
}
|
|
|
|
/** Require one sanitized invalid-request diagnostic from the real bridge. */
|
|
export function requireBridgeDiagnostic(chunks) {
|
|
const diagnostics = chunks
|
|
.join("")
|
|
.split("\n")
|
|
.filter((line) => line.trim().length > 0)
|
|
.map((line) => JSON.parse(line));
|
|
if (
|
|
!diagnostics.some(
|
|
(diagnostic) =>
|
|
diagnostic.type === "bridge-diagnostic" &&
|
|
diagnostic.category === "invalid_request" &&
|
|
diagnostic.message.includes(
|
|
"Unknown Hopper address or name: __rea_missing_procedure__",
|
|
),
|
|
)
|
|
)
|
|
throw new Error("The MCP runtime omitted the correlated Hopper diagnostic");
|
|
}
|
|
|
|
/** Verify named positive semantics from the source-owned C fixture. */
|
|
export async function verifyRealHopperFixture({
|
|
client,
|
|
options,
|
|
document,
|
|
oracle,
|
|
normalizedResult,
|
|
}) {
|
|
const main = await resolveFixtureProcedure(
|
|
client,
|
|
options,
|
|
oracle.mainProcedure,
|
|
normalizedResult,
|
|
);
|
|
const entry = await resolveFixtureProcedure(
|
|
client,
|
|
options,
|
|
oracle.entryProcedure,
|
|
normalizedResult,
|
|
);
|
|
const branch = await resolveFixtureProcedure(
|
|
client,
|
|
|