from acl_engine.engine import ACLEngine


def test_full_file_workflow_and_variable_resolution(tmp_path) -> None:
    engine = ACLEngine(workspace=tmp_path)
    acl_text = '\n'.join(
        [
            'util.echo(value="hello world") -> content',
            'file.write(path="output.txt", content=content)',
            'file.read(path="output.txt") -> read_back',
        ]
    )

    result = engine.execute(acl_text)

    assert result["status"] == "success"
    assert result["data"]["content"] == "hello world"
    assert result["data"]["read_back"] == "hello world"


def test_memory_workflow(tmp_path) -> None:
    engine = ACLEngine(workspace=tmp_path)
    acl_text = '\n'.join(
        [
            'memory.store(key="name", value="acl")',
            'memory.get(key="name") -> value',
        ]
    )

    result = engine.execute(acl_text)

    assert result["status"] == "success"
    assert result["data"]["value"] == "acl"


def test_system_and_file_results_can_be_chained_with_selectors(tmp_path) -> None:
    engine = ACLEngine(workspace=tmp_path)
    acl_text = '\n'.join(
        [
            'file.write(path="note.txt", content="hello")',
            'file.stat(path="note.txt") -> stat',
            'util.echo(value=stat.exists) -> exists',
        ]
    )

    result = engine.execute(acl_text)

    assert result["status"] == "success"
    assert result["data"]["exists"] is True