feat: add topology graph v0.2.2 contract

This commit is contained in:
赵义仑
2026-06-24 09:47:23 +08:00
parent a7458265c0
commit 2f12fe8cda
16 changed files with 1041 additions and 42 deletions

21
tests/schema.test.ts Normal file
View File

@@ -0,0 +1,21 @@
import assert from "node:assert/strict";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { test } from "node:test";
import Ajv from "ajv";
import { scanUrl } from "../src/engine.js";
test("topology graph JSON schema validates emitted scan artifacts", async () => {
const schema = JSON.parse(await readFile("schemas/topology-graph.schema.json", "utf8"));
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(schema);
const dir = await mkdtemp(path.join(tmpdir(), "action-topology-schema-test-"));
try {
const graph = await scanUrl({ url: "examples/simple.html", out: path.join(dir, "graph.json") });
assert.equal(validate(graph), true, JSON.stringify(validate.errors, null, 2));
} finally {
await rm(dir, { recursive: true, force: true });
}
});