fix(drawio): keep import command reference in sync (#109)

This commit is contained in:
Cathryn Lavery
2026-08-18 12:38:57 -05:00
committed by GitHub
parent 7942fa0227
commit 0947fdb6e5
7 changed files with 83 additions and 5 deletions
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
"""Regression tests for the draw.io import verifier."""
from __future__ import annotations
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
REFERENCE = Path("skills/diagram-design/references/import-drawio.md")
VERIFIER = Path("scripts/verify-drawio-import.py")
def run_verifier(root: Path) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, str(root / VERIFIER)],
cwd=root,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
)
def main() -> int:
with tempfile.TemporaryDirectory(prefix="diagram-design-drawio-test-") as tmp_dir:
clone = Path(tmp_dir) / "repo"
shutil.copytree(
ROOT,
clone,
ignore=shutil.ignore_patterns(".git", "__pycache__"),
)
reference = clone / REFERENCE
stale_name = "/diagram-design:import"
valid_name = "/diagram-design:import-drawio"
text = reference.read_text(encoding="utf-8")
if valid_name not in text:
raise AssertionError("test fixture lacks the valid slash name")
valid = run_verifier(clone)
if valid.returncode != 0:
raise AssertionError(
f"valid slash command failed verification:\n{valid.stdout}\n{valid.stderr}"
)
reference.write_text(text.replace(valid_name, stale_name), encoding="utf-8")
stale = run_verifier(clone)
if stale.returncode == 0:
raise AssertionError("stale slash command unexpectedly passed verification")
if "slash command" not in stale.stderr:
raise AssertionError(
f"stale slash command lacked a focused diagnostic:\n{stale.stderr}"
)
print("OK: draw.io verifier rejects a stale slash command name")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+10
View File
@@ -341,6 +341,16 @@ def check_security_and_limits(tmp: Path) -> None:
def check_docs() -> None:
import_text = IMPORT_REF.read_text(encoding="utf-8")
expected_slash_command = f"/diagram-design:{COMMAND.stem}"
documented_slash_commands = set(
re.findall(r"`(/diagram-design:[a-z0-9-]+)`", import_text)
)
if documented_slash_commands != {expected_slash_command}:
rendered = ", ".join(sorted(documented_slash_commands)) or "none"
fail(
"import-drawio.md slash command does not match "
f"{COMMAND.name}: expected {expected_slash_command}, found {rendered}"
)
for needle in (
"drawio_extract.py",
"output-spec.md",