Refactor AI Host to Backend Service and update related components

- Renamed references from "AI Host" to "Backend Service" throughout the codebase for consistency.
- Updated the registration and unregistration of context menus to include the Outliner.
- Changed the job protocol versioning and related constants for clarity.
- Modified the runtime installation messages and error handling to reflect the new terminology.
- Adjusted the user interface labels and messages in panels and operators to align with the new Backend Service terminology.
- Updated tests to ensure they reflect the changes in naming and functionality.
- Changed default value for background depth in geometry nodes asset to -1.0 for better handling of depth planes.
This commit is contained in:
2026-08-12 22:42:39 +08:00
parent e3d023cac5
commit 7d0983529e
17 changed files with 246 additions and 155 deletions

View File

@@ -43,10 +43,15 @@ class AddonTest(unittest.TestCase):
append=lambda draw: cls.context_menu_draws.append(draw),
remove=lambda draw: cls.context_menu_draws.remove(draw),
),
OUTLINER_MT_object=SimpleNamespace(
append=lambda draw: cls.outliner_menu_draws.append(draw),
remove=lambda draw: cls.outliner_menu_draws.remove(draw),
),
)
cls.registered = []
cls.status_bar_draws = []
cls.context_menu_draws = []
cls.outliner_menu_draws = []
fake_bpy.utils = SimpleNamespace(
register_class=cls.registered.append,
unregister_class=cls.registered.remove,
@@ -80,6 +85,7 @@ class AddonTest(unittest.TestCase):
self.registered.clear()
self.status_bar_draws.clear()
self.context_menu_draws.clear()
self.outliner_menu_draws.clear()
self.addon.operators._active_job = None
self.addon.image_depth._last_depth_plane_model = "BASE"
self.addon.image_mesh._last_mesh_model = "BASE"
@@ -107,6 +113,10 @@ class AddonTest(unittest.TestCase):
self.context_menu_draws,
[self.addon.draw_image_context_menu],
)
self.assertEqual(
self.outliner_menu_draws,
[self.addon.draw_image_context_menu],
)
self.addon.unregister()
@@ -116,6 +126,7 @@ class AddonTest(unittest.TestCase):
)
self.assertEqual(self.status_bar_draws, [])
self.assertEqual(self.context_menu_draws, [])
self.assertEqual(self.outliner_menu_draws, [])
def test_registers_depth_plane_operator_without_cache_rebuild(self):
self.assertIn(
@@ -149,7 +160,8 @@ class AddonTest(unittest.TestCase):
menu = self.addon.SnapFormImageMenu()
menu.layout = Layout()
menu.draw(None)
with patch.object(self.addon.runtime, "runtime_ready", return_value=True):
menu.draw(None)
self.assertEqual(
calls,
@@ -161,6 +173,34 @@ class AddonTest(unittest.TestCase):
],
)
def test_image_context_menu_only_installs_backend_when_missing(self):
calls = []
class Operator:
job_type = None
class Layout:
operator_context = None
def operator(self, identifier, **options):
operator = Operator()
calls.append((identifier, options, operator))
return operator
def separator(self):
calls.append("separator")
menu = self.addon.SnapFormImageMenu()
menu.layout = Layout()
with patch.object(self.addon.runtime, "runtime_ready", return_value=False):
menu.draw(None)
self.assertEqual(len(calls), 1)
identifier, options, operator = calls[0]
self.assertEqual(identifier, "snapform.run_job")
self.assertEqual(options["text"], "Install Backend")
self.assertEqual(operator.job_type, "INSTALL_RUNTIME")
def test_image_mesh_reference_plane_matches_image_empty_bounds(self):
source_object = SimpleNamespace(
data=SimpleNamespace(size=(401, 201)),
@@ -1945,13 +1985,13 @@ class AddonTest(unittest.TestCase):
def test_host_panel_exposes_shared_host_state_and_controls(self):
self.assertIn(self.addon.HostPanel, self.addon.CLASSES)
self.assertIn(self.addon.ControlHost, self.addon.CLASSES)
self.assertEqual(self.addon.HostPanel.bl_label, "Host")
self.assertEqual(self.addon.HostPanel.bl_label, "AI Backend")
def test_ai_operation_restarts_a_manually_stopped_host(self):
runtime = self.addon.runtime
connection = runtime.HostConnection(51234, "token", 42, "host")
health = {
"host_schema": runtime.HOST_SCHEMA,
"job_protocol_version": runtime.JOB_PROTOCOL_VERSION,
"instance_id": "host",
"busy": False,
"clients": 1,