Skip to content

fix(git): repository-local signing key message and TTY guard for the merge tool - #2173

Merged
josecelano merged 10 commits into
torrust:developfrom
da2ce7:2022-fix-merge-script-signing-message-and-tty
Sep 8, 2026
Merged

josecelano merged 10 commits into
torrust:developfrom
da2ce7:2022-fix-merge-script-signing-message-and-tty

Conversation

@da2ce7

@da2ce7 da2ce7 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The repository-local maintainer merge workflow vendored in #2022 has three rough edges that this PR addresses without touching the vendored github-merge.py (its provenance hash e390eb01…baad2 is unchanged):

  • The wrapper's preflight message and the merge skill told maintainers to run git config --global user.signingkey. Signing configuration for this repository is repository-local, so both now direct a repository-local git config user.signingkey and say the global scope stays unset. The check itself already used git config --get, which reads local scope, so only the guidance and the two test assertions that quoted it changed.
  • The vendored tool reads every prompt with a plain line read and its sign and push loops only accept s, x, or push, so at end of input (stdin not a terminal, closed, or redirected) it loops forever reprinting its prompt. The wrapper now refuses to start the interactive tool unless stdin is a terminal; --dry-run and every preflight diagnostic keep working non-interactively, because the guard runs last, immediately before the exec.
  • README-github-merge.md gains a "Known Upstream Issues" section recording, with verified line numbers, the two upstream behaviours above plus a third: a GitHub API failure while fetching PR comments raises a TypeError instead of the intended clean exit.

Two things surfaced while adding tests. The wrapper's own deterministic suite (contrib/dev-tools/git/tests/test-merge-pull-request.sh) was failing at the current develop tip: the missing-tool fixture deleted the vendored file without committing the deletion, so the clean-tree check fired before the assertion the fixture exists to make. That fixture now commits the removal (test(git): keep the missing-tool fixture's working tree clean). Nothing in CI runs this suite, only the skill mentions it, which is why the failure went unnoticed; wiring it into a CI job would be a reasonable follow-up. Secondly, exercising the delegation path now needs a pseudo-terminal, supplied by script(1) from util-linux; the suite fails fast with a named reason where script is absent (BSD script lacks --command).

Files touched

  • contrib/dev-tools/git/merge-pull-request.sh — repository-local signing-key message; require_interactive_stdin guard before the exec.
  • contrib/dev-tools/git/tests/test-merge-pull-request.sh — updated assertions; pseudo-terminal helper; two new cases (non-TTY refusal without invoking the tool, --dry-run still passing without a terminal); fixture fix.
  • .github/skills/dev/git-workflow/merge-pull-request/SKILL.md — repository-local signing prerequisite; interactive-terminal guardrail.
  • contrib/dev-tools/git/README-github-merge.md — "Known Upstream Issues"; coverage sentence lists the terminal refusal.

Validation

  • bash contrib/dev-tools/git/tests/test-merge-pull-request.sh: all 12 cases pass (10 pre-existing, 2 new) in 1.1 s; the non-TTY case was checked for non-vacuity by running the same scenario against the unmodified wrapper, which invoked the stub instead of refusing.
  • shellcheck on both shell files: clean.
  • linter all (torrust-linting 0.2.0): all linters passed (markdownlint, lychee, yamllint, taplo, cspell, clippy, rustfmt, shellcheck).
  • sha256sum contrib/dev-tools/git/github-merge.py matches the provenance hash recorded in the README.

Related to #2022 (already closed; this PR refines the workflow it introduced rather than resolving it).

Documentation follow-ups in this PR

