76 lines
3.2 KiB
Python
76 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "backend"))
|
|
|
|
from app.services.engine_service import topology_snapshot, topology_sidecars # noqa: E402
|
|
|
|
|
|
class TopologySnapshotTests(unittest.TestCase):
|
|
def result(self) -> dict:
|
|
return {
|
|
"topology_records": [
|
|
{
|
|
"record_id": "body:base:edge:0",
|
|
"kind": "edge",
|
|
"feature_id": "base",
|
|
"body_id": "body:base",
|
|
"owner_feature_ids": ["base"],
|
|
"geometry": {"curve_type": "line", "length_mm": 10},
|
|
},
|
|
{
|
|
"record_id": "body:base",
|
|
"kind": "body",
|
|
"feature_id": "base",
|
|
"body_id": "body:base",
|
|
"geometry": {},
|
|
},
|
|
]
|
|
}
|
|
|
|
def test_snapshot_preserves_runtime_edges(self) -> None:
|
|
snapshot = topology_snapshot(self.result(), task_id="cad_test", revision_id="rev_001")
|
|
self.assertEqual(snapshot["snapshot_id"], "cad_test/rev_001")
|
|
self.assertEqual(snapshot["records"][0]["record_id"], "body:base:edge:0")
|
|
self.assertTrue(snapshot["records"][0]["executable"])
|
|
|
|
def test_sidecars_are_derived_from_runtime_records(self) -> None:
|
|
snapshot = topology_snapshot(self.result())
|
|
selector, edges = topology_sidecars(self.result(), snapshot=snapshot)
|
|
self.assertEqual(edges["edges"][0]["record_id"], "body:base:edge:0")
|
|
self.assertEqual(selector["edges"][0]["source"], "runtime_snapshot")
|
|
|
|
def test_snapshot_excludes_superseded_body_records(self) -> None:
|
|
result = {
|
|
"feature_results": [
|
|
{"feature_id": "base", "body_id": "body:base"},
|
|
{"feature_id": "cut", "body_id": "body:cut"},
|
|
],
|
|
"topology_records": [
|
|
{"record_id": "body:base", "kind": "body", "body_id": "body:base", "feature_id": "base"},
|
|
{"record_id": "body:base:edge:0", "kind": "edge", "body_id": "body:base", "feature_id": "base"},
|
|
{"record_id": "body:cut", "kind": "body", "body_id": "body:cut", "feature_id": "cut"},
|
|
{"record_id": "body:cut:edge:0", "kind": "edge", "body_id": "body:cut", "feature_id": "cut"},
|
|
],
|
|
}
|
|
|
|
snapshot = topology_snapshot(result)
|
|
|
|
self.assertEqual(snapshot["body_id"], "body:cut")
|
|
self.assertEqual([record["record_id"] for record in snapshot["records"]], ["body:cut", "body:cut:edge:0"])
|
|
|
|
def test_preview_faces_are_audited_but_not_executable(self) -> None:
|
|
snapshot = topology_snapshot(
|
|
{"topology_records": []},
|
|
task_id="cad_test",
|
|
revision_id="rev_001",
|
|
preview={"topology_faces": [{"id": "preview_face", "surface_type": "plane", "center": [0, 0, 1], "normal": [0, 0, 1]}]},
|
|
)
|
|
self.assertEqual(snapshot["records"][0]["record_id"], "preview_face")
|
|
self.assertTrue(snapshot["records"][0]["synthetic"])
|
|
self.assertFalse(snapshot["records"][0]["executable"])
|