fix: normalize generated whitespace
This commit is contained in:
@@ -9,6 +9,57 @@ from lai_automation.git import GitWorkspace
|
||||
from lai_automation.models import ChangeSummary
|
||||
|
||||
|
||||
def test_normalize_changed_whitespace_cleans_new_text_file(
|
||||
settings,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
workspace = GitWorkspace(replace(settings, workspace_root=tmp_path), 1)
|
||||
workspace.path.mkdir(parents=True)
|
||||
changed = workspace.path / "new.php"
|
||||
changed.write_bytes(b"<?php \r\nreturn true;\t")
|
||||
workspace._git = Mock(
|
||||
side_effect=[
|
||||
subprocess.CompletedProcess([], 0, "", ""),
|
||||
subprocess.CompletedProcess([], 0, "new.php\n", ""),
|
||||
]
|
||||
)
|
||||
|
||||
normalized = workspace.normalize_changed_whitespace(
|
||||
ChangeSummary(("new.php",), 2, 0)
|
||||
)
|
||||
|
||||
assert normalized == ("new.php",)
|
||||
assert changed.read_bytes() == b"<?php\r\nreturn true;"
|
||||
|
||||
|
||||
def test_normalize_changed_whitespace_only_cleans_reported_tracked_lines(
|
||||
settings,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
workspace = GitWorkspace(replace(settings, workspace_root=tmp_path), 1)
|
||||
workspace.path.mkdir(parents=True)
|
||||
changed = workspace.path / "tracked.php"
|
||||
changed.write_bytes(b"<?php \nlegacy whitespace \n")
|
||||
workspace._git = Mock(
|
||||
side_effect=[
|
||||
subprocess.CalledProcessError(
|
||||
2,
|
||||
["git", "diff", "--check"],
|
||||
output="tracked.php:1: trailing whitespace.\n",
|
||||
stderr="",
|
||||
),
|
||||
subprocess.CompletedProcess([], 0, "", ""),
|
||||
]
|
||||
)
|
||||
|
||||
normalized = workspace.normalize_changed_whitespace(
|
||||
ChangeSummary(("tracked.php",), 1, 1)
|
||||
)
|
||||
|
||||
assert normalized == ("tracked.php",)
|
||||
assert changed.read_bytes() == b"<?php\nlegacy whitespace \n"
|
||||
|
||||
|
||||
def test_check_diff_accepts_clean_changed_file(settings, tmp_path: Path) -> None:
|
||||
workspace = GitWorkspace(replace(settings, workspace_root=tmp_path), 1)
|
||||
workspace.path.mkdir(parents=True)
|
||||
|
||||
@@ -68,6 +68,9 @@ def test_successful_issue_creates_pr_and_ready_label(
|
||||
workspace.has_symlink.return_value = False
|
||||
workspace.has_path.return_value = False
|
||||
workspace.commit.return_value = "abc123"
|
||||
workspace.normalize_changed_whitespace.return_value = (
|
||||
"tests/Feature/FixTest.php",
|
||||
)
|
||||
|
||||
Worker(settings, gitea, agent).process(issue, labels())
|
||||
|
||||
@@ -85,6 +88,8 @@ def test_successful_issue_creates_pr_and_ready_label(
|
||||
]
|
||||
)
|
||||
workspace.push.assert_called_once()
|
||||
workspace.normalize_changed_whitespace.assert_called_once()
|
||||
assert workspace.summary.call_count == 3
|
||||
assert workspace.check_diff.call_count == 2
|
||||
assert gitea.create_pull_request.call_args.args[0] == "ai/issue-7"
|
||||
assert "Fixes #7" in gitea.create_pull_request.call_args.args[2]
|
||||
@@ -115,6 +120,7 @@ def test_failed_tests_prevent_push_and_mark_issue_failed(
|
||||
workspace.summary.return_value = ChangeSummary(("app/Fix.php",), 2, 0)
|
||||
workspace.has_symlink.return_value = False
|
||||
workspace.has_path.return_value = False
|
||||
workspace.normalize_changed_whitespace.return_value = ()
|
||||
workspace.run_trusted.side_effect = [
|
||||
Mock(),
|
||||
RuntimeError("tests failed with token=hidden"),
|
||||
|
||||
Reference in New Issue
Block a user