Skip to content
17 changes: 16 additions & 1 deletion services/core/models/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@

@pytest.fixture
def no_hf_network(monkeypatch):
"""Disable live HuggingFace API calls; keep fileset create/update paths local."""
"""Disable live HuggingFace API calls; keep fileset create/update paths local.

Patches validate_storage and resolve_config to no-ops, then poisons
HfApi.repo_info (the method that actually egresses to huggingface.co)
so any un-patched code path fails loudly instead of silently succeeding
when we happen to not be rate-limited.
"""
from huggingface_hub import HfApi

async def _validate_noop(self):
return None
Expand All @@ -52,6 +59,14 @@ async def _resolve_passthrough(self):
monkeypatch.setattr(HuggingfaceStorageImpl, "validate_storage", _validate_noop)
monkeypatch.setattr(HuggingfaceStorageImpl, "resolve_config", _resolve_passthrough)

def _poisoned_repo_info(self, *args, **kwargs):
Comment thread
matthewgrossman marked this conversation as resolved.
Outdated
raise RuntimeError(
"HfApi.repo_info() called during a test using no_hf_network! "
"A code path is making real HuggingFace API calls that should be mocked."
)

monkeypatch.setattr(HfApi, "repo_info", _poisoned_repo_info)


# =============================================================================
# Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,10 @@ class TestTrustRemoteCodePermission:
trust_remote_code=True requires models.trust-remote-code.set.
"""

@pytest.fixture(autouse=True)
def _no_hf(self, no_hf_network):
"""These tests verify authorization logic, not HF connectivity."""

def test_create_model_trust_remote_code_true_has_permission_succeeds(self, sdk: NeMoPlatform):
"""Create with trust_remote_code=True succeeds when principal has models.trust-remote-code.set (repo not on allow list)."""
workspace = short_unique_name("trc-has")
Expand Down
Loading