Repository navigation
Stop shipping test suites in the wheel and the sdist - #10060
Conversation
VirusTotal flagged the published sdist (discussion #9577). The files it hit are tests/security/fixtures/malicious_sdist.tar.gz and malicious_wheel.whl, which embed a real supply-chain IOC literal on purpose so that the scan_packages.py regression tests can prove the scanner trips on it. The detection is a true positive on the fixture and a false positive on Unsloth, but the fixtures had no business being in a release artifact in the first place. Nothing under a tests/ directory is importable at runtime, and no workflow runs the suites from an installed package, so all six of them come out: tests/ 883 files (includes the flagged fixtures) studio/backend/tests/ 769 studio/frontend/tests/ 628 unsloth_cli/tests/ 21 studio/backend/hub/tests/ 17 unsloth/kernels/moe/tests/ 8 include-package-data is on with setuptools-scm as the file finder, so every tracked file under a surviving package directory ships unless something vetoes it. The existing exclude-package-data veto only covers the two studio backend suites, and it only holds for a wheel built straight from the git tree. build.sh runs plain `python -m build`, which builds the sdist first and then the wheel from THAT sdist, where the .git dir is gone. MANIFEST.in is the one veto that travels inside the sdist, so it is the thing that holds for both artifacts on the real release path. Measured with `python -m build` on this branch, against the same command on main: wheel 652 test paths -> 0, 45.4MB -> 43.6MB sdist 2326 test paths, 3 IOC fixtures -> 0 and 0, 58.6MB -> 48.1MB Diffing the two builds file by file, the only non-test change is MANIFEST.in appearing in the sdist. Nothing else was dropped from either artifact. The pruned wheel installs, exposes the unsloth entry point, and byte-compiles clean. wheel-smoke.yml already builds both artifacts on every PR touching the packaging, so the check that this stays fixed goes there.
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. |
The six prune lines only cover the six suites that exist today. A suite added anywhere else later, say scripts/tests/test_x.py, ships again: setuptools-scm hands every tracked file to the sdist and none of the six patterns match it. Verified by committing exactly that file and building the sdist twice, once with the prune list alone and once with the backstop: six prunes only scripts/tests/test_probe_regression.py SHIPS plus global-exclude absent, no tests path segment anywhere prune and a single * are both one level deep, so the general form needs **, and global-exclude cannot see a root-level tests/ at all, which is why prune tests stays. Confirmed at every depth against setuptools 80.9.0, the pinned build backend, on a scratch package with tests/ at the root and nested three deep. No effect on what ships today: the file sets of both artifacts are identical to the build before this commit.
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
A top-level attribution/ directory holding one file is repository clutter, and the file has no business being at the root: it is a vite config used by exactly one thing, the studiobench harness under tests/studio/studiobench, whose bridge_build.py is the only referrer in the tree. Three things fall out of the move for free. It stops shipping. attribution/ was a tracked top-level directory, so setuptools-scm put the config in the sdist of every release; under tests/ the prune from #10060 covers it. The published sdist was carrying a build config whose consumer, after #10060, no longer ships with it. It gains CI. studiobench-ci.yml triggers on tests/studio/studiobench/**, so a change to this config now runs the suite. Nothing anywhere triggered on attribution/, which is how this file managed to break twice inside its own introducing PR (#9296). Module resolution is unchanged. The config resolves its plugins through createRequire anchored at studio/frontend/package.json precisely because no ancestor of its own directory has a node_modules. That is still true of the new location, so the reason the anchoring exists survives intact. studio/frontend was the other obvious home and is the wrong one: package-data already globs frontend/*.ts, so parking it there would ship it inside the wheel. Verified by building the frontend with the config from both paths, against the same node_modules: before 525 js, 509 maps, 522 banner hits, 0 sourceMappingURL, 2430/2506 names after 525 js, 509 maps, 522 banner hits, 0 sourceMappingURL, 2430/2506 names Identical, including the SHA over the emitted relative paths -- and vite names chunks by content hash, so an identical path set means identical bytes. The built dist stays gitignored (the bare dist/ rule is unanchored). Both artifacts build with no attribution entry and no tests path segment. Suite green: 1400 passed, 155 skipped, ruff clean. Co-authored-by: danielhanchen <[email protected]>
`tests/security/fixtures/malicious_sdist.tar.gz` and `malicious_wheel.whl` embed the May-12 IOC literal on purpose, so the `scan_packages.py` regression tests can prove the scanner trips on it. That makes them true positives for other vendors too. Per the per-file scan in discussion #9577, they are the only two detected files in the whole fixture set: the sdist scores 2/60 and the wheel 2/65 (Tencent, Rising), and their presence is what makes Panda report `Exploit/CVE-2014-6271` against GitHub's `unsloth-main.zip`. #10060 took the test tree out of the PyPI artifacts, which fixed those. A repository archive contains `tests/` by construction, so it kept matching and users kept re-reporting it, twice in that thread alone. I said there that no packaging change can affect it. That is true, but a fixture change can: `fixtures/_build.py` is already a complete deterministic builder for exactly these archives, and nothing invoked it. The built outputs were simply committed beside it. So build them at session start instead: - `tests/security/conftest.py` gains a session-scoped autouse fixture calling `_build.build_all()`. It generates in place, so all dozen-odd `FIXTURES / "malicious_wheel.whl"` call sites keep working unchanged. Unlike the `network_blocker` fixture above it, this patches nothing and has no teardown, so session scope carries none of the leak-past-the-suite risk that docstring records. - The three archives are removed from git and added to `.gitignore`. - `_build.py` assembles the IOC host and artifact names from concatenated pieces, the way `test_scan_packages.py` already writes `_ioc_host = "git-tanstack." + "com"`. Insurance only: the #9577 scan found the `.py` sources undetected, so the archives leaving git is the part that matters. - New `test_no_archive_fixture_is_committed` reads `git ls-files`, not the directory, because the files are present on disk in every run and it is the index that has to stay empty. Determinism is already pinned by `SOURCE_DATE_EPOCH = 0` and the 1980 DOS-epoch zip dates, and I checked it rather than assumed it: the generated archives are byte-identical to the committed ones for all three. `test_fixture_bytes_are_deterministic` still compares a rebuild against the copy the suite is using, so it keeps its meaning. Verification: 589 passed, 6 skipped across `tests/security/`, with the archives deleted from disk first so the fixture is what produces them. The new guard was confirmed to bite by re-adding the three files to the index, reproducing main's state, where it fails. This does not clean the hashes already on VirusTotal, and Panda will keep flagging an archive of any older commit. It stops new ones.
…10979) * Stop committing the two fixture archives that antivirus vendors flag `tests/security/fixtures/malicious_sdist.tar.gz` and `malicious_wheel.whl` embed the May-12 IOC literal on purpose, so the `scan_packages.py` regression tests can prove the scanner trips on it. That makes them true positives for other vendors too. Per the per-file scan in discussion #9577, they are the only two detected files in the whole fixture set: the sdist scores 2/60 and the wheel 2/65 (Tencent, Rising), and their presence is what makes Panda report `Exploit/CVE-2014-6271` against GitHub's `unsloth-main.zip`. #10060 took the test tree out of the PyPI artifacts, which fixed those. A repository archive contains `tests/` by construction, so it kept matching and users kept re-reporting it, twice in that thread alone. I said there that no packaging change can affect it. That is true, but a fixture change can: `fixtures/_build.py` is already a complete deterministic builder for exactly these archives, and nothing invoked it. The built outputs were simply committed beside it. So build them at session start instead: - `tests/security/conftest.py` gains a session-scoped autouse fixture calling `_build.build_all()`. It generates in place, so all dozen-odd `FIXTURES / "malicious_wheel.whl"` call sites keep working unchanged. Unlike the `network_blocker` fixture above it, this patches nothing and has no teardown, so session scope carries none of the leak-past-the-suite risk that docstring records. - The three archives are removed from git and added to `.gitignore`. - `_build.py` assembles the IOC host and artifact names from concatenated pieces, the way `test_scan_packages.py` already writes `_ioc_host = "git-tanstack." + "com"`. Insurance only: the #9577 scan found the `.py` sources undetected, so the archives leaving git is the part that matters. - New `test_no_archive_fixture_is_committed` reads `git ls-files`, not the directory, because the files are present on disk in every run and it is the index that has to stay empty. Determinism is already pinned by `SOURCE_DATE_EPOCH = 0` and the 1980 DOS-epoch zip dates, and I checked it rather than assumed it: the generated archives are byte-identical to the committed ones for all three. `test_fixture_bytes_are_deterministic` still compares a rebuild against the copy the suite is using, so it keeps its meaning. Verification: 589 passed, 6 skipped across `tests/security/`, with the archives deleted from disk first so the fixture is what produces them. The new guard was confirmed to bite by re-adding the three files to the index, reproducing main's state, where it fails. This does not clean the hashes already on VirusTotal, and Panda will keep flagging an archive of any older commit. It stops new ones. * Publish the generated fixtures atomically, so four CI workers cannot race each other `.github/workflows/workflow-trigger-lint.yml:130` runs `pytest -q -n 4` over `tests/security` with the default `--dist load`, which scatters tests from ONE file across all four workers. Each worker runs the session-scoped autouse fixture and rewrote these three archives at their fixed paths while the others were reading them, and `write_bytes` truncates before it writes. The failure this produces is the nasty kind. A reader that catches the truncated window does not get a corrupt-file error; it gets a short member list and fails asserting scanner semantics -- `assert any("setup.py" in f.filename for f in blockers)` -- which nobody would trace back to a write race. Two guards, because either alone leaves a hole. The write is skipped entirely when the bytes on disk are already correct, so in the normal case only the first worker writes at all; otherwise it goes to a pid-unique temp name and `os.replace`, which is atomic on POSIX and on Windows. Without the pid the workers would collide on the temp file instead of the final one. What makes this sound rather than merely narrower: the build is deterministic (SOURCE_DATE_EPOCH, 1980 DOS times), so a reader sees either the complete old file or the complete new one and those are byte-identical. The three archives still hash to fe6927b5, 0c327818 and 7516530a -- the same bytes that were committed before they were generated -- and a test now pins that, because the equivalence argument depends on it. Honest note on how this was found and confirmed: a review flagged it and reported reproducing it at 16-28% with `-n 8`. I could NOT reproduce it in 22 runs on this box. The hazard is real by construction and the CI invocation that exposes it is real, but I am not going to claim a reproduction I did not get. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Stop build_all leaking SOURCE_DATE_EPOCH into the rest of the worker The assignment had no teardown. That was harmless while this file was run as a script, and is not harmless now that a session fixture calls it partway through a broader pytest run: it overwrote any caller-provided value for the remainder of the worker, and every later test and subprocess inherited the false epoch. Nothing in the builder read it either. Each writer is handed the fixed timestamp directly and zipfile takes the 1980 DOS tuple, so the assignment bought nothing in exchange for that reach. The generated bytes are unchanged, confirmed by hash before and after: fe6927b5, 0c327818, 7516530a. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…nslothai#10979) * Stop committing the two fixture archives that antivirus vendors flag `tests/security/fixtures/malicious_sdist.tar.gz` and `malicious_wheel.whl` embed the May-12 IOC literal on purpose, so the `scan_packages.py` regression tests can prove the scanner trips on it. That makes them true positives for other vendors too. Per the per-file scan in discussion unslothai#9577, they are the only two detected files in the whole fixture set: the sdist scores 2/60 and the wheel 2/65 (Tencent, Rising), and their presence is what makes Panda report `Exploit/CVE-2014-6271` against GitHub's `unsloth-main.zip`. unslothai#10060 took the test tree out of the PyPI artifacts, which fixed those. A repository archive contains `tests/` by construction, so it kept matching and users kept re-reporting it, twice in that thread alone. I said there that no packaging change can affect it. That is true, but a fixture change can: `fixtures/_build.py` is already a complete deterministic builder for exactly these archives, and nothing invoked it. The built outputs were simply committed beside it. So build them at session start instead: - `tests/security/conftest.py` gains a session-scoped autouse fixture calling `_build.build_all()`. It generates in place, so all dozen-odd `FIXTURES / "malicious_wheel.whl"` call sites keep working unchanged. Unlike the `network_blocker` fixture above it, this patches nothing and has no teardown, so session scope carries none of the leak-past-the-suite risk that docstring records. - The three archives are removed from git and added to `.gitignore`. - `_build.py` assembles the IOC host and artifact names from concatenated pieces, the way `test_scan_packages.py` already writes `_ioc_host = "git-tanstack." + "com"`. Insurance only: the unslothai#9577 scan found the `.py` sources undetected, so the archives leaving git is the part that matters. - New `test_no_archive_fixture_is_committed` reads `git ls-files`, not the directory, because the files are present on disk in every run and it is the index that has to stay empty. Determinism is already pinned by `SOURCE_DATE_EPOCH = 0` and the 1980 DOS-epoch zip dates, and I checked it rather than assumed it: the generated archives are byte-identical to the committed ones for all three. `test_fixture_bytes_are_deterministic` still compares a rebuild against the copy the suite is using, so it keeps its meaning. Verification: 589 passed, 6 skipped across `tests/security/`, with the archives deleted from disk first so the fixture is what produces them. The new guard was confirmed to bite by re-adding the three files to the index, reproducing main's state, where it fails. This does not clean the hashes already on VirusTotal, and Panda will keep flagging an archive of any older commit. It stops new ones. * Publish the generated fixtures atomically, so four CI workers cannot race each other `.github/workflows/workflow-trigger-lint.yml:130` runs `pytest -q -n 4` over `tests/security` with the default `--dist load`, which scatters tests from ONE file across all four workers. Each worker runs the session-scoped autouse fixture and rewrote these three archives at their fixed paths while the others were reading them, and `write_bytes` truncates before it writes. The failure this produces is the nasty kind. A reader that catches the truncated window does not get a corrupt-file error; it gets a short member list and fails asserting scanner semantics -- `assert any("setup.py" in f.filename for f in blockers)` -- which nobody would trace back to a write race. Two guards, because either alone leaves a hole. The write is skipped entirely when the bytes on disk are already correct, so in the normal case only the first worker writes at all; otherwise it goes to a pid-unique temp name and `os.replace`, which is atomic on POSIX and on Windows. Without the pid the workers would collide on the temp file instead of the final one. What makes this sound rather than merely narrower: the build is deterministic (SOURCE_DATE_EPOCH, 1980 DOS times), so a reader sees either the complete old file or the complete new one and those are byte-identical. The three archives still hash to fe6927b5, 0c327818 and 7516530a -- the same bytes that were committed before they were generated -- and a test now pins that, because the equivalence argument depends on it. Honest note on how this was found and confirmed: a review flagged it and reported reproducing it at 16-28% with `-n 8`. I could NOT reproduce it in 22 runs on this box. The hazard is real by construction and the CI invocation that exposes it is real, but I am not going to claim a reproduction I did not get. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Stop build_all leaking SOURCE_DATE_EPOCH into the rest of the worker The assignment had no teardown. That was harmless while this file was run as a script, and is not harmless now that a session fixture calls it partway through a broader pytest run: it overwrote any caller-provided value for the remainder of the worker, and every later test and subprocess inherited the false epoch. Nothing in the builder read it either. Each writer is handed the fixed timestamp directly and zipfile takes the 1980 DOS tuple, so the assignment bought nothing in exchange for that reach. The generated bytes are unchanged, confirmed by hash before and after: fe6927b5, 0c327818, 7516530a. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
What this fixes
Discussion #9577 reported a VirusTotal detection on Unsloth. The flagged files are
tests/security/fixtures/malicious_sdist.tar.gzandmalicious_wheel.whl, which deliberately embed a real supply chain IOC literal so thescan_packages.pyregression tests can prove the scanner trips on it:So it is a true positive on the fixture and a false positive on Unsloth. But those fixtures ship inside the published sdist, and they had no business being in a release artifact at all.
What ships today
Nothing under a
tests/directory is importable at runtime, and nothing runs the suites from an installed package (no--pyargsanywhere in the repo, and the only cross imports are tests importing tests). Six suites were reaching the artifacts:tests/studio/backend/tests/studio/frontend/tests/unsloth_cli/tests/studio/backend/hub/tests/unsloth/kernels/moe/tests/Why the existing veto did not cover it
include-package-datais on with setuptools-scm as the file finder, so every tracked file under a surviving package directory ships unless something vetoes it.packages.findonly decides importability, and theexclude-package-dataentries only cover the two Studio backend suites.More importantly,
exclude-package-dataonly holds for a wheel built straight from the git tree.build.shruns plainpython -m build, which builds the sdist first and then builds the wheel from that sdist, where the.gitdirectory is gone.MANIFEST.inis the one veto that travels inside the sdist, so it is what holds for both artifacts on the real release path. Theexclude-package-datablock stays as a second layer.Measured
python -m buildon this branch, against the same command onmain:For reference, the published
2026.8.22artifacts on PyPI carry 1388 test paths in the wheel and 2273 plus the 3 IOC fixtures in the sdist.Diffing the two builds file by file, the only non-test difference is
MANIFEST.initself appearing in the sdist. Nothing else was dropped from either artifact. The pruned wheel installs, exposes theunslothentry point, and byte-compiles clean, andtests/studio/install/test_package_discovery.py,tests/test_version_single_source.py,tests/security/test_scan_packages.pyandtests/test_source_read_encoding.pypass (143 passed, 1 skipped).Regression guard
wheel-smoke.ymlalready builds both artifacts on every PR that touches the packaging, so the check lives there: it fails if any shipped path has atestspath segment, or if anything namedmalicious_*appears. It fails onmaintoday and passes on this branch.Note on the original report
The reporter scanned a
unsloth-mainsource download. That is GitHub's archive of the repository, which by definition contains the test tree, so it will keep matching. This change is about the PyPI artifacts, which are whatpip install unslothactually fetches.