8000
Skip to content

Add tests for cache case resolution (from PR #4822)#4823

Merged
danielhanchen merged 1 commit intomainfrom
pr-4822-tests
Apr 3, 2026
Merged

Add tests for cache case resolution (from PR #4822)#4823
danielhanchen merged 1 commit intomainfrom
pr-4822-tests

Conversation

@danielhanchen
Copy link
Copy Markdown
Contributor

Summary

  • Adds unit tests for resolve_cached_repo_id_case covering exact-case hits, case-variant hits, tie-breaking, no-cache fallback, memoization, and late cache population
  • Adds route-level test verifying get_model_config normalizes casing before vision/embedding/audio checks
  • Separated from the runtime changes in PR studio: reuse HF cached repo casing to prevent duplicate downloads #4822 to keep that PR focused

Test plan

  • Tests are self-contained and mock external dependencies (structlog, HF cache dirs)
  • Run via pytest studio/backend/tests/test_cache_case_resolution.py studio/backend/tests/test_models_get_model_config_case_resolution.py

Tests for resolve_cached_repo_id_case and get_model_config case
resolution, separated from the runtime changes in PR #4822.
Copy link
Copy Markdown
Contributor
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces test suites for cache case resolution and model configuration routing. The feedback points out a potential test failure on case-insensitive filesystems, an incorrect mock for is_local_path due to local imports, and a limitation in the _DummyLogger mock that prevents method chaining.

Comment on lines +64 to +65
_mk_cache_repo(tmp_path, "Org/Model")
_mk_cache_repo(tmp_path, "org/model")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This test will fail on case-insensitive filesystems (like macOS or Windows) because models--Org--Model and models--org--model resolve to the same directory. Consequently, only one variant will exist on disk, and stats["tie_breaks"] will be 0 instead of 1.

To make this test cross-platform, consider mocking the directory listing logic (e.g., os.listdir or Path.iterdir) instead of relying on the actual filesystem, or skip the test if the filesystem is case-insensitive.

calls["from_identifier"] = model_name
return _DummyModelConfig()

monkeypatch.setattr(models_route, "is_local_path", lambda _: False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The mock for is_local_path is applied to the models_route module, but the get_model_config function in routes/models.py imports is_local_path locally from utils.models.model_config (line 600).

Because of this local import, the function will use the real is_local_path from the source module rather than the one you've patched on models_route. You should patch it on model_config_module instead.

Suggested change
monkeypatch.setattr(models_route, "is_local_path", lambda _: False)
monkeypatch.setattr(model_config_module, "is_local_path", lambda _: False)

Comment on lines +12 to +14
class _DummyLogger:
def __getattr__(self, _name):
return lambda *args, **kwargs: None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The _DummyLogger mock is too simplistic and will cause tests to crash if the code uses method chaining (e.g., logger.bind(...).info(...)), which is a common pattern with structlog.

Returning self from the mocked methods allows for such chaining.

Suggested change
class _DummyLogger:
def __getattr__(self, _name):
return lambda *args, **kwargs: None
class _DummyLogger:
def __getattr__(self, _name):
return lambda *args, **kwargs: self

Copy link
Copy Markdown
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f099dbb0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +21 to +24
from utils.paths.path_utils import (
resolve_cached_repo_id_case,
get_cache_case_resolution_stats,
reset_cache_case_resolution_state,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove imports of unresolved cache-resolution helpers

This test module imports resolve_cached_repo_id_case, get_cache_case_resolution_stats, and reset_cache_case_resolution_state, but none of those symbols exist in studio/backend/utils/paths/path_utils.py at this commit, so test collection will raise ImportError before any test runs. Unless the implementation is included in the same change, this commit breaks the backend test suite.

Useful? React with 👍 / 👎.

Comment on lines +52 to +55
monkeypatch.setattr(models_route, "is_local_path", lambda _: False)
monkeypatch.setattr(
models_route, "resolve_cached_repo_id_case", lambda _: "Org/Model"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Monkeypatch existing targets for get_model_config test

monkeypatch.setattr here targets routes.models.is_local_path and routes.models.resolve_cached_repo_id_case, but those attributes are not defined on routes.models in this commit. With default raising=True, setup fails with AttributeError, so the regression test never executes. Patch the real import locations (or add the runtime symbols in the same change) to keep the test runnable.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen merged commit 4020a70 into main Apr 3, 2026
5 checks passed
@danielhanchen danielhanchen deleted the pr-4822-tests branch April 3, 2026 20:58
shibizhao pushed a commit to shibizhao/unsloth-npu that referenced this pull request Apr 7, 2026
…ai#4823)

Tests for resolve_cached_repo_id_case and get_model_config case
resolution, separated from the runtime changes in PR unslothai#4822.
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

0