Skip to content

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

Merged
brettheap merged 3 commits into
mainfrom
fix/copilot-cosmetics
Sep 6, 2026
Merged

brettheap merged 3 commits into
mainfrom
fix/copilot-cosmetics

Conversation

@brettheap

@brettheap brettheap commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Lane: xfactory-2 (xFactory-2)
Claim: #63 (claim in the issue body, 2026-09-06T02:24Z, on Brett Heap's "pick up 12-14 and merge on green too")

Closes #63.

Three Copilot inline comments read AFTER their PRs merged (#56 for #55, #58 for #51, #60 for #50) and deferred as cosmetic. None changes behaviour a user sees today; each left a statement in the tree that was not true, or a bound that existed in one entry point and not in the other.

1. An explicitly EMPTY $OPENREPOSHAPE_REPO means unset (Copilot on #56)

self_bootstrap() reads the variable with a truthiness test, so OPENREPOSHAPE_REPO= falls to DEFAULT_SHAPE_REPO — while the comment above the read said checked_value refuses "an empty value", which it is never reached for. setup.sh reads the same variable as ${OPENREPOSHAPE_REPO:-<default>}: empty is unset there too.

Ruling (recorded on #63): empty means unset, in both entry points — the shell's own ${VAR:-default} reading, and the two entry points already agreed. Behaviour unchanged; the comment now says what the code does. One test per entry point pins it, OFFLINE: GIT_CONFIG_COUNT/_KEY_0/_VALUE_0 give the child process a url.<file-uri-of-this-checkout>.insteadOf <default> rewrite, so the clone of the DEFAULT repository resolves to this checkout without a network — the echoed git clone line naming the default URL is the proof that the empty value fell through to it. Each test also asserts its literal equals the source's own default, so they cannot drift apart. (GIT_CONFIG_COUNT needs git ≥ 2.31; the three runners and this box have 2.4x.)

2. The standard's own root gets a .gitattributes; the test helper tolerates CRLF (Copilot on #58)

tests/test_update_shape_add.py::unname_everywhere() stripped "<entry>",\n — a checkout made under Git for Windows' core.autocrlf=true default has CRLF sources, the helper stripped nothing, and #51's tests would fail on a machine whose only sin was that default. CI never saw it (Linux/macOS check out LF; the Windows job pins autocrlf=false). #51 gave the two TEMPLATES a .gitattributes; the standard's own root had none.

  • New root .gitattributes with the templates' rule * text=auto eol=lf and its own header (why the STANDARD wants LF bytes: its suite reads its sources as text, and shape_materialize copies their bytes into projects that pin digests). git add --renormalize . is a no-op: every tracked file is already i/lf.
  • tests/test_repo_hygiene.py: the root carries exactly that rule; root and both templates agree on the rule line (headers differ on purpose).
  • unname_everywhere matches \r?\n, because a checkout made before this lands keeps its CRLF until renormalised; one direct test feeds it a CRLF source.

3. The shim's --shape-ref guard gets REF_RE's length bound (Copilot on #60)

The case in setup.sh mirrored REF_RE's alphabet, first character, .. and .lock rules but not its length ({0,254} after the first character: at most 255). An over-long ref reached git checkout in the temporary clone where the Python would have refused it at parse time.

  • if [ "${#SHAPE_REF}" -gt 255 ]; then die ...; fi after the case — bash 3.2-clean; the refusal names the LENGTH, not the value (256+ characters of noise on stderr is not a fault a person can read).
  • Tests: a 256-character ref joins both parametrised refusal tests (Python and shim); a dedicated shim test asserts the refusal names --shape-ref and 255, exits 2, and does not echo the value.

What did not change

Behaviour of either entry point on any input a user types today; README.md and AGENTS.md (caps unchanged); the templates.

Tests

Review

  • Copilot, two rounds, all three findings folded in (aa1d5c9): (1) the shape case echoed the raw --shape-ref in its refusal, so a control character could forge a stderr line and an over-long ref that also failed the shape was echoed as noise → three checks now run in order: length, then control character — both refusing WITHOUT echoing the value, like the OPENREPOSHAPE_REPO guard above them — then the shape case, which by then only ever sees a printable ref of at most 255 characters; two new tests (a newline-carrying ref is refused and the forged line never reaches stderr; the over-long case is parametrised over a legal and an illegal shape, neither echoed). (2) The "only reached when $SHAPE_REF is non-empty" comment was inaccurate (the case runs and matches nothing) → reworded. (3) test_the_repositorys_own_root… → test_the_repository_root_carries_the_rule_too.
  • SonarCloud: gate passed. Its one new issue, S7688 ("use [[ instead of [") on the new length check, is deliberately NOT taken: the shim uses POSIX [ in its four existing tests, and one [[ would be the odd construct out in a file whose point is to be plain bash 3.2.
  • Codex: over its review quota. Sourcery: over its weekly budget.
  • Main moved under this PR (The optional MedxEHR clone comes from SHAPE_MEDXEHR_CLONE, and a guard keeps host paths out of the tree (#61) #64, b17ede6); taken as a merge commit 2bb8575 (the ruleset refuses force-push). Both PRs edited tests/test_repo_hygiene.py in disjoint regions; the merge was clean and The optional MedxEHR clone comes from SHAPE_MEDXEHR_CLONE, and a guard keeps host paths out of the tree (#61) #64's host-path guard passes over everything this PR adds.

Summary by Sourcery

Align repository and reference validation across both setup entry points while making line-ending handling consistent and safe.

Bug Fixes:

  • Treat an explicitly empty OPENREPOSHAPE_REPO as unset consistently across both setup entry points.
  • Make copy-list processing robust to CRLF line endings and add the standard repository root's LF .gitattributes policy.
  • Enforce the 255-character --shape-ref limit in the shell shim and safely reject overlong or control-character refs without echoing unsafe input.

Enhancements:

  • Align repository hygiene checks across the standard root and both templates, including shared line-ending rules.

Tests:

  • Add offline coverage for empty repository variables, overlong and control-character shape refs, root line-ending policy, and CRLF source handling.

…tes, 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]>
Copilot AI lite review requested due to automatic review settings September 6, 2026 02:44

@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 11 hours and 8 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR reconciles repository fallback semantics, line-ending normalization, and shape-reference validation between the Python and shell entry points, with focused offline, hygiene, CRLF, and boundary tests to prevent the implementations from drifting.

Sequence diagram for repository fallback in both entry points

sequenceDiagram
    participant Env as Environment
    participant Python as setup-project.py
    participant Shell as setup.sh
    participant Git as git clone
    Env->>Python: OPENREPOSHAPE_REPO
    alt unset or empty
        Python->>Git: clone DEFAULT_SHAPE_REPO
    else non-empty
        Python->>Python: checked_value
        Python->>Git: clone validated repository
    end
    Env->>Shell: OPENREPOSHAPE_REPO
    alt unset or empty
        Shell->>Git: clone DEFAULT_SHAPE_REPO
    else non-empty
        Shell->>Git: clone repository
    end
Loading

Flow diagram for shape-reference length validation

flowchart TD
    A[Read --shape-ref] --> B{Syntax rules pass?}
    B -- No --> C[die with ref validation error]
    B -- Yes --> D{Length greater than 255?}
    D -- Yes --> E[die with length error]
    D -- No --> F[git checkout validated ref]
Loading

File-Level Changes

Change Details Files
Align empty repository-variable handling across both entry points and pin the fallback behavior with offline tests.
  • Document that an unset or explicitly empty OPENREPOSHAPE_REPO selects the default repository.
  • Add Python and shell tests that verify the default URL is selected without network access and remains synchronized with each source default.
setup-project.py
tests/test_setup_project_py.py
tests/test_setup_sh.py
Ensure repository source files and update helpers remain line-ending safe on Windows checkouts.
  • Add the standard root’s .gitattributes with the LF normalization rule used by both templates.
  • Add hygiene tests for the root rule and agreement across all three locations.
  • Make copy-list entry removal accept LF and CRLF, with direct CRLF coverage.
.gitattributes
tests/test_repo_hygiene.py
tests/test_update_shape_add.py
Make the shell shim enforce the same 255-character shape-reference bound as the Python implementation.
  • Add a separate bash length check that reports the limit without echoing an overlong ref.
  • Cover 256-character refs in both Python and shim refusal tests, including exit status and diagnostic assertions.
setup.sh
tests/test_setup_project_py.py
tests/test_setup_sh.py

Assessment against linked issues

Issue Objective Addressed Explanation
#63 Make an explicitly empty OPENREPOSHAPE_REPO consistently mean unset in both setup-project.py and setup.sh, document that behavior, and add offline tests for both entry points. ✅
#63 Make the repository checkout and the unname_everywhere test helper robust to CRLF by adding the root .gitattributes rule, validating agreement with both templates, and matching either LF or CRLF line endings. ✅
#63 Make setup.sh's --shape-ref validation enforce the same maximum length as the Python REF_RE bound of 255 characters, with tests covering an overlong reference and ensuring the refusal reports the length without echoing the value. ✅

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

@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@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.

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

setup.sh still echoes the raw --shape-ref value in an error path, allowing control characters (notably newlines) to forge extra stderr lines unless the guard is reordered and a non-printable check is added.

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

Pull request overview

This PR aligns small but important edge-case behaviors across the two setup entry points and hardens cross-platform line-ending handling, primarily by adding regression tests and tightening the shim’s --shape-ref validation to match the Python rules.

Changes:

  • Add offline regression tests ensuring OPENREPOSHAPE_REPO="" falls back to the default repo in both setup.sh and setup-project.py.
  • Make tests/test_update_shape_add.py::unname_everywhere() tolerant of CRLF sources and add a direct CRLF-focused unit test.
  • Add a repository-root .gitattributes and hygiene tests asserting the root and templates agree on the LF rule; extend shim tests for a 256-character --shape-ref.
File summaries
File Description
tests/test_update_shape_add.py Switches copy-list entry stripping to CRLF-tolerant regex and adds a focused CRLF regression test.
tests/test_setup_sh.py Adds offline test for empty OPENREPOSHAPE_REPO defaulting and extends shim --shape-ref rejection coverage to 256 chars.
tests/test_setup_project_py.py Extends Python --shape-ref rejection coverage to 256 chars and adds offline test for empty OPENREPOSHAPE_REPO defaulting.
tests/test_repo_hygiene.py Adds checks that the repo root also carries the LF .gitattributes rule and that root/templates agree on the rule line.
setup.sh Adds a --shape-ref length guard (255) and updates the mirror comment to include the bound.
setup-project.py Corrects the OPENREPOSHAPE_REPO comment to reflect that empty means “unset” (truthiness fall-through).
.gitattributes Introduces a root-level LF normalization rule to avoid CRLF-caused test brittleness on Windows clones.
Review details
  • Files reviewed: 7/7 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 Outdated
Comment on lines +156 to +161
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
if [ "${#SHAPE_REF}" -gt 255 ]; then
die "--shape-ref is ${#SHAPE_REF} characters long; a branch, tag or commit this tool will pass to \`git checkout\` is at most 255 characters."
fi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Folded in as aa1d5c9: three checks in order — length, then control character, both refusing without echoing the value (like the OPENREPOSHAPE_REPO guard above), then the shape case, which by then only sees a printable ref of at most 255 characters. Tests: a newline-carrying ref's forged line never reaches stderr; the over-long case is parametrised over a legal and an illegal shape, neither echoed. Lane: xfactory-2 (xFactory-2)

Copilot AI review requested due to automatic review settings September 6, 2026 02:48

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.

🟢 Approval recommended

The functional changes are small, well-covered by new targeted tests, and the remaining findings are minor comment/naming nits rather than correctness risks.

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread setup.sh Outdated
Comment on lines +150 to +152
# 255 characters long. Only reached when $SHAPE_REF is non-empty — every
# alternative below requires at least one character to match. The LENGTH
# bound is checked separately, below, rather than folded into this `case`:
Comment thread tests/test_repo_hygiene.py Outdated
if line.strip() and not line.lstrip().startswith("#")]


def test_the_repositorys_own_root_carries_the_rule_too():
…hape-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]>
Copilot AI review requested due to automatic review settings September 6, 2026 02:57
@sonarqubecloud

sonarqubecloud Bot commented Sep 6, 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.

🟢 Approval recommended

The changes are cohesive, well-tested (including offline and platform-specific edge cases), and the remaining feedback is a minor docstring wording nit.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

tests/test_update_shape_add.py:99

  • Docstring says the line ending is “OPTIONAL (\r?\n)”, but \r?\n makes only the \r optional (LF vs CRLF), not the newline itself. Reword to avoid implying the entry line might have no trailing newline.
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@brettheap
brettheap merged commit ea03d80 into main Sep 6, 2026
6 checks passed
@brettheap
brettheap deleted the fix/copilot-cosmetics branch September 6, 2026 03:05
brettheap added a commit that referenced this pull request Sep 6, 2026
…e newline is required (#66) (#67)

Copilot's suppressed comment on PR #65, read after the merge: the docstring
said the line ending is "OPTIONAL (\r?\n)", which implies the entry line might
carry no newline at all. It cannot: \r?\n makes only the carriage return
optional, and the entry is matched as a whole line. Reworded to say so and to
keep the reason the \r is optional - a core.autocrlf=true checkout has CRLF
throughout until it is renormalised. No code changes.

Lane: xfactory-2 (xFactory-2)

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.

Three Copilot cosmetics read after #56, #58 and #60 landed: an empty $OPENREPOSHAPE_REPO, a CRLF-blind test helper, the shim's unbounded --shape-ref

2 participants