Skip to content

Commit 271f9b6

Browse files
committed
fix: report the configured CP-SAT timeout exactly in the not-optimal warning
A float timeout below 0.1s rendered as '0.0s' under {timeout:.1f}, so the warning that tells the user which limit to raise did not name the real limit. Use {timeout:g}, and cover the sub-decisecond case; the existing test used 0.5, which formats identically under both spellings.
1 parent d374799 commit 271f9b6

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

pr_split/logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@
7575
"Skipping PR for group '{group}': its base branch '{base}' was not pushed"
7676
)
7777
CP_SAT_NOT_OPTIMAL = (
78-
"CP-SAT stopped at the {timeout:.1f}s limit with a feasible but unproven-optimal plan "
78+
"CP-SAT stopped at the {timeout:g}s limit with a feasible but unproven-optimal plan "
7979
"({units} units, {groups} groups); raise --cp-sat-timeout for a better partition"
8080
)

tests/test_partitioning.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,36 @@ def solve_feasible(self: object, model: object) -> int:
149149
assert "0.5s limit" in warning
150150
assert "raise --cp-sat-timeout" in warning
151151

152+
def test_sub_decisecond_timeout_is_reported_exactly(
153+
self, monkeypatch: pytest.MonkeyPatch
154+
) -> None:
155+
cp_model = pytest.importorskip("ortools.sat.python.cp_model")
156+
from unittest.mock import patch
157+
158+
parsed = parse_diff(SAMPLE_DIFF)
159+
settings = _settings(
160+
monkeypatch,
161+
max_loc=10,
162+
partition_strategy=PartitionStrategy.CP_SAT,
163+
cp_sat_timeout=0.04,
164+
)
165+
real_solve = cp_model.CpSolver.Solve
166+
167+
def solve_feasible(self: object, model: object) -> int:
168+
real_solve(self, model)
169+
return cp_model.FEASIBLE
170+
171+
with (
172+
patch.object(cp_model.CpSolver, "Solve", solve_feasible),
173+
patch("pr_split.planner.partitioning.logger") as mock_logger,
174+
):
175+
partition_diff(parsed, settings)
176+
177+
warning = mock_logger.warning.call_args[0][0]
178+
# A timeout below 0.1s must not be rounded away to "0.0s"; the warning
179+
# tells the user which limit to raise, so it has to name the real value.
180+
assert "0.04s limit" in warning
181+
152182
def test_optimal_solution_does_not_warn(self, monkeypatch: pytest.MonkeyPatch) -> None:
153183
pytest.importorskip("ortools.sat.python.cp_model")
154184
from unittest.mock import patch

0 commit comments

Comments
 (0)