Spaces:
Runtime error
Runtime error
| """Tests for the Parameter Planner routing-manifest boundary.""" | |
| import pytest | |
| from ergo_agentic.datasources import DatasourceRegistry | |
| from ergo_agentic.domain.enums import Confidence, FocusGroup, WorkLocation | |
| from ergo_agentic.domain.manifest import ( | |
| BodyCoverage, | |
| DetectedAccessory, | |
| DisplayVisibleState, | |
| PostureContextHint, | |
| ScreenPresence, | |
| WorkspaceSemanticManifest, | |
| ) | |
| from ergo_agentic.nodes.parameter_planner import aggregate_scene_config, plan_parameters | |
| from ergo_agentic.nodes.routing import build_routing_manifest | |
| def registry() -> DatasourceRegistry: | |
| return DatasourceRegistry.from_knowledge_base() | |
| def _manifest( | |
| image_id: str, | |
| *, | |
| body_coverage: BodyCoverage = BodyCoverage.POSTURE_COVERAGE_SUFFICIENT, | |
| posture_hint: PostureContextHint = PostureContextHint.SITTING, | |
| chair_visible: bool = True, | |
| armrest_visible: bool = True, | |
| desk_visible: bool = True, | |
| keyboard_visible: bool = True, | |
| screens: list[ScreenPresence] | None = None, | |
| accessories: list[DetectedAccessory] | None = None, | |
| ) -> WorkspaceSemanticManifest: | |
| return WorkspaceSemanticManifest( | |
| image_id=image_id, | |
| work_location=WorkLocation.HOME_OFFICE, | |
| person_visible=body_coverage is not BodyCoverage.NONE, | |
| body_coverage=body_coverage, | |
| visible_body_regions=["head", "torso", "hips", "legs", "feet"] | |
| if body_coverage is BodyCoverage.POSTURE_COVERAGE_SUFFICIENT | |
| else ["hands"], | |
| posture_context_hint=posture_hint, | |
| chair_visible=chair_visible, | |
| chair_type="office chair" if chair_visible else None, | |
| armrest_visible=armrest_visible, | |
| desk_visible=desk_visible, | |
| feet_visible=body_coverage is BodyCoverage.POSTURE_COVERAGE_SUFFICIENT, | |
| screens=screens | |
| if screens is not None | |
| else [ | |
| ScreenPresence( | |
| type="monitor", | |
| coarse_layout_position="center", | |
| display_visible_state=DisplayVisibleState.CONTENT_VISIBLE, | |
| ) | |
| ], | |
| keyboard_mouse_visible=keyboard_visible, | |
| detected_accessories=accessories or [], | |
| overall_quality="good", | |
| analysis_confidence=Confidence.HIGH, | |
| reasoning="Fixture manifest.", | |
| ) | |
| def _state(*manifests: WorkspaceSemanticManifest, metadata: dict | None = None) -> dict: | |
| routing = build_routing_manifest( | |
| manifests=list(manifests), | |
| cv_results=[], | |
| metadata=metadata or {}, | |
| ) | |
| return { | |
| "image_manifests": list(manifests), | |
| "routing_manifest": routing, | |
| } | |
| def test_scene_config_comes_from_routing_manifest_not_standing_person() -> None: | |
| routing = build_routing_manifest( | |
| manifests=[ | |
| _manifest("img_1", posture_hint=PostureContextHint.STANDING), | |
| _manifest( | |
| "img_2", | |
| accessories=[ | |
| DetectedAccessory( | |
| type="sit-stand-desk", | |
| description="Visible adjustable desk legs.", | |
| ) | |
| ], | |
| ), | |
| ], | |
| cv_results=[], | |
| metadata={}, | |
| ) | |
| scene = aggregate_scene_config(routing) | |
| assert scene.screen_count == 1 | |
| assert scene.screen_types == ["monitor"] | |
| assert scene.has_standing_desk is True | |
| assert scene.work_location == WorkLocation.HOME_OFFICE | |
| assert scene.person_detected is True | |
| def test_planner_full_setup_includes_all_focus_groups(registry) -> None: | |
| result = plan_parameters( | |
| _state( | |
| _manifest("img_body"), | |
| _manifest("img_desk"), | |
| _manifest( | |
| "img_equipment", | |
| accessories=[ | |
| DetectedAccessory( | |
| type="sit-stand-desk", | |
| description="Visible adjustable desk legs.", | |
| ) | |
| ], | |
| ), | |
| ), | |
| registry=registry, | |
| ) | |
| plan = result["execution_plan"] | |
| assert plan["focus_groups"][FocusGroup.BODY_AND_CHAIR.value]["parameter_ids"] | |
| assert plan["focus_groups"][FocusGroup.DESK_AND_ARMS.value]["parameter_ids"] | |
| assert plan["focus_groups"][FocusGroup.SCREENS.value]["parameter_ids"] | |
| assert result["assessable_parameter_ids"] | |
| assert result["scene_config"].has_standing_desk is True | |
| def test_planner_chair_only_skips_screens_but_keeps_armrest(registry) -> None: | |
| result = plan_parameters( | |
| _state( | |
| _manifest( | |
| "img_chair", | |
| desk_visible=False, | |
| keyboard_visible=False, | |
| screens=[], | |
| ) | |
| ), | |
| registry=registry, | |
| ) | |
| plan = result["execution_plan"] | |
| body = plan["focus_groups"][FocusGroup.BODY_AND_CHAIR.value] | |
| assert body["parameter_ids"] | |
| assert body["image_ids"] == ["img_chair"] | |
| assert body["skip_reason"] is None | |
| desk = plan["focus_groups"][FocusGroup.DESK_AND_ARMS.value] | |
| desk_param_keys = [ | |
| registry.get_parameter(pid).options[0].key for pid in desk["parameter_ids"] | |
| ] | |
| assert all(k.startswith("chair-armRest-") for k in desk_param_keys) | |
| screens = plan["focus_groups"][FocusGroup.SCREENS.value] | |
| assert screens["parameter_ids"] == [] | |
| assert screens["skip_reason"] is not None | |
| def test_planner_skipped_parameters_include_unassessable(registry) -> None: | |
| result = plan_parameters( | |
| _state( | |
| _manifest( | |
| "img_chair", | |
| desk_visible=False, | |
| keyboard_visible=False, | |
| screens=[], | |
| ) | |
| ), | |
| registry=registry, | |
| ) | |
| skipped_param_keys = [ | |
| registry.get_parameter(pid).options[0].key for pid in result["skipped_parameters"] | |
| ] | |
| assert any(k.startswith("screens-") for k in skipped_param_keys) | |
| assert any(k.startswith("laptops-") for k in skipped_param_keys) | |
| def test_planner_chair_without_visible_armrest_skips_armrest(registry) -> None: | |
| result = plan_parameters( | |
| _state( | |
| _manifest( | |
| "chair_no_armrest", | |
| chair_visible=True, | |
| armrest_visible=False, | |
| desk_visible=False, | |
| keyboard_visible=False, | |
| screens=[], | |
| ) | |
| ), | |
| registry=registry, | |
| ) | |
| assert "Arm rest" not in result["assessable_parameters"] | |
| skipped_keys = [ | |
| registry.get_parameter(pid).options[0].key | |
| for pid in result["skipped_parameters"] | |
| ] | |
| assert any(k.startswith("chair-armRest-") for k in skipped_keys) | |
| def test_planner_does_not_enable_standing_desk_for_standing_person_only(registry) -> None: | |
| result = plan_parameters( | |
| _state(_manifest("img_standing", posture_hint=PostureContextHint.STANDING)), | |
| registry=registry, | |
| ) | |
| desk = result["execution_plan"]["focus_groups"][FocusGroup.DESK_AND_ARMS.value] | |
| desk_param_keys = [ | |
| registry.get_parameter(pid).options[0].key for pid in desk["parameter_ids"] | |
| ] | |
| assert not any(k.startswith("standingDesk-") for k in desk_param_keys) | |
| def test_planner_enables_standing_desk_only_when_equipment_visible(registry) -> None: | |
| result = plan_parameters( | |
| _state( | |
| _manifest( | |
| "img_standing_equipment", | |
| posture_hint=PostureContextHint.STANDING, | |
| accessories=[ | |
| DetectedAccessory(type="standing-desk", description="Visible standing desk.") | |
| ], | |
| ) | |
| ), | |
| registry=registry, | |
| ) | |
| desk = result["execution_plan"]["focus_groups"][FocusGroup.DESK_AND_ARMS.value] | |
| desk_param_keys = [ | |
| registry.get_parameter(pid).options[0].key for pid in desk["parameter_ids"] | |
| ] | |
| assert any(k.startswith("standingDesk-") for k in desk_param_keys) | |
| def test_planner_uses_routing_image_focus_coverage(registry) -> None: | |
| result = plan_parameters( | |
| _state( | |
| _manifest( | |
| "img_partial", | |
| body_coverage=BodyCoverage.PARTIAL, | |
| chair_visible=True, | |
| desk_visible=True, | |
| ), | |
| _manifest( | |
| "img_screens", | |
| body_coverage=BodyCoverage.NONE, | |
| chair_visible=False, | |
| armrest_visible=False, | |
| desk_visible=False, | |
| keyboard_visible=False, | |
| ), | |
| ), | |
| registry=registry, | |
| ) | |
| body = result["execution_plan"]["focus_groups"][FocusGroup.BODY_AND_CHAIR.value] | |
| assert body["parameter_ids"] == [] | |
| assert body["skip_reason"] == "person posture coverage insufficient" | |
| screens = result["execution_plan"]["focus_groups"][FocusGroup.SCREENS.value] | |
| assert screens["image_ids"] == ["img_partial", "img_screens"] | |
| def test_planner_no_person_skips_body_chair(registry) -> None: | |
| result = plan_parameters( | |
| _state( | |
| _manifest( | |
| "empty_room", | |
| body_coverage=BodyCoverage.NONE, | |
| chair_visible=True, | |
| armrest_visible=True, | |
| desk_visible=True, | |
| keyboard_visible=True, | |
| ) | |
| ), | |
| registry=registry, | |
| ) | |
| body = result["execution_plan"]["focus_groups"][FocusGroup.BODY_AND_CHAIR.value] | |
| assert body["parameter_ids"] == [] | |
| assert body["skip_reason"] is not None | |
| assert result["execution_plan"]["focus_groups"][FocusGroup.DESK_AND_ARMS.value][ | |
| "parameter_ids" | |
| ] | |
| assert result["execution_plan"]["focus_groups"][FocusGroup.SCREENS.value][ | |
| "parameter_ids" | |
| ] | |