diff --git a/inference/stages/load_prices.py b/inference/stages/load_prices.py index add1f6f..5cf27cb 100644 --- a/inference/stages/load_prices.py +++ b/inference/stages/load_prices.py @@ -119,16 +119,18 @@ def _verify_arctic_fresh(universe_lib, date_str: str) -> None: def _connect_arctic(bucket: str) -> "tuple[object, object]": - """Open the ArcticDB universe + macro libraries. Hard-fail on unreachable.""" - region = os.environ.get("AWS_REGION", "us-east-1") - uri = f"s3s://s3.{region}.amazonaws.com:{bucket}?path_prefix=arcticdb&aws_auth=true" + """Open the ArcticDB universe + macro libraries. Hard-fail on unreachable. + + Delegates to ``alpha_engine_lib.arcticdb.open_universe_lib`` / + ``open_macro_lib`` (L2771 chokepoint). ``PipelineAbort`` is preserved + on the failure path so existing pipeline-level except handlers stay + correctly typed. + """ + from alpha_engine_lib.arcticdb import open_universe_lib, open_macro_lib try: - arctic = adb.Arctic(uri) - return arctic.get_library("universe"), arctic.get_library("macro") + return open_universe_lib(bucket), open_macro_lib(bucket) except Exception as exc: - raise PipelineAbort( - f"ArcticDB unreachable at {uri}: {exc}" - ) from exc + raise PipelineAbort(str(exc)) from exc def load_price_data_from_arctic( diff --git a/inference/stages/run_inference.py b/inference/stages/run_inference.py index 13070aa..2f894dc 100644 --- a/inference/stages/run_inference.py +++ b/inference/stages/run_inference.py @@ -198,14 +198,8 @@ def _load_precomputed_features_from_arcticdb( inline compute_features. Those fallbacks masked a ``_run_gbm_inference`` miswiring where ArcticDB was never actually consulted in production. """ - region = os.environ.get("AWS_REGION", "us-east-1") - uri = f"s3s://s3.{region}.amazonaws.com:{ctx.bucket}?path_prefix=arcticdb&aws_auth=true" - try: - universe = adb.Arctic(uri).get_library("universe") - except Exception as exc: - raise RuntimeError( - f"ArcticDB universe library unreachable at {uri}: {exc}" - ) from exc + from alpha_engine_lib.arcticdb import open_universe_lib + universe = open_universe_lib(ctx.bucket) precomputed: dict[str, pd.Series] = {} n_err = 0 diff --git a/scripts/dry_run_meta_training.py b/scripts/dry_run_meta_training.py index 4d85cef..5497230 100644 --- a/scripts/dry_run_meta_training.py +++ b/scripts/dry_run_meta_training.py @@ -70,9 +70,8 @@ def pull_from_arcticdb(local_dir: Path) -> int: import pandas as pd import boto3 - region = os.environ.get("AWS_REGION", "us-east-1") - uri = f"s3s://s3.{region}.amazonaws.com:{BUCKET}?path_prefix={ARCTIC_PREFIX}&aws_auth=true" - arctic = _adb.Arctic(uri) + from alpha_engine_lib.arcticdb import open_arctic + arctic = open_arctic(BUCKET) universe = arctic.get_library("universe") macro_lib = arctic.get_library("macro") diff --git a/store/arctic_reader.py b/store/arctic_reader.py index c971815..b8bb6df 100644 --- a/store/arctic_reader.py +++ b/store/arctic_reader.py @@ -32,10 +32,9 @@ def _get_arctic(bucket: str) -> adb.Arctic: - """Create ArcticDB connection.""" - region = os.environ.get("AWS_REGION", "us-east-1") - uri = f"s3s://s3.{region}.amazonaws.com:{bucket}?path_prefix={ARCTIC_PREFIX}&aws_auth=true" - return adb.Arctic(uri) + """Create ArcticDB connection via the lib chokepoint (L2771).""" + from alpha_engine_lib.arcticdb import open_arctic + return open_arctic(bucket) def download_from_arctic( diff --git a/tests/test_arctic_reader.py b/tests/test_arctic_reader.py index 9a847c6..47a4168 100644 --- a/tests/test_arctic_reader.py +++ b/tests/test_arctic_reader.py @@ -10,9 +10,22 @@ @pytest.fixture def fake_arcticdb(monkeypatch): - """Replace store.arctic_reader.adb with a controllable mock.""" + """Replace the ``arcticdb`` module singleton's ``Arctic`` class with a + controllable mock. Patches at the singleton level so BOTH direct + ``import arcticdb as adb; adb.Arctic(...)`` callers AND the + ``alpha_engine_lib.arcticdb._import_arcticdb()`` lazy-import path + (used by ``open_arctic`` / ``open_universe_lib`` / ``open_macro_lib``) + pick up the mock. Without singleton-level patching, a lib-routed + call would bypass the mock and hit real S3 (post-L2771 chokepoint + migration).""" + import arcticdb as _real_arcticdb import store.arctic_reader as mod fake = MagicMock(name="arcticdb") + # Patch on the actual arcticdb module attribute — caught by both + # the consumer's `adb.Arctic(...)` and the lib's `open_arctic(...)`. + monkeypatch.setattr(_real_arcticdb, "Arctic", fake.Arctic) + # Also patch the consumer module's local ``adb`` reference for any + # legacy callers that still use it directly outside of `_get_arctic`. monkeypatch.setattr(mod, "adb", fake) return fake