Skip to content

Commit f96adf5

Browse files
committed
ci: the CI ceiling is 180s so the standalone import and legacy benchmark tests fit on a runner; the 4.0.1 tests type-check under mypy
1 parent 4f4a62f commit f96adf5

7 files changed

Lines changed: 28 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
126126
- name: Run tests
127127
run: |
128-
IPINFO_TOKEN='${{ secrets.IPINFO_TOKEN }}' REDIS_URL='redis://localhost:6379' GUARD_TESTS_MAX_TEST_SECONDS=60 uv run pytest -v --cov=guard_core --cov-fail-under=100 -W error
128+
IPINFO_TOKEN='${{ secrets.IPINFO_TOKEN }}' REDIS_URL='redis://localhost:6379' GUARD_TESTS_MAX_TEST_SECONDS=180 uv run pytest -v --cov=guard_core --cov-fail-under=100 -W error
129129
130130
- name: Notify Success on Slack Channel
131131
uses: rennf93/good-comms@master
@@ -202,7 +202,7 @@ jobs:
202202

203203
- name: Run tests in Docker
204204
run: |
205-
COMPOSE_BAKE=true PYTHON_VERSION=3.10 docker compose run --rm --build -e GUARD_TESTS_MAX_TEST_SECONDS=60 guard-core pytest -q -p no:cacheprovider -W error --ignore=tests/live_smoke --cov=guard_core --cov-branch --cov-fail-under=100
205+
COMPOSE_BAKE=true PYTHON_VERSION=3.10 docker compose run --rm --build -e GUARD_TESTS_MAX_TEST_SECONDS=180 guard-core pytest -q -p no:cacheprovider -W error --ignore=tests/live_smoke --cov=guard_core --cov-branch --cov-fail-under=100
206206
207207
- name: Tear down Docker Compose
208208
if: always()

tests/test_core/test_check_rate_limit_by_ip_autoban.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,10 @@ async def test_already_banned_ip_makes_zero_additional_ban_calls() -> None:
241241

242242
async def fake_ban(
243243
ip: str, duration: int, reason: str = "threshold_exceeded"
244-
) -> None:
244+
) -> bool:
245245
ban_calls.append((ip, duration, reason))
246246
manager.banned_ips[ip] = time.time() + duration
247+
return True
247248

248249
manager.ban_ip = fake_ban # type: ignore[method-assign]
249250

tests/test_sus_patterns/test_redos_cost_arbiter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import re
33
import time
4+
from collections.abc import Callable
5+
from typing import Any
46
from unittest.mock import MagicMock, patch
57

68
import pytest
@@ -205,10 +207,14 @@ def _fail_if_called(*args: object, **kwargs: object) -> None:
205207
assert result is None
206208

207209

210+
def _repeat_builder(unit: str) -> Callable[[int], str]:
211+
return lambda size: unit * size
212+
213+
208214
def test_time_reach_probes_subprocess_clips_timeout_to_remaining_budget() -> None:
209215
captured: dict[str, float] = {}
210216

211-
def _fake_run(*args: object, **kwargs: object) -> None:
217+
def _fake_run(*args: object, **kwargs: Any) -> None:
212218
captured["timeout"] = kwargs["timeout"]
213219
raise OSError("stop before actually spawning")
214220

@@ -438,7 +444,7 @@ def _fake_timing(
438444
_fake_timing,
439445
)
440446

441-
builders = [(lambda size, ch=ch: ch * size) for ch in ("a", "b", "c")]
447+
builders = [_repeat_builder(ch) for ch in ("a", "b", "c")]
442448
reason = _first_over_budget_reason(
443449
r"(\w+)*$", builders, _PATTERN_SAFETY_DEFAULT_CAP, None, _far_deadline()
444450
)

tests/test_sync/test_core/test_check_rate_limit_by_ip_autoban.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,10 @@ def test_already_banned_ip_makes_zero_additional_ban_calls() -> None:
237237

238238
def fake_ban(
239239
ip: str, duration: int, reason: str = "threshold_exceeded"
240-
) -> None:
240+
) -> bool:
241241
ban_calls.append((ip, duration, reason))
242242
manager.banned_ips[ip] = time.time() + duration
243+
return True
243244

244245
manager.ban_ip = fake_ban # type: ignore[method-assign]
245246

tests/test_sync/test_sus_patterns/test_redos_cost_arbiter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import re
33
import time
4+
from collections.abc import Callable
5+
from typing import Any
46
from unittest.mock import MagicMock, patch
57

68
import pytest
@@ -205,10 +207,14 @@ def _fail_if_called(*args: object, **kwargs: object) -> None:
205207
assert result is None
206208

207209

210+
def _repeat_builder(unit: str) -> Callable[[int], str]:
211+
return lambda size: unit * size
212+
213+
208214
def test_time_reach_probes_subprocess_clips_timeout_to_remaining_budget() -> None:
209215
captured: dict[str, float] = {}
210216

211-
def _fake_run(*args: object, **kwargs: object) -> None:
217+
def _fake_run(*args: object, **kwargs: Any) -> None:
212218
captured["timeout"] = kwargs["timeout"]
213219
raise OSError("stop before actually spawning")
214220

@@ -438,7 +444,7 @@ def _fake_timing(
438444
_fake_timing,
439445
)
440446

441-
builders = [(lambda size, ch=ch: ch * size) for ch in ("a", "b", "c")]
447+
builders = [_repeat_builder(ch) for ch in ("a", "b", "c")]
442448
reason = _first_over_budget_reason(
443449
r"(\w+)*$", builders, _PATTERN_SAFETY_DEFAULT_CAP, None, _far_deadline()
444450
)

tests/test_sync/test_threat_ban_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Any
2+
from typing import Any, cast
33
from unittest.mock import MagicMock
44

55
import pytest
@@ -447,7 +447,7 @@ def test_refused_ban_falls_through_to_400_not_403(
447447
caplog.set_level(logging.WARNING)
448448
check.check(request)
449449

450-
check.middleware.create_error_response.assert_called_once_with(
450+
cast(MagicMock, check.middleware.create_error_response).assert_called_once_with(
451451
status_code=400,
452452
default_message="Suspicious activity detected",
453453
)
@@ -482,7 +482,7 @@ def test_applied_ban_still_gives_403(
482482

483483
check.check(request)
484484

485-
check.middleware.create_error_response.assert_called_once_with(
485+
cast(MagicMock, check.middleware.create_error_response).assert_called_once_with(
486486
status_code=403,
487487
default_message="IP has been banned",
488488
)

tests/test_threat_ban_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Any
2+
from typing import Any, cast
33
from unittest.mock import AsyncMock, MagicMock
44

55
import pytest
@@ -447,7 +447,7 @@ async def test_refused_ban_falls_through_to_400_not_403(
447447
caplog.set_level(logging.WARNING)
448448
await check.check(request)
449449

450-
check.middleware.create_error_response.assert_called_once_with(
450+
cast(AsyncMock, check.middleware.create_error_response).assert_called_once_with(
451451
status_code=400,
452452
default_message="Suspicious activity detected",
453453
)
@@ -482,7 +482,7 @@ async def test_applied_ban_still_gives_403(
482482

483483
await check.check(request)
484484

485-
check.middleware.create_error_response.assert_called_once_with(
485+
cast(AsyncMock, check.middleware.create_error_response).assert_called_once_with(
486486
status_code=403,
487487
default_message="IP has been banned",
488488
)

0 commit comments

Comments
 (0)