Repository navigation
CI: guard the host default structurally, not by README heading - #9655
Conversation
The Launch-section slice in tests/sh/test_install_host_defaults.sh has now broken twice on correct README edits, once when '#### Update' was deleted and again when the -H 0.0.0.0 opt-in moved under '#### Remote HTTPS & LAN Access'. Parse the fenced code blocks instead and read the first studio command in document order as the primary one, so no heading is load-bearing. Also stop hand-spelling the needle. The host flag spellings are read off the typer.Option in unsloth_cli/commands/studio.py that declares them, and the detector matches the flag anywhere in the command rather than adjacent to it, which closes 'studio -p 8888 -H 0.0.0.0' and '--host 0.0.0.0' on all five negative assertions.
Note: the four sibling markers in this file, and how far they can be trustedThe README slice is the one that broke, but it is not the only marker in the file. Recording the size of the rest of the problem here so it does not get discovered one red at a time, rather than fixing it all in this PR. Four windows are still cut by
Measured, one reword each and nothing else changed: The good half: all four have a canary, so all four fail LOUDLY rather than going vacuous. That is the difference between these and the README slice as it was, where the negative half could keep passing on an empty window. Nothing here is silently guarding nothing. The bad half: all four take the file red on an edit that has nothing to do with host defaults, and two of them are keyed on prose in a comment, which has no reason to be stable at all. Rewording a comment in Three of the four windows run to end of file rather than to a terminator, which makes the negative assertion a superset of the region it names. That is safe, and strictly stronger, but the step names ("end-of-install block") are narrower than what is actually scanned. What this PR does about it: only the launcher terminator, which now reads the delimiter off the |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b898fb5763
ℹ️ 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".
| alternation = "|".join(re.escape(f) for f in sorted(flags, key = len, reverse = True)) | ||
| values = "|".join(re.escape(w) for w in sorted(WILDCARDS, key = len, reverse = True)) | ||
| return re.compile( | ||
| r"(?:^|\s)(?:%s)(?:\s+|=)(?:%s)(?=$|[^0-9A-Za-z._-])" % (alternation, values) |
There was a problem hiding this comment.
Recognize attached values for short host flags
When a README or installer command uses the valid Click spelling unsloth studio -H0.0.0.0, this pattern reports zero hits because it requires whitespace or = after -H. Click's upstream parser.py:405-412 explicitly consumes the characters remaining after a value-taking short option as its argument, and a CliRunner invocation confirms this sets host to 0.0.0.0; consequently every negative assertion here passes for a real wildcard launch. Handle attached values for single-dash options and add a detector fixture.
Useful? React with 👍 / 👎.
| for raw in text.splitlines(): | ||
| line = _COMMENT.sub("", raw) |
There was a problem hiding this comment.
Preserve continued command lines while scanning
When a fenced example or generated shell/PowerShell command wraps its arguments, such as unsloth studio \ followed by -H 0.0.0.0, scanning each physical line independently records only studio \ and never associates the wildcard flag on the next line. The probe therefore returns zero and allows the unsafe default in every guarded source; join shell backslash and PowerShell backtick continuations, or otherwise parse logical commands, before matching.
Useful? React with 👍 / 👎.
| if (at == 0 or before in _BEFORE) and after in ("", " ", "\t"): | ||
| out.append(line[at:].strip()) |
There was a problem hiding this comment.
Distinguish directory names from Studio invocations
When an earlier fenced setup block contains a non-command token such as cd studio, this condition classifies it as the primary Studio launch because a preceding space and end-of-line satisfy both boundaries. A synthetic README containing cd studio followed by unsloth studio -H 0.0.0.0 reports primary=studio, primary_binds_wildcard=no, and a positive wildcard opt-in, so all README assertions pass while the first real launch is unsafe. Use an invocation-aware matcher for README commands rather than accepting every bare studio token needed by the installer scan.
Useful? React with 👍 / 👎.
| import re | ||
| import sys | ||
|
|
||
| WILDCARDS = ("0.0.0.0", "[::]", "::") |
There was a problem hiding this comment.
Treat an empty host value as a wildcard bind
When a generated or documented launch uses unsloth studio -H '' (or --host ''), Click passes the empty string through and studio_default forwards it unchanged to Uvicorn; asyncio interprets host='' by listening on both 0.0.0.0 and ::. Because the wildcard set omits the empty host, the detector returns zero and every negative assertion accepts this network-exposed default. Include the empty-host spelling in the wildcard analysis or reject it at the CLI boundary.
Useful? React with 👍 / 👎.
| stripped = line.lstrip(" ") | ||
| indent = len(line) - len(stripped) | ||
| head = stripped[:1] | ||
| run = 0 | ||
| if indent <= 3 and head in ("`", "~"): |
There was a problem hiding this comment.
Parse fenced blocks nested inside Markdown lists
When the quickstart is reformatted as a list and its fenced command block is indented four spaces beneath the list item, this absolute indentation check ignores the block even though CommonMark treats it as a fenced block after removing the list container prefix. Other unrelated fences and Studio examples keep all three canaries green, so an unsafe primary command inside the list can be skipped in favor of a later safe command. Account for Markdown container prefixes or use a CommonMark parser before applying the three-space fence rule.
Useful? React with 👍 / 👎.
#9623 landed the heading-scoped form of this guard on main. Resolved to the structural form: the README is parsed as fenced code blocks and no heading is consulted, so a rename, reorder, merge or split of a section cannot take it red. #9623's diagnosis is carried over, its detector fixtures are kept and extended, and its two heading slices are the part deliberately dropped.
|
#9623 landed on main as Checked the resolution outside the conflict markers as well as inside, since a clean merge is not a faithful one. Main's side of that file contributed Re-ran everything on the merged tree, not just before it: 35 assertions pass, and all thirteen mutation cases still land the right way round, including the six heading-volatility cases against the real README. Every file touched restored byte-identical afterwards. Worth saying plainly, since main is now green on this test: this is not a red-fix any more, it is a replacement of the mechanism. The property is the same one from #5267 and #7774 and it is not being loosened. What changes is that it stops being expressible as "the text lives under this heading", which is the assumption that has now failed twice. |
There was a problem hiding this comment.
💡 Codex Review
When a launch hint outside this tail window gains a wildcard bind, the guard remains green even though the stated property covers every command an installer prints or generates. There are already such output sites: install.sh prints the WSL fallback command around line 1900, before the marker around line 5950, and install.ps1 prints the Application Control fallback around line 6357, before its marker around line 6449. Injecting -H 0.0.0.0 into the WSL hint produces zero hits in _end while a whole-file scan finds it, so scan all installer output sites or the complete installer rather than only the final block.
ℹ️ 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".
| return re.compile( | ||
| r"(?:^|\s)(?:%s)(?:\s+|=)(?:%s)(?=$|[^0-9A-Za-z._-])" % (alternation, values) |
There was a problem hiding this comment.
Handle quoted host flags and values
When a documented or generated shell/PowerShell command uses ordinary quoting, such as unsloth studio --host "0.0.0.0" or unsloth studio "--host" 0.0.0.0, the shell removes those quotes before invoking Click, so the command still binds the wildcard address. This regex only permits whitespace directly before the flag and whitespace or = directly before the address; the probe therefore reports zero hits for both forms, allowing an unsafe primary README command or installer launch to pass the guard. Parse shell tokens or explicitly accommodate quoted option/value tokens and add detector fixtures.
Useful? React with 👍 / 👎.
| blocks, unterminated = code_blocks(readme) | ||
| commands = [c for b in blocks for c in studio_commands(b)] |
There was a problem hiding this comment.
Include inline README commands in document order
When the README presents its first launch as inline code, for example Run `unsloth studio -H 0.0.0.0` to start, this list ignores it because commands are collected only from fenced blocks; a later safe fenced command is then reported as primary, and the existing wildcard example satisfies the opt-in assertion, so the test passes. This is a supported README presentation rather than a hypothetical syntax—the current file already contains an inline UNSLOTH_CPU_THREADS=8 unsloth studio -p 8888 instruction—so include executable inline-code commands when determining document order.
Useful? React with 👍 / 👎.
#9654 and this branch both edited tests/sh/test_install_host_defaults.sh. They fix different halves of the same guard and both are kept: * #9654 fixed WHAT the detector matches. Anchoring on the line start let `UNSLOTH_STUDIO_PASSWORD='x' unsloth studio --host=0.0.0.0` through. * this branch fixed WHERE the guard looks, replacing the README heading slice with fenced-code-block parsing. Git aligned the two because both sides appended a helper ending in the same PASS/FAIL tail, so only one function could own it. Both now carry their own. Two helpers from #9654 are dropped as unreachable after the merge, having no call site left once the probe supersedes them: assert_studio_wildcard_host_state and assert_not_contains. studio_commands is KEPT, because assert_wildcard_detection still calls it. A first pass removed it too and the suite caught that immediately with "studio_commands: command not found". The security property #9654 added survives, verified rather than assumed: injecting the prefixed env-assignment wildcard bind into the README's primary launch command fails the guard. FAIL: README: the primary launch command binds no wildcard host (expected 'no', got 'yes') Injecting the same shape into the Remote HTTPS and LAN Access section passes, which is correct: that is the documented opt-in. 47 assertions pass on the merged tree, and every referenced helper resolves.
Keeps both halves. #9654 fixed WHAT the detector matches: the command anywhere on the line rather than at its start, which is what let UNSLOTH_STUDIO_PASSWORD='x' unsloth studio --host=0.0.0.0 through. This branch fixes WHERE the guard looks: fenced code blocks rather than a heading slice. The detector here already matched anywhere on the line, so the resolution keeps it and folds in the four #9654 fixtures it did not already cover, including the prefixed shape verbatim. Twenty-four fixtures now, a strict superset of #9654's twelve. #9654's _playwright_robust.py and studio-ui-smoke.yml changes are untouched and byte-identical to main.
Two merges of f2fa54f landed on this branch at once. The other one re-added main's studio_commands helper and assert_wildcard_detection alongside the probe, which leaves two definitions of 'a studio command that binds a wildcard host' in one file, only one of which any real assertion consumes. Twelve fixtures then pin a function with no callers, which is the vacuity shape this file keeps producing, and two detectors are free to drift apart. Resolved to one detector. All twelve of #9654's fixture cases are kept as cases, including UNSLOTH_STUDIO_PASSWORD='x' unsloth studio --host=0.0.0.0 verbatim, and the probe answers them: twenty-four fixtures, a strict superset.
|
Merged Two merges of What I resolved outside the conflict markers. The other resolution re-added main's All twelve of #9654's fixtures are kept as cases, including
Re-ran everything on the merged result, not on either parent. 39 assertions pass. All thirteen mutation cases still land the right way round: the guard fails when the primary command gains One note for whoever else has this branch: I am holding |
|
Not touching the branch, but one fact from the previous run that should not be read the wrong way. On
The run now in flight on Local on the merged tree here: 39 assertions, 0 failures, and the full thirteen-case mutation matrix still lands the right way round. |
There was a problem hiding this comment.
💡 Codex Review
When the generated Windows launcher or its pre-tail fallback instruction gains a wildcard host, this extraction never sees it because it starts at install.ps1's interactive-terminal comment around line 6449, while $studioCommand is generated around line 2336 and the AppLocker fallback is printed around line 6357. Either command can therefore regress to -H 0.0.0.0 while this test remains green; include those generated and printed launch regions in the scan.
ℹ️ 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".
| import re | ||
| import sys | ||
|
|
||
| WILDCARDS = ("0.0.0.0", "[::]", "::") |
There was a problem hiding this comment.
Recognize equivalent wildcard address spellings
When a documented or generated launch uses a valid equivalent such as unsloth studio -H 0:0:0:0:0:0:0:0 or -H 0, this tuple does not classify it as a wildcard even though Python's socket binding resolves those values to :: and 0.0.0.0, respectively. The probe consequently reports zero hits and allows the command to expose Studio on every interface; normalize host literals or include the equivalent IPv4 and IPv6 unspecified-address forms.
Useful? React with 👍 / 👎.
Repo tests (CPU)is red on main ata39638feb:The README does contain
0.0.0.0, twice. The guard sliced the file by heading:and the opt-in now sits under the sibling
#### Remote HTTPS & LAN Access, which is a better home for it, since-H 0.0.0.0is LAN access. The README is right. The guard's assumption about which heading the text lives under is what was wrong.This is the second failure of this exact slice. The comment on the line above it records the first:
#### Updatewas deleted, the section silently ran to end of file, and the fix was to stop at any heading. Recent README history is a run of directUpdate README.mdpushes (10c198755,70a348bab,aea0e186d,d321b4b91,3914575a8), so heading structure is edited often and on purpose. It is not a stable index and it should not be load-bearing. Patching the slice a third time buys another few weeks.The property, stated without reference to any heading
unsloth studiocommand the README shows must not bind a wildcard host.Provenance is #5267 (default the Studio host to 127.0.0.1) and #7774 (anchor the host-defaults assertions), so the assertion is kept, not dropped.
What the guard does now
Parses the README's fenced code blocks (CommonMark rules, line-anchored, so the inline
```unsloth/unsloth```span in the Docker paragraph does not open a block), pulls the studio commands out of them, and reads the first one in document order as the primary. No heading is consulted anywhere.The needle is derived, not re-spelled
-Hwas hard-coded. That is a live hole, not a hypothetical one:assert_not_contains "$window" "studio -H 0.0.0.0"missesstudio -p 8888 -H 0.0.0.0, because the flag is no longer adjacent to the subcommand.--host 0.0.0.0and-H=0.0.0.0entirely.-Hand all five negative assertions match nothing, forever, silently.Measured on this tree, against the version on main: inject
unsloth studio -p 8888 -H 0.0.0.0as the README's Launch command and the old file exits 0, withPASS: README: Launch section primary command has no -H 0.0.0.0. Inject the same intostudio/setup.sh's launch hint andPASS: studio/setup.sh: launch hint has no '-H 0.0.0.0'.So the spellings are now read off the
typer.Optioninunsloth_cli/commands/studio.pythat declares them, anchored on the Python parameter name rather than on the CLI surface string, and one detector is shared by the README half and the four installer windows so they cannot drift apart.unsloth studio's own default stays where it is, asserted structurally intests/studio/test_cli_studio_defaults.py.I also read the heredoc terminator off the
<<that opens it, instead of hard-codingLAUNCHER_EOF.Anti-vacuity
34 assertions, 0 failures on a clean tree. Every case below mutated the real file, was confirmed on disk by md5, and was restored from a byte snapshot.
Must fail:
-H 0.0.0.0FAIL: the primary launch command binds no wildcard host--host 0.0.0.0-p 8888 -H 0.0.0.0FAIL: a wildcard-host bind is documented as an explicit opt-inFAIL: shows at least two studio launch commandsFAIL: the studio CLI declares a long --host optionstudio/setup.shlaunch hint binds0.0.0.0FAIL: the launch hint binds no wildcard hostinstall.shend block binds0.0.0.0FAIL: end-of-install commands bind no wildcard hostinstall.ps1end block binds--host 0.0.0.0FAIL: end-of-install commands bind no wildcard host0.0.0.0FAIL: the generated launcher binds no wildcard hostMust pass, against the real README as it stands on main, not a synthetic one. This is the whole point:
#### Launchto#### Start the server,#### Remote HTTPS & LAN Accessto#### Networking,### Unsloth Studio (web UI)to### Studio)studio --secure####to#####For comparison, on the first of those, the heading-scoped form fails with:
The detector has 20 fixtures of its own, because every negative assertion in this file passes when the detector sees nothing, so a detector that quietly stops matching turns the file green while guarding nothing. It has to catch the quoted
printf "..."shape andexec "$UNSLOTH_EXE" studio, and it has to leave-H 127.0.0.1,-H ::1,-H 0.0.0.0.5,llama-server --host 0.0.0.0, a trailing# add -H 0.0.0.0comment andunsloth-studio-launcheralone.Overlap
studio -H 0.0.0.0literal, sostudio -p 8888 -H 0.0.0.0still passes there. Its overlay-rail half is a different failure and does not overlap this at all. The two touch the same file, so whichever lands second wants a look.Checked
bash tests/sh/test_install_host_defaults.sh: 34 passed, 0 failedbash -n,git diff --check, shellcheck clean at-S warning(twoSC2016at-S style, both deliberate literal$)tests/studio/test_ci_shell_suite_coverage.pyandtests/studio/test_playwright_suites_run_in_ci.py: 36 passed