Skip to content

fix(tests): Mock HF in integration tests#259

Draft
matthewgrossman wants to merge 4 commits into
mainfrom
mgrossman/aircore-744-python-integration-tests-hit-hugging-face-rate-limits
Draft

fix(tests): Mock HF in integration tests#259
matthewgrossman wants to merge 4 commits into
mainfrom
mgrossman/aircore-744-python-integration-tests-hit-hugging-face-rate-limits

Conversation

@matthewgrossman

@matthewgrossman matthewgrossman commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Problem

TestTrustRemoteCodePermission integration tests create HuggingFace-backed filesets (storage.type=huggingface), which triggers real HF Hub API calls (repo_info, get_hf_file_metadata) during validate_storage() and resolve_config(). These calls are rate-limited by HuggingFace, causing all 6 tests to fail with:

nemo_platform.InternalServerError: Error code: 502 - {'detail': 'Storage backend unavailable:
Rate limited for https://huggingface.co/api/models/Qwen/Qwen3-0.6B/revision/main'}

Setting HF_TOKEN in CI (PR #202) reduced the frequency but didn't eliminate the issue — rate limits still apply to authenticated users, and concurrent CI runs sharing the same token compound the problem.

Strategy

Mock at the boundary, not in the test logic. These tests verify authorization behavior (who can set trust_remote_code), not HuggingFace connectivity. The real HF API calls are an unnecessary side effect of fileset creation that adds fragility without testing anything meaningful.

Added an autouse _mock_hf_storage fixture to TestTrustRemoteCodePermission that patches HfApi — the same pattern used by the existing unit tests in services/core/files/tests/test_huggingface_backend.py. The mock returns a synthetic repo_info with an empty siblings list (skipping the file metadata check) and a fake commit SHA for resolve_config().

No fixture files needed — just a 16-line mock that prevents the 6 failing tests from ever hitting the network.

Test plan

  • CI integration tests pass (specifically TestTrustRemoteCodePermission — the 6 tests that were failing)
  • No other integration test regressions

Fixes AIRCORE-744

Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
The conftest.py patches hf_hub_download and AutoConfig.from_pretrained
to serve from local fixtures, preventing HuggingFace API calls.
The download_fixtures.py script regenerates fixtures when new models
are added to tests.

Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 19025/25079 75.9% 62.4%
Integration Tests 12032/23851 50.4% 25.6%

The 5K lines of HF config fixtures were unnecessary — the parallelism
tests are always skipped in CI (torch not installed). Stripped down to
only the change that fixes the actual CI failures: mocking HfApi in
TestTrustRemoteCodePermission.

Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant