Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ jobs:
- name: Test Windows AW_VERSION export for Rust PE resources
run: python3 -m pytest scripts/tests/test_makefile_aw_version.py -q

- name: Test submodule bump prompt
run: python3 -m pytest scripts/tests/test_bump_submodules.py -q

build-qt:
name: Build Qt artifacts (${{ matrix.os }}${{ (matrix.research || (github.event_name == 'workflow_dispatch' && inputs.edition == 'research') || endsWith(github.ref_name, '-research')) && ', research' || '' }})${{ needs.nightly-submodules.outputs.latest == 'true' && ' [latest submodules]' || '' }}
needs: nightly-submodules
Expand Down
33 changes: 28 additions & 5 deletions scripts/bump-submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ confirm() {
if [ "$DRY" = 1 ]; then echo " [dry-run] would: $*"; return 1; fi
if [ "$YES" = 1 ]; then return 0; fi
printf '%s [Enter=yes / n=skip / q=quit] ' "$*"
read -r answer
# End of input is not an answer: an empty one means "yes", so a closed or
# non-terminal stdin would otherwise accept every commit and push.
if ! read -r answer; then
echo; echo "no answer on stdin; aborting (pass --yes to run unattended)" >&2
exit 1
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
fi
case "$answer" in
q|Q) echo "aborted"; exit 1 ;;
n|N) return 1 ;;
Expand Down Expand Up @@ -446,8 +451,23 @@ elif [ "$DRY" = 1 ]; then
LOCK_ALIGNED=1
DRY_BUMPED="$DRY_BUMPED aw-tauri" # the lock commit moves the aw-tauri pointer too
else
# One --precise moves every package that shares the git source.
(cd aw-tauri/src-tauri && cargo update -q -p aw-server --precise "$SERVER_SHA")
# This pair was clean at preflight. Undo only our uncommitted relock on
# abort (including EOF/q in confirm), so a retry is not blocked as dirty.
restore_relock() {
if [ "$(git hash-object "$LOCK" 2>/dev/null)" = "$relock_worktree" ] &&
[ "$(git -C aw-tauri rev-parse :src-tauri/Cargo.lock 2>/dev/null)" = "$relock_index" ]; then
git -C aw-tauri checkout -q HEAD -- src-tauri/Cargo.lock
else
warn "Cargo.lock changed after relocking; preserving working and staged edits"
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
fi
}
# Capture even a failed cargo update so its partial changes can be undone.
relock_status=0
(cd aw-tauri/src-tauri && cargo update -q -p aw-server --precise "$SERVER_SHA") || relock_status=$?
relock_worktree=$(git hash-object "$LOCK")
relock_index=$(git -C aw-tauri rev-parse :src-tauri/Cargo.lock)
trap restore_relock EXIT
[ "$relock_status" = 0 ] || exit "$relock_status"
stale=$(grep "aw-server-rust.git?branch=master#" "$LOCK" | grep -vc "#$SERVER_SHA" || true)
if [ "$stale" != 0 ]; then
echo "some aw-server-rust crates did not relock to ${SERVER_SHA:0:7}:" >&2
Expand All @@ -457,16 +477,19 @@ else
git -C aw-tauri diff --stat -- src-tauri/Cargo.lock | sed 's/^/ /'
if confirm "commit in aw-tauri: \"build(deps): updated cargo locks\" (aw-server-rust -> ${SERVER_SHA:0:7})?"; then
run aw-tauri add -- src-tauri/Cargo.lock
relock_index=$relock_worktree
run aw-tauri commit -q -m "build(deps): updated cargo locks

aw-server-rust -> $SERVER_SHA"
trap - EXIT
push_master aw-tauri
LOCK_ALIGNED=1
else
# A dirty, uncommitted lock would pass the checker here and vanish in
# CI. Restore it so the tree matches what will actually be built.
git -C aw-tauri checkout -q -- src-tauri/Cargo.lock
warn "aw-tauri lock commit declined; lock restored to the committed (old) revision"
restore_relock
trap - EXIT
warn "aw-tauri lock commit declined"
fi
fi

Expand Down
176 changes: 176 additions & 0 deletions scripts/tests/test_bump_submodules.py
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")
Comment thread
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"
)
Loading