# SPDX-License-Identifier: AGPL-3.0-or-later
"""Shared test helpers."""

from __future__ import annotations

from typing import Any, Dict


def build_run_config(run_id: str, **overrides: Any) -> Dict[str, Any]:
    config = {
        "schema_version": 1,
        "run_id": run_id,
        "root_contract": {
            "description": "Add a health-check endpoint",
            "owned_scope": ["src/health/**"],
            "acceptance_command": "pytest tests/health",
        },
        "executor_profile": "scripted-fixture-v1",
        "budgets": {"MODEL_COST": 10.0},
        "policy_version": 1,
        "project_kernel": {
            "schema_version": 1,
            "kernel_id": "KERNEL-001",
            "repository_commit": "a1b2c3d4e5f6",
            "frozen_at": "2026-09-19T00:00:00Z",
        },
        "experiment_manifest": {
            "schema_version": 1,
            "manifest_id": "MANIFEST-001",
            "manifest_hash": "sha256:deadbeef",
        },
    }
    config.update(overrides)
    return config


def experiment_authorization():
    """The clearly-labelled test-fixture owner decision used by the frozen
    experiment acceptance tests. A real pilot must supply its own recorded
    authorization; this value only exists so the harness tests exercise the
    same code-enforced gate as production."""
    from orchestrator import spend

    return spend.ExperimentAuthorization(
        owner="test-fixture",
        limit=100000.0,
        authorized_at="2026-01-01T00:00:00Z",
        method="test-fixture",
    )


def open_test_spend_ledger(workdir):
    from orchestrator import spend

    return spend.open_spend_ledger(workdir, experiment_authorization())
