from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def test_workflow_version_schema_enforces_one_active_version_per_environment():
    migration = (ROOT / "migrations/versions/20260716_20_workflow_versions.py").read_text(encoding="utf-8")

    assert "dataflow_workflow_versions" in migration
    assert "UNIQUE (dataflow_uid, environment, version_no)" in migration
    assert "WHERE status = 'active'" in migration
    assert "definition_hash" in migration
    assert "n8n_workflow_id" in migration


def test_workflow_mapping_uses_stable_uid_not_numeric_id():
    repository = (ROOT / "app/core/data_flow/workflow_repository.py").read_text(encoding="utf-8")

    assert "ensure_governance_uid" in repository
    assert "dataflow_uid" in repository
