feat: add deterministic Diagram IR v2 authoring

This commit is contained in:
2026-09-03 10:05:29 +00:00
parent 305006c8cb
commit 50a07b90a9
31 changed files with 2108 additions and 98 deletions
+51
View File
@@ -0,0 +1,51 @@
import assert from "node:assert/strict";
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { spawnSync } from "node:child_process";
import test from "node:test";
const CLI = resolve("src/cli/commands.ts");
test("CLI exposes YAML build with an explicit output path", () => {
const dir = mkdtempSync(join(tmpdir(), "drawio-cli-build-test-"));
const input = join(dir, "spec.yaml");
const output = join(dir, "diagram.drawio");
try {
writeFileSync(input, "version: 1\nnodes:\n - { id: one, label: One }\n", "utf8");
const result = spawnSync(process.execPath, ["--import", "tsx", CLI, "--action", "build", "--file", input, "--output", output], {
cwd: resolve("."),
encoding: "utf8",
});
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.match(result.stdout, /action: build/);
assert.equal(existsSync(output), true);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test("CLI rejects partially numeric page indexes", () => {
const result = spawnSync(process.execPath, ["--import", "tsx", CLI, "--action", "summary", "--file", "unused.drawio", "--page", "1abc"], {
cwd: resolve("."),
encoding: "utf8",
});
assert.equal(result.status, 1);
assert.match(result.stderr, /non-negative integer/);
});
test("CLI validate exits non-zero when the validation summary is invalid", () => {
const dir = mkdtempSync(join(tmpdir(), "drawio-cli-validate-test-"));
const input = join(dir, "empty.drawio");
try {
writeFileSync(input, `<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel>`, "utf8");
const result = spawnSync(process.execPath, ["--import", "tsx", CLI, "--action", "validate", "--file", input], {
cwd: resolve("."),
encoding: "utf8",
});
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /valid: false/);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});