Skip to content

Fold duplicated backend, hub and package tests into parametrized runs - #10499

Merged
danielhanchen merged 26 commits into
mainfrom
slim-tests-3
Sep 10, 2026
Merged

danielhanchen merged 26 commits into
mainfrom
slim-tests-3

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

What this does

Removes 3,888 lines across five test areas without changing what any test checks. Third of three chunks of studio/backend/tests (files test_passthrough_healing.py onward), plus studio/backend/hub/tests, tests/python, tests/kaggle and unsloth/kernels/moe/tests.

area before after removed
studio/backend/tests (chunk 3) 190,255 187,572 2,683 (1.41%)
studio/backend/hub/tests 15,764 14,859 905 (5.74%)
tests/python 38,008 37,753 255 (0.67%)
tests/kaggle 32,239 32,194 45 (0.14%)
unsloth/kernels/moe/tests 2,480 2,480 0
total 278,746 274,858 3,888 (1.39%)

105 files changed, 8,321 insertions, 12,209 deletions.

The figures above are measured against the current merge base, which has moved with pre-commit.ci reformatting and merges of main.

Where the lines went

  1. Copy-pasted tests folded into @pytest.mark.parametrize, about 3,400 lines. Node ids change by design here: test_foo becomes test_fold[foo]. Every folded case carries the original test name minus its test_ prefix as the param id, so each case stays individually addressable and the original name is recoverable by grep. For the few originals that were already parametrized, the id is that name plus the original case label. Measured against current main, 481 node ids are renamed this way and 482 appear in their place (one original asserted two things and became two cases), so the total collected goes from 57,740 to 57,741 and no case is dropped.
  2. Payload builders for repeated marker literals. test_safetensors_tool_loop.py repeated the DeepSeek full-width and Kimi ASCII tool-call envelopes hundreds of times; _ds_call, _kimi_call and _kimi_section plus the _DS_* constants removed 328 lines from that file alone.
  3. Verbatim repeated setup hoisted to module-level helpers, using symtable free-variable analysis so nothing is captured wrongly, and repeated try/finally save-restore folded into a contextlib.contextmanager (_restores_hardware_verdict, 13 call sites).

Example from studio/backend/hub/tests/test_dataset_local_options.py:

-def test_snapshot_options_treat_tsv_as_its_own_builder(tmp_path):
+@pytest.mark.parametrize(
+    "train_text, sibling_name, sibling_text",
+    [
+        # tsv carries a tab separator, so datasets sees two different builders.
+        pytest.param("text\nrow\n", "test.tsv", "text\trow\n", id = "snapshot_options_treat_tsv_as_its_own_builder"),
+        pytest.param("", "train2.csv", "text\nrow\n", id = "snapshot_options_reject_a_csv_split_holding_one_empty_file"),
+    ],
+)
+def test_snapshot_options_rejects_unusable_splits(tmp_path, train_text, sibling_name, sibling_text):

Biggest files: hub/tests/test_model_services.py -655, test_sandbox_files_and_storage_roots.py -574, test_safetensors_tool_loop.py -328, test_video_backend.py -273, test_sd_cpp_install.py -135.

How I checked coverage did not move

A detached base worktree was built at the base commit and identical commands run in both trees.

  • Per-file collect counts: identical for 104 of 105 files. The one difference is a gain, test_transformers_version.py 315 to 316.
  • All 95 changed backend files in one run: base 122 failed / 7,852 passed / 108 skipped / 81 errors, head 122 failed / 7,853 passed / 108 skipped / 81 errors, with the FAILED and ERROR node id sets byte-identical at 203 ids each.
  • All changed tests/python and tests/kaggle files: 2 failed / 1,501 passed / 74 skipped / 10 deselected at both revisions, same two node ids.
  • pytest.mark.skipif count unchanged at 56. No marker added or removed, no -m gpu.

Folding copy-pasted tests into parametrize necessarily lowers the raw def test_ count (7,121 to 6,720) and assert count, which is why the collected node count is the invariant that matters here rather than the function count.

Because much of the work was script-driven, every comment and every string or bytes literal value in all changed files was diffed against base, then re-checked at word level for whether each vanished comment's content survives elsewhere in the file. Two genuine losses were found and restored: a Finding 5: provenance tag, and three inline fuzz-input labels in test_tool_call_parser_strict.py. One unintended prose edit (behavior rewritten to behaviour) was reverted.

What I threw away

A fuzzy extraction pass worth about 1,677 lines was abandoned entirely after the literal audit showed it had parameterized assertion literals and two payload values had vanished from test_safetensors_tool_loop.py.

Eight files were reverted after automated passes broke them, several later redone by hand. Fourteen more were reverted because the change was net zero or negative and was pure churn.

Mechanical comment stripping across these areas measured at only about 650 lines and was judged not worth the risk. tests/kaggle is 26.6% comments, but sampling shows they are measured ladder-probe evidence and cost-of-getting-it-wrong notes, so that area is nearly untouched.

