coreason-meta-engineering 0.1.0

Rust port of the CoReason Agentic Forge & AST Manipulation Layer
Documentation
# Copyright (c) 2026 CoReason, Inc
#
# This software is proprietary and dual-licensed
# Licensed under the Prosperity Public License 3.0 (the "License")
# A copy of the license is available at <https://prosperitylicense.com/versions/3.0.0>
# For details, see the LICENSE file
# Commercial use beyond a 30-day trial requires a separate license
#
# Source Code: <https://github.com/CoReason-AI/coreason-runtime>

import os
import shutil
import tempfile
from collections.abc import Generator

import pytest


@pytest.fixture(autouse=True)
def setup_workspace(request: pytest.FixtureRequest) -> Generator[None]:
    """Automatically configure COREASON_WORKSPACE_ROOT and COREASON_CLA_ACCEPTED for all tests."""
    old_root = os.environ.get("COREASON_WORKSPACE_ROOT")
    old_cla = os.environ.get("COREASON_CLA_ACCEPTED")
    os.environ["COREASON_CLA_ACCEPTED"] = "yes"

    # If the test requests tmp_path, use that as the workspace root.
    if "tmp_path" in request.fixturenames:
        tmp_path = request.getfixturevalue("tmp_path")
        os.environ["COREASON_WORKSPACE_ROOT"] = str(tmp_path)
        yield
    else:
        temp_dir = tempfile.mkdtemp()
        os.environ["COREASON_WORKSPACE_ROOT"] = temp_dir
        try:
            yield
        finally:
            shutil.rmtree(temp_dir, ignore_errors=True)

    # Restore the original environment variables
    if old_root is not None:
        os.environ["COREASON_WORKSPACE_ROOT"] = old_root
    elif "COREASON_WORKSPACE_ROOT" in os.environ:
        del os.environ["COREASON_WORKSPACE_ROOT"]

    if old_cla is not None:
        os.environ["COREASON_CLA_ACCEPTED"] = old_cla
    elif "COREASON_CLA_ACCEPTED" in os.environ:
        del os.environ["COREASON_CLA_ACCEPTED"]