Compare commits

..
17 Commits
Author SHA1 Message Date
devx-ci-bot ddb0f17886 release: v0.47.8 [skip ci] 2026-08-03 21:53:01 +00:00
kiretoandemo a8a8b743f3 DEVX-147: fix: increase CI_SCALE_FACTOR default from 4 to 6
Post-merge / detect-and-configure (push) Successful in 18s
Post-merge / release-and-maintain (push) Successful in 2m1s
Co-authored-by: kireto <kireto@oblachno.com>
2026-08-03 21:51:43 +00:00
gitea-actions-bot a487bddb09 chore: update badge URLs to commit 283191bf [skip ci] 2026-08-03 21:42:42 +00:00
devx-ci-bot e3a37c95c1 release: v0.47.7 [skip ci] 2026-08-03 21:41:37 +00:00
emilandemo 9bb461e12f DEVX-146: fix: scale check_test_speed limits on CI runners
Post-merge / detect-and-configure (push) Successful in 20s
Post-merge / release-and-maintain (push) Successful in 2m2s
Co-authored-by: emil User <emil.simeonov@tutanota.com>
2026-08-03 21:40:17 +00:00
gitea-actions-bot 32193a0e6d chore: update badge URLs to commit d49dc712 [skip ci] 2026-08-03 15:34:38 +00:00
devx-ci-bot 155c4a204a release: v0.47.6 [skip ci] 2026-08-03 15:34:03 +00:00
emo 491137f944 DEVX-3: fix: configure git auth in setup_image for git+https deps 2026-08-03 15:33:16 +00:00
gitea-actions-bot 48cd33be22 chore: update badge URLs to commit cd7648fd [skip ci] 2026-08-03 14:56:33 +00:00
devx-ci-bot 2fae9bc723 release: v0.47.5 [skip ci] 2026-08-03 14:55:50 +00:00
emo bfc2ebec81 DEVX-2: fix: push wiki to main branch instead of master 2026-08-03 14:55:10 +00:00
devx-ci-bot e01c39b4b8 release: v0.47.4 [skip ci] 2026-08-03 14:41:33 +00:00
emo aa93e894a6 DEVX-1: fix: add User-Agent header to _download in install_tools 2026-08-03 14:40:51 +00:00
gitea-actions-bot 004b890463 chore: update badge URLs to commit 82b4caf3 [skip ci] 2026-07-17 02:11:54 +00:00
devx-ci-bot 587906f518 release: v0.47.3 [skip ci] 2026-07-17 02:11:15 +00:00
emil d743ba93eb DEVX-144: fix: bake promtool into ci-full image, add download timeout, speed up tests
Post-merge / release-and-maintain (push) Waiting to run
Post-merge / detect-and-configure (push) Waiting to run
2026-07-17 02:10:17 +00:00
gitea-actions-bot c7351a495a chore: update badge URLs to commit eeaec1e7 [skip ci] 2026-07-17 00:45:48 +00:00
14 changed files with 214 additions and 38 deletions
+36
View File
@@ -2,6 +2,42 @@
All notable changes to this project will be documented in this file.
## [0.47.8] - 2026-08-03
### Bug Fixes
- Increase CI_SCALE_FACTOR default from 4 to 6
## [0.47.7] - 2026-08-03
### Bug Fixes
- Scale check_test_speed limits on CI runners
## [0.47.6] - 2026-08-03
### Bug Fixes
- Configure git auth in setup_image for git+https deps
## [0.47.5] - 2026-08-03
### Bug Fixes
- Push wiki to main branch instead of master
## [0.47.4] - 2026-08-03
### Bug Fixes
- Add User-Agent header to _download in install_tools
## [0.47.3] - 2026-07-17
### Bug Fixes
- Bake promtool into ci-full image, add download timeout, speed up tests
## [0.47.2] - 2026-07-17
### Bug Fixes
+9 -9
View File
@@ -16,12 +16,12 @@ quality badges.
[![CI](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions/workflows/ci.yml/badge.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![License: GPL-3.0](https://img.shields.io/badge/license-GPL--3.0-blue)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
[![Coverage](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/coverage.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Tests](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/tests.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Docs](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/docs.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
[![Code Quality](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/quality.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Version](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/version.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
[![Python](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/python.svg)](https://www.python.org/downloads/)
[![Coverage](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/coverage.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Tests](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/tests.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Docs](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/docs.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
[![Code Quality](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/quality.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Version](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/version.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
[![Python](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/python.svg)](https://www.python.org/downloads/)
## Why devx?
@@ -87,7 +87,7 @@ extra index and list devx in your dependencies:
```toml
[project]
dependencies = [
"devx>=0.47.2",
"devx>=0.47.8",
]
[tool.pip]
@@ -101,8 +101,8 @@ pip install -e .
```
> **Note:** If your project requires a specific devx version, pin it in
> `dependencies` (for example, `"devx==0.47.2"`) or use a version constraint
> (for example, `"devx>=0.47.2,<0.48"`).
> `dependencies` (for example, `"devx==0.47.8"`) or use a version constraint
> (for example, `"devx>=0.47.8,<0.48"`).
### Optional extras
+3 -2
View File
@@ -20,5 +20,6 @@ COPY . /tmp/devx
RUN pip install --no-cache-dir /tmp/devx[release,molecule,deploy] \
&& rm -rf /tmp/devx
# Install git-cliff (changelog generator for release job) and OpenTofu (for infra deploy jobs)
RUN python3 -m devx.tools.install_tools --tool git-cliff --tool tofu
# Install git-cliff (changelog generator for release job), OpenTofu (for infra deploy jobs),
# and promtool (Prometheus rule validator — used by every infra CI run for alert validation)
RUN python3 -m devx.tools.install_tools --tool git-cliff --tool tofu --tool promtool
+8 -8
View File
@@ -12,12 +12,12 @@ project to be reusable across all oblachno-oss repositories.
[![CI](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions/workflows/ci.yml/badge.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![License: GPL-3.0](https://img.shields.io/badge/license-GPL--3.0-blue)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
[![Coverage](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/coverage.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Tests](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/tests.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Docs](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/docs.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
[![Code Quality](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/quality.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Version](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/version.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
[![Python](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/4e6bada89275c693958c53ae8c5fd9fb562329b8/python.svg)](https://www.python.org/downloads/)
[![Coverage](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/coverage.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Tests](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/tests.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Docs](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/docs.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
[![Code Quality](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/quality.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
[![Version](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/version.svg)](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
[![Python](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/raw/commit/283191bf653119bdc945a27cc921d3a8225f09ea/python.svg)](https://www.python.org/downloads/)
## Overview
@@ -74,14 +74,14 @@ Add devx to your `pyproject.toml` dependencies and configure the registry:
```toml
[project]
dependencies = [
"devx>=0.47.2",
"devx>=0.47.8",
]
[tool.pip]
extra-index-url = "https://git.oblachno.oblachno.fyi/api/packages/oblachno-oss/pypi/simple"
```
Pin a specific version if needed: `"devx==0.47.2"` or `"devx>=0.47.2,<0.48"`.
Pin a specific version if needed: `"devx==0.47.8"` or `"devx>=0.47.8,<0.48"`.
### Optional extras
+2 -2
View File
@@ -48,12 +48,12 @@ Add devx to your `pyproject.toml`:
```toml
[project]
dependencies = [
"devx>=0.47.2",
"devx>=0.47.8",
]
[project.optional-dependencies]
dev = [
"devx>=0.47.2",
"devx>=0.47.8",
]
```
+1 -1
View File
@@ -1,3 +1,3 @@
"""devx — reusable development and CI/CD tools for oblachno-oss projects."""
__version__ = "0.47.2"
__version__ = "0.47.8"
+1 -1
View File
@@ -252,7 +252,7 @@ def commit_and_push(wiki_dir: Path, wiki_url: str, dry_run: bool) -> bool:
# Push
result = subprocess.run( # nosec
["git", "push", "--force", wiki_url, "HEAD:master"],
["git", "push", "--force", wiki_url, "HEAD:main"],
cwd=wiki_dir,
capture_output=True,
text=True,
+1 -1
View File
@@ -309,7 +309,7 @@ devx-lint: devx-lint-ruff devx-lint-format devx-typecheck devx-lint-bandit devx-
# ── Testing ───────────────────────────────────────────────────────────────────
devx-test-unit:
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -q --no-cov
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -q --no-cov -n 8
devx-pytest-cov:
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -n auto --cov=$(DEVX_COV_PKG) --cov-report=term-missing --cov-fail-under=100
+48 -6
View File
@@ -11,6 +11,18 @@ Usage:
The module runs ``make test-unit`` with ``PYTEST_ADDOPTS=--durations=0`` so
that pytest emits per-test timing lines alongside the summary. Both the
total wall-clock time and individual test durations are parsed and validated.
CI runner scaling
-----------------
CI runners (Gitea Actions Docker containers) are typically 5-8x slower than
local development machines due to shared CPU, fewer cores, and container
overhead. When the ``CI`` environment variable is set (standard CI
convention), both the total and per-test limits are multiplied by
``CI_SCALE_FACTOR`` (default 6) to account for this. This keeps the local
budget strict while preventing false failures on slower CI runners.
The scale factor can be overridden via the ``DEVX_CI_SCALE_FACTOR``
environment variable.
"""
from __future__ import annotations
@@ -27,6 +39,12 @@ DEFAULT_MAX_SECONDS = 10.0
DEFAULT_MAX_SINGLE_SECONDS = 0.5
TEST_COMMAND = ["make", "test-unit"]
# CI runners are typically 5-8x slower than local machines (shared CPU,
# fewer cores, container overhead). Scale limits up when running on CI
# so the gate catches real regressions, not infrastructure slowness.
CI_SCALE_FACTOR = float(os.environ.get("DEVX_CI_SCALE_FACTOR", "6"))
_IS_CI = bool(os.environ.get("CI") or os.environ.get("GITEA_ACTIONS"))
# Matches pytest summary line: "234 passed in 0.70s"
_TIMING_RE = re.compile(r"(\d+) passed.* in ([0-9.]+)s")
@@ -38,6 +56,13 @@ _TIMING_RE = re.compile(r"(\d+) passed.* in ([0-9.]+)s")
_DURATION_LINE_RE = re.compile(r"^(\d+\.?\d*)s\s+call\s+(.+)$")
def _ci_scale_limit(limit: float) -> float:
"""Scale a time limit by the CI factor when running on CI."""
if _IS_CI:
return limit * CI_SCALE_FACTOR
return limit
def run_tests() -> tuple[str, str]:
"""Execute the unit-test suite and return (stdout, stderr).
@@ -123,21 +148,38 @@ def check_per_test_speed(
def main(max_seconds: float, max_single_seconds: float) -> None:
"""Run tests, parse timings, and enforce both budgets."""
# Scale limits for CI runners (slower CPU, fewer workers).
effective_max = _ci_scale_limit(max_seconds)
effective_single = _ci_scale_limit(max_single_seconds)
if _IS_CI:
click.echo(
_(
"[check-test-speed] CI environment detected — scaling limits by {factor}x "
"(total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)",
factor=CI_SCALE_FACTOR,
orig=max_seconds,
eff=effective_max,
orig_s=max_single_seconds,
eff_s=effective_single,
)
)
stdout, stderr = run_tests()
combined = stdout + "\n" + stderr
click.echo(combined, err=False)
duration = parse_duration(combined)
check_speed(duration, max_seconds)
check_speed(duration, effective_max)
if max_single_seconds > 0:
if effective_single > 0:
per_test = parse_per_test_durations(combined)
violations = check_per_test_speed(per_test, max_single_seconds)
violations = check_per_test_speed(per_test, effective_single)
if violations:
msg = _(
"Per-test speed check FAILED: {count} test(s) exceed {limit}s limit.",
count=len(violations),
limit=max_single_seconds,
limit=effective_single,
)
click.echo(f"\n{msg}", err=True)
for v in violations:
@@ -148,8 +190,8 @@ def main(max_seconds: float, max_single_seconds: float) -> None:
_(
"Unit tests passed in {duration:.2f}s (under {max}s limit, all tests under {single}s per-test limit).",
duration=duration,
max=max_seconds,
single=max_single_seconds,
max=effective_max,
single=effective_single,
)
)
+8 -2
View File
@@ -65,8 +65,14 @@ def _ensure_target_dir() -> Path:
def _download(url: str, dest: Path) -> None:
"""Download a file from ``url`` to ``dest``."""
urllib.request.urlretrieve(url, dest) # nosec B310
"""Download a file from ``url`` to ``dest`` with a 60s timeout.
A User-Agent header is set because some CDNs (e.g. dl.gitea.com)
return 403 to requests with Python's default User-Agent.
"""
req = urllib.request.Request(url, headers={"User-Agent": "devx/install-tools"})
with urllib.request.urlopen(req, timeout=60) as resp, open(dest, "wb") as f: # nosec B310
shutil.copyfileobj(resp, f)
def _download_and_extract_tarball(url: str, binary_name: str) -> Path:
+11
View File
@@ -81,6 +81,17 @@ def _install_in_image(
username,
token,
)
# Configure git URL rewrite so git+https dependencies can authenticate
subprocess.run( # nosec B603, B607
[
"git",
"config",
"--global",
f"url.https://{username}:{token}@{gitea_host}/.insteadOf",
f"https://{gitea_host}/",
],
check=True,
)
click.echo(f"[setup-image] Linked {opt_venv}" + (f" with [{extras}]" if extras else "") + ".")
subprocess.run(cmd, check=True, env=env) # nosec B603
+9 -1
View File
@@ -3822,5 +3822,13 @@
"pl": "importlib.reload({mod}) called {n} time(s) in test '{test}' — odd count leaves module in modified state. Add a final reload to restore defaults or wrap in try/finally.",
"ru": "importlib.reload({mod}) called {n} time(s) in test '{test}' — odd count leaves module in modified state. Add a final reload to restore defaults or wrap in try/finally.",
"zh": "importlib.reload({mod}) called {n} time(s) in test '{test}' — odd count leaves module in modified state. Add a final reload to restore defaults or wrap in try/finally."
},
"[check-test-speed] CI environment detected — scaling limits by {factor}x (total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)": {
"en": "[check-test-speed] CI environment detected — scaling limits by {factor}x (total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)",
"bg": "[check-test-speed] CI environment detected — scaling limits by {factor}x (total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)",
"de": "[check-test-speed] CI environment detected — scaling limits by {factor}x (total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)",
"pl": "[check-test-speed] CI environment detected — scaling limits by {factor}x (total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)",
"ru": "[check-test-speed] CI environment detected — scaling limits by {factor}x (total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)",
"zh": "[check-test-speed] CI environment detected — scaling limits by {factor}x (total: {orig}s → {eff}s, per-test: {orig_s}s → {eff_s}s)"
}
}
}
+55
View File
@@ -10,6 +10,7 @@ from devx.tools.check_test_speed import (
DEFAULT_MAX_SECONDS,
DEFAULT_MAX_SINGLE_SECONDS,
TEST_COMMAND,
_ci_scale_limit,
check_per_test_speed,
check_speed,
cli,
@@ -144,7 +145,26 @@ def test_main_module_block() -> None:
mock_cli.assert_called_once_with([])
class TestCiScaleLimit:
def test_no_scaling_when_not_ci(self) -> None:
with patch("devx.tools.check_test_speed._IS_CI", False):
assert _ci_scale_limit(10.0) == 10.0
assert _ci_scale_limit(0.5) == 0.5
def test_scales_when_ci(self) -> None:
with patch("devx.tools.check_test_speed._IS_CI", True):
with patch("devx.tools.check_test_speed.CI_SCALE_FACTOR", 4.0):
assert _ci_scale_limit(10.0) == 40.0
assert _ci_scale_limit(0.5) == 2.0
def test_custom_scale_factor(self) -> None:
with patch("devx.tools.check_test_speed._IS_CI", True):
with patch("devx.tools.check_test_speed.CI_SCALE_FACTOR", 2.5):
assert _ci_scale_limit(10.0) == 25.0
class TestMain:
@patch("devx.tools.check_test_speed._IS_CI", False)
@patch("devx.tools.check_test_speed.run_tests")
@patch("devx.tools.check_test_speed.parse_duration")
@patch("devx.tools.check_test_speed.check_speed")
@@ -174,6 +194,7 @@ class TestMain:
mock_parse_per.assert_called_once()
mock_check_per.assert_called_once_with([], DEFAULT_MAX_SINGLE_SECONDS)
@patch("devx.tools.check_test_speed._IS_CI", False)
@patch("devx.tools.check_test_speed.run_tests")
@patch("devx.tools.check_test_speed.parse_duration")
def test_slow_total_exits(
@@ -189,6 +210,7 @@ class TestMain:
assert result.exit_code == 1
assert "too slow" in result.output.lower()
@patch("devx.tools.check_test_speed._IS_CI", False)
@patch("devx.tools.check_test_speed.run_tests")
@patch("devx.tools.check_test_speed.parse_duration")
@patch("devx.tools.check_test_speed.check_speed")
@@ -213,6 +235,7 @@ class TestMain:
assert "Per-test speed check FAILED" in result.output
assert "test_slow" in result.output
@patch("devx.tools.check_test_speed._IS_CI", False)
@patch("devx.tools.check_test_speed.run_tests")
def test_parse_failure_exits(
self,
@@ -225,6 +248,7 @@ class TestMain:
assert result.exit_code == 1
assert "Could not parse" in result.output
@patch("devx.tools.check_test_speed._IS_CI", False)
@patch("devx.tools.check_test_speed.run_tests")
@patch("devx.tools.check_test_speed.parse_duration")
@patch("devx.tools.check_test_speed.check_speed")
@@ -248,6 +272,7 @@ class TestMain:
assert result.exit_code == 0
mock_check.assert_called_once_with(0.5, 1.5)
@patch("devx.tools.check_test_speed._IS_CI", False)
@patch("devx.tools.check_test_speed.run_tests")
@patch("devx.tools.check_test_speed.parse_duration")
@patch("devx.tools.check_test_speed.check_speed")
@@ -270,6 +295,7 @@ class TestMain:
mock_parse_per.assert_not_called()
mock_check_per.assert_not_called()
@patch("devx.tools.check_test_speed._IS_CI", False)
@patch("devx.tools.check_test_speed.run_tests")
@patch("devx.tools.check_test_speed.parse_duration")
@patch("devx.tools.check_test_speed.check_speed")
@@ -292,3 +318,32 @@ class TestMain:
result = runner.invoke(cli, ["--max-single-seconds", "1.0"])
assert result.exit_code == 0
mock_check_per.assert_called_once_with([], 1.0)
@patch("devx.tools.check_test_speed._IS_CI", True)
@patch("devx.tools.check_test_speed.CI_SCALE_FACTOR", 4.0)
@patch("devx.tools.check_test_speed.run_tests")
@patch("devx.tools.check_test_speed.parse_duration")
@patch("devx.tools.check_test_speed.check_speed")
@patch("devx.tools.check_test_speed.parse_per_test_durations")
@patch("devx.tools.check_test_speed.check_per_test_speed")
def test_ci_scales_limits(
self,
mock_check_per: MagicMock,
mock_parse_per: MagicMock,
mock_check: MagicMock,
mock_parse: MagicMock,
mock_run: MagicMock,
) -> None:
mock_run.return_value = ("out\n", "err\n")
mock_parse.return_value = 30.0 # would fail local (10s) but pass CI (40s)
mock_parse_per.return_value = []
mock_check_per.return_value = []
runner = CliRunner()
result = runner.invoke(cli, [])
assert result.exit_code == 0
assert "CI environment detected" in result.output
assert "scaling limits by 4.0x" in result.output
# check_speed called with scaled limit
mock_check.assert_called_once_with(30.0, 40.0)
mock_check_per.assert_called_once_with([], 2.0)
+22 -5
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import platform
import urllib.request
from pathlib import Path
from unittest.mock import patch
@@ -47,13 +48,29 @@ class TestDownload:
def test_download(self, tmp_path: Path) -> None:
dest = tmp_path / "file.bin"
def _write_file(url: str, path: Path) -> tuple[str, None]:
Path(path).write_bytes(b"data")
return str(path), None
class _FakeResponse:
def __init__(self) -> None:
self._sent = False
with patch("urllib.request.urlretrieve", side_effect=_write_file) as mock_retrieve:
def __enter__(self) -> _FakeResponse:
return self
def __exit__(self, *args: object) -> None:
pass
def read(self, n: int = -1) -> bytes:
if self._sent:
return b""
self._sent = True
return b"data"
with patch("urllib.request.urlopen", return_value=_FakeResponse()) as mock_urlopen:
install_tools._download("https://example.com/file", dest)
mock_retrieve.assert_called_once()
mock_urlopen.assert_called_once()
call_args = mock_urlopen.call_args
req = call_args.args[0]
assert isinstance(req, urllib.request.Request)
assert req.get_header("User-agent") == "devx/install-tools"
assert dest.read_bytes() == b"data"