Feature: Deferred Physical Resource Types
  As a CleverAgents developer
  I want built-in deferred physical resource type YAMLs to validate
  So that git object taxonomy and filesystem link types are available

  # ── Git object taxonomy types register for phys_deferred ───

  Scenario: git YAML validates for phys_deferred
    Given the built-in "git" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git" for phys_deferred
    And the spec resource_kind should be "physical" for phys_deferred
    And the spec sandbox_strategy should be "none" for phys_deferred
    And the spec user_addable should be true for phys_deferred
    And the spec built_in should be true for phys_deferred

  Scenario: git-remote YAML validates for phys_deferred
    Given the built-in "git-remote" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-remote" for phys_deferred
    And the spec resource_kind should be "physical" for phys_deferred
    And the spec user_addable should be false for phys_deferred

  Scenario: git-branch YAML validates for phys_deferred
    Given the built-in "git-branch" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-branch" for phys_deferred

  Scenario: git-tag YAML validates for phys_deferred
    Given the built-in "git-tag" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-tag" for phys_deferred

  Scenario: git-commit YAML validates for phys_deferred
    Given the built-in "git-commit" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-commit" for phys_deferred

  Scenario: git-tree YAML validates for phys_deferred
    Given the built-in "git-tree" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-tree" for phys_deferred

  Scenario: git-tree-entry YAML validates for phys_deferred
    Given the built-in "git-tree-entry" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-tree-entry" for phys_deferred

  Scenario: git-stash YAML validates for phys_deferred
    Given the built-in "git-stash" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-stash" for phys_deferred

  Scenario: git-submodule YAML validates for phys_deferred
    Given the built-in "git-submodule" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "git-submodule" for phys_deferred

  # ── Filesystem link types register for phys_deferred ───────

  Scenario: fs-symlink YAML validates for phys_deferred
    Given the built-in "fs-symlink" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "fs-symlink" for phys_deferred
    And the spec resource_kind should be "physical" for phys_deferred
    And the spec user_addable should be false for phys_deferred

  Scenario: fs-hardlink YAML validates for phys_deferred
    Given the built-in "fs-hardlink" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec should be valid for phys_deferred
    And the spec name should be "fs-hardlink" for phys_deferred
    And the spec resource_kind should be "physical" for phys_deferred
    And the spec user_addable should be false for phys_deferred

  # ── Parent/child constraints for phys_deferred ─────────────

  Scenario: git parent is git-checkout for phys_deferred
    Given the built-in "git" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git-checkout" for phys_deferred
    And the spec child_types should contain "git-remote" for phys_deferred
    And the spec child_types should contain "git-branch" for phys_deferred
    And the spec child_types should contain "git-tag" for phys_deferred
    And the spec child_types should contain "git-commit" for phys_deferred
    And the spec child_types should contain "git-stash" for phys_deferred
    And the spec child_types should contain "git-submodule" for phys_deferred

  Scenario: git-remote parent is git for phys_deferred
    Given the built-in "git-remote" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git" for phys_deferred
    And the spec should have empty child_types for phys_deferred

  Scenario: git-branch parent is git for phys_deferred
    Given the built-in "git-branch" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git" for phys_deferred
    And the spec child_types should contain "git-commit" for phys_deferred

  Scenario: git-tag parent is git for phys_deferred
    Given the built-in "git-tag" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git" for phys_deferred
    And the spec child_types should contain "git-commit" for phys_deferred

  Scenario: git-commit parents are git-branch, git-tag, and git for phys_deferred
    Given the built-in "git-commit" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git-branch" for phys_deferred
    And the spec parent_types should contain "git-tag" for phys_deferred
    And the spec parent_types should contain "git" for phys_deferred
    And the spec child_types should contain "git-tree" for phys_deferred

  Scenario: git-tree parents are git-commit and git-tree for phys_deferred
    Given the built-in "git-tree" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git-commit" for phys_deferred
    And the spec parent_types should contain "git-tree" for phys_deferred
    And the spec child_types should contain "git-tree-entry" for phys_deferred
    And the spec child_types should contain "git-tree" for phys_deferred

  Scenario: git-tree-entry parent is git-tree for phys_deferred
    Given the built-in "git-tree-entry" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git-tree" for phys_deferred
    And the spec should have empty child_types for phys_deferred

  Scenario: git-stash parent is git for phys_deferred
    Given the built-in "git-stash" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git" for phys_deferred
    And the spec should have empty child_types for phys_deferred

  Scenario: git-submodule parent is git for phys_deferred
    Given the built-in "git-submodule" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "git" for phys_deferred
    And the spec should have empty child_types for phys_deferred

  Scenario: fs-symlink parent is fs-directory for phys_deferred
    Given the built-in "fs-symlink" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "fs-directory" for phys_deferred
    And the spec should have empty child_types for phys_deferred

  Scenario: fs-hardlink parent is fs-directory for phys_deferred
    Given the built-in "fs-hardlink" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec parent_types should contain "fs-directory" for phys_deferred
    And the spec should have empty child_types for phys_deferred

  # ── Capabilities for phys_deferred ─────────────────────────

  Scenario: fs-symlink has read-only capabilities for phys_deferred
    Given the built-in "fs-symlink" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec capabilities read should be true for phys_deferred
    And the spec capabilities write should be false for phys_deferred

  Scenario: fs-hardlink has read-write capabilities for phys_deferred
    Given the built-in "fs-hardlink" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec capabilities read should be true for phys_deferred
    And the spec capabilities write should be true for phys_deferred

  Scenario: git-commit has read-only capabilities for phys_deferred
    Given the built-in "git-commit" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec capabilities read should be true for phys_deferred
    And the spec capabilities write should be false for phys_deferred

  Scenario: git-branch has read-write capabilities for phys_deferred
    Given the built-in "git-branch" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec capabilities read should be true for phys_deferred
    And the spec capabilities write should be true for phys_deferred

  # ── Auto-discovery bounded depth for phys_deferred ─────────

  Scenario: git has auto-discovery with bounded depth for phys_deferred
    Given the built-in "git" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec auto_discovery should be enabled for phys_deferred
    And the spec auto_discovery scan_depth should be 1 for phys_deferred

  Scenario: git-tree has auto-discovery with bounded depth for phys_deferred
    Given the built-in "git-tree" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec auto_discovery should be enabled for phys_deferred
    And the spec auto_discovery scan_depth should be 2 for phys_deferred

  Scenario: git-commit has auto-discovery with depth 1 for phys_deferred
    Given the built-in "git-commit" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec auto_discovery should be enabled for phys_deferred
    And the spec auto_discovery scan_depth should be 1 for phys_deferred

  Scenario: git-tree-entry has no auto-discovery for phys_deferred
    Given the built-in "git-tree-entry" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then the spec auto_discovery should be none for phys_deferred

  # ── Registry bootstrap for phys_deferred ───────────────────

  Scenario: all deferred physical types are in BUILTIN_NAMES for phys_deferred
    Given the ResourceTypeSpec BUILTIN_NAMES set for phys_deferred
    Then BUILTIN_NAMES should contain "git" for phys_deferred
    And BUILTIN_NAMES should contain "git-remote" for phys_deferred
    And BUILTIN_NAMES should contain "git-branch" for phys_deferred
    And BUILTIN_NAMES should contain "git-tag" for phys_deferred
    And BUILTIN_NAMES should contain "git-commit" for phys_deferred
    And BUILTIN_NAMES should contain "git-tree" for phys_deferred
    And BUILTIN_NAMES should contain "git-tree-entry" for phys_deferred
    And BUILTIN_NAMES should contain "git-stash" for phys_deferred
    And BUILTIN_NAMES should contain "git-submodule" for phys_deferred
    And BUILTIN_NAMES should contain "fs-symlink" for phys_deferred
    And BUILTIN_NAMES should contain "fs-hardlink" for phys_deferred

  Scenario: all deferred physical types are in _BUILTIN_TYPES for phys_deferred
    Given the _BUILTIN_TYPES list for phys_deferred
    Then _BUILTIN_TYPES should contain entry "git" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-remote" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-branch" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-tag" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-commit" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-tree" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-tree-entry" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-stash" for phys_deferred
    And _BUILTIN_TYPES should contain entry "git-submodule" for phys_deferred
    And _BUILTIN_TYPES should contain entry "fs-symlink" for phys_deferred
    And _BUILTIN_TYPES should contain entry "fs-hardlink" for phys_deferred

  # ── Negative: auto_discovery validation ──────────────────

  Scenario: Auto-discovery with invalid rule type is rejected for phys_deferred
    Given a physical type config with invalid auto_discovery rule type for phys_deferred
    When I attempt to create a ResourceTypeSpec from it for phys_deferred
    Then the phys_deferred creation should fail with "not a known built-in type"

  Scenario: Auto-discovery with empty pattern is rejected for phys_deferred
    Given a physical type config with empty auto_discovery pattern for phys_deferred
    When I attempt to create a ResourceTypeSpec from it for phys_deferred
    Then the phys_deferred creation should fail with "pattern"

  Scenario: Auto-discovery with excessive scan_depth is rejected for phys_deferred
    Given a physical type config with scan_depth 99 for phys_deferred
    When I attempt to create a ResourceTypeSpec from it for phys_deferred
    Then the phys_deferred creation should fail with "exceeds maximum"

  Scenario: Self-referential type without scan_depth is rejected for phys_deferred
    Given a self-referential type config without scan_depth for phys_deferred
    When I attempt to create a ResourceTypeSpec from it for phys_deferred
    Then the phys_deferred creation should fail with "self-referential"

  # ── as_cli_dict regression: both auto_discovery schemas ──

  Scenario: as_cli_dict works for rules-based auto_discovery for phys_deferred
    Given the built-in "git" YAML for phys_deferred
    When I load the YAML via from_config for phys_deferred
    Then as_cli_dict should succeed and include auto_discovery for phys_deferred

  Scenario: as_cli_dict works for trigger-based auto_discovery for phys_deferred
    Given the built-in "devcontainer-instance" type from registry for phys_deferred
    Then as_cli_dict should succeed and include auto_discovery for phys_deferred
