Skip to content

Reuse scaffold identity helpers in pin and gitignore checks - #153

Merged
Deicyde merged 3 commits into
mainfrom
golf/scaffold-pin-helpers
Oct 6, 2026
Merged

Deicyde merged 3 commits into
mainfrom
golf/scaffold-pin-helpers

Conversation

@Deicyde

@Deicyde Deicyde commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #96. scaffold.py defined _cross_interface_identity twice, with the second definition shadowing the first. Its _file_identity also duplicated the existing _node_identity/_is_link helpers. This change drops the duplicates.

Also in this change:

  • The two clean-checkout git diff commands in plugin_pin are built from shared parts. The argv is the same as before.
  • hashlib constructors are called directly; requires-python is 3.10.
  • The hash length comes from _committed_scaffold_entries.

A second commit factors the scaffold copy, commit, and _here/_TEMPLATES patching that the plugin_pin tests repeated into _git_output, _autoform_checkout and _run_from. Each test keeps its own assertions.

A third commit fixes a regression from the first. _git_blob_id called hashlib.new directly, so an interpreter without SHA-1 or SHA-256 raised ValueError out of plugin_pin instead of leaving the pin unset, as main does. It now returns None in that case, and test_plugin_pin_is_empty_when_git_digests_are_unavailable pins it. Without the fix, that test fails.

Two flags in _git_checkout_clean are not pinned by any test on this branch: the --cached half of the check, and --no-replace-objects. Dropping either one still leaves all 22 plugin-pin tests in tests/test_scaffold.py passing. That includes test_plugin_pin_ignores_git_replacement_objects, which the separate blob comparison in _committed_scaffold_entries still satisfies.

The argv matches main's, and the test refactor keeps every assertion, so main probably has the same gap. I did not rerun the mutation on main. This PR does not close the gap.

Tests: ruff check is clean. On dd90820: tests/test_scaffold.py 100 passed. The digest test fails without the third commit.

Build the two clean-checkout git diff commands from shared parts, call
hashlib constructors directly (requires-python is 3.10), rely on
_committed_scaffold_entries for the single hash length, and drop the
shadowed _cross_interface_identity plus _file_identity in favour of the
existing _node_identity and _is_link helpers.
Factor the repeated scaffold-copy, commit, and _here/_TEMPLATES patching
into _git_output, _autoform_checkout, and _run_from. Each test keeps its
own assertions.
Calling hashlib.sha1/sha256 directly raised when the interpreter could
not provide the digest, so plugin_pin failed instead of omitting the
workflows as main does. Go back to hashlib.new and treat ValueError as
an unidentified blob; only the TypeError fallback for interpreters
without usedforsecurity was dead under requires-python 3.10.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 6, 2026
@Deicyde Deicyde added the review: ready Review complete with no known merge blockers label Oct 6, 2026
@Deicyde
Deicyde marked this pull request as ready for review October 6, 2026 04:37
@Deicyde

Deicyde commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Exact-head review at a38dbb49: helper reuse preserves Git argv, canonical executable-bit handling, descriptor/named identity checks, link refusal, and fail-closed digest behavior. _committed_scaffold_entries already guarantees one object-ID length and unique paths, so the simplified comparison assumptions hold. Test helper extraction preserves assertions; all nine CI checks and the 100-test scaffold suite pass. No blocker remains. Non-blocking follow-up: directly pin the --cached and --no-replace-objects argv invariants, which this PR correctly preserves but existing behavior tests do not uniquely exercise.

@Deicyde
Deicyde merged commit f8465bc into main Oct 6, 2026
9 checks passed
@Deicyde
Deicyde deleted the golf/scaffold-pin-helpers branch October 6, 2026 05:13
@Deicyde

Deicyde commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Post-merge notes on a38dbb4, which merged as f8465bc. autoform_cli/scaffold.py and tests/test_scaffold.py haven't changed on main since, so line numbers are at main 71b251c.

Verdict: nothing to fix. This agrees with the review above. Two optional golf items on private helpers:

  1. scaffold.py:399 re-implements the executable-bit rule (0 lines).
    • It computes "100755" if mode & 0o111 else "100644" inline.
    • _canonical_template_mode (:370-373) owns the same rule for the template surface (:380), the running-vs-checkout comparison (:472-473) and generated files (:791).
    • The output is identical today, but if the helper changes, this comparison won't follow it.
    • Fix: else {0o644: "100644", 0o755: "100755"}[_canonical_template_mode(mode)],. That is main's form before this PR (dd90820:442), indexed instead of .get.
  2. _git_blob_id can't take its unknown-length branch (2 lines; it predates this PR).
    • Its only caller (:394-400) passes the length of an object ID that _committed_scaffold_entries has already matched against [0-9a-f]{40}|[0-9a-f]{64} (:339).
    • Fix: replace :358-360 with algorithm = {40: "sha1", 64: "sha256"}[length].
    • Keep the hashlib.new(...) / except ValueError fallback, which test_plugin_pin_is_empty_when_git_digests_are_unavailable (tests/test_scaffold.py:953) pins.

Not run locally.

Posted by PR swarm: PR Swarm Lead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. review: ready Review complete with no known merge blockers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant