This repository has been archived on 2026-10-14. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mortar/tests/baseline.test.mjs
tony 43fe76158c
Mortar contribution checks / Mortar baseline and browser checks (push) Successful in 3m15s
Extract independent MIT Mortar kit and contribution workflow
2026-10-13 22:16:21 +01:00

45 lines
1.6 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { mkdtemp, cp, readFile, writeFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { checkKit, ROOT } from "../scripts/check.mjs";
test("all public exports have valid contracts and previews", async () =>
assert.deepEqual((await checkKit()).findings, []));
test("baseline rejects path escape, missing dependencies, hidden exports and hosted coupling", async () => {
const dir = await mkdtemp(join(tmpdir(), "mortar-baseline-"));
try {
for (const name of [
"src",
"previews",
"manifests",
"package.json",
"baseline-policy.json",
])
await cp(join(ROOT, name), join(dir, name), { recursive: true });
const file = join(dir, "manifests/mortar-button.json");
const c = JSON.parse(await readFile(file, "utf8"));
c.source = "../outside.tsx";
c.contract.dependencies = ["missing"];
await writeFile(file, JSON.stringify(c));
await writeFile(
join(dir, "src/index.ts"),
"export { Surprise } from './primitives.js';\n",
{ flag: "a" },
);
await writeFile(
join(dir, "src/forbidden.ts"),
"fetch('https://example.invalid'); const classes='bg-indigo-600';\n",
);
const result = await checkKit(dir);
assert.equal(result.passed, false);
for (const rule of ["M001", "M002", "M003", "M004", "M005"])
assert.ok(
result.findings.some((f) => f.rule === rule),
rule,
);
} finally {
await rm(dir, { recursive: true, force: true });
}
});