From 066bcf6380a8ccd67a93618d58954321972a11e1 Mon Sep 17 00:00:00 2001 From: Michael Dold Date: Sat, 7 Nov 2026 18:06:02 +0100 Subject: [PATCH 1/6] Fix audit findings: subdir hint, subject split, diagram and file-name guards - check_tools: when the model is only in a subdirectory, say to start Claude there; the MCP server is started on `model` relative to the session. - use case diagrams group subjects by name and type, so `vehicle : Car` and `vehicle : Truck` no longer merge; untyped same-name subjects still do. - render fails when two DIAGRAMS entries end in the same name instead of one overwriting the other's SVG. - a model file name with a space stops make with what to rename, instead of "No rule to make target". - sysml-author: a `sysml` without find/relations wants `make tools`. Tests: unit tests for the subdir hint and the subject split; acceptance mutations for both make guards. Co-Authored-By: Claude Opus 5.5 --- examples/vehicle/Makefile | 5 ++ plugins/sysml-rflp/scripts/check_tools.py | 20 ++++++-- .../sysml-rflp/skills/sysml-author/SKILL.md | 2 +- plugins/sysml-rflp/templates/project/Makefile | 5 ++ src/sysml2kit/render.py | 43 +++++++++++----- tests/acceptance.py | 43 ++++++++++++---- tests/test_check_tools.py | 40 +++++++++++++++ tests/test_render.py | 51 ++++++++++++++++++- 8 files changed, 180 insertions(+), 29 deletions(-) create mode 100644 tests/test_check_tools.py diff --git a/examples/vehicle/Makefile b/examples/vehicle/Makefile index 4225168..3971c53 100644 --- a/examples/vehicle/Makefile +++ b/examples/vehicle/Makefile @@ -9,6 +9,8 @@ STRICT ?= -W --keep-going SYSML_GIT = https://github.com/MichaelD-42/sysml-v2-rs MODEL := $(shell find model -name '*.sysml' | sort) +# make splits file names on spaces, so `my part.sysml` would become two missing files +$(if $(shell find model -name '*.sysml' -name '* *'),$(error model file names must not contain spaces; rename: $(shell find model -name '*.sysml' -name '* *'))) RESULTS := $(wildcard test-results/*.xml) GEN := docs/_generated # Usages whose internal structure is drawn, by qualified name (e.g. MyLogical::system MyFunctions::operate) @@ -45,6 +47,9 @@ render: build/model.json # start empty: a renamed subject or a dropped DIAGRAMS entry must not leave its old picture behind rm -f $(GEN)/*.svg $(SYSML2KIT) usecases build/model.json $(GEN) + @# each diagram is saved under its last name segment, so two entries ending alike would overwrite each other + @dups=$$(for d in $(DIAGRAMS); do echo $${d##*::}; done | sort | uniq -d); \ + if [ -n "$$dups" ]; then echo "DIAGRAMS: more than one entry ends in $$dups" >&2; exit 1; fi for d in $(DIAGRAMS); do $(SYSML) diagram --internal $$d model > $(GEN)/$$(echo $$d | sed 's/.*:://').svg || exit 1; done # two passes: the trace graph needs the complete need set, RST needs included diff --git a/plugins/sysml-rflp/scripts/check_tools.py b/plugins/sysml-rflp/scripts/check_tools.py index feb1245..9d86867 100644 --- a/plugins/sysml-rflp/scripts/check_tools.py +++ b/plugins/sysml-rflp/scripts/check_tools.py @@ -1,13 +1,25 @@ -"""SessionStart: in an RFLP project, say which pipeline tools are missing (silent when all are there).""" +"""SessionStart: in an RFLP project, say which pipeline tools are missing and whether the MCP server can see the model.""" + import os import shutil import sys from pathlib import Path project = Path(os.environ.get("CLAUDE_PROJECT_DIR", ".")) -if not (project / "model").is_dir() and not list(project.glob("*/model/trace.sysml")): - sys.exit(0) -missing = [tool for tool in ("sysml", "sysml2kit", "test-reports", "sphinx-build") if not shutil.which(tool)] +nested = [trace.parent.parent for trace in project.glob("*/model/trace.sysml")] +if not (project / "model").is_dir(): + if not nested: + sys.exit(0) + # the plugin starts `sysml mcp --project model`, relative to where Claude was started + print( + f"sysml-rflp: the model is in a subdirectory; start Claude in {' or '.join(map(str, nested))} " + "so the sysml MCP server (find, relations, outline) sees it." + ) +missing = [ + tool + for tool in ("sysml", "sysml2kit", "test-reports", "sphinx-build") + if not shutil.which(tool) +] if missing: print( f"sysml-rflp: missing on PATH: {', '.join(missing)}. " diff --git a/plugins/sysml-rflp/skills/sysml-author/SKILL.md b/plugins/sysml-rflp/skills/sysml-author/SKILL.md index 104c5f5..34a3e25 100644 --- a/plugins/sysml-rflp/skills/sysml-author/SKILL.md +++ b/plugins/sysml-rflp/skills/sysml-author/SKILL.md @@ -5,7 +5,7 @@ description: Create and change SysML v2 models (.sysml files) - use cases, requi # SysML v2 authoring -`references/patterns.sysml` is a checked example of every construct the pipeline maps; copy from it. The `sysml` MCP server answers syntax and name questions: `notation` (how to write a construct), `visible_names` (what resolves at a point), `outline`, `library_search`, `check`. To read an existing model, use `find` (elements by kind, namespace, name, or a relation they lack: `kind: RequirementUsage, without: verifies`) and `relations` (every link of one element both ways, by qualified or short name) instead of opening files. +`references/patterns.sysml` is a checked example of every construct the pipeline maps; copy from it. The `sysml` MCP server answers syntax and name questions: `notation` (how to write a construct), `visible_names` (what resolves at a point), `outline`, `library_search`, `check`. To read an existing model, use `find` (elements by kind, namespace, name, or a relation they lack: `kind: RequirementUsage, without: verifies`) and `relations` (every link of one element both ways, by qualified or short name) instead of opening files. If the server says it has no tool `find`, the installed `sysml` predates these tools: run `make tools`. ## Conventions diff --git a/plugins/sysml-rflp/templates/project/Makefile b/plugins/sysml-rflp/templates/project/Makefile index 9043b34..fbeb01c 100644 --- a/plugins/sysml-rflp/templates/project/Makefile +++ b/plugins/sysml-rflp/templates/project/Makefile @@ -9,6 +9,8 @@ STRICT ?= -W --keep-going SYSML_GIT = https://github.com/MichaelD-42/sysml-v2-rs MODEL := $(shell find model -name '*.sysml' | sort) +# make splits file names on spaces, so `my part.sysml` would become two missing files +$(if $(shell find model -name '*.sysml' -name '* *'),$(error model file names must not contain spaces; rename: $(shell find model -name '*.sysml' -name '* *'))) RESULTS := $(wildcard test-results/*.xml) GEN := docs/_generated # Usages whose internal structure is drawn, by qualified name (e.g. MyLogical::system MyFunctions::operate) @@ -45,6 +47,9 @@ render: build/model.json # start empty: a renamed subject or a dropped DIAGRAMS entry must not leave its old picture behind rm -f $(GEN)/*.svg $(SYSML2KIT) usecases build/model.json $(GEN) + @# each diagram is saved under its last name segment, so two entries ending alike would overwrite each other + @dups=$$(for d in $(DIAGRAMS); do echo $${d##*::}; done | sort | uniq -d); \ + if [ -n "$$dups" ]; then echo "DIAGRAMS: more than one entry ends in $$dups" >&2; exit 1; fi for d in $(DIAGRAMS); do $(SYSML) diagram --internal $$d model > $(GEN)/$$(echo $$d | sed 's/.*:://').svg || exit 1; done # two passes: the trace graph needs the complete need set, RST needs included diff --git a/src/sysml2kit/render.py b/src/sysml2kit/render.py index 7b84801..45bbe04 100644 --- a/src/sysml2kit/render.py +++ b/src/sysml2kit/render.py @@ -33,15 +33,31 @@ def _text(x, y, text, cls="", anchor="middle"): def use_cases(elements): - """[(subject name, [(use case need id, name, [actor names])])] from SysML interchange JSON.""" + """[(subject title, [(use case need id, name, [actor names])])] from SysML interchange JSON. + + Use cases are grouped by subject name and type: untyped `subject vehicle;` in several use + cases is one subject, while `vehicle : Car` and `vehicle : Truck` are two, titled with their type. + """ by_id = {e["@id"]: e for e in elements} - def member_name(membership): + def member(membership): target = membership.get("ownedMemberElement") or membership.get( "ownedRelatedElement" ) target = target[0] if isinstance(target, list) and target else target - return by_id.get(target["@id"], {}).get("name") if target else None + return by_id.get(target["@id"], {}) if target else {} + + def member_name(membership): + return member(membership).get("name") + + def subject_key(membership): + subject = member(membership) + types = subject.get("type") or [] + types = types if isinstance(types, list) else [types] + typed = [by_id[t["@id"]] for t in types if t["@id"] in by_id] + return subject.get("name"), ( + typed[0].get("qualifiedName") or typed[0].get("name") if typed else None + ) subjects = {} for e in elements: @@ -50,17 +66,11 @@ def member_name(membership): memberships = [ by_id[m["@id"]] for m in e.get("ownedMembership", []) if m["@id"] in by_id ] - subject = ( - next( - ( - member_name(m) - for m in memberships - if m["@type"] == "SubjectMembership" - ), - None, - ) - or "system" + name, type_ = next( + (subject_key(m) for m in memberships if m["@type"] == "SubjectMembership"), + (None, None), ) + subject = (name or "system", type_) actors = [ member_name(m) for m in memberships if m["@type"] == "ActorMembership" ] @@ -72,7 +82,12 @@ def member_name(membership): [a for a in actors if a], ) ) - return sorted((s, sorted(ucs)) for s, ucs in subjects.items()) + names = [name for name, _ in subjects] + # the type goes into the title only where the name alone would merge two subjects + return sorted( + (f"{name} : {type_}" if type_ and names.count(name) > 1 else name, sorted(ucs)) + for (name, type_), ucs in subjects.items() + ) def use_case_svg(subject, cases): diff --git a/tests/acceptance.py b/tests/acceptance.py index ea43716..e53a07c 100644 --- a/tests/acceptance.py +++ b/tests/acceptance.py @@ -4,6 +4,7 @@ Run: python tests/acceptance.py """ +import json import os import re import shutil @@ -29,7 +30,7 @@ def build(target, edit=None): if edit: edit(work) args = ["make", "-C", str(work), target] + [f"{k}={v}" for k, v in TOOLS.items()] - result = subprocess.run(args, capture_output=True, text=True) + result = subprocess.run(args, check=False, capture_output=True, text=True) return result.returncode, result.stdout + result.stderr, work @@ -103,6 +104,22 @@ def edit(work): replace("test-results/junit.xml", 'value="STC-004"', 'value="STC-099"'), r"unknown outgoing link 'STC-099'", ), + ( + "two diagrams ending in the same name fail instead of overwriting each other", + "render", + replace( + "Makefile", + "DIAGRAMS := VehicleLogical::vehicle", + "DIAGRAMS := VehicleLogical::vehicle Other::vehicle", + ), + r"more than one entry ends in vehicle", + ), + ( + "a model file name with a space fails with what to rename", + "lint", + lambda work: (work / "model/my parts.sysml").write_text("package Spaced;\n"), + r"must not contain spaces; rename: model/my parts\.sysml", + ), ( "satisfy end without a short name fails the bridge", "all", @@ -125,10 +142,10 @@ def main(): html = (work / "docs/_build/html/model.html").read_text() checks = { "SR-003 shows its satisfying component": re.search( - r'id="SR-003".*?satisfied by.*?LC-001', html, re.S + r'id="SR-003".*?satisfied by.*?LC-001', html, re.DOTALL ), "SR-003 shows its system test": re.search( - r'id="SR-003".*?verified by.*?STC-003', html, re.S + r'id="SR-003".*?verified by.*?STC-003', html, re.DOTALL ), "diagrams are embedded": all( f"_images/{n}.svg" in html @@ -162,8 +179,10 @@ def incremental(work): remake = ["make", "-C", str(work), "all"] + [f"{k}={v}" for k, v in TOOLS.items()] use_cases = work / "model/requirements/use_cases.sysml" original = use_cases.read_text() - use_cases.write_text(original.replace("subject vehicle;", "subject car;")) # every use case - result = subprocess.run(remake, capture_output=True, text=True) + use_cases.write_text( + original.replace("subject vehicle;", "subject car;") + ) # every use case + result = subprocess.run(remake, check=False, capture_output=True, text=True) out = result.stdout + result.stderr failed = report( "a renamed subject's old diagram is gone, so the page pointing at it fails", @@ -174,7 +193,7 @@ def incremental(work): ) use_cases.write_text(original) (work / "test-results/junit.xml").unlink() - result = subprocess.run(remake, capture_output=True, text=True) + result = subprocess.run(remake, check=False, capture_output=True, text=True) stale = "testresult" in (work / "docs/_generated/results-needs.json").read_text() failed += report( "deleted test results disappear on rebuild", @@ -182,7 +201,7 @@ def incremental(work): result.stdout + result.stderr, ) (work / "model/verification/system_tests.sysml").unlink() - result = subprocess.run(remake, capture_output=True, text=True) + result = subprocess.run(remake, check=False, capture_output=True, text=True) out = result.stdout + result.stderr return failed + report( "deleted model file fails the rebuild (sysreq-verified)", @@ -202,9 +221,15 @@ def hook(work): )(work) def run(path): - event = '{"tool_name": "Edit", "tool_input": {"file_path": "%s"}}' % path + event = json.dumps( + {"tool_name": "Edit", "tool_input": {"file_path": str(path)}} + ) return subprocess.run( - [sys.executable, str(script)], input=event, capture_output=True, text=True + [sys.executable, str(script)], + input=event, + check=False, + capture_output=True, + text=True, ) broken, other = run(target), run(work / "docs/index.rst") diff --git a/tests/test_check_tools.py b/tests/test_check_tools.py new file mode 100644 index 0000000..81e350b --- /dev/null +++ b/tests/test_check_tools.py @@ -0,0 +1,40 @@ +"""The SessionStart check: say when the model is in a subdirectory, where the sysml MCP server cannot see it.""" + +import os +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +SCRIPT = ( + Path(__file__).resolve().parent.parent / "plugins/sysml-rflp/scripts/check_tools.py" +) + + +def run(project): + env = {**os.environ, "CLAUDE_PROJECT_DIR": str(project)} + return subprocess.run( + [sys.executable, str(SCRIPT)], + env=env, + check=False, + capture_output=True, + text=True, + ).stdout + + +class CheckToolsTest(unittest.TestCase): + def test_a_model_in_a_subdirectory_says_where_to_start_claude(self): + with tempfile.TemporaryDirectory() as root: + (Path(root) / "car/model").mkdir(parents=True) + (Path(root) / "car/model/trace.sysml").write_text("package Trace;\n") + self.assertIn(f"start Claude in {Path(root) / 'car'}", run(root)) + + def test_a_model_at_the_root_needs_no_hint(self): + with tempfile.TemporaryDirectory() as root: + (Path(root) / "model").mkdir() + self.assertNotIn("start Claude in", run(root)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_render.py b/tests/test_render.py index fb30c3e..2b34e91 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -1,6 +1,7 @@ import re import unittest import xml.etree.ElementTree as ET +from typing import ClassVar from sysml2kit.render import CHAR_W, trace_svg, use_case_svg, use_cases @@ -30,7 +31,7 @@ def segments(d): class TraceSvgTest(unittest.TestCase): - NEEDS = { + NEEDS: ClassVar = { "CRS-001": need("crs"), "SR-001": need("sysreq", satisfies=["CRS-001"]), "SR-002": need("sysreq", satisfies=["CRS-001"]), @@ -122,6 +123,54 @@ def test_use_cases_without_an_id_are_still_drawn(self): root = ET.fromstring(use_case_svg(*cases[0])) self.assertEqual(len(list(root.iter(f"{SVG}ellipse"))), 2) + def test_subjects_with_one_name_but_different_types_get_separate_diagrams(self): + def case(uc, subject, type_id=None): + s = {"@id": subject, "@type": "ReferenceUsage", "name": "vehicle"} + if type_id: + s["type"] = [{"@id": type_id}] + return [ + { + "@id": uc, + "@type": "UseCaseUsage", + "name": uc, + "ownedMembership": [{"@id": uc + "m"}], + }, + { + "@id": uc + "m", + "@type": "SubjectMembership", + "ownedMemberElement": {"@id": subject}, + }, + s, + ] + + types = [ + { + "@id": "car", + "@type": "PartDefinition", + "name": "Car", + "qualifiedName": "P::Car", + }, + { + "@id": "truck", + "@type": "PartDefinition", + "name": "Truck", + "qualifiedName": "P::Truck", + }, + ] + split = use_cases( + case("drive", "s1", "car") + case("haul", "s2", "truck") + types + ) + self.assertEqual( + split, + [ + ("vehicle : P::Car", [("", "drive", [])]), + ("vehicle : P::Truck", [("", "haul", [])]), + ], + ) + # untyped subjects of one name are the same subject, as in the example model + merged = use_cases(case("drive", "s1") + case("haul", "s2")) + self.assertEqual(merged, [("vehicle", [("", "drive", []), ("", "haul", [])])]) + def test_long_actor_names_stay_inside_the_image(self): actor = "maintenanceTechnicianOnDuty" root = ET.fromstring(use_case_svg("s", [("UC-001", "service", [actor])])) From a258bd8e45f64fec3bd5e5356e881e576878e531 Mon Sep 17 00:00:00 2001 From: Michael Dold Date: Sat, 7 Nov 2026 18:06:02 +0100 Subject: [PATCH 2/6] Run ruff in CI and fix what it reports CI's unit job runs `ruff check` and `ruff format --check`, pinned to 0.17.4, with ruff's default rules. Fixes: explicit `check=False` where the exit code is read by hand, `re.DOTALL`/`re.MULTILINE` over aliases, unused noqa, a ClassVar fixture, and the lint-hook test event built with json.dumps (a path with a quote broke the hand-built JSON). The rest is `ruff format`. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 1 + README.md | 1 + plugins/sysml-rflp/scripts/lint_on_edit.py | 13 +++++++++++-- src/sysml2kit/cli.py | 13 ++++++++++--- src/sysml2kit/needs.py | 2 +- tests/omg_corpus.py | 7 ++++--- tests/test_template.py | 15 ++++++++++++--- 7 files changed, 40 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 978e9a7..07f03c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ jobs: - uses: actions/setup-python@v5 with: { python-version: "3.12" } - run: PYTHONPATH=src python -m unittest discover -s tests + - run: pip install ruff==0.17.4 && ruff check . && ruff format --check . plugin: runs-on: ubuntu-24.04 diff --git a/README.md b/README.md index 5f4fcd1..25013f0 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ PYTHONPATH=src python -m unittest discover -s tests # bridge and renderer python tests/acceptance.py # example build + mutations (needs the tools) python tests/omg_corpus.py # OMG release corpus through the pipeline claude plugin validate . # marketplace and plugin manifests +ruff check . && ruff format --check . # lint and format (CI pins ruff 0.17.4) ``` ## License diff --git a/plugins/sysml-rflp/scripts/lint_on_edit.py b/plugins/sysml-rflp/scripts/lint_on_edit.py index a5a02aa..7ace121 100644 --- a/plugins/sysml-rflp/scripts/lint_on_edit.py +++ b/plugins/sysml-rflp/scripts/lint_on_edit.py @@ -1,4 +1,5 @@ """PostToolUse: after a .sysml file is written, run `sysml check` on its project's model/ and report errors to Claude.""" + import json import shutil import subprocess @@ -12,7 +13,15 @@ model = next((p for p in path.resolve().parents if p.name == "model"), None) if model is None: sys.exit(0) -result = subprocess.run(["sysml", "--color", "never", "check", str(model)], capture_output=True, text=True) +result = subprocess.run( + ["sysml", "--color", "never", "check", str(model)], + check=False, + capture_output=True, + text=True, +) if result.returncode != 0: - print(f"sysml check {model} failed after editing {path.name}:\n{result.stdout}{result.stderr}", file=sys.stderr) + print( + f"sysml check {model} failed after editing {path.name}:\n{result.stdout}{result.stderr}", + file=sys.stderr, + ) sys.exit(2) # feeds stderr back to Claude diff --git a/src/sysml2kit/cli.py b/src/sysml2kit/cli.py index 4e6bf9a..e9a4189 100644 --- a/src/sysml2kit/cli.py +++ b/src/sysml2kit/cli.py @@ -13,14 +13,21 @@ def main(argv=None): parser = argparse.ArgumentParser(prog="sysml2kit", description=__doc__) sub = parser.add_subparsers(dest="command", required=True) - p = sub.add_parser("needs", help="interchange JSON (`sysml export`) -> sphinx-needs needs.json") + p = sub.add_parser( + "needs", help="interchange JSON (`sysml export`) -> sphinx-needs needs.json" + ) p.add_argument("export") p.add_argument("output") - p.add_argument("model_files", nargs="+", help="the .sysml files, for source locations") + p.add_argument( + "model_files", nargs="+", help="the .sysml files, for source locations" + ) p = sub.add_parser("usecases", help="one use case diagram SVG per subject") p.add_argument("export") p.add_argument("output_dir") - p = sub.add_parser("trace", help="RFLP trace graph SVG from a sphinx-needs needs.json (`sphinx-build -b needs`)") + p = sub.add_parser( + "trace", + help="RFLP trace graph SVG from a sphinx-needs needs.json (`sphinx-build -b needs`)", + ) p.add_argument("needs_json") p.add_argument("output") args = parser.parse_args(argv) diff --git a/src/sysml2kit/needs.py b/src/sysml2kit/needs.py index 5716dfa..8843821 100644 --- a/src/sysml2kit/needs.py +++ b/src/sysml2kit/needs.py @@ -33,7 +33,7 @@ "Trace::Realizes": "realizes", "Trace::Verifies": "verifies", } -COMMENT = re.compile(r"/\*.*?\*/|//[^\n]*", re.S) +COMMENT = re.compile(r"/\*.*?\*/|//[^\n]*", re.DOTALL) # reStructuredText inline markup; doc text is plain text, so these are escaped RST_INLINE = re.compile(r"([\\*`_|])") diff --git a/tests/omg_corpus.py b/tests/omg_corpus.py index f0e232b..8d916cf 100644 --- a/tests/omg_corpus.py +++ b/tests/omg_corpus.py @@ -14,8 +14,8 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src")) -from sysml2kit.needs import BridgeError, convert # noqa: E402 -from sysml2kit.render import use_case_svg, use_cases # noqa: E402 +from sysml2kit.needs import BridgeError, convert +from sysml2kit.render import use_case_svg, use_cases RELEASE_TAG = "2026-09.1" SYSML = os.environ.get("SYSML", "sysml") @@ -45,6 +45,7 @@ def main(): root = release / "sysml" / "src" / folder check = subprocess.run( [SYSML, "--color", "never", "check", str(root)], + check=False, capture_output=True, text=True, ) @@ -58,7 +59,7 @@ def main(): failures += not ok files = sorted(str(p) for p in root.rglob("*.sysml")) export = subprocess.run( - [SYSML, "export", *files], capture_output=True, text=True + [SYSML, "export", *files], check=False, capture_output=True, text=True ) if export.returncode != 0: print(f"FAIL export {folder}: {export.stderr[-500:]}") diff --git a/tests/test_template.py b/tests/test_template.py index 180ad60..dc0f9f1 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -7,17 +7,26 @@ ROOT = Path(__file__).resolve().parent.parent TEMPLATE = ROOT / "plugins/sysml-rflp/templates/project" EXAMPLE = ROOT / "examples/vehicle" -SAME = ["docs/ubproject.toml", "docs/schemas.json", "docs/traceability.rst", "model/trace.sysml", ".gitignore"] +SAME = [ + "docs/ubproject.toml", + "docs/schemas.json", + "docs/traceability.rst", + "model/trace.sysml", + ".gitignore", +] class TemplateSyncTest(unittest.TestCase): def test_shared_files_are_identical(self): for name in SAME: - self.assertEqual((TEMPLATE / name).read_text(), (EXAMPLE / name).read_text(), name) + self.assertEqual( + (TEMPLATE / name).read_text(), (EXAMPLE / name).read_text(), name + ) def test_makefile_differs_only_in_diagrams(self): def strip(path): - return re.sub(r"^DIAGRAMS :=.*$", "", path.read_text(), flags=re.M) + return re.sub(r"^DIAGRAMS :=.*$", "", path.read_text(), flags=re.MULTILINE) + self.assertEqual(strip(TEMPLATE / "Makefile"), strip(EXAMPLE / "Makefile")) From 3f59b4ea2b1ed0c482f18379694e4054ed81878b Mon Sep 17 00:00:00 2001 From: Michael Dold Date: Sat, 7 Nov 2026 18:06:02 +0100 Subject: [PATCH 3/6] Release 0.1.1 Bump the plugin and package to 0.1.1 so installed plugins pick up the changes since 0.1.0, and pin new projects' sysml2kit to the v0.1.1 tag. Co-Authored-By: Claude Opus 5.5 --- plugins/sysml-rflp/.claude-plugin/plugin.json | 2 +- plugins/sysml-rflp/templates/project/requirements.txt | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/sysml-rflp/.claude-plugin/plugin.json b/plugins/sysml-rflp/.claude-plugin/plugin.json index 4fc1819..1dd01aa 100644 --- a/plugins/sysml-rflp/.claude-plugin/plugin.json +++ b/plugins/sysml-rflp/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "sysml-rflp", "displayName": "SysML v2 RFLP", - "version": "0.1.0", + "version": "0.1.1", "description": "Author, lint and render SysML v2 models, trace them to sphinx-needs, and derive use cases, system requirements, functions and logical architecture from customer requirements (RFLP)", "author": { "name": "Michael Dold" }, "repository": "https://github.com/MichaelD-42/sysml2-kit", diff --git a/plugins/sysml-rflp/templates/project/requirements.txt b/plugins/sysml-rflp/templates/project/requirements.txt index 32dcb2b..b775931 100644 --- a/plugins/sysml-rflp/templates/project/requirements.txt +++ b/plugins/sysml-rflp/templates/project/requirements.txt @@ -1,4 +1,4 @@ sphinx==9.1.1 sphinx-needs==9.2.0 ub-test-reports==2.0.0 -sysml2kit @ git+https://github.com/MichaelD-42/sysml2-kit@v0.1.0 +sysml2kit @ git+https://github.com/MichaelD-42/sysml2-kit@v0.1.1 diff --git a/pyproject.toml b/pyproject.toml index 5080e8d..b222ab4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "sysml2kit" -version = "0.1.0" +version = "0.1.1" description = "Bridge SysML v2 models into sphinx-needs traceability and render use case and trace diagrams" readme = "README.md" license = "MIT" From e6c4238a0af25e3dca8b5b5eda05d7c3f8f8aa83 Mon Sep 17 00:00:00 2001 From: Michael Dold Date: Sat, 7 Nov 2026 18:08:54 +0100 Subject: [PATCH 4/6] Treat multi-line notes //* */ as comments when locating declarations The comment pattern matched `//` first and blanked only the note's first line, so a requirement commented out with a multi-line note became the source location over the live one. Co-Authored-By: Claude Opus 5.5 --- src/sysml2kit/needs.py | 3 ++- tests/test_needs.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sysml2kit/needs.py b/src/sysml2kit/needs.py index 8843821..a30c987 100644 --- a/src/sysml2kit/needs.py +++ b/src/sysml2kit/needs.py @@ -33,7 +33,8 @@ "Trace::Realizes": "realizes", "Trace::Verifies": "verifies", } -COMMENT = re.compile(r"/\*.*?\*/|//[^\n]*", re.DOTALL) +# multi-line note `//* */` first, or `//` would take only its first line +COMMENT = re.compile(r"//\*.*?\*/|/\*.*?\*/|//[^\n]*", re.DOTALL) # reStructuredText inline markup; doc text is plain text, so these are escaped RST_INLINE = re.compile(r"([\\*`_|])") diff --git a/tests/test_needs.py b/tests/test_needs.py index 3ce9643..fbf3a07 100644 --- a/tests/test_needs.py +++ b/tests/test_needs.py @@ -205,6 +205,12 @@ def test_mentions_in_comments_are_not_declarations(self): files.append(f.name) self.assertEqual(source_locations(files), {"UC-001": f"{files[1]}:3"}) + def test_a_declaration_inside_a_multi_line_note_is_not_the_declaration(self): + text = "package P {\n //* old:\n requirement <'SR-9'> gone;\n */\n requirement <'SR-9'> kept;\n}\n" + with tempfile.NamedTemporaryFile("w", suffix=".sysml", delete=False) as f: + f.write(text) + self.assertEqual(source_locations([f.name]), {"SR-9": f"{f.name}:5"}) + if __name__ == "__main__": unittest.main() From 1def37a220a457131bb35d3a6fa87ebaae822a0e Mon Sep 17 00:00:00 2001 From: Michael Dold Date: Sat, 7 Nov 2026 18:08:54 +0100 Subject: [PATCH 5/6] Test that package, plugin and template pin name one version A release bumps three places; the test fails when one is left behind. Co-Authored-By: Claude Opus 5.5 --- tests/test_template.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_template.py b/tests/test_template.py index dc0f9f1..63c6780 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -1,5 +1,6 @@ """The vehicle example must be the project template plus content; shared files may not drift apart.""" +import json import re import unittest from pathlib import Path @@ -30,5 +31,19 @@ def strip(path): self.assertEqual(strip(TEMPLATE / "Makefile"), strip(EXAMPLE / "Makefile")) +class ReleaseVersionTest(unittest.TestCase): + def test_package_plugin_and_template_pin_name_one_version(self): + package = re.search( + r'^version = "(.+)"', (ROOT / "pyproject.toml").read_text(), re.MULTILINE + )[1] + plugin = json.loads( + (ROOT / "plugins/sysml-rflp/.claude-plugin/plugin.json").read_text() + )["version"] + pin = re.search( + r"sysml2-kit@v(\S+)", (TEMPLATE / "requirements.txt").read_text() + )[1] + self.assertEqual((package, plugin, pin), (package, package, package)) + + if __name__ == "__main__": unittest.main() From c28e278af7dc20068ae47e65c217e4884979350b Mon Sep 17 00:00:00 2001 From: Michael Dold Date: Sat, 7 Nov 2026 18:08:54 +0100 Subject: [PATCH 6/6] Fail CI at the ls-remote step when the fork's main cannot be resolved An empty SYSML_REV used to surface later as a cargo error. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07f03c9..f36642f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: runs-on: ubuntu-24.04 steps: # track the fork main; key the cache on the commit it is at now, so a new commit rebuilds - - run: echo "SYSML_REV=$(git ls-remote "$SYSML_GIT" refs/heads/main | cut -f1)" >> "$GITHUB_ENV" + - run: rev=$(git ls-remote "$SYSML_GIT" refs/heads/main | cut -f1) && test -n "$rev" && echo "SYSML_REV=$rev" >> "$GITHUB_ENV" - id: cache uses: actions/cache@v4 with: