@tdd_issue @tdd_issue_8588
Feature: TDD Issue #8660 — ActorLoader.list_actors namespace filter inside lock

  As a developer
  I want to ensure ``ActorLoader.list_actors(..., namespace=...)`` applies the
  namespace filter while holding the threading lock
  So that concurrent modifications to the actor cache cannot corrupt the filtered
  result set and no ``RuntimeError: dictionary changed size during iteration`` is raised

  Background:
    Given a temporary directory with multiple namespace groups of actor YAML files


  Scenario: list_actors with namespace returns only matching actors
    When I create an ActorLoader from that directory
    And the loader discovers all actors
    Then filtering by namespace "local" should return only local actors
    And filtering by namespace "remote" should return only remote actors

  Scenario: list_actors without namespace returns all actors
    When I create an ActorLoader from that directory
    And the loader discovers all actors
    Then calling ``list_actors()`` without a filter should return every actor


  Scenario: list_actors namespace filter is thread-safe under concurrent mutation
    When I create an ActorLoader with initial actors from multiple namespaces
    And another thread concurrently adds and removes YAML files (triggering ``discover()``)
    And a worker repeatedly calls ``list_actors(namespace=...)`` in parallel
    Then no exceptions should be raised
    And every returned result should be internally consistent

  Scenario: filtering by non-existent namespace returns empty list
    When I create an ActorLoader from that directory
    And the loader discovers all actors
    Then filtering by a non-existent namespace should return an empty list
