Skip to content

setup-project.py: Copilot's five post-merge findings on #53 (#55) - #56

Merged
brettheap merged 1 commit into
mainfrom
fix/setup-project-copilot
Sep 5, 2026
Merged

brettheap merged 1 commit into
mainfrom
fix/setup-project-copilot

Conversation

@brettheap

@brettheap brettheap commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Lane: xfactory-2 (xFactory-2)
Claim: #55 (claim in the issue body)

Closes #55.

Copilot left six inline comments on #53 across three review rounds; the last round landed after the final push and the PR merged on the standing "merge on green" word before it was read. One was already fixed in acd460b (--shape-ref validated). These are the other five, all in setup-project.py:

  1. The module docstring promised pure-ASCII OUTPUT. It now promises pure-ASCII SOURCE and pure-ASCII fixed markers and messages, and says plainly that echoed values (--elected-by, git config user.name) and child output are whatever bytes they are, written through a UTF-8 errors="replace" stream.
  2. --help said --into defaults to .. always. It now also says that in self-bootstrap mode the effective default is the directory you ran the command from.
  3. OPENREPOSHAPE_REPO reached git clone unguarded. It is now checked (empty, leading -, control characters refused; the refusal names the variable) and the clone argv carries -- before the repository argument, so git never reads it as an option regardless. setup.sh shares the exposure and is byte-frozen until One definition for the two entry points: setup.sh becomes a shim over setup-project.py (follow-up of #49) #50; noted there.
  4. PYTHON_CMD was Path(sys.executable).name, not reliably retypable. It is now the platform-conventional command, exactly as scripts/repo_shape.py's PYTHON; sys.executable stays for every argv.
  5. _main() duplicated two strings that constants already existed for. Output byte-identical.

Three new tests: a hostile OPENREPOSHAPE_REPO refuses with exit 2 and names the variable; the echoed clone line carries --; the preflight's bootstrap line names python3/python by platform. Source still pure ASCII; every other printed string unchanged.

Evidence: python3 -m pytest tests -q → 573 passed (570 on main). Both CI jobs on this PR.

Merge word: not yet given — awaiting Brett Heap.

🤖 Generated with Claude Code

Summary by Sourcery

Harden self-bootstrap setup validation and clarify its user-facing guidance while preserving existing output behavior.

Bug Fixes:

  • Validate OPENREPOSHAPE_REPO before cloning and guard the repository argument against option parsing.
  • Use platform-conventional Python command names in retypable bootstrap guidance.

Enhancements:

  • Clarify output encoding guarantees and self-bootstrap --into behavior.
  • Reuse existing prerequisite error messages in _main().

Tests:

  • Add coverage for hostile repository environment values, clone argument guarding, and platform-specific bootstrap Python guidance.

The docstring now promises ASCII for the SOURCE and the fixed markers this file writes, not for echoed values or child output; --help says what --into defaults to in self-bootstrap mode; OPENREPOSHAPE_REPO is checked (empty, leading -, control characters refused, the variable named) and the shape clone carries -- before the repository argument; PYTHON_CMD is the platform-conventional command, matching repo_shape.PYTHON, so a remediation names something the reader can type; _main() uses the GIT_MISSING and PREREQ_MISSING constants. Three tests. 573 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 21:24
@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 16 hours and 28 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

The PR applies five post-merge fixes in setup-project.py: it tightens documentation and output encoding semantics, validates and defensively passes OPENREPOSHAPE_REPO to git, makes displayed Python commands retypable across platforms, corrects self-bootstrap help, and deduplicates preflight strings, with tests covering the new repository and platform behaviors.

Sequence diagram for validated self-bootstrap repository cloning

sequenceDiagram
    participant User
    participant SetupProject as setup-project.py
    participant Git

    User->>SetupProject: self_bootstrap(opts, original_argv, invocation_dir)
    SetupProject->>SetupProject: checked_value(OPENREPOSHAPE_REPO, raw_shape_repo, PATH_RE)
    alt repository value accepted
        SetupProject->>Git: git clone -- shape_repo checkout
        Git-->>SetupProject: clone result
    else repository value rejected
        SetupProject-->>User: named validation error
    end
Loading

File-Level Changes

Change Details Files
Clarify the script's output encoding contract and preserve byte-safe handling of echoed and child-process output.
  • Restrict the ASCII guarantee to source and fixed markers/messages.
  • Document UTF-8 replacement handling for externally sourced output.
setup-project.py
Make self-bootstrap repository selection safer before invoking git.
  • Validate OPENREPOSHAPE_REPO using the existing value-checking rules and identify the variable on refusal.
  • Insert -- before the repository argument in the clone command.
  • Add coverage for hostile values and echoed clone arguments.
setup-project.py
tests/test_setup_project_py.py
Use a platform-conventional Python command in human-facing bootstrap instructions while continuing to execute children with sys.executable.
  • Set PYTHON_CMD to python3 on POSIX and python on Windows.
  • Add a platform-specific preflight output test and update the source invariant.
setup-project.py
tests/test_setup_project_py.py
Correct self-bootstrap help text and remove duplicated preflight message literals.
  • Document the effective --into default when running in self-bootstrap mode.
  • Reuse existing constants for missing-git and prerequisite messages without changing output bytes.
setup-project.py

Assessment against linked issues

Issue Objective Addressed Explanation
#55 Constrain the module docstring's ASCII guarantee to the source and to fixed markers/messages emitted by the script, excluding user-supplied values and child-process output. ✅
#55 Correct the --into help text so it explains that self-bootstrap mode uses the invocation directory as the effective default parent. ✅
#55 Protect OPENREPOSHAPE_REPO from argument injection by rejecting empty, leading-dash, or control-character values and placing -- before the repository argument in git clone; document setup.sh's unchanged exposure. ✅
#55 Use the platform-conventional retypable interpreter name (python3 on non-Windows and python on Windows) in human-facing strings while retaining sys.executable for child-process argv. ✅
#55 Replace duplicated git-missing and prerequisite-missing messages in _main() with the existing GIT_MISSING and PREREQ_MISSING constants. ✅

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

$OPENREPOSHAPE_REPO set to an explicitly empty string currently bypasses the intended empty-value refusal due to a truthiness check, and the test suite doesn’t cover this case.

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

Pull request overview

This PR addresses follow-up hardening and documentation correctness in setup-project.py (post-merge findings from #53/#55), focusing on safer self-bootstrap behavior and ensuring user-facing guidance remains platform-correct while keeping output stable.

Changes:

  • Tighten and clarify the module docstring’s ASCII guarantees and output encoding behavior.
  • Improve --help text for --into to reflect the effective default in self-bootstrap mode.
  • Harden self-bootstrap cloning by validating $OPENREPOSHAPE_REPO and adding -- before the repository argument; also reuse existing prerequisite error message constants.
  • Extend tests for platform-specific bootstrap messaging and self-bootstrap clone argument guarding.
File summaries
File Description
setup-project.py Clarifies ASCII/encoding guarantees, updates help text, validates/guards $OPENREPOSHAPE_REPO for git clone, and deduplicates prerequisite messages.
tests/test_setup_project_py.py Adds coverage for platform-specific bootstrap messaging and self-bootstrap clone argument guarding with $OPENREPOSHAPE_REPO.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • 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-project.py
Comment on lines +613 to +615
raw_shape_repo = os.environ.get("OPENREPOSHAPE_REPO")
shape_repo = (checked_value("OPENREPOSHAPE_REPO", raw_shape_repo, PATH_RE)
if raw_shape_repo else DEFAULT_SHAPE_REPO)
Comment on lines +813 to +828
def test_a_hostile_openreposhape_repo_refuses(tmp_path):
"""`OPENREPOSHAPE_REPO` reaches `git clone` as the repository argument,
which is exactly the argument git itself will never refuse for us: a
leading `-` there is an OPTION to git, not a name. `-c core.x=y` is the
shape of a value that would turn the clone into a config injection, and
it is refused before `git` ever sees it - by the same `checked_value`
rule as every flag on the command line - naming the environment
variable so the person fixing this knows what to change."""
outside = make_outside_checkout(tmp_path)
result = run_entry("--org", "demoorg", "--project", "Sample", "--yes",
"--local-remote-dir", str(tmp_path / "remotes"),
cwd=outside, script=outside / "setup-project.py",
extra_env={"OPENREPOSHAPE_REPO": "-c core.x=y"})
assert result.returncode == 2
assert "OPENREPOSHAPE_REPO" in result.stderr
assert not (tmp_path / "remotes").exists()
@brettheap
brettheap merged commit 4fe7840 into main Sep 5, 2026
5 checks passed
@brettheap
brettheap deleted the fix/setup-project-copilot branch September 5, 2026 21:32
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

2 participants