fix(pipeline): complete Round 4 repair pass - restore instrument recall, fix spatial line callouts, enable equipment datasheets & twin PSVs

This commit is contained in:
Abhinav Gupta
2026-08-13 10:51:05 +05:30
parent 6c89ab9fb7
commit 7c40c311c5
7 changed files with 195 additions and 40 deletions
+29
View File
@@ -79,3 +79,32 @@ class TestLineTagGrammar:
"Expected a flag_reason for out-of-range size 900"
)
def test_line_from_to_spatial_isolation(self):
"""
Priority 2 Fix: Assert that an off-page annotation text (FROM 27-PIT-0001B)
is ONLY assigned to the line spatially adjacent to it, and unrelated lines
elsewhere on the sheet do NOT inherit that annotation string.
"""
from src.agents.compiler import CompilerAgent
from src.models import UniversalEngineeringGraph
compiler = CompilerAgent()
texts = [
{"value": "FROM 27-PIT-0001B IN 3RD STAGE", "classification": "NOTE", "attributes": {"pos_x": 0.10, "pos_y": 0.10}},
{"value": "8\"-PV-26-9035-FC11S-08", "classification": "LINE_TAG", "tag": "8\"-PV-26-9035-FC11S-08", "attributes": {"pos_x": 0.11, "pos_y": 0.11}},
{"value": "3\"-VA-26-9121-AC21-00", "classification": "LINE_TAG", "tag": "3\"-VA-26-9121-AC21-00", "attributes": {"pos_x": 0.85, "pos_y": 0.85}},
]
geom = {"traces": [
{"tag": "8\"-PV-26-9035-FC11S-08", "grid_path": [[0.11, 0.11]]},
{"tag": "3\"-VA-26-9121-AC21-00", "grid_path": [[0.85, 0.85]]},
]}
lines = compiler._compile_lines(texts, geom, [])
line1 = next(l for l in lines if "9035" in l.tag)
line2 = next(l for l in lines if "9121" in l.tag)
# Line 1 (close at 0.11, 0.11) SHOULD get the off-page callout
assert line1.from_node is not None and "27-PIT-0001B" in line1.from_node
# Line 2 (far away at 0.85, 0.85) MUST NOT inherit that callout
assert line2.from_node is None
+39
View File
@@ -179,3 +179,42 @@ class TestEquipmentDatasheet:
assert flange["outlet_size"] == '4"'
assert flange["inlet_spec"] == "300#"
def test_twin_psv_flange_spec_inheritance(self):
"""
Priority 4 Fix: Twin PSVs 26-PSV-9027A and 26-PSV-9027B must both inherit
flange specs extracted from the shared cluster.
"""
from src.agents.parallel_vision import _inject_datasheet_attributes
structured = [
{"tag": "26-PSV-9027A", "classification": "PSV_TAG", "attributes": {"pos_y": 0.50, "pos_x": 0.50}},
{"tag": "26-PSV-9027B", "classification": "PSV_TAG", "attributes": {"pos_y": 0.52, "pos_x": 0.50}},
]
ocr_items = [
{"text": '3"x4" 300# 150#', "center_y": 0.51, "center_x": 0.50},
]
enriched = _inject_datasheet_attributes(structured, ocr_items)
psv_a = next(i for i in enriched if i["tag"] == "26-PSV-9027A")
psv_b = next(i for i in enriched if i["tag"] == "26-PSV-9027B")
assert psv_a["attributes"].get("inlet_size") == '3"'
assert psv_b["attributes"].get("inlet_size") == '3"'
def test_equipment_completeness_confidence_scaling(self):
"""
Criteria 5 Fix: Equipment with full 7/7 datasheet fields must have 1.0 (100%) confidence,
while equipment with 0 datasheet fields must have 0.60 (60%) confidence.
"""
from src.agents.compiler import CompilerAgent
compiler = CompilerAgent()
full_eq = [{"classification": "EQUIPMENT_TAG", "tag": "26-KA-902", "value": "Compressor",
"attributes": {"duty": "1835 kW", "flow_rate": "62809 kg/h", "design_pressure": "286 Barg",
"design_temperature": "160 C", "material": "LTCS", "vendor": "MAN", "quantity": "1"}}]
empty_eq = [{"classification": "EQUIPMENT_TAG", "tag": "26-KA-903", "value": "Compressor", "attributes": {}}]
res_full = compiler._compile_equipment(full_eq, [])
res_empty = compiler._compile_equipment(empty_eq, [])
assert res_full[0].confidence == 1.0
assert res_empty[0].confidence == 0.60
+16
View File
@@ -126,3 +126,19 @@ class TestSetpointFilter:
]
assert _is_setpoint_context_spatial(0, items) is True
def test_real_instrument_next_to_setpoint_text_kept(self):
"""
Priority 1 Fix: Real instrument TIT-9025 adjacent to 'SD HH: 150 BARG'
must be KEPT as INSTRUMENT_TAG, while bare setpoint PI-150 must be REJECTED.
"""
items = [
{"text": "26-TIT-9025", "confidence": 0.95, "center_x": 0.50, "center_y": 0.30},
{"text": "TIT-9025", "confidence": 0.95, "center_x": 0.50, "center_y": 0.31},
{"text": "SD HH: 150 BARG", "confidence": 0.95, "center_x": 0.52, "center_y": 0.32},
{"text": "PI-150", "confidence": 0.95, "center_x": 0.52, "center_y": 0.33},
]
result = classify_paddle_results(items, drawing_type="PID")
inst_tags = [r["tag"] for r in result if r["classification"] == "INSTRUMENT_TAG"]
assert "26-TIT-9025" in inst_tags or "TIT-9025" in inst_tags
assert "PI-150" not in inst_tags