85 lines
4.9 KiB
HTML
85 lines
4.9 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Jurisdiction Engine Test Lab</title>
|
|
<style>
|
|
body { font-family: system-ui, sans-serif; max-width: 900px; margin: 40px auto; padding: 0 20px; }
|
|
button { padding: 10px 16px; cursor: pointer; }
|
|
#summary { margin: 20px 0; font-weight: 700; }
|
|
.pass { color: #176b2c; }
|
|
.fail { color: #a51d2d; }
|
|
pre { white-space: pre-wrap; background: #f5f5f5; padding: 16px; border-radius: 8px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Jurisdiction Engine Test Lab</h1>
|
|
<p>Browser regression suite for the pure Jurisdiction Engine.</p>
|
|
<button id="run">Run tests</button>
|
|
<div id="summary">Not run.</div>
|
|
<pre id="log"></pre>
|
|
|
|
<script type="module">
|
|
import {
|
|
resolveJurisdiction,
|
|
isValidResolution,
|
|
getResolutionPriority,
|
|
getSourceConfidence,
|
|
hasJurisdiction,
|
|
hasPolicy,
|
|
JURISDICTION_CATALOG,
|
|
POLICIES
|
|
} from "../jurisdiction/index.js";
|
|
|
|
const tests = [
|
|
["fixed us-ma", () => {
|
|
const r = resolveJurisdiction({mode:"fixed", jurisdiction:"us-ma"});
|
|
return r.status === "resolved" && r.jurisdiction.id === "us-ma" && r.policy.id === "us-state-privacy" && r.source === "site-config" && r.confidence === "explicit";
|
|
}],
|
|
["fixed eu", () => resolveJurisdiction({mode:"fixed", jurisdiction:"eu"}).policy.id === "eu-privacy"],
|
|
["fixed global", () => resolveJurisdiction({mode:"fixed", jurisdiction:"global"}).policy.id === "global-baseline"],
|
|
["global mode", () => resolveJurisdiction({mode:"global"}).jurisdiction.id === "global"],
|
|
["auto server", () => resolveJurisdiction({mode:"auto", request:{jurisdiction:"us-ca", source:"server"}}).source === "server"],
|
|
["auto application", () => resolveJurisdiction({mode:"auto", visitor:{jurisdiction:"us-ma", source:"application"}}).source === "application"],
|
|
["auto browser", () => resolveJurisdiction({mode:"auto", visitor:{jurisdiction:"eu", source:"browser"}}).source === "browser"],
|
|
["auto fallback", () => { const r=resolveJurisdiction({mode:"auto"}); return r.status === "fallback" && r.jurisdiction.id === "global"; }],
|
|
["unknown signal fallback", () => resolveJurisdiction({mode:"auto", request:{jurisdiction:"xx-unknown", source:"server"}}).status === "fallback"],
|
|
["server beats browser", () => resolveJurisdiction({mode:"auto", request:{jurisdiction:"us-ma",source:"server"}, visitor:{jurisdiction:"eu",source:"browser"}}).jurisdiction.id === "us-ma"],
|
|
["site config beats server", () => resolveJurisdiction({mode:"auto", site:{jurisdiction:"us-ca",source:"site-config"}, request:{jurisdiction:"eu",source:"server"}}).jurisdiction.id === "us-ca"],
|
|
["fixed requires jurisdiction", () => { try { resolveJurisdiction({mode:"fixed"}); return false; } catch { return true; } }],
|
|
["fixed rejects unknown", () => { try { resolveJurisdiction({mode:"fixed",jurisdiction:"xx"}); return false; } catch { return true; } }],
|
|
["invalid mode", () => { try { resolveJurisdiction({mode:"random"}); return false; } catch { return true; } }],
|
|
["invalid input", () => { try { resolveJurisdiction(null); return false; } catch { return true; } }],
|
|
["catalog policies exist", () => Object.values(JURISDICTION_CATALOG).every(e => hasPolicy(e.policy))],
|
|
["result contract", () => [resolveJurisdiction({mode:"fixed",jurisdiction:"us-ma"}),resolveJurisdiction({mode:"global"}),resolveJurisdiction({mode:"auto"})].every(isValidResolution)],
|
|
["source priority", () => getResolutionPriority("site-config") > getResolutionPriority("server") && getResolutionPriority("server") > getResolutionPriority("application") && getResolutionPriority("application") > getResolutionPriority("browser") && getResolutionPriority("browser") > getResolutionPriority("fallback")],
|
|
["confidence mapping", () => getSourceConfidence("site-config") === "explicit" && getSourceConfidence("server") === "high" && getSourceConfidence("application") === "medium" && getSourceConfidence("browser") === "low" && getSourceConfidence("fallback") === "default"],
|
|
["initial catalog", () => ["global","us","us-ma","us-ca","eu"].every(hasJurisdiction) && POLICIES["global-baseline"] !== undefined]
|
|
];
|
|
|
|
const run = document.querySelector("#run");
|
|
const summary = document.querySelector("#summary");
|
|
const log = document.querySelector("#log");
|
|
|
|
run.addEventListener("click", () => {
|
|
let passed = 0;
|
|
const lines = [];
|
|
for (const [name, fn] of tests) {
|
|
try {
|
|
const ok = Boolean(fn());
|
|
if (!ok) throw new Error("Assertion returned false");
|
|
passed++;
|
|
lines.push(`PASS: ${name}`);
|
|
} catch (error) {
|
|
lines.push(`FAIL: ${name} — ${error.message}`);
|
|
}
|
|
}
|
|
summary.textContent = `${passed}/${tests.length} tests passed`;
|
|
summary.className = passed === tests.length ? "pass" : "fail";
|
|
log.textContent = lines.join("\n");
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|