Files
autocad-mcp-pro/tests/test_benchmark_v6.py
T
Umut CANandClaude Opus 5.5 ba41428c88 bench: matrix v7 adds takeoff_roundtrip and understand_foreign; five understanding checks; the live smoke and the field-test script
The evidence for track H, in the shape tracks A, E, B + G and F used.

- benchmarks/tasks_v7.py: 21 tasks, DEFAULT_MATRIX = "v7"; v6 to v2 stay
  addressable. Both new tasks read the synthetic plant pair and nothing
  else. takeoff_roundtrip: the P&ID called schematic, every routable run's
  layout length equal to the rectilinear MST of its tags, sizes and services
  as drawn (a return drawn on the supply layer included), the cable metres
  rounded up after the allowance, an unstated power left empty.
  understand_foreign: inches over millimetres flagged, the stray entity found
  by handle, two plan copies separated, five layers classified. A test breaks
  each input and watches its gate fail by name.
- Five correctness checks, every number worked out by hand in its docstring;
  the published A/B report is re-run over 48 checks: 26 / 48 -> 48 / 48,
  zero regressed.
- scripts/smoke_understand_com.py reads the pair through the live engine -
  snapshots, the DWG route, both takeoffs and a diff - and closes every
  document it opens; the CHANGELOG records what it returned.
  scripts/field_test_takeoff.py runs the takeoffs on a user's own files,
  refuses to write inside the repository and prints no quantity by default.
- The README token table is remeasured; check_doc_numbers derives the task
  count from the v7 matrix; CLAUDE.md, both READMEs, the CHANGELOG and the
  spec status line say what shipped.

One reader defect found on the way: describe.tag_occurrences read a wiring
callout ("Wiring to CP-2") as a place its panel is written, so the scale
check called CP-2 ambiguous and read "Wiring to CP1" as a phantom tag CP1 -
10 tags and 45 pairs (13.3 % within 10 %) where the generator placed 11 and
55 (21.8 %). A callout is no longer a tag occurrence, the rule
network.tag_occurrences already kept; two tests failed before the fix.

The smoke works only in documents it opened from its own temporary folder,
known by full path; it attaches with GetActiveObject only (the backend's
Dispatch fallback would launch AutoCAD), checks in the same COM-thread call
that the active document is its own before each snapshot, the DWG save and
the move, closes its documents with Close(False) and re-activates the
document that was active when it started. No new ActiveX member: Documents,
Item, FullName, ActiveDocument, Activate and Close are the ones the backend
already calls. Measured on AutoCAD 2026 (25.1s): exit 0, model-space types
equal file / live / DWG, export 0.104 s, no document of the run left open.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
2026-09-24 15:10:37 +03:00

120 lines
4.4 KiB
Python

"""The v6 task matrix: v5 plus what track F added.
``arch_roundtrip`` is track F's evidence - a two-room plan drawn from one
spec, read back off the drawing by the room reader that never sees the spec,
and gated on the numbers the design spec fixed in advance: every room's
detected area within 0.1 % of its label's and of the hand-computed net floor,
the schedules listing the drawn tags, ``drawing_critique(focus=None)`` at
zero and the finalize score at least 90. The published competitor reports
were never asked it and the chart shows them ``not_run``.
"""
from __future__ import annotations
import pytest
from benchmarks.tasks_v5 import TASKS_V5
from benchmarks.tasks_v6 import DEFAULT_MATRIX, MATRICES, NEW_TASKS_V6, TASKS_V6, task_by_id
def test_v6_extends_v5_without_touching_it():
assert TASKS_V6[: len(TASKS_V5)] == TASKS_V5
assert [t.task_id for t in NEW_TASKS_V6] == ["arch_roundtrip"]
assert len(TASKS_V6) == 19
assert MATRICES["v5"] == TASKS_V5 and MATRICES["v6"] == TASKS_V6
assert DEFAULT_MATRIX == "v6"
assert task_by_id("arch_roundtrip").category == "arch"
def test_the_adapter_implements_every_v6_task():
from benchmarks.adapters.autocad_mcp_pro import AutoCADMCPProAdapter
for task in TASKS_V6:
assert hasattr(AutoCADMCPProAdapter, f"_task_{task.task_id}"), task.task_id
def test_the_hand_areas_are_the_net_floor_not_the_axis_area():
from benchmarks.adapters.autocad_mcp_pro import ROUNDTRIP_AREAS_MM2
assert ROUNDTRIP_AREAS_MM2 == {"01": 27_743_750.0, "02": 21_993_750.0}
# the axis areas the rooms would report if the wall thickness were ignored
assert 5000.0 * 6000.0 not in ROUNDTRIP_AREAS_MM2.values()
assert 4000.0 * 6000.0 not in ROUNDTRIP_AREAS_MM2.values()
def test_the_suite_carries_the_four_architectural_checks():
from benchmarks.correctness_suite import CHECKS
for name in (
"arch_junction_l_t_x",
"arch_room_area_net",
"arch_opening_cuts_wall",
"arch_rooms_detect_foreign",
):
assert CHECKS[name][1] == "Architecture"
assert len(CHECKS) == 48
@pytest.mark.asyncio
async def test_arch_roundtrip_passes_headlessly(tmp_path):
"""The benchmark task itself, run once here so a regression in the wall
engine, the room reader, the schedules or the critique fails the suite and
not only the matrix."""
from benchmarks.adapters.autocad_mcp_pro import AutoCADMCPProAdapter
adapter = AutoCADMCPProAdapter(backend="ezdxf")
await adapter.setup(tmp_path)
try:
await adapter._reset()
passed, metrics, _artifacts = await adapter._task_arch_roundtrip()
finally:
await adapter.cleanup()
assert passed, metrics
assert metrics["critique_issues"] == 0, metrics["critique_focuses"]
assert metrics["score"] >= 90.0
assert metrics["door_tags"] == ["D1", "D2"] and metrics["window_tags"] == ["W1", "W2"]
for number in ("01", "02"):
assert metrics["rooms"][number]["agrees"], metrics["rooms"]
@pytest.mark.asyncio
async def test_arch_roundtrip_fails_loudly_when_a_room_label_is_removed(tmp_path, monkeypatch):
"""The gate has to be able to fail. One room left without its label is
enough: the reader still finds the face, the critique names
arch_room_unlabelled, and the room is missing from the area comparison."""
from benchmarks.adapters.autocad_mcp_pro import AutoCADMCPProAdapter
from engineering.arch import rooms
real = rooms.label_room
async def skip_the_hall(backend, room_dict, **kw):
if room_dict.get("number") == "02":
return {"ok": True, "skipped": True}
return await real(backend, room_dict, **kw)
monkeypatch.setattr(rooms, "label_room", skip_the_hall)
adapter = AutoCADMCPProAdapter(backend="ezdxf")
await adapter.setup(tmp_path)
try:
await adapter._reset()
passed, metrics, _artifacts = await adapter._task_arch_roundtrip()
finally:
await adapter.cleanup()
assert passed is False
assert "arch_room_unlabelled" in metrics["critique_focuses"]
assert "02" not in metrics["rooms"]
@pytest.mark.asyncio
async def test_the_net_area_check_measures_the_label():
from benchmarks import correctness_suite
assert await correctness_suite.arch_room_area_net() is True
@pytest.mark.asyncio
async def test_the_foreign_plan_check_passes():
from benchmarks import correctness_suite
assert await correctness_suite.arch_rooms_detect_foreign() is True