blob: 19dde2e0bf08d5b53dc5f3902b867ce875d3c05a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
"""Tests for hooks/gh-pr-create-confirm.py — --body-file reads real content."""
from conftest import load_hook
hook = load_hook("gh-pr-create-confirm.py")
# --- existing parsing still works (regression guard) -----------------------
def test_parse_title_and_inline_body():
cmd = 'gh pr create --title "feat: thing" --body "does the thing"'
fields = hook.parse_pr_create(cmd)
assert fields["title"] == "feat: thing"
assert fields["body"] == "does the thing"
def test_parse_reviewers():
cmd = 'gh pr create --title "x" --reviewer alice,bob'
fields = hook.parse_pr_create(cmd)
assert fields["reviewers"] == ["alice", "bob"]
# --- new: --body-file reads the real content -------------------------------
def test_body_file_reads_real_content(tmp_path):
f = tmp_path / "body.md"
f.write_text("## Problem\nthings broke\n\n## Fix\nfixed them\n")
fields = hook.parse_pr_create(f'gh pr create --title "x" --body-file {f}')
assert "things broke" in fields["body"]
assert "fixed them" in fields["body"]
# No longer the old placeholder.
assert not fields["body"].startswith("(body read from file")
def test_body_file_attribution_is_caught(tmp_path):
f = tmp_path / "body.md"
f.write_text("## Summary\nshipped a feature \U0001F916 generated with Claude\n")
fields = hook.parse_pr_create(f'gh pr create --title "feat: x" --body-file {f}')
scan_text = "\n".join(
filter(None, [fields.get("title"), fields.get("body")])
)
hits = hook.scan_attribution(scan_text)
assert hits # robot emoji + 'Generated with Claude' both leak
def test_body_file_clean_content_no_hits(tmp_path):
f = tmp_path / "body.md"
f.write_text("## Summary\nfixed the off-by-one in the pager\n")
fields = hook.parse_pr_create(f'gh pr create --title "fix: pager" --body-file {f}')
scan_text = "\n".join(
filter(None, [fields.get("title"), fields.get("body")])
)
assert hook.scan_attribution(scan_text) == []
# --- unreadable file keeps an informative could-not-inspect placeholder ----
def test_body_file_missing_keeps_could_not_inspect_placeholder(tmp_path):
missing = tmp_path / "nope.md"
fields = hook.parse_pr_create(f'gh pr create --title "x" --body-file {missing}')
assert "could not inspect" in fields["body"]
assert str(missing) in fields["body"]
def test_body_file_oversized_keeps_placeholder(tmp_path, monkeypatch):
f = tmp_path / "big.md"
f.write_text("x" * 5000)
monkeypatch.setattr(hook, "read_referenced_file", lambda p: None)
fields = hook.parse_pr_create(f'gh pr create --title "x" --body-file {f}')
assert "could not inspect" in fields["body"]
|