Repository navigation
openRepoShape: workdir() set its EXIT trap inside a $(...) subshell, so the temp dir was gone before setup.sh landed in it — every fetching run refused (#74) - #75
Conversation
…so the temp dir was gone before setup.sh landed in it — every fetching run refused (#74) `workdir()` printed its path and every caller read it as `$(workdir)` — a command substitution, which is a subshell. The `trap 'rm -rf …' EXIT` was therefore the SUBSHELL's trap and fired the instant the substitution closed: the directory was deleted before `fetch_from_repo` could write into it, and `$WORKDIR` in the main shell was still empty. Every run without `$OPENREPOSHAPE_SETUP_SH` — which is every real run — died with `line 76: /tmp/tmp.XXXX/setup.sh: No such file or directory` and then the misleading `REFUSED: could not fetch setup.sh …`, and `curl … | bash -s -- --install` failed the same way, fetching itself into the same vanished directory. A trap only ever fires in the shell that set it, so `workdir()` now makes the directory and sets the trap in the main shell and prints nothing; the two callers say `workdir` and then read `$WORKDIR`. Nothing else moves — the usage text, the fetch order and the argument handling are untouched. Two tests pin it, both offline: a fake `gh` first on `$PATH` answers the one API call the command makes (a stub `setup.sh` that prints where it ran from, and this checkout's own bytes for `openRepoShape`), with `curl` shadowed by a script that refuses so nothing can reach the network. One runs `--doctor` with `$OPENREPOSHAPE_SETUP_SH` unset and asserts the fetched script ran, was handed `--doctor`, and that its directory is gone AFTERWARDS rather than during; the other runs `bash -s -- --install` from stdin and asserts the installed copy is executable and byte-identical to this file. Both fail against the old shim with the refusal above. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Reviewer's GuideFixes temporary-directory lifetime by moving workdir setup and its EXIT trap out of command substitution, restoring setup.sh fetching for --doctor and stdin-based installation. Adds offline tests that exercise both paths, verify execution and installation, and confirm cleanup occurs only after the command completes. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@codex review |
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. This enables the previously broken fetching and installation paths, causing fetched scripts to execute and potentially write an installed command or other bounded local state. Reverting stops future runs but does not automatically remove artifacts or other effects from runs that already succeeded.
There was a problem hiding this comment.
🟡 Changes recommended
workdir() can now return non-zero when $WORKDIR is already set (due to the if compound command’s exit status), which can unexpectedly terminate the script under set -e.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes a real execution bug in the openRepoShape front-door script where workdir()’s EXIT trap was being set inside a command-substitution subshell, causing the temporary directory to be deleted before fetched payloads could be written and executed; adds offline tests to prevent regressions on the fetch path.
Changes:
- Make
workdir()set up the temp directory + EXIT cleanup trap in the main shell and have callers read$WORKDIRinstead of$(workdir). - Refactor test environment construction (
command_env(...)) to allow exercising the fetch path offline. - Add two offline tests that validate fetched
setup.shexecution and stdin-based self-install behavior without permitting network fallback.
File summaries
| File | Description |
|---|---|
| openRepoShape | Adjusts workdir() usage so fetched scripts land in a live temp dir and cleanup happens at process exit. |
| tests/test_openreposhape_command.py | Adds offline fetch-path coverage via a fake gh + refusing curl, and factors env setup to reach that path safely. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| workdir() { | ||
| if [ -z "$WORKDIR" ]; then | ||
| WORKDIR="$(mktemp -d)" | ||
| trap 'rm -rf -- "$WORKDIR"' EXIT | ||
| fi |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
On Copilot's " bash -euo pipefail -c 'WORKDIR=""; workdir() { if [ -z "$WORKDIR" ]; then WORKDIR="$(mktemp -d)"; trap "rm -rf -- \"$WORKDIR\"" EXIT; fi; }
workdir; first=$WORKDIR; workdir
echo "second call returned $? under set -e; WORKDIR unchanged: $([ "$first" = "$WORKDIR" ] && echo yes || echo no); still alive"'
# second call returned 0 under set -e; WORKDIR unchanged: yes; still aliveAnd in this script |



Lane: xfactory-2 (xFactory-2)
Claim: #74 (comment) (2026-09-09T00:18Z, on Brett Heap's "fix it")
Closes #74.
workdir()made the temporary directory and settrap 'rm -rf -- "$WORKDIR"' EXIT, and every caller read it as$(workdir)— a command substitution, which is a SUBSHELL. The trap was therefore the subshell's, fired the instant the substitution closed, and removed the directory beforefetch_from_repowrote a byte into it; the parent's$WORKDIRstayed empty as well. Every run that has to fetchsetup.sh— the scaffold itself,--doctor, and the README'scurl … | bash -s -- --install(which fetches its own bytes when run from stdin) — died withline 76: /tmp/tmp.XXXX/setup.sh: No such file or directoryand then the misleadingREFUSED: could not fetch setup.sh …, on a machine wheregh apiandcurlboth fetch the file fine by hand.git blameputs the function at a48d1f3 (#37), so the command has never worked from a fetch. Unaffected:./openRepoShape --installfrom a file, and any run with$OPENREPOSHAPE_SETUP_SHset — which is every run the suite made, which is how it got through.The fix:
workdirtakes no output. It makes the directory and sets the trap in the main shell, and its two callers read$WORKDIR. Three lines moved, oneprintfgone, one comment saying why; usage text, fetch order and argument handling are byte-identical.Two tests pin it, both offline: a fake
ghfirst on$PATHanswers the one API call the command makes (contents/setup.shwith a stub that prints where it ran from;contents/openRepoShapewith this checkout's own bytes), and a shadowcurlrefuses so no test can fall through to the network. The first runs--doctorwith$OPENREPOSHAPE_SETUP_SHunset and asserts the fetched script RAN and that its directory is gone AFTERWARDS — the trap fires at the end, in the right shell. The second is the documented one-line install,bash -s -- --installfrom stdin into a temporary$OPENREPOSHAPE_BIN_DIR. Both fail onmain'sopenRepoShapewith exactly the reportedNo such file or directory, and pass here.run_cmd's environment-building is factored intocommand_env(…, setup_sh=)so the fetch path can be reached without disturbing the twenty existing calls; the module docstring no longer claims the fetch cannot be exercised.Verified by hand as well:
bash ./openRepoShape --doctornow self-bootstraps from upstreammainand prints the preflight table endingthis machine is ready. Full suite: 622 passed, 1 skipped, and one pre-existing failure unrelated to this change (test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies, which fails identically onmainon this workstation because sibling checkouts ofopenXdoxandopenDoxsit beside this one and the validator resolves the link from disk).🤖 Generated with Claude Code
Summary by Sourcery
Keep fetched command payloads available through execution by moving temporary-directory cleanup into the main shell and cover both fetching callers with offline tests.
Bug Fixes:
Enhancements:
Tests: