feat(pid): pid_tag_parse, catalogue and ISA-5.1 resources, prompt rewritten onto the tools

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
Umut CAN
2026-09-16 12:29:04 +03:00
co-authored by Claude Opus 5
parent d80ae17411
commit c441609254
8 changed files with 309 additions and 37 deletions
+73
View File
@@ -0,0 +1,73 @@
"""pid_tag_parse tool, the two P&ID resources, the rewritten prompt, the contact sheet."""
from __future__ import annotations
import json
import pytest
import pytest_asyncio
from fastmcp import Client
import server
@pytest_asyncio.fixture
async def client(monkeypatch):
monkeypatch.setenv("AUTOCAD_MCP_BACKEND", "ezdxf")
async with Client(server.mcp) as connected:
yield connected
@pytest.mark.asyncio
async def test_tag_parse_tool(client):
out = (await client.call_tool("pid_tag_parse", {"tag": "10-FIC-101A"})).structured_content
assert out["valid"] is True and out["description"] == "Flow Indicating Controller"
out = (
await client.call_tool(
"pid_tag_parse",
{"tag": "Q-1", "kind": "equipment", "equipment_prefixes": {"Q": "quench"}},
)
).structured_content
assert out["equipment_kind"] == "quench"
@pytest.mark.asyncio
async def test_resources_serve_the_catalogue_and_the_letter_tables(client):
uris = {str(r.uri) for r in await client.list_resources()}
assert {"autocad://pid/symbols", "autocad://standards/isa51"} <= uris
symbols = json.loads((await client.read_resource("autocad://pid/symbols"))[0].text)
assert symbols["catalog_version"] == "1" and any(
s["symbol"] == "gate" for s in symbols["symbols"]
)
isa = json.loads((await client.read_resource("autocad://standards/isa51"))[0].text)
assert isa["first_letters"]["F"] == "Flow" and "rules" in isa
@pytest.mark.asyncio
async def test_prompt_walks_the_tool_workflow(client):
prompt = await client.get_prompt(
"prompt_pid_diagram", {"project_name": "Unit 7", "revision": "B"}
)
text = "\n".join(m.content.text for m in prompt.messages)
for needle in (
"drawing_plan",
'layer_set_id="pid"',
"pid_symbol_insert",
"pid_line_draw",
"pid_graph",
"drawing_critique",
"drawing_finalize",
"pid_from_spec",
"Unit 7",
"Ø10",
):
assert needle in text, needle
assert "circle with triangle" not in text, "no hand-drawn symbols"
def test_catalog_contact_sheet_renders_every_symbol(tmp_path):
pytest.importorskip("matplotlib")
from scripts.render_pid_catalog import render
result = render(tmp_path / "sheet.png")
assert result["symbols"] >= 100 and result["bytes"] > 10_000
+6 -4
View File
@@ -512,8 +512,10 @@ async def test_tool_group_sizes_are_unchanged():
`pid_symbol_insert`, then 2 -> 3 when `pid_line_draw` joined, 3 -> 4
when the reader `pid_graph` joined and 4 -> 7 when the three graph
deliverables (`pid_instrument_index` / `pid_line_list` /
`pid_equipment_list`) joined and 7 -> 8 when `pid_from_spec` (a whole
sheet from one declarative spec, in one transaction) joined; the `pid`
`pid_equipment_list`) joined, 7 -> 8 when `pid_from_spec` (a whole
sheet from one declarative spec, in one transaction) joined and 8 -> 9
when `pid_tag_parse` (the ISA-5.1 tag grammar as a read-only tool)
joined; the `pid`
tag is ranked first in `_GROUP_TAG_PRIORITY` so those tools file under
`pid` rather than under their secondary `query` / `create` tags. Every
other number here has been unchanged since the snapshot was taken.
@@ -532,7 +534,7 @@ async def test_tool_group_sizes_are_unchanged():
"entity_query": 9,
"layers": 14,
"layouts": 12,
"pid": 8,
"pid": 9,
"premium": 12,
"solids": 5,
"system": 7,
@@ -541,4 +543,4 @@ async def test_tool_group_sizes_are_unchanged():
"validation": 1,
"view": 4,
}
assert sum(sizes.values()) == 165
assert sum(sizes.values()) == 166