Repository navigation
fix(install): describe automatic setup and guard truncated downloads - #1902
Conversation
The help text said the installer only installs the CLI and that `rea setup` must be run separately, but the installer starts `rea setup` interactively whenever a terminal is available. Describe that behaviour and the --no-setup/--no-prompt opt-out. Wrap the installer body in `main` and call it on the last line, so a truncated `curl | bash` download fails to parse instead of executing a partial script. Behaviour is otherwise unchanged. Add an installer scenario that runs a copy truncated right after the npm install line and requires that it prints nothing and never invokes npm; it fails against the previous script. Validation: bash -n, shellcheck 0.10.0, installScript boundary tests.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7d0605853
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| fi | ||
| } | ||
|
|
||
| main "$@" |
There was a problem hiding this comment.
Keep the final invocation incomplete until the last byte
If the piped download is cut off immediately after the bytes main (or its following space) on this last line, Bash sees a syntactically complete command at EOF and runs the parsed function with no positional parameters. In the documented bash -s -- --dry-run/--version/--no-setup path this silently discards the caller's flags, so a supposed dry run can resolve the latest release, invoke npm, and potentially start setup—the partial-execution condition this wrapper is meant to prevent. Put the call inside a compound construct whose closing token must arrive before execution, and cover truncations of this tail as well.
AGENTS.md reference: AGENTS.md:L11-L11
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Cutting the old script off right after main made a bash -s -- --dry-run run go ahead and invoke npm install; I reproduced this locally. 4d92e65 replaces the last line with a brace group ({, main "$@", exit $?, }, each on its own line) and adds a comment explaining why. Bash won't run the group until it reads the closing brace, so any truncation inside it is a parse error. A new boundary test pipes the script to bash -s -- --dry-run, cutting it at every byte offset from the end of main() to EOF. It asserts that npm and the installed binary are never invoked and that offsets inside the group exit non-zero with no stdout. bash -n and shellcheck 0.11.0 are clean.
Wrapping the installer in main() kept a truncated download from running
a partial body, but the last line was a bare `main "$@"`. If the piped
download stopped right after `main` (or `main `), bash saw a complete
command at EOF and ran main with no positional parameters. Under the
documented `curl ... | bash -s -- --dry-run` (or --version / --no-setup)
path that silently dropped the caller's flags, so a dry run could resolve
the latest release, run npm, and start setup.
The call now sits in a brace group:
{
main "$@"
exit $?
}
Bash does not run the group until it has read the closing brace, so
every truncation inside it is a syntax error and nothing executes; a
truncation before the group leaves only function definitions. A comment
in install.sh records why the bare call is not enough.
Validation: a new boundary test pipes install.sh to `bash -s --
--dry-run` truncated at every byte offset from the end of main() to EOF
and asserts that npm and the rea binary are never invoked; offsets
inside the group must exit non-zero with a bash parse error and no
stdout, offsets before it must print nothing, and the complete group
must finish the dry run. Reproduced the original bug by cutting the old
script after `main`: the dry run invoked npm install. `bash -n` and
shellcheck 0.11.0 are clean.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d92e65479
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # `main` would be a complete command at EOF and run main without the caller's | ||
| # flags (so `bash -s -- --dry-run` could install). Inside this group, every | ||
| # truncation before the closing brace is a syntax error and nothing runs. | ||
| { |
There was a problem hiding this comment.
Start the truncation guard before the preamble
On the documented curl ... | bash path (docs/installation.md:50), this brace is opened only after the top-level set -euo pipefail has already been streamed. If the transfer stops immediately after the bytes set, Bash reaches EOF with a valid no-argument builtin; Bash's help set states that when no arguments are given, all shell variables are printed, so inherited tokens can be emitted to stdout before this guard is ever seen. Start the incomplete compound command before line 2 and include preamble byte cutoffs in the truncation test.
AGENTS.md reference: AGENTS.md:L11-L11
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 677cad7. A { now opens on line 2, right after the shebang, and the matching } is the last line. Everything in between, from set -euo pipefail through the final main "$@" / exit $?, sits inside that one group, so a download cut off after the bytes set is a syntax error and never a bare set. The truncation test now pipes every prefix of install.sh (byte 0 to EOF, about 6,100 cuts) into bash -s -- --dry-run with a minimal environment. For each cut it asserts empty stdout, no npm or rea invocation, a syntax error once the group is open, and a dry run only for the complete file. shellcheck 0.11.0 and bash -n are clean, and I checked by hand that set -e/-u still take effect inside the group.
The previous guard only wrapped the final `main "$@"` invocation, so the preamble streamed on the `curl ... | bash` path before any incomplete compound command was open. A download cut off right after the bytes `set` reached EOF with a complete, argument-less `set`, which prints every shell variable, so inherited tokens could reach stdout. The brace group now opens on line 2, directly after the shebang, and closes on the last line, enclosing `set -euo pipefail`, the constants, the functions and the final `main "$@"` / `exit $?`. Bash must therefore read the whole file before running anything; any earlier cut is a syntax error at EOF. `set -euo pipefail` still applies inside the group (checked manually for `false`, an unbound variable, and a failing function body), and shellcheck 0.11.0 and `bash -n` are clean. The truncation test now pipes every prefix of install.sh, from byte 0 to EOF (about 6,100 cuts, run 16 at a time with a minimal environment that includes a sentinel variable), into `bash -s -- --dry-run`. Before the group opens it must exit quietly; inside the group it must fail with a syntax error; in every case stdout stays empty and neither npm nor rea is invoked. Only the complete script performs the dry run.
Summary
This PR fixes two problems in
install.sh:--helptext says the installer only installs the CLI and thatrea setupmust be run separately. In fact, the installer startsrea setupinteractively whenever a terminal is available.curl … | bash. If the download is cut off, bash runs a partial script.Problem and expected behavior
npm installline. Bash then runs a prefix of the installer with whatever state that prefix leaves behind.main(), andmain "$@"is the last line. A truncated download no longer parses, so nothing runs. The help text now describes the automatic interactiverea setupand the--no-setup/--no-promptopt-outs.Change and scope
install.sh: themainwrapper (the diff is mostly re-indentation) and the help text. Behavior is otherwise unchanged.tests/boundary/filesystem/installScript.test.ts: a new scenario runs a copy truncated right after the npm install line. It requires that the copy prints nothing and never invokes npm.Contract and boundary impact
docs/user-visible-errors.csvmessages are unchanged.Evidence and regression coverage
install.shin place, the new test fails (× runs nothing from a download truncated after the npm install line; 1 failed, 28 passed). With this change, all 29 pass.Validation performed
bash -n install.sh: OK.npx vitest run tests/boundary/filesystem/installScript.test.ts: 29 passed. Against the base script: 1 failed, as expected.npx tsc --noEmit: clean.npx oxlint: 0 errors.npm run verify:module-boundaries: passed.npm run format: no changes.Compatibility, safety, and release
curl | bashpath against partial execution.Limits / not verified
shellcheckwas not available on this host for this rebase. It was run (0.10.0, clean) on the same change when it was originally written.npm run verify:packagewas not run.