28 lines
1.5 KiB
JavaScript
28 lines
1.5 KiB
JavaScript
export const BROWSER_COMPATIBILITY_SCHEMA = "browser-simulation-compatibility.v1";
|
|
|
|
export async function runCompatibilityMatrix(client, { cycles = 8, chunk = 2 } = {}) {
|
|
if (!client || typeof client.hello !== "function" || typeof client.attach !== "function" || typeof client.stepMany !== "function") throw new Error("browser_client_invalid");
|
|
if (!Number.isSafeInteger(cycles) || cycles < 0 || cycles > 1000000 || !Number.isSafeInteger(chunk) || chunk < 1) throw new Error("browser_matrix_limit");
|
|
const capabilities = await client.hello();
|
|
const ready = await client.attach("compat-attach");
|
|
const stepped = await client.stepMany(cycles, { chunk, operationPrefix: "compat-step" });
|
|
const snapshot = await client.snapshot("compat-snapshot");
|
|
return {
|
|
schema: BROWSER_COMPATIBILITY_SCHEMA,
|
|
status: "verified",
|
|
context_id: client.contextId,
|
|
session_id: client.sessionId,
|
|
capabilities: capabilities.kind,
|
|
session_ready: ready.kind,
|
|
cycles,
|
|
chunks: stepped.chunks,
|
|
snapshot_kind: snapshot.kind,
|
|
logical_tick: snapshot.simulation_tick ?? stepped.last?.simulation_tick ?? 0,
|
|
};
|
|
}
|
|
|
|
export function performanceBudget({ cycles, chunks, maxCycles = 1000000, maxChunks = 1000000 } = {}) {
|
|
if (!Number.isSafeInteger(cycles) || cycles < 0 || cycles > maxCycles || !Number.isSafeInteger(chunks) || chunks < 0 || chunks > maxChunks) return { status: "blocked", code: "browser_performance_budget" };
|
|
return { status: "verified", cycles, chunks, logical_only: true };
|
|
}
|