Repository navigation
Share builders and setup helpers in the studio backend tests, part 2 - #10498
Merged
Merged
Conversation
added 18 commits
September 8, 2026 04:42
…studio backend tests
…-in in the passthrough tests
…rt path is unchanged
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex security review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
danielhanchen
added a commit
to Souravrajvi0/unsloth
that referenced
this pull request
Sep 9, 2026
One conflict, in studio/backend/tests/test_hub_token_caller_identity.py. Main's unslothai#10498 hoisted the repeated function-local imports in that file; this branch hoisted the same ones and 58 more in the same pass, so the branch side is a superset and is taken whole. Confirmed every module unslothai#10498 lifted (seed_routes, asyncio, fastapi, inspect, model_config_module) is present at module level here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Removes 4,362 lines from
studio/backend/testswithout changing what any test checks. Second of three chunks (filestest_hf_cache_settings.pythroughtest_partial_resume_verdict.py, 248 files, 183,744 lines).79 files changed, 2,760 insertions, 7,122 deletions.
The figures above are measured against the current merge base, which has moved with
pre-commit.cireformatting and merges ofmain.Where the lines went
_wired()intest_openai_auto_switchcovers 66 sites of 9 lines each,_run_tool_loop()and_backend_and_payloads()intest_llama_cpp_tool_loopcover 95 and 102 sites.Example from
test_llama_cpp_tool_loop.py:Biggest files:
test_openai_tool_passthrough.py-956,test_openai_auto_switch.py-927,test_llama_cpp_tool_loop.py-858,test_llama_cpp_mtp_detection.py-251,test_hosted_result_replay.py-196.How I checked coverage did not move
Whole-area run of the 245 runnable files, before and after:
Separately, every pytest node id was collected repo-wide in this branch and in a worktree of the merge base, from the repo root and from
studio/backendwithhub/testsincluded, and the two sets diffed: 62,026 ids on each side, nothing lost and nothing gained. That is the check that matters here, because adef test_count in the AST still counts a test that no longer gets collected.Per file, across all 80 changed files:
def test_5,170 to 5,170,assert12,184 to 12,184,pytest.raises406 to 406, skip and xfail markers 55 to 55, parametrize case counts unchanged.I also ran a comment census in both directions, which is worth describing because the first version of it was wrong. It originally only checked that no new comment text appeared, which catches a regex rewriting prose but is blind to deletions. Corrected, it reports every removed comment instance as accounted for: one deduplicated from two copies to one, and one moved into a helper docstring. Three
# noqa: PLC0415markers were removed while their imports were at module scope; those imports are back inside their functions and the markers with them.Four facts were dropped by folds and have been restored:
apple_budget_mib = 23_000, # ~22 GB: weights fit, native KV doesn't# 0 = Auto context (the branch that caps); the native 8192 above is the target., folded into the_launch_auto_8kdocstring since it applies to all three call sites that passn_ctx = 0# nothing pinned, so the preflight re-asks the gate; no marker, so it abstains# case-insensitivebeside a deliberately lowercase variantWhat I threw away
Automated parametrization of near-identical tests was measured at only about 213 lines area-wide once clusters carrying comments were excluded, and merging via
ast.unparsewould have silently deleted in-body comments and reflowed every string literal. Not applied.Blanket collapsing of one-argument-per-line call formatting was worth about 3,500 lines but is reformatting for its own sake, so calls were only collapsed as part of an actual helper extraction.
Three passes were reverted for breaking tests: hoisting lifted methods out of nested classes, hoisting two different
_resolvebodies collided at module scope, and wrapper defaults referencing a fixture function were evaluated at definition time.Import hoisting, and why most of it was reverted
Hoisting a function-local import to module scope moves that import from run time to collection time. Where the module then pulls in something it did not pull in before, this is not a refactor, it is a behaviour change, and under a shared invocation it can be fatal.
The first version of this branch hoisted
from main import _is_same_origin_requestto module scope in the threetest_index_bootstrap_*files.mainimportsloggers.config, and oncehub/testsis collected in the same invocation that resolves to something that is not the package:41 tests stopped being collected. Neither
pytest testsfromstudio/backendnor an AST-level count ofdef test_can see that, which is why the node id diff above is the check this branch is verified with.Rather than patch those three files, the invariant was restored across the whole pass: a hoist is kept only where the module's import-time footprint is byte-identical to base. That was measured, not reasoned about, by importing each test module in a fresh interpreter and diffing the resulting
sys.modulestop-level packages between the two trees. 31 of the 64 files that had hoists pulled new packages at import time, includingcore,routes,hub,httpx,huggingface_hub,fastapi,sqlite3,ssl,PILandnumpy. Only themaincase was fatal today; the rest were latent.129 imports went back inside the functions that use them, none were kept, and the re-probe flags none of the 31. The three
test_index_bootstrap_*files had the hoist as their only change and are reverted to base exactly. This costs 2,162 lines against the earlier figure, which is the right trade: those lines were bought with collection-time coupling.Local test state
99 pre-existing failures in this chunk on this box, identical before and after, dominated by
pytest.mark.asynciobeing unregistered on this install.test_nudge_tool_calls_wiring.pydoes not collect here (AttributeErrorintorchaowhile importing unsloth) and aborts the run, so it was excluded from both the baseline and the final measurement, along withtest_mcp_server.pyandtest_rag_ocr_fallback.pyfor missing optional deps.I am not claiming a clean local suite. The claim is that the failure set is identical with and without this change.