"""Housekeeping nits bundle (issue 10). Covers the testable items: start-export id parsing, aws_env no longer baking in a default profile/region, the lineage `source` enum member, and python version alignment. Runnable without a test harness:: .venv/bin/python tests/test_housekeeping_nits.py """ from __future__ import annotations import json import os import pathlib import sys import tomllib from types import SimpleNamespace ROOT = pathlib.Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) from ingestion.common.aws import aws_env from ingestion.extract.tidbcloud.engine.export import parse_export_id def test_parse_export_id_variants() -> None: assert parse_export_id('{"exportId": "exp-1"}') == "exp-1" assert parse_export_id('{"id": "exp-2"}') == "exp-2" assert parse_export_id('{"export": {"exportId": "exp-3"}}') == "exp-3" # `export create` does not accept --output and prints a plain line; parse the exp- token. assert parse_export_id("export exp-biewtu5tm5a3tpezosh7f2wtga is running now") == "exp-biewtu5tm5a3tpezosh7f2wtga" assert parse_export_id("not json") is None # degrades gracefully; export still ran assert parse_export_id('{"state": "RUNNING"}') is None # A null/non-dict "export" must degrade to None, not raise AttributeError. assert parse_export_id('{"export": null}') is None assert parse_export_id('{"export": "exp-x"}') is None def test_aws_env_does_not_bake_in_defaults() -> None: set_env = aws_env(SimpleNamespace(aws_profile="myprof", aws_region="eu-west-1")) assert set_env["AWS_PROFILE"] == "myprof" assert set_env["AWS_REGION"] == "eu-west-1" # With nothing configured, aws_env must not inject a default — it leaves the ambient # environment untouched (no hardcoded pingcap-datalake / us-west-2). unset_env = aws_env(SimpleNamespace(aws_profile=None, aws_region=None)) assert unset_env.get("AWS_PROFILE") == os.environ.get("AWS_PROFILE") assert unset_env.get("AWS_REGION") == os.environ.get("AWS_REGION") def test_lineage_enum_includes_source() -> None: for name in ( "data-product-contract.authored.v0.schema.json", "data-product-contract.runtime-view.v0.schema.json", ): schema = json.loads((ROOT / "schemas" / name).read_text()) enum = schema["$defs"]["lineageRef"]["properties"]["kind"]["enum"] assert "source" in enum, f"{name} lineageRef.kind must allow 'source'" def test_python_version_matches_requires_python() -> None: pinned = (ROOT / ".python-version").read_text().strip() # e.g. "3.12" requires = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]["requires-python"] assert requires == f">={pinned}", f".python-version {pinned} should match requires-python {requires}" if __name__ == "__main__": cases = [value for name, value in sorted(globals().items()) if name.startswith("test_") and callable(value)] for case in cases: case() print(f"ok {case.__name__}") print(f"\n{len(cases)} passed")