Repository navigation
fix(bump-submodules): end of input aborts instead of accepting every prompt #1572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TimeToBuildBob
wants to merge
5
commits into
ActivityWatch:master
Choose a base branch
from
TimeToBuildBob:fix/bump-submodules-eof-is-not-yes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
−5
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b35a6ba
fix(bump-submodules): end of input aborts instead of accepting every …
TimeToBuildBob 8c7dea6
fix(bump-submodules): restore uncommitted lock on prompt abort
TimeToBuildBob 920947a
fix(bump-submodules): preserve lock edits made during prompts
TimeToBuildBob 8a3c155
test(bump-submodules): isolate fixture commits from signing
TimeToBuildBob 3b5337f
fix(bump-submodules): clean up a failed lockfile commit
TimeToBuildBob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| """Tests for the confirm() prompt in scripts/bump-submodules.sh. | ||
|
|
||
| Without --yes, every commit/push step is gated on confirm(). An empty answer | ||
| means "yes" (Enter accepts), so end of input must not be read as an empty | ||
| answer: with stdin closed or not a terminal, the run would otherwise commit | ||
| and push to master with nobody confirming. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| SCRIPT = Path(__file__).parents[1] / "bump-submodules.sh" | ||
|
|
||
|
|
||
| def _confirm_source() -> str: | ||
| text = SCRIPT.read_text() | ||
| match = re.search(r"^confirm\(\) \{\n.*?^\}\n", text, re.M | re.S) | ||
| assert match, "confirm() not found in bump-submodules.sh" | ||
| return match.group(0) | ||
|
|
||
|
|
||
| def run_confirm(stdin: str | None) -> subprocess.CompletedProcess[str]: | ||
| script = ( | ||
| "set -euo pipefail\n" | ||
| + _confirm_source() | ||
| + "DRY=0 YES=0\n" | ||
| + 'if confirm "push?"; then echo ACCEPTED; else echo SKIPPED; fi\n' | ||
| ) | ||
| return subprocess.run( | ||
| ["bash", "-c", script], | ||
| input=stdin, | ||
| stdin=subprocess.DEVNULL if stdin is None else None, | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=10, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("answer", "expected"), | ||
| [("\n", "ACCEPTED"), ("y\n", "ACCEPTED"), ("n\n", "SKIPPED")], | ||
| ) | ||
| def test_interactive_answers(answer: str, expected: str) -> None: | ||
| result = run_confirm(answer) | ||
| assert result.returncode == 0, result.stderr | ||
| assert result.stdout.strip().endswith(expected) | ||
|
|
||
|
|
||
| def test_quit_aborts() -> None: | ||
| result = run_confirm("q\n") | ||
| assert result.returncode != 0 | ||
| assert "ACCEPTED" not in result.stdout | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("stdin", [None, ""], ids=["devnull", "closed-pipe"]) | ||
| def test_end_of_input_is_not_yes(stdin: str | None) -> None: | ||
| result = run_confirm(stdin) | ||
| assert "ACCEPTED" not in result.stdout | ||
| assert result.returncode != 0 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("answer", "committed", "exit_code", "edit"), | ||
| [ | ||
| ("", False, 1, ""), | ||
| ("q\n", False, 1, ""), | ||
| ("n\n", False, 0, ""), | ||
| ("\n", True, 1, ""), | ||
| ("\n\n", True, 0, ""), | ||
| ("\n", False, 1, "commit-failure"), | ||
| ("q\n", False, 1, "worktree"), | ||
| ("q\n", False, 1, "index"), | ||
| ("n\n", False, 0, "worktree"), | ||
| ("", False, 1, "index"), | ||
| ], | ||
| ids=[ | ||
| "eof", | ||
| "quit", | ||
| "decline", | ||
| "push-eof", | ||
| "accept", | ||
| "commit-failure", | ||
| "quit-edited", | ||
| "quit-staged", | ||
| "decline-edited", | ||
| "eof-staged", | ||
| ], | ||
| ) | ||
| def test_relock_prompt_leaves_clean_tree( | ||
| tmp_path: Path, answer: str, committed: bool, exit_code: int, edit: str | ||
| ) -> None: | ||
| """Exercise the real relock branch, including confirm's process-level exit.""" | ||
| tauri = tmp_path / "aw-tauri" | ||
| lock = tauri / "src-tauri" / "Cargo.lock" | ||
| lock.parent.mkdir(parents=True) | ||
| lock.write_text("old lock\n") | ||
|
|
||
| def git(*args: str) -> str: | ||
| return subprocess.check_output( | ||
| ["git", "-C", str(tauri), *args], text=True | ||
| ).strip() | ||
|
|
||
| git("init", "-q") | ||
| git("config", "user.name", "Test") | ||
| git("config", "user.email", "test@example.invalid") | ||
| git("config", "core.hooksPath", "/dev/null") | ||
| git("config", "commit.gpgsign", "false") | ||
| git("add", ".") | ||
| git("commit", "-qm", "initial lock") | ||
|
TimeToBuildBob marked this conversation as resolved.
Resolved
|
||
| before = git("rev-parse", "HEAD") | ||
| text = SCRIPT.read_text() | ||
| helpers = text.split( | ||
| "# ---------------------------------------------------------------- helpers\n" | ||
| )[1] | ||
| helpers = helpers.split( | ||
| "# ---------------------------------------------------------------- preflight" | ||
| )[0] | ||
| relock = text.split( | ||
| "# ---------------------------------------------------------------- 3. Tauri Cargo pin" | ||
| )[1] | ||
| relock = relock.split("\nelse\n", 1)[1] | ||
| relock = relock.split( | ||
| "# ---------------------------------------------------------------- 4. bundle" | ||
| )[0] | ||
| relock = relock.rsplit("\nfi", 1)[0] | ||
| edit_prompt = "" | ||
| if edit in ("worktree", "index"): | ||
| edit_prompt = ( | ||
| _confirm_source().replace("confirm()", "prompt_confirm()") | ||
| + "confirm() { echo 'user edit' > \"$LOCK\"; " | ||
| + ("git -C aw-tauri add src-tauri/Cargo.lock; " if edit == "index" else "") | ||
| + 'prompt_confirm "$@"; }\n' | ||
| ) | ||
| if edit == "commit-failure": | ||
| edit_prompt = ( | ||
| 'git() { if [ "${3:-}" = commit ]; then return 1; fi; command git "$@"; }\n' | ||
| ) | ||
| result = subprocess.run( | ||
| [ | ||
| "bash", | ||
| "-c", | ||
| "set -euo pipefail\n" | ||
| + helpers | ||
| + "DRY=0 YES=0 PUSH=1 SERVER_SHA=new\n" | ||
| + "LOCK=aw-tauri/src-tauri/Cargo.lock\n" | ||
| + "cargo() { echo 'aw-server-rust.git?branch=master#new' > Cargo.lock; }\n" | ||
| # Do not push; the relock branch must clear cleanup before this prompt. | ||
| + 'push_master() { confirm "push?"; }\n' | ||
| + edit_prompt | ||
| + relock, | ||
| ], | ||
| cwd=tmp_path, | ||
| input=answer, | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=10, | ||
| ) | ||
| assert result.returncode == exit_code, result.stderr | ||
| if edit in ("worktree", "index"): | ||
| assert lock.read_text() == "user edit\n" | ||
| assert "changed" in result.stderr | ||
| assert git("show", ":src-tauri/Cargo.lock") == ( | ||
| "user edit" if edit == "index" else "old lock" | ||
| ) | ||
| assert git("rev-parse", "HEAD") == before | ||
| return | ||
| assert git("status", "--porcelain") == "" | ||
| assert (git("rev-parse", "HEAD") != before) is committed | ||
| assert lock.read_text() == ( | ||
| "aw-server-rust.git?branch=master#new\n" if committed else "old lock\n" | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.