Skip to content

setup.sh is a shim over setup-project.py: the flow exists once (#50) - #60

Merged
brettheap merged 3 commits into
mainfrom
fix/setup-sh-shim
Sep 5, 2026
Merged

brettheap merged 3 commits into
mainfrom
fix/setup-sh-shim

Conversation

@brettheap

@brettheap brettheap commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Lane: xfactory-2 (xFactory-2)
Claim: #50 (comment)

Closes #50.

What this changes

setup.sh is now a shim over setup-project.py, so the start-a-project flow exists once. Brett Heap, 2026-09-05: "pick up #50 and #51 too". #53 kept the 500-line bash intact on purpose and held the two entry points together with a flag-parity test; this is the consolidation it deferred, as its own PR so a bisect points at the delegation and not at Windows support.

The shim keeps exactly three jobs. It finds a Python 3.9 or newer (python3, then python, each probed with the interpreter's own sys.version_info) before anything else. When it is not already inside a checkout of the standard it clones one into a temporary directory, exactly as the old section (0) did — the (0) self-bootstrap block byte for byte, --depth 1 under the same rule, --shape-ref honoured, -- before the repository argument, the cleanup trap owning the directory and --keep-shape-checkout keeping it. And it tells the Python where the person was standing: --into <invocation dir> injected FIRST so an explicit --into still wins (the #39 property). Everything else — preflight, organisation, names, plan, the one yes, scaffold, clone, bootstrap, hand-over — is setup-project.py's. From a checkout it execs the Python with no cd, because the Python reads origin from the invocation directory.

One new handshake, and it is a safety fix. A shim-cloned checkout is a real checkout, so the Python would take the developer path and DETECT the organisation from whatever repository the person happened to be standing in — a curl | bash run started inside ~/work/acme-website would scaffold three repositories into acme. The shim sets OPENREPOSHAPE_SELF_BOOTSTRAP=1 on the hand-over command only, and the Python then requires --org, with the same sentence self_bootstrap() already uses, before the preflight.

Also fixed while here: the old file leaked bash: line 36: BASH_SOURCE[0]: unbound variable under cat setup.sh | bash -s --; the shim writes ${BASH_SOURCE[0]:-$0}. The shim is written to bash 3.2 rules for the tests-macos job that #57 added: ${1+"$@"} everywhere, no associative arrays, no mapfile, no ${var,,}, mktemp -d with an explicit template.

What a human will notice, stated because the acceptance asks

  • The preflight glyphs are [ok]/[!!] (pure-ASCII Python) where bash printed ✓/✗.
  • make is neither probed nor used; bootstrap runs as python3 scripts/bootstrap.py, which is what make bootstrap ran.
  • The shim checks its own two prerequisites, a Python 3.9+ and git, one refusal each, before anything else; the old preflight reported every missing prerequisite in one pass. Everything else is still reported together by the Python's preflight.
  • --help from curl | bash clones the standard before printing usage, because the banner is the Python's; from a checkout nothing changes.
  • A flag missing its value exits 2 (the Python's default refusal), where bash's ${2:?} exited 1. One parser now; the divergence A native Windows path: setup-project.py, a windows-latest job, and the README route (#49) #53's review recorded is resolved, not tolerated.
  • A failing child (scaffold-project.py, git clone, bootstrap.py) prints a REFUSED: line naming it, where set -e exited silently.

Adversarial Opus review before opening, folded in

The reviewer confirmed the shim, the trap and the handshake and found the gaps in the one surface the shim still owns, section 0: no git probe before the clone (git: command not found, exit 127, where the Python prints the house refusal); OPENREPOSHAPE_REPO guarded only for a leading -, so a control character could print a forged REFUSED: line; --shape-ref guarded only for -, so a..b or topic.lock reached git checkout with git's own error; the exec used the script directory where the guard had proven the git toplevel, which broke bash -s from a subdirectory of a checkout; a leaked OPENREPOSHAPE_SELF_BOOTSTRAP misdescribing a fork checkout (now unset before the developer exec); and four docs left saying make bootstrap or setup.sh --help. All fixed, each guard with a bash-side test, all offline (three new tests; 585 → 591).

Tests

tests/test_setup_sh.py: exactly two assertion edits, each with its comment — the preflight line now matches the RUNNING interpreter (python 3.x.y (path)) instead of the literal python3 (which passed by accident off the bootstrap runs as line), and the usage banner is usage: setup-project.py (one banner, printed by the one implementation, invoked under two names). One fixture change, not an assertion: test_self_bootstrap_without_org_refuses sets OPENREPOSHAPE_REPO to this checkout, because the refusal now fires after the clone and the test must stay offline. The flag-parity test is retired — it parsed a usage heredoc the shim does not have and would have errored, and parity of two lists is moot when there is one — and replaced by test_setup_sh_parses_no_flags_of_its_own (the shim may name only the six flags about the checkout it makes) and test_the_two_entry_points_say_self_bootstrap_the_same_way. test_the_shim_handshake_requires_an_org runs from a fork directory and was proven red without the handshake.

Every other test in the bash suite now exercises the shim's pass-through end to end. README § "What setup.sh does" says what the shim is and shows the commands the Python runs; the cap moves 945 → 948.

Evidence

python3 -m pytest tests -q → 591 passed (main at 1a706dc: 582). All three CI jobs on this PR — the tests-macos job is the shim's first real bash 3.2 run. Adversarial Opus review before opening.

Merge word: Brett Heap, 2026-09-05, "merge #50 and #51 on green too".

🤖 Generated with Claude Code

Summary by Sourcery

Make setup-project.py the single project-creation flow and reduce setup.sh to a safe cross-platform delegation shim.

Bug Fixes:

  • Prevent self-bootstrap runs from inferring the organisation from an unrelated checkout and standardise refusal handling across both entry points.
  • Fix piped-stdin execution, checkout path handling, bootstrap invocation, and validation of repository and shape-ref inputs.

Enhancements:

  • Consolidate project setup into setup-project.py, reducing setup.sh to a Bash 3.2-compatible shim that handles interpreter discovery, Git checks, self-bootstrap, and invocation-directory preservation.
  • Use a single parser, usage banner, preflight, and setup flow for both entry points, including direct execution of scripts/bootstrap.py without requiring make.

CI:

  • Extend the test suite with shim delegation, handshake, input-validation, missing-Git, and Bash compatibility coverage, while replacing flag-parity checks with shim-specific delegation checks.

Documentation:

  • Update contributor and user documentation to describe setup.sh as a shim and document direct bootstrap execution through scripts/bootstrap.py.

Tests:

  • Update setup tests for the unified Python-owned output and add offline coverage for self-bootstrap safety and shim-owned guards.

brettheap and others added 3 commits September 5, 2026 18:30
The bash entry point keeps exactly three jobs - find a Python 3.9+ (python3, then python), clone the standard into a temporary directory when it is not already inside a checkout, and tell the Python where the person was standing (--into first, so the #39 property holds) - and hands everything else to setup-project.py. Developer path: exec with NO cd, because the Python reads origin from the invocation directory. Self-bootstrap: the (0) block byte for byte, -- before the repository argument, --shape-ref and --keep-shape-checkout scanned but never consumed, the trap owns the temp checkout. New handshake OPENREPOSHAPE_SELF_BOOTSTRAP=1: a shim-cloned checkout is a real checkout, so without it the Python would detect the organisation from whatever repository the person stood in; with it, --org is required, one wording, after the clone. ${BASH_SOURCE[0]:-$0} removes the unbound-variable line the old file leaked under curl | bash. Bash 3.2 clean for the tests-macos job. Two assertion edits in test_setup_sh.py (the running interpreter, one usage banner); the flag-parity test retired for a test that setup.sh parses no flags of its own. 575 tests.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ol-character and ref-rule guards, exec from the proven toplevel (#50)

Adversarial review before opening, all in the one surface the shim still owns: the shim probes git itself before any clone (a missing git looked like not-a-checkout and died at git clone with 127 where the Python prints the house refusal); OPENREPOSHAPE_REPO refuses control characters as well as a leading -, without echoing the value; --shape-ref mirrors the Python REF_RE (alphanumeric start, no .., no .lock, the ref alphabet); the developer exec runs setup-project.py from the git toplevel the guard proved, not from $SCRIPT_DIR, so bash -s from a subdirectory of a checkout works; the handshake variable is unset before that exec so a leaked value cannot misdescribe a fork; README, AGENTS.md and the openRepoShape command say scripts/bootstrap.py and setup-project.py where they said make bootstrap and setup.sh --help; both scan false positives named. Three bash-side tests for the guards, offline. 591 tests.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 5, 2026 23:10
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 15 hours and 54 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@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, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@sourcery-ai

sourcery-ai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

setup.sh is consolidated into a small, Bash 3.2-compatible front end that validates prerequisites, performs only the required self-bootstrap checkout work, preserves the caller’s directory and arguments, and hands the complete flow to setup-project.py; the Python entry point now owns the single parser and behavior, with a handshake preventing unsafe organisation detection and expanded tests/docs covering the delegation.

Sequence diagram for setup.sh delegation and self-bootstrap

sequenceDiagram
    participant User
    participant Shim as setup.sh
    participant Git
    participant Python as setup-project.py
    participant Flow as Project flow

    User->>Shim: Invoke with arguments
    Shim->>Shim: find_python()
    Shim->>Git: Check git and detect checkout
    alt Existing openRepoShape checkout
        Shim->>Python: exec with --into and original arguments
    else No checkout
        Shim->>Git: clone --depth 1 ... -- repository
        Shim->>Git: checkout --shape-ref
        Shim->>Python: run with --into and OPENREPOSHAPE_SELF_BOOTSTRAP=1
        Python->>Python: Require --org
    end
    Python->>Flow: Parse flags and run preflight
    Flow->>Flow: Scaffold, clone, and run scripts/bootstrap.py
    Shim-->>User: Preserve child status and clean temporary checkout
Loading

File-Level Changes

Change Details Files
Reduce setup.sh to a Bash 3.2-compatible bootstrap shim and delegate the project-creation flow to setup-project.py.
  • Probe for Python 3.9+ and git before any checkout work.
  • Preserve self-bootstrap cloning, ref selection, cleanup, and keep-checkout behavior.
  • Detect the checkout top level and execute the Python without changing the invocation directory.
  • Inject --into first so explicit user values override it, and pass all remaining arguments through unchanged.
  • Retain only shim-owned parsing/guards for checkout bootstrap options and harden repository/ref validation.
setup.sh
Add an explicit hand-over contract so self-bootstrapped runs cannot infer an organisation from an unrelated checkout.
  • Set OPENREPOSHAPE_SELF_BOOTSTRAP only for the delegated command.
  • Require --org in setup-project.py under the handshake using the shared self-bootstrap refusal.
  • Unset leaked handshake state on the normal developer path.
setup-project.py
setup.sh
tests/test_setup_project_py.py
Make setup-project.py the single user-facing implementation and align its runtime behavior and documentation with the new ownership model.
  • Use one parser, usage banner, preflight, scaffold flow, failure reporting, and direct Python bootstrap command.
  • Update documentation and agent guidance to describe setup.sh as a shim and remove make-bootstrap instructions.
  • Update the installed command usage text and repository hygiene cap.
setup-project.py
README.md
AGENTS.md
openRepoShape
tests/test_openreposhape_command.py
tests/conftest.py
tests/test_repo_hygiene.py
Revise the test suite from cross-entry-point flag parity to delegation, handshake, and shim safety coverage.
  • Update assertions for the running interpreter and shared setup-project.py usage banner.
  • Retire the duplicated flag-list parity test and verify the shim defines no flow flags.
  • Add tests for matching self-bootstrap output, required organisation hand-off, hostile repository/ref inputs, missing git, and invocation-directory behavior.
  • Keep self-bootstrap tests offline and report 591 passing tests.
tests/test_setup_sh.py
tests/test_setup_project_py.py

Assessment against linked issues

Issue Objective Addressed Explanation
#50 Consolidate the two entry points so that setup.sh becomes a small Bash shim that finds a supported Python interpreter, self-bootstraps a temporary openRepoShape checkout when necessary, preserves the invocation directory and arguments, and delegates the complete setup flow to setup-project.py. ✅
#50 Preserve existing integrations and documented behavior, including the openRepoShape command, README instructions, self-bootstrap handling, argument pass-through, cleanup, and the required updates to the two affected setup.sh assertions. ✅
#50 Remove the redundant flag-parity requirement or replace it with an appropriate regression guard reflecting that setup-project.py is now the single implementation. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud

sonarqubecloud Bot commented Sep 5, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The shim’s --shape-ref validation is missing the Python flow’s 255-character limit, so an unbounded ref can still reach git checkout before Python parsing/validation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR consolidates the project-creation “front door” so setup-project.py is the single source of truth for the setup flow, while setup.sh becomes a minimal Bash 3.2-compatible shim that bootstraps (when needed) and delegates to the Python implementation.

Changes:

  • Replaced the former ~500-line setup.sh implementation with a delegation shim (Python discovery, git presence check, self-bootstrap clone, --into injection, and the self-bootstrap --org handshake).
  • Updated tests to reflect the unified Python-owned preflight/usage output and added shim-focused coverage (guards + handshake behavior).
  • Refreshed docs and command help text to describe setup.sh as a shim and setup-project.py as the flow, and to reflect bootstrap running via scripts/bootstrap.py.
File summaries
File Description
setup.sh Replaced full flow with a Bash shim that finds Python, self-bootstraps a checkout when needed, and hands off to setup-project.py (incl. OPENREPOSHAPE_SELF_BOOTSTRAP handshake).
setup-project.py Centralizes wording/behavior as the canonical flow; adds shared ORG_REQUIRED refusal used by both direct self-bootstrap and shim handover.
openRepoShape Updates usage/help text to refer to setup-project.py options and clarifies that ./setup.sh --help prints the Python usage.
README.md Updates “What setup.sh does” and related sections to describe shim delegation and bootstrap via scripts/bootstrap.py.
AGENTS.md Updates bootstrap references from make bootstrap to scripts/bootstrap.py (what make bootstrap runs).
tests/test_setup_sh.py Adjusts assertions for Python-owned output and adds shim-guard tests (hostile repo env, invalid --shape-ref, missing git).
tests/test_setup_project_py.py Replaces the old flag-parity test with tests asserting setup.sh remains a shim and that self-bootstrap wording stays aligned.
tests/test_openreposhape_command.py Updates expected usage line to match the new delegation model.
tests/conftest.py Updates Windows skip rationale to match the new interpreter-probing shim behavior.
tests/test_repo_hygiene.py Updates README line-count cap with rationale reflecting the shim documentation additions.
Review details
  • Files reviewed: 10/10 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.

Comment thread setup.sh
Comment on lines +129 to +136
# Mirrors `setup-project.py`'s REF_RE: a ref starts with a letter or digit,
# holds only letters, digits, '.', '_', '/', '-', is never a `..` range and
# never ends in `.lock` (git's own lock-file name for one). Only reached when
# $SHAPE_REF is non-empty — every alternative below requires at least one
# character to match.
case "$SHAPE_REF" in
[!A-Za-z0-9]*|*..*|*.lock|*[!A-Za-z0-9._/-]*) die "--shape-ref is '$SHAPE_REF', which is not a branch, tag or commit this tool will pass to \`git checkout\`: a ref starts with a letter or digit, uses only letters, digits, '.', '_', '/', '-', has no '..' and does not end in '.lock'." ;;
esac
@brettheap
brettheap merged commit a0962e8 into main Sep 5, 2026
6 checks passed
@brettheap
brettheap deleted the fix/setup-sh-shim branch September 5, 2026 23:18
brettheap added a commit that referenced this pull request Sep 6, 2026
…tes, the shim's --shape-ref length bound (#63) (#65)

* Empty $OPENREPOSHAPE_REPO means unset, the standard's own .gitattributes, the shim's --shape-ref length bound (#63)

Three Copilot inline comments read after their PRs merged (#56, #58, #60) and
deferred as cosmetic. None changes what a user sees today; each left a
statement in the tree that was not true, or a bound present in one entry point
and absent from the other.

setup-project.py: the comment above the $OPENREPOSHAPE_REPO read claimed that
checked_value refuses an empty value; the truthiness test in front of it means
an empty value is never checked and falls to DEFAULT_SHAPE_REPO, exactly as
setup.sh's ${OPENREPOSHAPE_REPO:-<default>} does. Ruled on #63: empty means
unset in both entry points. Behaviour unchanged; the comment now says so. One
test per entry point pins it offline by handing the child a
url.<file-uri>.insteadOf <default> rewrite through GIT_CONFIG_COUNT, so the
echoed clone line naming the default URL proves the empty value fell through.

.gitattributes at the root: the templates got theirs in #51; the checkout that
ships them had none, so a core.autocrlf=true clone of openRepoShape itself
turned every LF into CRLF and unname_everywhere() in the update-shape-add
tests, which matches a copy-list line whole, stripped nothing. Same rule,
* text=auto eol=lf, its own header; git add --renormalize is a no-op because
every tracked file is already LF. Hygiene tests pin the rule and its agreement
with both templates; the helper matches \r?\n anyway, for a checkout made
before this landed.

setup.sh: the --shape-ref case mirrored REF_RE's alphabet but not its 255
character bound, so an over-long ref reached git checkout in the temporary
clone. A length check after the case refuses it, naming the length rather than
echoing the value. bash 3.2 clean. A 256-character ref joins both parametrised
refusal tests; a dedicated shim test asserts the refusal names --shape-ref and
255, exits 2 and does not echo the value.

611 -> 619 tests.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* PR #65 review: the shim refuses an over-long or control-character --shape-ref before anything echoes it (#63)

Copilot on PR #65: the shape `case` echoed the raw --shape-ref in its refusal,
so a value holding a newline could forge a line onto stderr, and an over-long
ref that also failed the shape was echoed as 255+ characters of noise. Three
checks now run in order - length, then a control character, both refusing
without naming the value the way the OPENREPOSHAPE_REPO guard above them does,
then the shape case, which by then only ever sees a printable ref of at most
255 characters. Two tests: a newline-carrying ref is refused and the forged
line never reaches stderr; the over-long test is parametrised over a legal
shape and an illegal one, and neither is echoed.

Also from the review: the comment claiming the case is "only reached when
non-empty" (it runs unconditionally and matches nothing) is reworded, and the
hygiene test named "repositorys" is renamed.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
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.

One definition for the two entry points: setup.sh becomes a shim over setup-project.py (follow-up of #49)

2 participants