Feature: Cross-actor subgraph cycle detection reads actor_ref field
  As a CleverAgents developer
  I want the actor compiler to correctly detect cross-actor subgraph cycles
  So that mutually-referencing actors raise SubgraphCycleError at compile time

  Background:
    Given the actor compiler is available

  # ────────────────────────────────────────────────────────────
  # Bug fix: actor_ref is a top-level NodeDefinition field
  # ────────────────────────────────────────────────────────────

  @tdd_issue @tdd_issue_1431
  Scenario: Mutually-referencing actors raise SubgraphCycleError
    Given actor "test/actor-a" has a subgraph node with actor_ref "test/actor-b"
    And actor "test/actor-b" has a subgraph node with actor_ref "test/actor-a"
    And a registry containing both actors
    When I compile actor "test/actor-a" with the registry resolver
    Then the compilation should raise SubgraphCycleError
    And the cycle error message should mention "cycle"

  @tdd_issue @tdd_issue_1431
  Scenario: Non-cyclic subgraph reference compiles successfully
    Given actor "test/actor-x" has a subgraph node with actor_ref "test/actor-y"
    And actor "test/actor-y" has no subgraph nodes
    And a registry containing both actors
    When I compile actor "test/actor-x" with the registry resolver
    Then the actor compilation should succeed
    And the actor subgraph_refs should map "sub" to "test/actor-y"

  @tdd_issue @tdd_issue_1431
  Scenario: Subgraph node actor_ref is reflected in compiled metadata
    Given actor "test/actor-p" has a subgraph node with actor_ref "test/actor-q"
    And actor "test/actor-q" has no subgraph nodes
    And a registry containing both actors
    When I compile actor "test/actor-p" with the registry resolver
    Then the actor compilation should succeed
    And the compiled node "sub" should have subgraph set to "test/actor-q"
