Agent skill that turns natural language, code, Terraform/K8s, SQL, OpenAPI, AsyncAPI, Protobuf and GraphQL sources into editable, tested draw.io architecture diagrams: incremental sync, multi-view projection, drift diff, CI architecture tests, whiteboard derasterize, interactive HTML/PPTX/Mermaid exports.
Python agent-skillsarchitecturearchitecture-diagramasyncapibpmnc4-modelclaude-codediagramdiagrams-as-codedrawioflowchartgithub-actionsgraphqlimage-to-diagramkubernetesmcp-serverprotobufsysmlterraformuml
test: add a dependency-free regression suite + CI (#28)
Agents365.aidc69ae6af709
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlnew file mode 100644index 0000000..3e86b02--- /dev/null+++ b/.github/workflows/tests.yml@@ -0,0 +1,29 @@+name: tests++on:+ push:+ paths:+ - "skills/drawio-skill/scripts/**"+ - "skills/drawio-skill/data/**"+ - "skills/drawio-skill/styles/**"+ - "tests/**"+ - ".github/workflows/tests.yml"+ pull_request:+ paths:+ - "skills/drawio-skill/scripts/**"+ - "skills/drawio-skill/data/**"+ - "skills/drawio-skill/styles/**"+ - "tests/**"++jobs:+ unittest:+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-python@v5+ with:+ python-version: "3.11"+ - name: Install Graphviz (for importer transitive reduction)+ run: sudo apt-get update && sudo apt-get install -y graphviz+ - name: Run tests+ run: python3 -W error::ResourceWarning -m unittest discover -s tests -vdiff --git a/skills/drawio-skill/SKILL.md b/skills/drawio-skill/SKILL.mdindex 030fbeb..cdaa8b5 100644--- a/skills/drawio-skill/SKILL.md+++ b/skills/drawio-skill/SKILL.md@@ -1,12 +1,12 @@---name: drawio-skill-version: 1.13.0+version: 1.13.1description: Use when the user requests diagrams, flowcharts, architecture diagrams, ER diagrams, UML / sequence / class diagrams, network topology, ML/DL model figures (Transformer/CNN/LSTM), mind maps, or any visualization. Also use proactively when explaining systems with 3+ components, complex data flows, or relationships that benefit from visual representation. Best suited when the diagram needs custom styling, rich shape vocabulary, swimlanes, or exportable images (PNG/SVG/PDF/JPG). Generates .drawio XML and exports locally via the native draw.io desktop CLI.license: MIThomepage: https://github.com/Agents365-ai/drawio-skillcompatibility: Requires draw.io desktop app CLI on PATH (macOS/Linux/Windows). Self-check step requires a vision-enabled model (e.g., Claude Sonnet/Opus); gracefully skipped if unavailable. Optional auto-layout (scripts/autolayout.py) needs Graphviz (dot).platforms: [macos, linux, windows]-metadata: {"openclaw":{"requires":{"anyBins":["draw.io","drawio"]},"emoji":"📐","os":["darwin","linux","win32"],"install":[{"id":"brew-drawio","kind":"brew","formula":"drawio","bins":["drawio"],"label":"Install draw.io via Homebrew","os":["darwin"]},{"id":"brew-graphviz","kind":"brew","formula":"graphviz","bins":["dot"],"label":"Install Graphviz for optional autolayout.py","os":["darwin"],"optional":true}]},"hermes":{"tags":["drawio","diagram","flowchart","architecture","visualization","uml"],"category":"design","requires_tools":["drawio","draw.io"],"related_skills":["mermaid","excalidraw","plantuml"]},"author":"Agents365-ai","version":"1.13.0"}+metadata: {"openclaw":{"requires":{"anyBins":["draw.io","drawio"]},"emoji":"📐","os":["darwin","linux","win32"],"install":[{"id":"brew-drawio","kind":"brew","formula":"drawio","bins":["drawio"],"label":"Install draw.io via Homebrew","os":["darwin"]},{"id":"brew-graphviz","kind":"brew","formula":"graphviz","bins":["dot"],"label":"Install Graphviz for optional autolayout.py","os":["darwin"],"optional":true}]},"hermes":{"tags":["drawio","diagram","flowchart","architecture","visualization","uml"],"category":"design","requires_tools":["drawio","draw.io"],"related_skills":["mermaid","excalidraw","plantuml"]},"author":"Agents365-ai","version":"1.13.1"}---# Draw.io Diagramsdiff --git a/skills/drawio-skill/scripts/autolayout.py b/skills/drawio-skill/scripts/autolayout.pyindex 51e2858..1fd6846 100644--- a/skills/drawio-skill/scripts/autolayout.py+++ b/skills/drawio-skill/scripts/autolayout.py@@ -52,7 +52,8 @@ def load_palette():"""Ordered (fill, stroke) list from the default preset's palette; fall backto the same colours inline if the preset file can't be read."""try:- pal = json.load(open(_PALETTE_FILE, encoding="utf-8"))["palette"]+ with open(_PALETTE_FILE, encoding="utf-8") as fh:+ pal = json.load(fh)["palette"]colors = [(pal[r]["fillColor"], pal[r]["strokeColor"]) for r in _PALETTE_ORDER if r in pal]if colors:return colorsdiff --git a/tests/README.md b/tests/README.mdnew file mode 100644index 0000000..f8743c5--- /dev/null+++ b/tests/README.md@@ -0,0 +1,24 @@+# Tests++Dependency-free regression tests for the bundled scripts (stdlib `unittest`+only — no pip install). They live at the repo root so they are **not** shipped+with the skill package.++```bash+# from the repo root+python3 -m unittest discover -s tests -v+```++## Coverage++| Area | What's locked in |+|---|---|+| `shapesearch.py` | Soundex codes, index loads, known queries resolve, **title-exact ranking** (`dynamodb` → *DynamoDB*), empty on no match |+| `aiicons.py` | variant families, brand/token matching, `-color` preference with mono fallback (OpenAI) |+| `encode_drawio_url.py` | **CJK + `%` round-trip** (the encodeURIComponent-before-deflate fix), viewer vs editor URLs |+| `autolayout.py` | palette sourced from `default.json` (not the fallback), group tinting, explicit-style wins, `--mono` |+| `validate.py` | good `.drawio` passes (exit 0), dangling edge fails (exit 1) |+| importers | `pyimports` intra-project edge, `pyclasses` inheritance edge + no hard-coded colour |++Auto-layout is exercised through `to_drawio()` with synthetic positions, so the+suite needs **no Graphviz or draw.io** to run.diff --git a/tests/test_scripts.py b/tests/test_scripts.pynew file mode 100644index 0000000..ac5f3a1--- /dev/null+++ b/tests/test_scripts.py@@ -0,0 +1,225 @@+#!/usr/bin/env python3+"""Dependency-free regression tests for the bundled scripts.++Run from the repo root:+ python3 -m unittest discover -s tests -v++Uses only the standard library (unittest). Pure-function behaviour is tested by+importing the scripts directly; CLI/exit-code behaviour (validate, importers) is+tested via subprocess against tiny temp fixtures. No Graphviz/draw.io needed —+auto-layout is exercised through to_drawio() with synthetic node positions.+"""+import base64+import gzip+import importlib.util+import json+import os+import subprocess+import sys+import tempfile+import unittest+import urllib.parse+import zlib++ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+SCRIPTS = os.path.join(ROOT, "skills", "drawio-skill", "scripts")+DATA = os.path.join(ROOT, "skills", "drawio-skill", "data")+++def load(name):+ """Import a bundled script module by file path."""+ path = os.path.join(SCRIPTS, name + ".py")+ spec = importlib.util.spec_from_file_location(name, path)+ mod = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(mod)+ return mod+++def run(script, *args, **kw):+ """Run a script as a subprocess; return CompletedProcess."""+ return subprocess.run([sys.executable, os.path.join(SCRIPTS, script), *args],+ capture_output=True, text=True, **kw)+++class TestShapeSearch(unittest.TestCase):+ @classmethod+ def setUpClass(cls):+ cls.m = load("shapesearch")+ with gzip.open(os.path.join(DATA, "shape-index.json.gz"), "rt", encoding="utf-8") as f:+ cls.shapes = json.load(f)+ cls.tm = cls.m.build_tag_map(cls.shapes)++ def search(self, q, n=5):+ return self.m.search(self.shapes, self.tm, q, n)++ def test_soundex(self):+ self.assertEqual(self.m.soundex("Robert"), "R163")+ self.assertEqual(self.m.soundex("Jackson"), "J250")++ def test_index_loaded(self):+ self.assertGreater(len(self.shapes), 10000)+ self.assertTrue(self.tm)++ def test_known_shapes(self):+ self.assertIn("Lambda", self.search("aws lambda")[0]["title"])+ self.assertIn("Actor", self.search("uml actor")[0]["title"])++ def test_title_exact_ranking(self):+ # The v1.11.1 fix: the shape literally titled "DynamoDB" ranks first,+ # above tag-only neighbours like "Attribute".+ self.assertEqual(self.search("aws dynamodb")[0]["title"], "DynamoDB")++ def test_no_match_is_empty(self):+ self.assertEqual(self.search("zzzznotashape"), [])+++class TestAiIcons(unittest.TestCase):+ @classmethod+ def setUpClass(cls):+ cls.m = load("aiicons")+ with open(os.path.join(DATA, "lobe-icons.json"), encoding="utf-8") as fh:+ manifest = json.load(fh)+ cls.fam = cls.m.families(manifest["icons"])++ def test_families_group_variants(self):+ self.assertIn("claude", self.fam)+ self.assertIn("claude-color", self.fam["claude"])++ def test_search_matches_brand(self):+ self.assertEqual(self.m.search(self.fam, "claude", 1)[0], "claude")+ # token matching: a brand word inside a phrase still matches+ self.assertEqual(self.m.search(self.fam, "use the openai logo", 1)[0], "openai")++ def test_variant_preference(self):+ # claude has a colour variant; openai is mono-only -> falls back.+ self.assertEqual(self.m.pick_variant("claude", self.fam["claude"], "color"), "claude-color")+ self.assertEqual(self.m.pick_variant("openai", self.fam["openai"], "color"), "openai")++ def test_unknown_brand(self):+ self.assertEqual(self.m.search(self.fam, "definitelynotabrand", 3), [])+++class TestEncodeUrl(unittest.TestCase):+ @classmethod+ def setUpClass(cls):+ cls.m = load("encode_drawio_url")++ @staticmethod+ def decode(b64):+ # Reverse the encoder: inflate, then decodeURIComponent.+ inflated = zlib.decompress(base64.b64decode(b64), -zlib.MAX_WBITS).decode("utf-8")+ return urllib.parse.unquote(inflated)++ def test_roundtrip_cjk_and_percent(self):+ # The v1.11.0 fix: encodeURIComponent before deflate keeps % and CJK safe.+ xml = '<mxGraphModel><root><mxCell value="登录 100% & ok"/></root></mxGraphModel>'+ b64 = self.m._deflate_b64(xml)+ self.assertEqual(self.decode(b64), xml)++ def test_viewer_and_editor_urls(self):+ xml = "<mxGraphModel><root/></mxGraphModel>"+ self.assertIn("viewer.diagrams.net", self.m.encode(xml))+ self.assertIn("#R", self.m.encode(xml))+ self.assertIn("app.diagrams.net", self.m.edit_url(xml))+ self.assertIn("#create=", self.m.edit_url(xml))+++class TestAutolayoutColor(unittest.TestCase):+ @classmethod+ def setUpClass(cls):+ cls.m = load("autolayout")+ cls.pal = cls.m.load_palette()++ def test_palette_from_design_file(self):+ # Sourced from styles/built-in/default.json, not the inline fallback.+ self.assertNotEqual(self.pal, self.m._FALLBACK_PALETTE)+ self.assertEqual(self.pal[0], ("#dae8fc", "#6c8ebf")) # primary++ def _render(self, color):+ graph = {"direction": "TB", "nodes": [+ {"id": "a", "label": "A", "group": "mod1"},+ {"id": "b", "label": "B", "group": "mod2"},+ {"id": "c", "label": "C", "style": "fillColor=#ff0000;"},+ {"id": "d", "label": "D"},+ ], "edges": []}+ pos = {"a": (1, 4), "b": (3, 4), "c": (5, 4), "d": (7, 4)}+ return self.m.to_drawio(graph, 5, pos, {}, color=color)++ def test_grouped_nodes_coloured(self):+ out = self._render(color=True)+ self.assertIn("fillColor=#d5e8d4", out) # b tinted by mod2 (success/green)+ self.assertIn("strokeColor=#82b366", out) # mod2 container border colour+ self.assertIn("fillColor=#ff0000", out) # explicit style preserved++ def test_mono_disables_colour(self):+ out = self._render(color=False)+ self.assertIn("strokeColor=#999999", out) # grey container+ self.assertNotIn("fillColor=#d5e8d4", out) # no group tint+ self.assertIn("fillColor=#ff0000", out) # explicit style still wins+++class TestValidateCli(unittest.TestCase):+ GOOD = ('<mxfile><diagram name="P1"><mxGraphModel><root>'+ '<mxCell id="0"/><mxCell id="1" parent="0"/>'+ '<mxCell id="2" value="A" vertex="1" parent="1">'+ '<mxGeometry x="0" y="0" width="80" height="40" as="geometry"/></mxCell>'+ '<mxCell id="3" value="B" vertex="1" parent="1">'+ '<mxGeometry x="200" y="0" width="80" height="40" as="geometry"/></mxCell>'+ '<mxCell id="4" edge="1" parent="1" source="2" target="3">'+ '<mxGeometry relative="1" as="geometry"/></mxCell>'+ '</root></mxGraphModel></diagram></mxfile>')+ BAD = ('<mxfile><diagram name="P1"><mxGraphModel><root>'+ '<mxCell id="0"/><mxCell id="1" parent="0"/>'+ '<mxCell id="2" value="A" vertex="1" parent="1">'+ '<mxGeometry x="0" y="0" width="80" height="40" as="geometry"/></mxCell>'+ '<mxCell id="4" edge="1" parent="1" source="2" target="nope">'+ '<mxGeometry relative="1" as="geometry"/></mxCell>'+ '</root></mxGraphModel></diagram></mxfile>')++ def _check(self, xml):+ with tempfile.NamedTemporaryFile("w", suffix=".drawio", delete=False) as f:+ f.write(xml)+ path = f.name+ try:+ return run("validate.py", path)+ finally:+ os.unlink(path)++ def test_good_passes(self):+ self.assertEqual(self._check(self.GOOD).returncode, 0)++ def test_dangling_edge_fails(self):+ r = self._check(self.BAD)+ self.assertEqual(r.returncode, 1)+ self.assertIn("error", r.stdout)+++class TestImportersCli(unittest.TestCase):+ @staticmethod+ def _write(path, text):+ with open(path, "w", encoding="utf-8") as f:+ f.write(text)++ def test_pyimports_edge(self):+ with tempfile.TemporaryDirectory() as d:+ self._write(os.path.join(d, "a.py"), "import b\n")+ self._write(os.path.join(d, "b.py"), "x = 1\n")+ r = run("pyimports.py", d)+ graph = json.loads(r.stdout)+ ids = {n["id"] for n in graph["nodes"]}+ self.assertEqual(ids, {"a", "b"})+ self.assertIn({"source": "a", "target": "b"}, graph["edges"])++ def test_pyclasses_inheritance(self):+ with tempfile.TemporaryDirectory() as d:+ self._write(os.path.join(d, "m.py"), "class A: pass\nclass B(A): pass\n")+ r = run("pyclasses.py", d)+ graph = json.loads(r.stdout)+ self.assertEqual(len(graph["nodes"]), 2)+ self.assertEqual(graph["edges"], [{"source": "m.B", "target": "m.A"}])+ # No hard-coded colour anymore (coloured by group in autolayout).+ self.assertNotIn("style", graph["nodes"][0])+++if __name__ == "__main__":+ unittest.main()