Skip to content

Commit 6d9d182

Browse files
test: add integration tests for CLI --title flag wiring and multiline breaking change footers
1 parent 2cda9ef commit 6d9d182

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

‎tests/test_changelog.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ def test_parse_commit_message_body_breaking() -> None:
9090
assert entry.is_breaking is True
9191

9292

93+
def test_parse_commit_message_multiline_breaking_footer() -> None:
94+
multiline_body = (
95+
"Migrate internal auth from HMAC tokens to OAuth2 bearer tokens.\n\n"
96+
"This improves security and aligns with current RFC specifications.\n\n"
97+
"Reviewed-on: https://github.com/example/repo/pull/42\n"
98+
"BREAKING CHANGE: HMAC tokens are no longer accepted on API v2 endpoints."
99+
)
100+
entry = parse_commit_message(
101+
commit_hash="def789",
102+
subject="feat(auth): transition to oauth2 tokens",
103+
body=multiline_body,
104+
)
105+
assert entry.commit_type == "feat"
106+
assert entry.scope == "auth"
107+
assert entry.description == "transition to oauth2 tokens"
108+
assert entry.is_breaking is True
109+
110+
111+
def test_parse_commit_message_multiline_breaking_hyphen_footer() -> None:
112+
multiline_body = (
113+
"Remove deprecated configuration parameters.\n\n"
114+
"BREAKING-CHANGE: The 'legacy_mode' setting has been completely removed."
115+
)
116+
entry = parse_commit_message(
117+
commit_hash="abc999",
118+
subject="refactor(config): prune legacy config options",
119+
body=multiline_body,
120+
)
121+
assert entry.commit_type == "refactor"
122+
assert entry.is_breaking is True
123+
124+
93125
def test_parse_commit_message_non_conventional() -> None:
94126
entry = parse_commit_message(
95127
commit_hash="ghi789",
@@ -165,6 +197,35 @@ def test_extract_commits_between_real_git(git_repo: Path) -> None:
165197
assert "feat(core): add module a" in subjects
166198

167199

200+
def test_extract_commits_between_multiline_breaking_footer(git_repo: Path) -> None:
201+
subprocess.run(["git", "tag", "v2.0.0"], cwd=git_repo, check=True)
202+
file_path = git_repo / "breaking.py"
203+
file_path.write_text("API_V2 = True\n")
204+
subprocess.run(["git", "add", "breaking.py"], cwd=git_repo, check=True)
205+
subprocess.run(
206+
[
207+
"git",
208+
"commit",
209+
"-m",
210+
"feat(api): overhaul authorization",
211+
"-m",
212+
"Replaces API keys with scoped OAuth tokens.",
213+
"-m",
214+
"BREAKING CHANGE: Plain API keys are no longer supported.",
215+
],
216+
cwd=git_repo,
217+
check=True,
218+
)
219+
subprocess.run(["git", "tag", "v2.1.0"], cwd=git_repo, check=True)
220+
221+
commits = extract_commits_between("v2.0.0", "v2.1.0", repo=git_repo)
222+
assert len(commits) == 1
223+
assert commits[0].commit_type == "feat"
224+
assert commits[0].scope == "api"
225+
assert commits[0].is_breaking is True
226+
assert "Plain API keys are no longer supported" in commits[0].body
227+
228+
168229
def test_generate_changelog_empty_range(git_repo: Path) -> None:
169230
res = generate_changelog(from_ref="HEAD", to_ref="HEAD", repo_dir=git_repo)
170231
assert res.is_fallback is False

‎tests/test_cli.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,55 @@ def test_pr_summary_cli_gh_error(git_repo: Path) -> None:
491491
assert "GitHub CLI ('gh') not found" in res.output
492492

493493

494+
def test_pr_summary_cli_gh_success_with_title(git_repo: Path) -> None:
495+
from unittest.mock import patch
496+
497+
from conftest import commit_file
498+
499+
subprocess.run(["git", "checkout", "-b", "feature-gh-success"], cwd=git_repo, check=True)
500+
commit_file(git_repo, "gh_success.py", "x = 2\n", "feat: gh success")
501+
502+
real_run = subprocess.run
503+
gh_calls: list[list[str]] = []
504+
505+
def fake_run(
506+
cmd: list[str], *args: object, **kwargs: object
507+
) -> subprocess.CompletedProcess[bytes]:
508+
if cmd and cmd[0] == "gh":
509+
gh_calls.append(cmd)
510+
return subprocess.CompletedProcess(args=cmd, returncode=0, stdout=b"", stderr=b"")
511+
return real_run(cmd, *args, **kwargs) # type: ignore[no-any-return,call-overload]
512+
513+
with (
514+
patch("shutil.which", return_value="/usr/bin/gh"),
515+
patch("subprocess.run", side_effect=fake_run),
516+
):
517+
# Long form --title
518+
res = runner.invoke(
519+
cli.app,
520+
["pr-summary", "--no-copy", "--create-pr", "--title", "CLI PR Title", "--base", "main"],
521+
)
522+
assert res.exit_code == 0
523+
assert len(gh_calls) == 1
524+
cmd_args = gh_calls[0]
525+
assert "--title" in cmd_args
526+
title_idx = cmd_args.index("--title")
527+
assert cmd_args[title_idx + 1] == "CLI PR Title"
528+
529+
# Short form -t
530+
gh_calls.clear()
531+
res = runner.invoke(
532+
cli.app,
533+
["pr-summary", "--no-copy", "--create-pr", "-t", "Short Title", "--base", "main"],
534+
)
535+
assert res.exit_code == 0
536+
assert len(gh_calls) == 1
537+
cmd_args = gh_calls[0]
538+
assert "--title" in cmd_args
539+
title_idx = cmd_args.index("--title")
540+
assert cmd_args[title_idx + 1] == "Short Title"
541+
542+
494543
def test_changelog_cli_empty_range(git_repo: Path) -> None:
495544
res = runner.invoke(cli.app, ["changelog", "--from", "HEAD", "--to", "HEAD"])
496545
assert res.exit_code == 0

0 commit comments

Comments
 (0)