Repository navigation
Tests: extract setup.sh's fast path without depending on if vs elif - #9579
Merged
Merged
Conversation
tests/sh/test_setup_desktop_backend_version_fastpath.sh slices the version fast path out of studio/setup.sh with awk. The start anchor matched the condition text but not the keyword in front of it, so when #8515 put a duplicate-metadata branch ahead of it and the condition became an elif, the slice began at `elif` and could not parse. Three of the six cases failed with a bare "syntax error near unexpected token", and the other three passed vacuously: a block that never sources leaves _SKIP_PYTHON_DEPS at the false the test itself set. studio/setup.sh is unchanged and correct. `bash -n studio/setup.sh` is clean, the new branch only precedes the fast path, and setup.ps1 grew the matching elseif in the same commit, so the two stay mirrored. The extraction now matches the condition as a literal, without the keyword, checks that the keyword is an if or an elif, and re-emits the block as a standalone `if`. Every assumption it makes reports itself: exactly one condition line, an if/elif keyword, the _setup_pin= end anchor present, a non-empty body that still sets _SKIP_PYTHON_DEPS and still consults UNSLOTH_DESKTOP_BACKEND_VERSION, and `bash -n` on the result. A slice that no longer matches setup.sh now says so by name instead of emitting a syntax error against a temp file. The sibling test_setup_xpu_fastpath_escape.sh already guards its own slice this way. The cases also stop trusting the default: the block reports BLOCK_FAILED_TO_RUN if sourcing fails and BLOCK_NOT_ENTERED if the fast path was never taken, so no case can pass on a block that did nothing.
This was referenced Aug 23, 2026
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Aug 23, 2026
…its text (unslothai#9591) * Read the settings route's contract off its parse tree, not its text `Repo tests (CPU)` has been red on main since unslothai#9492 (1f475d7) on test_the_backfill_fills_in_fields_rather_than_skipping_known_keys. The rule the test guards did not change. unslothai#9492 added a third name to the `model_dump(exclude = {...})` set in `update_openai_auto_switch_override`, the formatter then split the set one name per line, and assert '"remove", "fill_absent_fields"' in route no longer matched, because `route` is the raw source text of studio/backend/routes/settings.py and the two names now have a newline and sixteen spaces between them. Both names are still excluded. Nothing about the write-mode-is-not-a-saved-field rule moved. This is the third failure of this shape on main in as many days (unslothai#9578, unslothai#9579), so pinning a new literal only moves the next one into the future. A test that has to be re-edited whenever a set literal is reflowed is not testing the thing it names. The frontend greps in this file have no parser to hand. The backend does. Three helpers read the rule out of settings.py's AST instead: - `_model_dump_exclusions` returns the names the one `model_dump(exclude = ...)` in a given function leaves out. Exactly one such call, or the answer would be a union and a name dropped from the call that matters could hide behind another. - `_annotated_field` returns the annotation and literal default of a field on a pydantic model, so "declared as a bool defaulting to False" is asserted as that rather than as a substring. - `_forwarded_keywords` returns the keyword arguments passed as `name = payload.name`, which is the part the storage layer depends on. Each raises rather than returning empty when it cannot find what it was pointed at, so a renamed handler or field reddens here instead of passing vacuously. Verified by mutation against the repaired test, one at a time on settings.py: | Mutation | Result | |---------------------------------------------------|--------| | unmodified main | pass | | `"fill_absent_fields"` dropped from the exclude set| fail | | the exclude set reflowed onto one line, reordered | pass | | the payload field defaulted to True | fail | | `fill_absent_fields` no longer forwarded to the db | fail | | the route handler renamed | fail | | the payload field renamed | fail | The reflow is the case that caused this outage and is now the only one that stays green; every mutation that actually breaks the contract still reddens. Local: `tests/studio/test_model_picker_contracts.py` 187 passed, was 186 passed 1 failed. No production code changed. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.
The red
tests/sh/test_setup_desktop_backend_version_fastpath.shfails 3 of 6 onmain:The test slices the version fast path out of
studio/setup.shwith awk and sources the slice. The start anchor matched the condition text but was blind to the keyword in front of it, so the slice began atelifand could not parse.The other three cases passed vacuously, not correctly. They expect
false, and a block that never sources leaves_SKIP_PYTHON_DEPSat thefalsethe test itself set a line earlier.Where it came from
90644db9e(#8515, "Studio: repair duplicate package metadata during updates") put a duplicate-metadata branch ahead of the fast path, so the fast path became theelifof that chain. Confirmed by running the test either side rather than by reading the diff:f1f95f71f(#8515's parent)90644db9e(#8515)The test itself predates that commit (added in
dc26127a4, #8670).The production side is correct
studio/setup.shis not touched here.bash -n studio/setup.shis clean, so the shipped script was never broken.elifis the identical condition the oldifhad, and when it is 2 the fast path is skipped so the dependency pass repairs the duplicate metadata, which is the intent.UNSLOTH_DESKTOP_BACKEND_VERSIONescape inside the branch, is unchanged.studio/setup.ps1grew the matchingelseif ($_InstalledVersionProbeExit -eq 2)in the same commit, and the XPU pin escape the surrounding comment says it mirrors is present on both sides. No follow-up issue needed.So the defect is entirely in how the test slices, and the fix belongs in the test.
The fix
The extraction matches the condition as a literal without the keyword, checks separately that the keyword is an
ifor anelif, and re-emits the block as a standaloneif. Re-anchoring on the enclosingifwas rejected: it reproduces the same defect one line up, and the enclosing branch is different logic.Every assumption the slice makes now reports itself as drift by name:
iforelif_setup_pin=end anchor still follows it_SKIP_PYTHON_DEPS=true, and still consultsUNSLOTH_DESKTOP_BACKEND_VERSIONbash -non the extracted fragment, with the numbered fragment and the parser error printedNext time
setup.shmoves, the test saysthe fast-path extraction no longer matches studio/setup.sh -- ...instead of a cryptic syntax error against a temp file the reader has never heard of.The cases also stop trusting the default: the runner prints
BLOCK_FAILED_TO_RUNif sourcing fails andBLOCK_NOT_ENTEREDif the fast path was never taken, so no case can pass on a block that did nothing.Why not have setup.sh expose the decision as a sourceable function
Considered and rejected, and this is a real tradeoff.
setup.shhas no sourced-helper precedent: it is the only.shunderstudio/, it sources nothing from the tree, and it runs top to bottom, so a test cannot source it without either a new shipped file (which then has to survive packaging and every install path) or a sourcing guard in an installer that runs on user machines. It is also deliberately mirrored againstsetup.ps1, which cannot take the same split. And the block is not a pure decision: it runs$VENV_DIR/bin/pythonprobes, emitsstep/substepoutput, and mutates several globals. A self-verifying extraction is the accepted outcome, and it is the pattern the siblingtests/sh/test_setup_xpu_fastpath_escape.shalready uses (content assertions plusbash -non its own slice).Verification
All 6 cases pass, and the whole
tests/shsuite is green.Mutation testing, each mutation applied to a throwaway copy of
setup.sh, shows the test still has teeth and that the failure modes are distinguishable:ifinstead ofelif(pre-#8515 shape)ifnorelifwhile)"_setup_pin=end anchor renamedfiinside the blockbash -nerror_SKIP_PYTHON_DEPSstepnever runsBLOCK_NOT_ENTERED, where the old test would have passed 3The last two rows are the point: a behavioural regression fails as a test failure, and a structural change to
setup.shfails as drift with a name.