Because the merge tool copies the PR title verbatim into the merge commit subject, two documentation commits ride along: AGENTS.md gains a "Pull request titles" note in the Git Workflow section (one Conventional Commits line, no PR number, [#<issue>] only for the issue the PR implements or closes, related or closed issues in the body), and the open-pull-request skill's second title example is aligned to the same bracketed form (docs(agents): [#1697] … instead of a trailing (#1697)).

Signing configuration in this estate is per repository: the global Git
configuration carries no signing key, so the previous message sent a
maintainer to a scope that is deliberately left unset and the preflight
would keep failing after they followed it. The check itself is unchanged
because 'git config --get' already reads the local scope.
The fixture commits the vendored tool and then deleted it from the
working tree, so the wrapper reported an unclean working tree and never
reached the vendored-tool check the case exists to assert. Committing the
removal restores the intended path; the assertion has never held since
the fixture was introduced.
The vendored tool reads its prompts with a plain line read, and its sign
and push loops only leave on 's', 'x', or 'push'. With stdin closed,
redirected, or otherwise not a terminal, every read returns end of input
immediately and those loops reprint their prompt forever, so an
unattended run hangs instead of failing. The wrapper now refuses to start
it in that case with a message that names the terminal requirement.

The guard sits last, immediately before the exec, so the argument,
repository, branch, signing-key, vendored-tool, and Python
preconditions - and the whole --dry-run path, which never reaches the
vendored tool - stay usable from a script. The delegation test runs the
wrapper under a pseudo terminal so the contract stays testable from a
non-interactive runner.
The prerequisite step configured the signing key globally, which the
wrapper's preflight now rejects: signing configuration for this
repository is local, and the global scope stays unset. The new guardrail
records why the merge tool needs a terminal - its prompts never end at
end of input, so an unattended run hangs - and points at --dry-run for
non-interactive validation.
Three behaviors of the vendor copy are worth knowing before a merge
attempt: a failed comment fetch raises rather than exiting with its own
diagnostic, the prompts never end at end of input, and the missing-key
message names the global configuration scope. Recording them keeps the
copy byte-identical and its provenance hash unchanged, which the
local-change policy requires, while the coverage boundary now also names
the terminal refusal the tests exercise.
@da2ce7
da2ce7 requested a review from a team as a code owner September 8, 2026 14:27
Copilot AI lite review requested due to automatic review settings September 8, 2026 14:27
@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.68%. Comparing base (2e1f2b9) to head (94b1024).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2173      +/-   ##
===========================================
- Coverage    84.69%   84.68%   -0.02%     
===========================================
  Files          351      351              
  Lines        29657    29657              
  Branches     29657    29657              
===========================================
- Hits         25119    25116       -3     
- Misses        4184     4189       +5     
+ Partials       354      352       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@da2ce7 da2ce7 changed the title fix(git): [#2022] repository-local signing key message and TTY guard for the merge tool fix(git): repository-local signing key message and TTY guard for the merge tool Sep 8, 2026

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 new test dependency check for script(1) does not verify util-linux flag support (e.g. --command), so the suite can fail non-obviously on systems with BSD script.

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

Pull request overview

This PR refines the repository-local maintainer merge workflow wrapper and its documentation/tests, addressing known rough edges in the vendored github-merge.py without modifying the vendored script itself. It updates signing-key guidance to match repository-local configuration, adds a TTY guard to prevent an infinite prompt loop when stdin is non-interactive, and documents upstream behaviors with verified line references.

Changes:

  • Update signing-key guidance (wrapper + skill + tests) to recommend repository-local git config user.signingkey … rather than --global.
  • Add an interactive-stdin (TTY) guard to the wrapper to prevent the vendored tool from looping forever on EOF; extend the test suite with a pseudo-terminal helper plus new cases covering the guard and --dry-run.
  • Add a “Known Upstream Issues” section documenting upstream behaviors with line-number references and update the stated deterministic test boundary.
File summaries
File Description
contrib/dev-tools/git/merge-pull-request.sh Adjusts the signing-key guidance and adds a stdin TTY precondition before invoking the vendored interactive tool.
contrib/dev-tools/git/tests/test-merge-pull-request.sh Updates assertions, adds pseudo-terminal execution support, adds new test cases, and fixes the missing-tool fixture to keep the tree clean.
.github/skills/dev/git-workflow/merge-pull-request/SKILL.md Updates maintainer/agent workflow guidance to match repository-local signing configuration and the new interactive-terminal guardrail.
contrib/dev-tools/git/README-github-merge.md Documents known upstream issues with verified line references and updates the deterministic coverage boundary description.
Review details
  • Files reviewed: 4/4 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.

@josecelano josecelano self-assigned this Sep 8, 2026
@josecelano

Copy link
Copy Markdown
Member

ACK 94b1024

@josecelano
josecelano merged commit c05045b into torrust:develop Sep 8, 2026
18 checks passed
@da2ce7
da2ce7 deleted the 2022-fix-merge-script-signing-message-and-tty branch September 10, 2026 09:25

This branch was previously deployed

1 inactive deployment
coverage — 94b10240 Deployed Sep 8, 2026 by da2ce7 via Generate Coverage Report #1952
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.

3 participants