Feature: Deferred Virtual Resource Types
  As a CleverAgents developer
  I want built-in virtual resource types (remote, submodule, symlink)
  So that equivalence tracking can link physical resources across repos and layers

  # ── Existence and loading ─────────────────────────────────

  Scenario: remote YAML validates for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should be valid
    And the virt_deferred schema name should be "remote"

  Scenario: submodule YAML validates for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should be valid
    And the virt_deferred schema name should be "submodule"

  Scenario: symlink YAML validates for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should be valid
    And the virt_deferred schema name should be "symlink"

  # ── Resource kind ─────────────────────────────────────────

  Scenario: remote is a virtual resource type for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema resource_kind should be "virtual"

  Scenario: submodule is a virtual resource type for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema resource_kind should be "virtual"

  Scenario: symlink is a virtual resource type for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema resource_kind should be "virtual"

  # ── Not user-addable ──────────────────────────────────────

  Scenario: remote is not user-addable for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema user_addable should be false

  Scenario: submodule is not user-addable for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema user_addable should be false

  Scenario: symlink is not user-addable for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema user_addable should be false

  # ── Built-in and unnamespaced ─────────────────────────────

  Scenario: remote is built-in and unnamespaced for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema built_in should be true
    And the virt_deferred schema name should not contain "/"

  Scenario: submodule is built-in and unnamespaced for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema built_in should be true
    And the virt_deferred schema name should not contain "/"

  Scenario: symlink is built-in and unnamespaced for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema built_in should be true
    And the virt_deferred schema name should not contain "/"

  # ── Sandbox strategy ──────────────────────────────────────

  Scenario: remote has no sandbox strategy for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema sandbox_strategy should be "none"

  Scenario: submodule has no sandbox strategy for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema sandbox_strategy should be "none"

  Scenario: symlink has no sandbox strategy for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema sandbox_strategy should be "none"

  # ── Capabilities (all false for virtual) ──────────────────

  Scenario: remote has all capabilities false for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred capabilities should have read false
    And the virt_deferred capabilities should have write false
    And the virt_deferred capabilities should have sandbox false
    And the virt_deferred capabilities should have checkpoint false

  Scenario: submodule has all capabilities false for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred capabilities should have read false
    And the virt_deferred capabilities should have write false
    And the virt_deferred capabilities should have sandbox false
    And the virt_deferred capabilities should have checkpoint false

  Scenario: symlink has all capabilities false for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred capabilities should have read false
    And the virt_deferred capabilities should have write false
    And the virt_deferred capabilities should have sandbox false
    And the virt_deferred capabilities should have checkpoint false

  # ── Equivalence metadata ──────────────────────────────────

  Scenario: remote has equivalence metadata for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema equivalence should be present
    And the virt_deferred equivalence criteria should contain "url"

  Scenario: submodule has equivalence metadata for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema equivalence should be present
    And the virt_deferred equivalence criteria should contain "url"
    And the virt_deferred equivalence criteria should contain "path"

  Scenario: symlink has equivalence metadata for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema equivalence should be present
    And the virt_deferred equivalence criteria should contain "name"
    And the virt_deferred equivalence criteria should contain "target_path"

  # ── Domain model loading ──────────────────────────────────

  Scenario: remote YAML loads as domain model for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML as a ResourceTypeSpec for virt_deferred
    Then the virt_deferred domain model should be valid
    And the virt_deferred domain model name should be "remote"
    And the virt_deferred domain model resource_kind should be "virtual"

  Scenario: submodule YAML loads as domain model for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML as a ResourceTypeSpec for virt_deferred
    Then the virt_deferred domain model should be valid
    And the virt_deferred domain model name should be "submodule"
    And the virt_deferred domain model resource_kind should be "virtual"

  Scenario: symlink YAML loads as domain model for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML as a ResourceTypeSpec for virt_deferred
    Then the virt_deferred domain model should be valid
    And the virt_deferred domain model name should be "symlink"
    And the virt_deferred domain model resource_kind should be "virtual"

  # ── Child types ───────────────────────────────────────────

  Scenario: remote allows git-remote children for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema child_types should contain "git-remote"

  Scenario: submodule allows git-submodule children for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema child_types should contain "git-submodule"

  Scenario: symlink allows fs-symlink children for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema child_types should contain "fs-symlink"

  Scenario: symlink allows git-tree-entry children for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema child_types should contain "git-tree-entry"

  # ── No parent types ───────────────────────────────────────

  Scenario: remote has no parent types for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should have empty parent_types

  Scenario: submodule has no parent types for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should have empty parent_types

  Scenario: symlink has no parent types for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should have empty parent_types

  # ── No CLI args ───────────────────────────────────────────

  Scenario: remote has no cli_args for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should have 0 cli_args

  Scenario: submodule has no cli_args for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should have 0 cli_args

  Scenario: symlink has no cli_args for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema should have 0 cli_args

  # ── No handler ────────────────────────────────────────────

  Scenario: remote has no handler for virt_deferred
    Given the built-in remote YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema handler should be none

  Scenario: submodule has no handler for virt_deferred
    Given the built-in submodule YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema handler should be none

  Scenario: symlink has no handler for virt_deferred
    Given the built-in symlink YAML file for virt_deferred
    When I load the YAML via schema for virt_deferred
    Then the virt_deferred schema handler should be none

  # ── Registry bootstrap includes virtual types ─────────────

  Scenario: builtin types list includes deferred virtual types for virt_deferred
    Given the registry builtin types list for virt_deferred
    Then the registry should contain type "remote" for virt_deferred
    And the registry should contain type "submodule" for virt_deferred
    And the registry should contain type "symlink" for virt_deferred

  Scenario: deferred virtual types in registry are not user-addable for virt_deferred
    Given the registry builtin types list for virt_deferred
    Then the registry type "remote" should not be user_addable for virt_deferred
    And the registry type "submodule" should not be user_addable for virt_deferred
    And the registry type "symlink" should not be user_addable for virt_deferred

  Scenario: deferred virtual types in registry are virtual for virt_deferred
    Given the registry builtin types list for virt_deferred
    Then the registry type "remote" should be virtual for virt_deferred
    And the registry type "submodule" should be virtual for virt_deferred
    And the registry type "symlink" should be virtual for virt_deferred

  Scenario: deferred virtual types in registry have equivalence for virt_deferred
    Given the registry builtin types list for virt_deferred
    Then the registry type "remote" should have equivalence for virt_deferred
    And the registry type "submodule" should have equivalence for virt_deferred
    And the registry type "symlink" should have equivalence for virt_deferred

  # ── BUILTIN_NAMES includes virtual types ──────────────────

  Scenario: BUILTIN_NAMES includes deferred virtual type names for virt_deferred
    Given the ResourceTypeSpec BUILTIN_NAMES set for virt_deferred
    Then BUILTIN_NAMES should contain "remote" for virt_deferred
    And BUILTIN_NAMES should contain "submodule" for virt_deferred
    And BUILTIN_NAMES should contain "symlink" for virt_deferred

  # ── DB roundtrip via bootstrap ─────────────────────────────

  Scenario: virtual types survive DB roundtrip after bootstrap for virt_deferred
    Given a virt_deferred fresh in-memory resource registry with bootstrap
    When I query the virt_deferred registry for type "remote"
    Then the virt_deferred db type "remote" should exist
    And the virt_deferred db type "remote" should have kind "virtual"
    And the virt_deferred db type "remote" should not be user_addable
    And the virt_deferred db type "remote" should have equivalence with criteria "url"
    When I query the virt_deferred registry for type "submodule"
    Then the virt_deferred db type "submodule" should exist
    And the virt_deferred db type "submodule" should have kind "virtual"
    And the virt_deferred db type "submodule" should not be user_addable
    And the virt_deferred db type "submodule" should have equivalence with criteria "url,path"
    When I query the virt_deferred registry for type "symlink"
    Then the virt_deferred db type "symlink" should exist
    And the virt_deferred db type "symlink" should have kind "virtual"
    And the virt_deferred db type "symlink" should not be user_addable
    And the virt_deferred db type "symlink" should have equivalence with criteria "name,target_path"

  Scenario: virtual types appear in list_types after bootstrap for virt_deferred
    Given a virt_deferred fresh in-memory resource registry with bootstrap
    When I list all virt_deferred registry types
    Then the virt_deferred type list should include "remote"
    And the virt_deferred type list should include "submodule"
    And the virt_deferred type list should include "symlink"

  # ── Negative tests ─────────────────────────────────────────

  Scenario: virtual type without equivalence fails validation for virt_deferred
    When I create a virt_deferred virtual type config without equivalence
    Then the virt_deferred config creation should raise a validation error

  Scenario: from_config rejects missing name for virt_deferred
    When I create a virt_deferred config without name
    Then the virt_deferred config creation should raise a ValueError

  Scenario: from_config rejects missing resource_kind for virt_deferred
    When I create a virt_deferred config without resource_kind
    Then the virt_deferred config creation should raise a ValueError

  # ── Manual add rejection (F-001 / F-003) ───────────────────

  Scenario: manual register_resource rejects remote as not user-addable
    Given a virt_deferred fresh in-memory resource registry with bootstrap
    When I attempt to manually register a resource of type "remote" for virt_deferred
    Then the virt_deferred manual registration should be rejected
    And the virt_deferred rejection message should mention "not user-addable"

  Scenario: manual register_resource rejects submodule as not user-addable
    Given a virt_deferred fresh in-memory resource registry with bootstrap
    When I attempt to manually register a resource of type "submodule" for virt_deferred
    Then the virt_deferred manual registration should be rejected
    And the virt_deferred rejection message should mention "not user-addable"

  Scenario: manual register_resource rejects symlink as not user-addable
    Given a virt_deferred fresh in-memory resource registry with bootstrap
    When I attempt to manually register a resource of type "symlink" for virt_deferred
    Then the virt_deferred manual registration should be rejected
    And the virt_deferred rejection message should mention "not user-addable"

  # ── Equivalence criteria validation (F-004) ────────────────

  Scenario: equivalence with non-string criteria element fails validation
    When I create a virt_deferred virtual type config with criteria containing 123
    Then the virt_deferred config creation should raise a validation error

  Scenario: equivalence with empty-string criteria element fails validation
    When I create a virt_deferred virtual type config with criteria containing ""
    Then the virt_deferred config creation should raise a validation error