Merging _FakeWanPipeSingle and _FakeWanPipeMoE in test_video_backend.py was rejected: their __call__ signatures differ deliberately, so that the cfg2 gate must not thread guidance_scale_2.

Style

ast.unparse rewrites quote style and keyword spacing, which would have put gratuitous churn in the diff. A tokenize-based pass scoped strictly to the 6,717 added line numbers normalised it back, skipping any literal containing a nested quote, apostrophe, escape or DeepSeek marker character, and comparing ast.dump before and after per file as proof no literal value moved. Single-quoted strings 1,370 to 1,358 and unspaced keyword arguments 1,375 to 1,361, both now slightly below base.

Local test state

Pre-existing on this box and identical at base and head: 3 collection errors in unsloth/kernels/moe/tests (No module named 'grouped_gemm'), 3 backend files failing to collect (No module named 'utils.paths.path_utils'), test_video_backend.py at 90 failed standalone, 2 failures in tests/python, and 2 in test_utils.py that only appear in a combined multi-file run from cross-file GPU mock pollution.

I am not claiming a clean local suite. The claim is that the failure set is identical with and without this change.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-09T22:16:57.216751Z 9c10007 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pre-commit-ci
pre-commit-ci Bot requested a review from NilayYadav as a code owner September 8, 2026 14:08
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 199e4673e2

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 199e4673e2

ℹ️ 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".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 5 commits September 8, 2026 20:09
The parametrize folds shortened or reworded some case IDs, so the pre-fold
test name could no longer be recovered from the node ID by grep. Restore it:
every folded case now carries the original test name minus its test_ prefix,
and originals that were themselves parametrized carry that name plus their
original case label.

IDs only. No test input, expected value or assertion is changed. Collected
node id count is unchanged at 57741.
_shared_setup_4 built its knowledge base inside `with _connection() as conn`
and then returned that connection. _connection is a `closing(...)`, so the
handle is already closed by the time the caller sees it. All four call sites
happen to shadow it with their own `with _connection() as conn` before any
use, which is why nothing fails today, but the helper is new here and handing
a closed connection to whoever writes the next test against it is a trap.

Return the routes module alone and unpack a single value at the call sites.
_shared_setup_7 built its zip inside `with zipfile.ZipFile(archive, "w") as zf`
and returned that handle; _shared_setup_10 did the same with the file object
from `with open(...) as f`. Both are closed by the time the caller sees them.

Nothing fails today because the four zip call sites immediately shadow `zf`
with their own `with zipfile.ZipFile(archive) as zf`, and the three record
call sites never touch `f` at all. Both helpers are new here, so this is a
trap we would be creating rather than inheriting.

Return the archive path and the root directory alone, and unpack a single
value at the seven call sites.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 9b059b99f8

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: bef08f2ec0

ℹ️ 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".

Drop the generated per-helper setup narration and collapse multi-line
case notes to one line where a single line carries the same fact.
Comments only; the parsed AST of every touched file is unchanged.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@danielhanchen
danielhanchen merged commit 38f78af into main Sep 10, 2026
42 of 45 checks passed
@danielhanchen
danielhanchen deleted the slim-tests-3 branch September 10, 2026 00:11
danielhanchen added a commit that referenced this pull request Sep 10, 2026
…ose and in keys

Resolves the merge with main. Two files conflicted:

- tests/data/refactor_guard/patch_targets.json: took main's side under
  utils.hf_cache_settings.active_hf_hub_cache. This PR touches neither that
  setting nor test_rag_embeddings.py.
- tests/test_safetensors_tool_loop.py: main folded these into parametrized runs
  in #10499, so three of the four conflicts were main deleting tests whose ids
  it preserved as parametrize ids. Took the deletion. The fourth was a genuine
  union of this PR's guard class and main's DeepSeek helpers; kept both.

Main's fold re-encoded the pre-PR expectation that a markerless execution-class
rehearsal promotes, so six of its new cases asserted that python[ARGS]{...}
still fires. Applied the substitution this PR had already made to the
individual tests before the merge: a benign name in place of the blocked one.

Also fixes two ways a blocked bare-JSON body stayed readable:

- The masking walk only followed a chain from the START of the text, so
  "Answer:\n{"name":"terminal",...}" left it unwalked and the wrapper quoted
  inside the blocked body was reconsidered on its own and executed as python.
  It now resumes at the next brace, but only across inert prose: markup in the
  gap owns the object behind it, and resuming past a trusted marker masked a
  legitimately marked call's arguments.
- Only values were masked, so tool markup spelled into a top-level KEY was
  promoted out of a truncated object the balanced-leading-object guard cannot
  claim. Key contents are masked as data too; the classification keys stay
  readable so the call still reads as blocked downstream.

Corpus of 3430 cases: parse_tool_calls_from_text and strip_tool_markup are
byte-identical, and the 18 changed _mask_blocked_bodies cases are all prose
ahead of a blocked terminal call. Baselines merged by hand for the three new
symbols and the four hashes that moved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants