*** Settings ***
Documentation       Resource Type Schema YAML Load Test
Library             Process
Library             OperatingSystem

*** Variables ***
${FIXTURE_YAML}     ${CURDIR}/fixtures/resource_type_fixture.yaml

*** Test Cases ***
Load Resource Type YAML Fixture And Assert Fields
    [Documentation]    Load a resource type YAML fixture and verify fields
    ${script}=    Catenate    SEPARATOR=\n
    ...    import sys
    ...    import yaml
    ...    from cleveragents.resource.schema import ResourceTypeConfigSchema
    ...    schema = ResourceTypeConfigSchema.from_yaml_file("${FIXTURE_YAML}")
    ...    assert schema.name == "myorg/robot-test", f"name mismatch: {schema.name}"
    ...    assert schema.resource_kind == "physical", f"kind mismatch: {schema.resource_kind}"
    ...    assert schema.sandbox_strategy == "git_worktree", f"strategy mismatch: {schema.sandbox_strategy}"
    ...    assert len(schema.cli_args) == 2, f"cli_args count mismatch: {len(schema.cli_args)}"
    ...    assert schema.cli_args[0].name == "path", f"first arg name mismatch: {schema.cli_args[0].name}"
    ...    assert schema.cli_args[1].name == "branch", f"second arg name mismatch: {schema.cli_args[1].name}"
    ...    assert schema.capabilities["read"] is True
    ...    assert schema.capabilities["write"] is True
    ...    print("All resource type schema assertions passed")
    ${result}=    Run Process    ${PYTHON}    -c    ${script}
    Should Be Equal As Integers    ${result.rc}    0    Resource type schema load failed: ${result.stderr}
    Should Contain    ${result.stdout}    All resource type schema assertions passed

Resource Type Domain Model From Config
    [Documentation]    Load a resource type config dict and verify domain model
    ${script}=    Catenate    SEPARATOR=\n
    ...    import yaml
    ...    from cleveragents.domain.models.core.resource_type import ResourceTypeSpec
    ...    f = open("${FIXTURE_YAML}")
    ...    config = yaml.safe_load(f)
    ...    f.close()
    ...    spec = ResourceTypeSpec.from_config(config)
    ...    assert spec.name == "myorg/robot-test", f"name: {spec.name}"
    ...    assert spec.resource_kind.value == "physical"
    ...    assert spec.sandbox_strategy.value == "git_worktree"
    ...    cli_dict = spec.as_cli_dict()
    ...    assert "name" in cli_dict
    ...    assert "capabilities" in cli_dict
    ...    print("All resource type domain model assertions passed")
    ${result}=    Run Process    ${PYTHON}    -c    ${script}
    Should Be Equal As Integers    ${result.rc}    0    Domain model load failed: ${result.stderr}
    Should Contain    ${result.stdout}    All resource type domain model assertions passed

*** Keywords ***
