ci(release): enforce changed-scope Ruff gate
Publish verified PortfolioHub image / verify (push) Canceled after 0s
Publish verified PortfolioHub image / publish (push) Canceled after 0s

This commit is contained in:
2026-09-13 15:41:35 +09:00
parent 1010d257ad
commit 4520fbbfbd
5 changed files with 147 additions and 89 deletions
+28 -19
View File
@@ -1,24 +1,33 @@
from scripts.ruff_ratchet import BASELINE_BY_RULE, BASELINE_TOTAL, baseline_regressions
from collections import Counter
from scripts.ruff_ratchet import normalized_findings
def _diagnostics(**counts: int) -> list[dict[str, str]]:
return [{"code": code} for code, count in counts.items() for _ in range(count)]
def test_normalized_findings_ignore_line_number_changes(tmp_path):
source = tmp_path / "sample.py"
source.write_text("\nvalue = missing\n", encoding="utf-8")
diagnostics = [
{
"filename": str(source),
"code": "F821",
"message": "Undefined name `missing`",
"location": {"row": 2, "column": 9},
}
]
assert normalized_findings(diagnostics, tmp_path) == Counter(
{("sample.py", "F821", "Undefined name `missing`", "value = missing"): 1}
)
def test_exact_baseline_passes() -> None:
diagnostics = _diagnostics(**BASELINE_BY_RULE)
assert len(diagnostics) == BASELINE_TOTAL
assert baseline_regressions(diagnostics) == []
def test_normalized_findings_preserve_duplicate_count(tmp_path):
source = tmp_path / "sample.py"
source.write_text("missing\n", encoding="utf-8")
diagnostic = {
"filename": str(source),
"code": "F821",
"message": "Undefined name `missing`",
"location": {"row": 1, "column": 1},
}
def test_new_rule_fails_from_zero_baseline() -> None:
assert baseline_regressions([{"code": "E501"}]) == ["E501: 1 > 0"]
def test_existing_rule_increase_fails() -> None:
diagnostics = _diagnostics(I001=BASELINE_BY_RULE["I001"] + 1)
assert baseline_regressions(diagnostics) == ["I001: 91 > 90"]
def test_reduced_debt_passes() -> None:
assert baseline_regressions(_diagnostics(I001=1, F401=1)) == []
assert normalized_findings([diagnostic, diagnostic], tmp_path).total() == 2