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
2 changes: 1 addition & 1 deletion .github/workflows/gh-aw-fragments/safe-output-create-pr.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ safe-inputs:
# Guard: detect merge commits
# Find the fork point with the upstream branch to scope the check
upstream_sha = ''
for ref in ['@{upstream}', 'origin/HEAD', 'origin/main']:
for ref in ['@{upstream}', 'origin/HEAD', 'origin/main', 'origin/master']:
r = run(['git', 'merge-base', 'HEAD', ref])
if r.returncode == 0 and r.stdout.strip():
upstream_sha = r.stdout.strip()
Expand Down
45 changes: 45 additions & 0 deletions tests/test_safe_input_ready_to_make_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,51 @@ def test_merge_commit_detected(self, py_code, tmp_path):
assert output["status"] == "error"
assert "Merge commit" in output["error"]

def test_origin_master_fallback(self, py_code, tmp_path):
"""origin/master should be used when upstream and origin/HEAD are unavailable."""
repo = tmp_path / "repo"
repo.mkdir()

def git(*args):
subprocess.run(
["git"] + list(args),
cwd=str(repo),
capture_output=True,
check=True,
)

# Create a repo with 'master' as default branch
git("init", "-b", "master")
git("config", "user.email", "test@test.com")
git("config", "user.name", "Test")
(repo / "file.txt").write_text("hello\n")
git("add", "file.txt")
git("commit", "-m", "init")

# Set up a bare remote and push
remote = tmp_path / "remote.git"
subprocess.run(
["git", "clone", "--bare", str(repo), str(remote)],
capture_output=True,
check=True,
)
git("remote", "add", "origin", str(remote))
git("fetch", "origin")

# Do NOT set upstream tracking and remove origin/HEAD
subprocess.run(
["git", "-C", str(repo), "remote", "set-head", "origin", "--delete"],
capture_output=True,
)

# Make a new commit so there's a diff
(repo / "new.txt").write_text("new\n")
git("add", "new.txt")
git("commit", "-m", "add new")

output = run_py_in_repo(py_code, str(repo))
assert output["status"] == "ok"
Copy link
Contributor

Choose a reason for hiding this comment

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

[LOW] Test does not verify the origin/master path is actually exercised

This assertion only checks for status == "ok", so the test can pass even if origin/HEAD remains available and the new fallback branch (origin/master) is never used. Because the remote set-head --delete call above ignores its return code, a failure there would make this test a false positive.

Please add an assertion that origin/HEAD is unavailable (or that merge-base HEAD origin/HEAD fails) and that merge-base HEAD origin/master succeeds, so this test proves the intended fallback behavior.


def test_no_upstream_fails_closed(self, py_code, tmp_path):
"""Without an upstream ref, the create guard should fail closed."""
repo = make_git_repo(tmp_path, with_upstream=False)
Expand Down
Loading