Feature: Resource CLI coverage r3 — remaining uncovered lines
  As a developer
  I want every uncovered branch and error handler in resource.py exercised
  So that the line-rate reaches close to 100 %

  # -----------------------------------------------------------------------
  # _resource_dict: str() fallback for created_at / updated_at (lines 159, 162)
  # -----------------------------------------------------------------------

  Scenario: _resource_dict uses str() when dates lack isoformat
    Given rccov3 a mock resource whose dates lack isoformat
    When rccov3 I call _resource_dict on it
    Then rccov3 the result created_at should be a plain string
    And rccov3 the result updated_at should be a plain string

  # -----------------------------------------------------------------------
  # type_remove: ResourceTypeParentRemovalError (lines 280-281)
  # -----------------------------------------------------------------------

  Scenario: type_remove catches ResourceTypeParentRemovalError
    Given rccov3 a service whose remove_type raises ResourceTypeParentRemovalError
    When rccov3 I invoke type_remove with yes flag
    Then rccov3 the command should have failed
    And rccov3 the output should contain "has subtypes"

  # -----------------------------------------------------------------------
  # type_remove: generic Exception handler (lines 288-289)
  # -----------------------------------------------------------------------

  Scenario: type_remove catches unexpected generic exception
    Given rccov3 a service whose remove_type raises a RuntimeError
    When rccov3 I invoke type_remove with yes flag
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # type_list: empty list branch (lines 310-311)
  # -----------------------------------------------------------------------

  Scenario: type_list shows message when no types registered
    Given rccov3 a service whose list_types returns empty
    When rccov3 I invoke type_list
    Then rccov3 the output should contain "No resource types registered"

  # -----------------------------------------------------------------------
  # type_list: generic Exception handler (lines 347-351)
  # -----------------------------------------------------------------------

  Scenario: type_list catches unexpected generic exception
    Given rccov3 a service whose list_types raises a RuntimeError
    When rccov3 I invoke type_list
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # type_show: generic Exception handler (lines 388-392)
  # -----------------------------------------------------------------------

  Scenario: type_show catches unexpected generic exception
    Given rccov3 a service whose show_type raises a RuntimeError
    When rccov3 I invoke type_show for "anything"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # _print_type_panel: chain resolution failure (lines 420-422)
  # -----------------------------------------------------------------------

  Scenario: _print_type_panel falls back when chain resolution fails
    Given rccov3 a type spec that inherits from another type
    And rccov3 a service whose resolve_type_inheritance_chain raises an exception
    When rccov3 I call _print_type_panel on the spec
    Then rccov3 the panel output should contain "..."

  # -----------------------------------------------------------------------
  # _format_properties: mounts JSON rendering (lines 465-471)
  # -----------------------------------------------------------------------

  Scenario: _format_properties renders mounts from JSON
    When rccov3 I call _format_properties with valid mounts JSON
    Then rccov3 the formatted output should contain "mount:"
    And rccov3 the formatted output should contain "/workspace"

  Scenario: _format_properties falls back on invalid mounts JSON
    When rccov3 I call _format_properties with invalid mounts JSON
    Then rccov3 the formatted output should contain "mounts:"

  # -----------------------------------------------------------------------
  # resource_add: image property (line 622)
  # -----------------------------------------------------------------------

  Scenario: resource_add stores image property for container-instance
    Given rccov3 a service that successfully registers a resource
    When rccov3 I invoke resource_add with image "ubuntu:latest"
    Then rccov3 the service register_resource was called with image in properties

  # -----------------------------------------------------------------------
  # resource_add: mount on non-container type (lines 624-626, 629-630)
  # -----------------------------------------------------------------------

  Scenario: resource_add rejects mount on non-container type
    Given rccov3 a service that successfully registers a resource
    When rccov3 I invoke resource_add with mount on git-checkout type
    Then rccov3 the command should have failed
    And rccov3 the output should contain "only valid for"

  # -----------------------------------------------------------------------
  # resource_list: generic Exception handler (lines 729-733)
  # -----------------------------------------------------------------------

  Scenario: resource_list catches unexpected generic exception
    Given rccov3 a service whose list_resources raises a RuntimeError
    When rccov3 I invoke resource_list
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # resource_show: generic Exception handler (lines 786-790)
  # -----------------------------------------------------------------------

  Scenario: resource_show catches unexpected generic exception
    Given rccov3 a service whose show_resource raises a RuntimeError
    When rccov3 I invoke resource_show for "anything"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # resource_tree: generic Exception handler (lines 847-851)
  # -----------------------------------------------------------------------

  Scenario: resource_tree catches unexpected generic exception
    Given rccov3 a service whose get_resource_tree raises a RuntimeError
    When rccov3 I invoke resource_tree for "anything"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # resource_inspect: empty tree_data path (line 950)
  # -----------------------------------------------------------------------

  Scenario: resource_inspect with tree flag but empty tree data
    Given rccov3 a service whose show_resource returns a mock and get_resource_tree returns empty
    When rccov3 I invoke resource_inspect with tree flag and json format
    Then rccov3 the output should contain "children"

  # -----------------------------------------------------------------------
  # resource_inspect: generic Exception handler (lines 1004-1008)
  # -----------------------------------------------------------------------

  Scenario: resource_inspect catches unexpected generic exception
    Given rccov3 a service whose show_resource raises a RuntimeError
    When rccov3 I invoke resource_inspect for "anything"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # _read_resource_file: path from properties (line 1019)
  # -----------------------------------------------------------------------

  Scenario: _read_resource_file resolves path from properties when location is None
    Given rccov3 a mock resource with no location but properties path
    When rccov3 I call _read_resource_file with a valid relative path
    Then rccov3 the file read result should contain expected content

  # -----------------------------------------------------------------------
  # _read_resource_file: path traversal rejection (line 1028)
  # -----------------------------------------------------------------------

  Scenario: _read_resource_file rejects path traversal
    Given rccov3 a mock resource with a known location
    When rccov3 I call _read_resource_file with a traversal path
    Then rccov3 the file read result should contain "path traversal rejected"

  # -----------------------------------------------------------------------
  # resource_link_child: generic Exception handler (lines 1091-1095)
  # -----------------------------------------------------------------------

  Scenario: resource_link_child catches unexpected generic exception
    Given rccov3 a service whose link_child raises a RuntimeError
    When rccov3 I invoke resource_link_child
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # resource_unlink_child: generic Exception handler (lines 1162-1163)
  # -----------------------------------------------------------------------

  Scenario: resource_unlink_child catches unexpected generic exception
    Given rccov3 a service whose unlink_child raises a RuntimeError
    When rccov3 I invoke resource_unlink_child with yes flag
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # resource_stop: confirmation prompt path (lines 1314-1316)
  # -----------------------------------------------------------------------

  Scenario: resource_stop prompts for confirmation when yes is False
    Given rccov3 a running devcontainer resource for stop
    When rccov3 I invoke resource_stop without yes flag and confirm
    Then rccov3 the output should contain "Stopped"

  # -----------------------------------------------------------------------
  # resource_stop: CleverAgentsError handler (lines 1333-1335)
  # -----------------------------------------------------------------------

  Scenario: resource_stop catches CleverAgentsError
    Given rccov3 a service whose show_resource raises CleverAgentsError
    When rccov3 I invoke resource_stop for "bad-resource"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Error:"

  # -----------------------------------------------------------------------
  # resource_stop: generic Exception handler (lines 1336-1340)
  # -----------------------------------------------------------------------

  Scenario: resource_stop catches unexpected generic exception
    Given rccov3 a service whose show_resource raises a TypeError for stop
    When rccov3 I invoke resource_stop for "bad-resource"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"

  # -----------------------------------------------------------------------
  # resource_rebuild: path from properties fallback (lines 1389-1390)
  # -----------------------------------------------------------------------

  Scenario: resource_rebuild resolves location from properties path
    Given rccov3 a stopped devcontainer resource with no location but properties path
    When rccov3 I invoke resource_rebuild with yes flag
    Then rccov3 the output should contain "Rebuilt"

  # -----------------------------------------------------------------------
  # resource_rebuild: confirmation prompt (lines 1397-1399)
  # -----------------------------------------------------------------------

  Scenario: resource_rebuild prompts for confirmation when yes is False
    Given rccov3 a stopped devcontainer resource for rebuild
    When rccov3 I invoke resource_rebuild without yes flag and confirm
    Then rccov3 the output should contain "Rebuilt"

  # -----------------------------------------------------------------------
  # resource_rebuild: CleverAgentsError handler (lines 1412-1414)
  # -----------------------------------------------------------------------

  Scenario: resource_rebuild catches CleverAgentsError
    Given rccov3 a service whose show_resource raises CleverAgentsError
    When rccov3 I invoke resource_rebuild for "bad-resource"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Error:"

  # -----------------------------------------------------------------------
  # resource_rebuild: generic Exception handler (lines 1415-1419)
  # -----------------------------------------------------------------------

  Scenario: resource_rebuild catches unexpected generic exception
    Given rccov3 a service whose show_resource raises a TypeError for rebuild
    When rccov3 I invoke resource_rebuild for "bad-resource"
    Then rccov3 the command should have failed
    And rccov3 the output should contain "Unexpected error"
