Skip to content

Read the installers' own code, not the scripts they emit - #10701

Merged
danielhanchen merged 1 commit into
mainfrom
ci/here-string-aware-ps1-scanning
Sep 10, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/here-string-aware-ps1-scanning

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Repo tests (CPU) has been red on main since #10540, and the installer change is right. The test was reading the wrong text.

What broke

tests/sh/test_tauri_retry_failure_context.sh asserts that studio/setup.ps1 exits in exactly one place, the tail of Exit-SetupFailure. It counted exit lines with a grep over the raw file:

_ps_setup_exit_count=$(grep -Ec '^[[:space:]]*exit[[:space:]]+' "$SETUP_PS1" || true)
if [ "$_ps_setup_exit_count" -ne 1 ] || ! grep -q '^[[:space:]]*exit \$Code$' "$SETUP_PS1"; then

#10540 made the Windows installer emit its native path helper instead of compiling it, which put a probe script into a here-string:

    $probe = @'                                                    # setup.ps1:1667
...
if ('UnslothStudioEmitProbe' -as [type]) { ...; exit 0 }
exit 1                                                             # setup.ps1:1692
'@                                                                 # setup.ps1:1693

That exit 1 is the emitted probe's control flow, not the installer's. The count went to 2 and the guard fired.

The fix

tests/sh/_ps1_source.sh adds ps1_code, which blanks here-string bodies and keeps one blank line per body line so grep -n and sed addresses still point at the real file. Two details it has to get right, both learned from the files themselves:

  • The opener is detected with quoted strings blanked first. Both studio/setup.ps1:909 and install.ps1:2280 redact credentials with a -replace whose line genuinely ends in @':

    $Text = $Text -replace '(https?://)[^/@\s`]+@', '$1<redacted>@'
  • The terminator must sit in column 0, which is PowerShell's rule. install.ps1 builds a .bat from an array containing "@echo off",, and a lenient match closes the here-string there.

Two more readers were looking at emitted text

Neither was red, and one of them was quietly wrong:

  • tests/studio/test_installer_av_shapes.py opened a here-string on that same redaction line and stayed open until the next terminator. Every check in the file silently skipped setup.ps1:910-1692 and install.ps1:2281-3024, about 780 and 740 lines each, including the whole emit-probe region the file exists to police. With the fix those lines are scanned again and all 44 assertions still hold.

  • tests/sh/test_install_rollback_lifecycle.sh matched ^ } finally {$ at install.ps1:2894, inside the emitted launcher ($launcherContent = @", lines 2823-3024). It passed only because grep -A3 concatenated the context of all four matches and one of the real ones supplied Restore-StudioVenvRollback.

Guarding the filter

tests/sh/test_ps1_code_view.sh pins it both ways: an exit added to real code is counted, an exit added inside a here-string is not. Also covers the redaction line, the column-0 rule, the expandable @" ... "@ form, a comment that merely mentions a delimiter, and that line numbers survive.

Verification

All 64 tests/sh/test_*.sh suites pass. tests/studio/test_installer_av_shapes.py and tests/test_installer_interactive_prompts.py pass 136/136.

$ . tests/sh/_ps1_source.sh
$ ps1_code studio/setup.ps1 | grep -nE '^[[:space:]]*exit[[:space:]]+'
179:    exit $Code
$ ps1_code install.ps1 | grep -nE '^    \} finally \{$'
7085:    } finally {
7285:    } finally {
7419:    } finally {

No production file changes.

tests/sh/test_tauri_retry_failure_context.sh asserts studio/setup.ps1 exits in
exactly one place, the tail of Exit-SetupFailure. It counted `exit` lines with a
grep over the raw file, so when #10540 made the installer emit its native path
helper through a here-string instead of compiling it, the emitted probe's
`exit 1` counted as the installer's own and main went red. The installer change
is right; the test was reading the wrong text.

tests/sh/_ps1_source.sh adds ps1_code, which blanks here-string bodies and keeps
one blank line per body line so grep -n and sed addresses still point at the real
file. Two details it has to get right, both learned from the files themselves:
the opener is detected with quoted strings blanked first, because setup.ps1:909
and install.ps1:2280 redact credentials with a -replace whose line genuinely ends
in @'; and the terminator must sit in column 0, because install.ps1 builds a .bat
from an array containing "@echo off",.

Two more readers were looking at emitted text:

  - tests/studio/test_installer_av_shapes.py opened a here-string on that same
    redaction line, then stayed open until the next terminator. Every check in
    the file silently skipped setup.ps1:910-1692 and install.ps1:2281-3024. With
    the fix those lines are scanned again and all 44 assertions still hold.

  - tests/sh/test_install_rollback_lifecycle.sh matched `} finally {` inside the
    emitted launcher at install.ps1:2894, and passed only because grep -A3
    concatenated the context of all four matches.

tests/sh/test_ps1_code_view.sh guards the filter both ways: an exit added to real
code is counted, an exit added inside a here-string is not.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 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
🔒 Security Review ✅ Completed 2026-09-10T06:50:12.592256Z ea6798d PR opened
ℹ️ 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.

@danielhanchen
danielhanchen merged commit bd8df9b into main Sep 10, 2026
25 of 27 checks passed
@danielhanchen
danielhanchen deleted the ci/here-string-aware-ps1-scanning branch September 10, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant