Repository navigation
Cut the host-defaults installer windows from structure, not from comments - #9662
Conversation
…ents tests/sh/test_install_host_defaults.sh sliced install.sh, install.ps1 and studio/setup.sh on hand-written markers, two of which were comment prose. A comment exists to be rewritten, so this guard went red twice for reasons that had nothing to do with host defaults, and three of the four windows ran to end of file, so each negative assertion covered more than its label claimed. The launcher window was worse than fragile: it could go vacuous. It found its start with an awk pattern and its terminator with a separate, stricter grep that also required the << on the same line. Wrap that redirect across a line continuation and the grep matches nothing, the derived delimiter is the empty string, and $0 == delim then matches the first blank line inside the heredoc. The window collapses from 357 lines to 6, the shebang canary sits inside those 6 and still passes, and a -H 0.0.0.0 on the launcher's own exec line reports 39 pass / 0 fail. Each window is now cut from the file's own structure: the heredoc's own delimiter, read off the same matched line that opens it; the top-level if that declares the post-install branch; the PowerShell brace block. Every one asserts it closed on its own closing token, so a close that never matched is a report rather than a silent run to end of file. studio/setup.sh is read whole and labelled as such, because its footer header opens three different top-level blocks and no structural boundary picks out the right one. Two whole-file backstops catch a wildcard bind that lands outside every window. 39 pass / 0 fail before, 45 pass / 0 fail after.
…installer-windows
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c96a50219d
ℹ️ 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".
| _ps_brace_block() { | ||
| awk -v pat="$2" ' | ||
| !found && $0 ~ pat { found = 1 } | ||
| found { print; depth += gsub(/[{]/, "&") - gsub(/[}]/, "&"); if (depth <= 0) exit } |
There was a problem hiding this comment.
Ignore non-syntactic braces in the PowerShell block parser
When a comment or quoted string inside the inspected $IsInteractive block contains an unmatched brace—for example, a diagnostic string that mentions }—gsub treats it as PowerShell structure and may terminate the window early. The closing-token assertion then fails even though the installer behavior and host defaults are unchanged, recreating the behavior-preserving-comment-edit failure this change is intended to eliminate; strip comments/strings or use PowerShell's parser when balancing braces.
Useful? React with 👍 / 👎.
| "studio/setup.sh: the launch hint binds no wildcard host" \ | ||
| "$_setup_tail" | ||
| "install.ps1: no launch command anywhere in the file binds a wildcard host" \ | ||
| "$(cat "$INSTALL_PS1")" |
There was a problem hiding this comment.
Exclude PowerShell block comments from the whole-file scan
When install.ps1 contains a <# ... #> block comment before the end-of-install block with an example such as unsloth studio --host 0.0.0.0, this new whole-file assertion reports it as a launch command even though PowerShell never executes or prints it. The probe removes only # line comments, so applying it to the entire raw source introduces false CI failures for behavior-preserving documentation or commented-out examples; strip PowerShell block comments before scanning.
Useful? React with 👍 / 👎.
| sub(/^[ \t]+/, " ", nxt) | ||
| line = line nxt | ||
| } | ||
| if (!index(line, target) || !index(line, "<<")) next |
There was a problem hiding this comment.
Require an actual redirect when selecting the heredoc opener
When any earlier comment or unrelated line contains both _css_launcher and a heredoc example such as <<'EXAMPLE', this substring check selects that line instead of the real launcher redirect. The derived delimiter then differs from the launcher's terminator and the test fails on an installer behavior-preserving comment edit—the exact instability this helper is intended to remove; ignore comments and verify that the target is the heredoc's redirection destination.
Useful? React with 👍 / 👎.
Follow-up to #9655, which replaced the README heading slice in
tests/sh/test_install_host_defaults.shwith a structural probe. Four sibling windows were inventoried at the time and deliberately left alone. This does those four.The security property is unchanged and is not weakened anywhere: the installers and README must not put a wildcard bind (
0.0.0.0,[::],::) in a default launch command, and the LAN opt-in must still be documented as an opt-in. This is about how the file finds the region it asserts on.What was wrong
Three of the four windows ran to end of file, so each negative assertion covered a superset of the region its label named. Two of them were anchored on comment prose:
/cat > "\$_css_launcher"/+ a secondgrepfor the terminator/In interactive terminals//In interactive terminals//"launch"/A comment is the worst possible anchor, because a comment exists to be rewritten. Rewording either of those two turns this guard red on an edit that has nothing to do with host defaults, which is how it took
mainred twice already.The one that could go quiet
The launcher window is not just fragile. It can go vacuous, and I have a reproduction on
b3d86b2d0.It found its start with an awk pattern that matched
cat > "$_css_launcher", and found its terminator with a separate, strictergrepthat also required the<<on that same line. Wrap the redirect across a line continuation, which is a formatting change and nothing more:The
grepnow matches nothing, so the derived delimiter is the empty string, so$0 == delimmatches the first blank line inside the heredoc. The window collapses from 357 lines to 6. The#!/usr/bin/env bashcanary sits inside those 6 and still passes.With that reformat in place I changed the launcher's own launch line to
so every TTY launch of the installed Studio binds the LAN, and the suite reported
PASS: 39 / FAIL: 0 / ALL PASSED. On this branch the same tree reports 2 failures.To be clear about the scope: this is the only one of the four that can be quiet. The other three fail loudly on a marker reword. Their cost is a red on
mainfrom an unrelated edit, plus the end-of-file over-reach, not a blind guard.What replaces them
Each window is now cut from the file's own structure.
install.shlauncher is the heredoc, bounded by its own delimiter, where the start and the terminator come from the same matched line in the same helper. There is no second pattern left to disagree with the first. The helper also joins backslash continuations while it is looking for the opener, so the redirect and its<<are matched as one shell logical line however they are wrapped, and it stops joining the moment the heredoc opens, because the launcher body has continuations of its own and those are content.install.shend block is the top-levelifthat declares the post-install branch, through thefiin column zero that closes it, anchored on_SKIP_AUTOSTARTrather than on the comment above it.install.ps1end block is theif ($IsInteractive) {block, through the line where its braces balance again.studio/setup.shis deliberately not windowed, and the label says so. Its footer sits in a top-levelif [ "$_LLAMA_ONLY" = "1" ]; thenblock, and that same header opens three different top-level blocks in that file, so no structural boundary picks out the footer, only the ordinal "the third one", which is a hand-written marker wearing a different hat. The old anchor ran to end of file from"launch"anyway, so reading the whole file loses no coverage and gains the rest of it. Over-reporting there is cheap: the file's own wildcard opt-in is prose (add -H 0.0.0.0 for LAN / cloud access) with nostudioword in it, so it is not a launch command and does not trip this.Every window now asserts that it closed on its own closing token (
LAUNCHER_EOF,fi,}). That is what turns a close that never matched into a report instead of a silent run to end of file, and it is the assertion that would have caught the vacuity above.Two whole-file backstops were added for
install.shandinstall.ps1. The windows name the region each guard is about, which is what makes a failure readable; the backstops name the file, which is what makes the family hard to defeat. Both installers are clean today because their opt-in text is prose rather than a runnable command.Both directions, per window
Every mutation was applied to a byte snapshot and restored with md5 confirmation, never with
git checkout --. Each row was run against theorigin/mainguard and this branch's guard on the same mutated tree.execlineexecLAUNCHER_EOF->STUDIO_LAUNCH_EOFcat >"$_css_launcher" <<substephintIn interactive terminals--host=0.0.0.0on the interactive autostartexecIn interactive terminalscommentStart-Processarg list"launch"renamed to"start"studio_commands()forced to return[]W1-c is the vacuity. W1-b, W1-e, W2-b, W2-c, W3-b and W4-b are the reds this removes. W1-e and W4-c are coverage the old windows did not have. The blinding row is the anti-vacuity check on the detector itself: forcing the shared matcher to see nothing produces 15 failures, not a quiet green.
Counts
39 pass / 0 fail before, 45 pass / 0 fail after. The six new assertions are three window-closed checks, one "a heredoc terminator was derived" canary, and the two whole-file backstops.
No installer, README or CLI file is touched; the diff is this one test file.
shellcheck -e SC1090,SC2034andbash -n, the two checks lint-ci runs over committed shell, are both clean.