"""Helper script for actor registry persistence Robot tests.

Invoked by Robot Framework via ``Run Process`` to verify domain-model
behaviour in a subprocess with the real package installed.

Usage::

    python helper_actor_registry_persistence.py <test_name>

Where *test_name* is one of:

- ``list_yaml_metadata`` - verify yaml_text / compiled_metadata round-trip
- ``schema_version_default`` - verify default schema_version is ``"1.0"``
- ``namespaced_name`` - verify a namespaced name is preserved
"""

from __future__ import annotations

import sys


def _test_list_yaml_metadata() -> None:
    from cleveragents.domain.models.core.actor import Actor

    actor = Actor(
        name="local/test",
        provider="openai",
        model="gpt-4",
        config_hash=Actor.compute_hash({}),
        yaml_text="name: local/test\nprovider: openai\nmodel: gpt-4",
        schema_version="1.0",
        compiled_metadata={"nodes": 2},
    )
    assert actor.name == "local/test", f"Expected 'local/test', got {actor.name!r}"
    assert actor.schema_version == "1.0", (
        f"Expected schema_version '1.0', got {actor.schema_version!r}"
    )
    assert actor.yaml_text is not None, "yaml_text should not be None"
    assert actor.compiled_metadata is not None, "compiled_metadata should not be None"
    print("yaml-metadata-ok")


def _test_schema_version_default() -> None:
    from cleveragents.domain.models.core.actor import Actor

    actor = Actor(
        name="local/default-ver",
        provider="openai",
        model="gpt-4",
        config_hash=Actor.compute_hash({}),
    )
    assert actor.schema_version == "1.0", (
        f"Expected schema_version '1.0', got {actor.schema_version!r}"
    )
    print("schema-version-default-ok")


def _test_namespaced_name() -> None:
    from cleveragents.domain.models.core.actor import Actor

    actor = Actor(
        name="local/valid-name",
        provider="openai",
        model="gpt-4",
        config_hash=Actor.compute_hash({}),
    )
    assert actor.name == "local/valid-name", (
        f"Expected name 'local/valid-name', got {actor.name!r}"
    )
    print("namespaced-name-ok")


_TESTS = {
    "list_yaml_metadata": _test_list_yaml_metadata,
    "schema_version_default": _test_schema_version_default,
    "namespaced_name": _test_namespaced_name,
}

if __name__ == "__main__":
    name = sys.argv[1]
    _TESTS[name]()
