优化agent

This commit is contained in:
2026-08-25 11:01:59 +08:00
parent 9f8a55ff07
commit 51575161dc
34 changed files with 2687 additions and 456 deletions
+81 -1
View File
@@ -5,7 +5,8 @@ import tempfile
import unittest
from pathlib import Path
from app.services.engine_service import load_engine, validate_cdsl
from app.services.engine_service import load_engine, normalize_cdsl_for_engine, validate_cdsl
from app.services.flange_sleeve_template import TEMPLATE_ID, build_flange_sleeve_cdsl
from app.settings import get_settings
@@ -88,6 +89,85 @@ class ProfileSchemaTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "positions\\[0\\].*not of type 'object'"):
validate_cdsl(cdsl, self.engine)
def test_normalizes_unambiguous_legacy_llm_field_names_before_validation(self) -> None:
legacy_cdsl = {
"schema": "cad.cdsl.llm.v1",
"part_id": "legacy-flange-base",
"geometry": {"sketches": [{
"id": "base_sketch",
"plane": "XY",
"offset_mm": 12,
"profile": {"type": "circle", "radius_mm": 20},
}]},
"features": [{
"id": "base_add",
"atomic_id": "extrude_add_blind",
"sketch": "base_sketch",
"params": {"distance_mm": 8},
}],
}
normalized, repairs = normalize_cdsl_for_engine(legacy_cdsl)
self.assertEqual(legacy_cdsl["geometry"]["sketches"][0]["plane"], "XY")
self.assertEqual(normalized["features"][0]["sketch_id"], "base_sketch")
self.assertNotIn("sketch", normalized["features"][0])
self.assertEqual(normalized["features"][0]["depends_on"], [])
self.assertEqual(normalized["geometry"]["sketches"][0]["workplane"], {
"origin_mm": [0.0, 0.0, 12.0],
"x_dir": [1.0, 0.0, 0.0],
"normal": [0.0, 0.0, 1.0],
})
self.assertEqual(len(repairs), 3)
validate_cdsl(normalized, self.engine)
def test_normalizer_rewrites_the_legacy_revolve_axis_point_name(self) -> None:
normalized, repairs = normalize_cdsl_for_engine({
"features": [{
"id": "turn",
"atomic_id": "revolve_add",
"params": {"axis": {"point_mm": [0, 0, 0], "direction": [0, 0, 1]}},
}],
})
axis = normalized["features"][0]["params"]["axis"]
self.assertEqual(axis["origin_mm"], [0, 0, 0])
self.assertNotIn("point_mm", axis)
self.assertIn("features[0].params.axis: point_mm -> origin_mm", repairs)
def test_flange_sleeve_template_is_schema_valid_and_runtime_buildable(self) -> None:
cdsl, plan = build_flange_sleeve_cdsl({
"template": TEMPLATE_ID,
"name": "Template flange sleeve",
"flange_width_mm": 120,
"flange_height_mm": 120,
"flange_thickness_mm": 14,
"corner_chamfer_mm": 10,
"tube_outer_diameter_mm": 70,
"tube_straight_length_mm": 95,
"tip_outer_diameter_mm": 62,
"tip_length_mm": 28,
"bore_diameter_mm": 46,
"boss_outer_diameter_mm": 82,
"boss_height_mm": 5,
"mount_hole_diameter_mm": 12,
"mount_counterbore_diameter_mm": 24,
"mount_counterbore_depth_mm": 5,
"mount_hole_u_mm": 42,
"mount_hole_v_mm": 42,
})
self.assertEqual(plan["name"], "Template flange sleeve")
self.assertEqual(cdsl["features"][1]["depends_on"], ["flange_plate"])
self.assertEqual(cdsl["geometry"]["sketches"][0]["workplane"]["x_dir"], [0.0, 1.0, 0.0])
validate_cdsl(cdsl, self.engine)
with tempfile.TemporaryDirectory() as directory:
step_path = Path(directory) / "flange-sleeve.step"
result = self.engine.run_cdsl_only(cdsl, step_path)
self.assertEqual(result["engine"], "cdsl_only")
self.assertTrue(step_path.is_file())
self.assertGreater(step_path.stat().st_size, 0)
def test_cdsl_only_rebuild_preserves_its_actual_failure(self) -> None:
cdsl = {
"schema": "cad.cdsl.llm.v1",