Public Access
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddb0f17886 | ||
|
|
a8a8b743f3 | ||
|
|
a487bddb09 | ||
|
|
e3a37c95c1 | ||
|
|
9bb461e12f | ||
|
|
32193a0e6d | ||
|
|
155c4a204a | ||
|
|
491137f944 | ||
|
|
48cd33be22 | ||
|
|
2fae9bc723 | ||
|
|
bfc2ebec81 | ||
|
|
e01c39b4b8 | ||
|
|
aa93e894a6 | ||
|
|
004b890463 | ||
|
|
587906f518 | ||
|
|
d743ba93eb | ||
|
|
c7351a495a | ||
|
|
4de11bfc18 | ||
|
|
a02bf6d70e | ||
|
|
368c87aabf |
@@ -2,6 +2,48 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
||||||
|
|
||||||
|
- Add retry logic to TeaCLI for transient HTTP errors (502/503/504/429)
|
||||||
|
|
||||||
## [0.47.1] - 2026-07-16
|
## [0.47.1] - 2026-07-16
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ quality badges.
|
|||||||
|
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
||||||
[](https://www.python.org/downloads/)
|
[](https://www.python.org/downloads/)
|
||||||
|
|
||||||
## Why devx?
|
## Why devx?
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ extra index and list devx in your dependencies:
|
|||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"devx>=0.47.1",
|
"devx>=0.47.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.pip]
|
[tool.pip]
|
||||||
@@ -101,8 +101,8 @@ pip install -e .
|
|||||||
```
|
```
|
||||||
|
|
||||||
> **Note:** If your project requires a specific devx version, pin it in
|
> **Note:** If your project requires a specific devx version, pin it in
|
||||||
> `dependencies` (for example, `"devx==0.47.1"`) or use a version constraint
|
> `dependencies` (for example, `"devx==0.47.8"`) or use a version constraint
|
||||||
> (for example, `"devx>=0.47.1,<0.48"`).
|
> (for example, `"devx>=0.47.8,<0.48"`).
|
||||||
|
|
||||||
### Optional extras
|
### Optional extras
|
||||||
|
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ COPY . /tmp/devx
|
|||||||
RUN pip install --no-cache-dir /tmp/devx[release,molecule,deploy] \
|
RUN pip install --no-cache-dir /tmp/devx[release,molecule,deploy] \
|
||||||
&& rm -rf /tmp/devx
|
&& rm -rf /tmp/devx
|
||||||
|
|
||||||
# Install git-cliff (changelog generator for release job) and OpenTofu (for infra deploy jobs)
|
# Install git-cliff (changelog generator for release job), OpenTofu (for infra deploy jobs),
|
||||||
RUN python3 -m devx.tools.install_tools --tool git-cliff --tool tofu
|
# 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
@@ -12,12 +12,12 @@ project to be reusable across all oblachno-oss repositories.
|
|||||||
|
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/src/branch/master/LICENSE)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/wiki)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/actions)
|
||||||
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
[](https://git.oblachno.oblachno.fyi/oblachno-oss/devx/releases)
|
||||||
[](https://www.python.org/downloads/)
|
[](https://www.python.org/downloads/)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
@@ -74,14 +74,14 @@ Add devx to your `pyproject.toml` dependencies and configure the registry:
|
|||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"devx>=0.47.1",
|
"devx>=0.47.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.pip]
|
[tool.pip]
|
||||||
extra-index-url = "https://git.oblachno.oblachno.fyi/api/packages/oblachno-oss/pypi/simple"
|
extra-index-url = "https://git.oblachno.oblachno.fyi/api/packages/oblachno-oss/pypi/simple"
|
||||||
```
|
```
|
||||||
|
|
||||||
Pin a specific version if needed: `"devx==0.47.1"` or `"devx>=0.47.1,<0.48"`.
|
Pin a specific version if needed: `"devx==0.47.8"` or `"devx>=0.47.8,<0.48"`.
|
||||||
|
|
||||||
### Optional extras
|
### Optional extras
|
||||||
|
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ Add devx to your `pyproject.toml`:
|
|||||||
```toml
|
```toml
|
||||||
[project]
|
[project]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"devx>=0.47.1",
|
"devx>=0.47.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
"devx>=0.47.1",
|
"devx>=0.47.8",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""devx — reusable development and CI/CD tools for oblachno-oss projects."""
|
"""devx — reusable development and CI/CD tools for oblachno-oss projects."""
|
||||||
|
|
||||||
__version__ = "0.47.1"
|
__version__ = "0.47.8"
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ def commit_and_push(wiki_dir: Path, wiki_url: str, dry_run: bool) -> bool:
|
|||||||
|
|
||||||
# Push
|
# Push
|
||||||
result = subprocess.run( # nosec
|
result = subprocess.run( # nosec
|
||||||
["git", "push", "--force", wiki_url, "HEAD:master"],
|
["git", "push", "--force", wiki_url, "HEAD:main"],
|
||||||
cwd=wiki_dir,
|
cwd=wiki_dir,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
|
|||||||
+58
-20
@@ -40,21 +40,35 @@ Usage::
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess # nosec B404
|
import subprocess # nosec B404
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
from tenacity import (
|
||||||
|
before_sleep_log,
|
||||||
|
retry,
|
||||||
|
retry_if_exception_type,
|
||||||
|
stop_after_attempt,
|
||||||
|
wait_exponential,
|
||||||
|
)
|
||||||
|
|
||||||
from devx.config import GITEA_API_URL
|
from devx.config import GITEA_API_URL, MAX_RETRIES, RETRY_BACKOFF_BASE, RETRY_STATUS_CODES
|
||||||
from devx.i18n import _
|
from devx.i18n import _
|
||||||
from devx.tokens import get_ci_token
|
from devx.tokens import get_ci_token
|
||||||
|
|
||||||
|
logger = logging.getLogger("gitea_cli")
|
||||||
|
|
||||||
|
|
||||||
class TeaCLIError(Exception):
|
class TeaCLIError(Exception):
|
||||||
"""Raised when a tea CLI command fails."""
|
"""Raised when a tea CLI command fails."""
|
||||||
|
|
||||||
|
|
||||||
|
class _TransientTeaError(TeaCLIError):
|
||||||
|
"""Tea CLI error caused by a transient HTTP status (502/503/504/429)."""
|
||||||
|
|
||||||
|
|
||||||
def configure_tea_login(login_name: str = "devx") -> None:
|
def configure_tea_login(login_name: str = "devx") -> None:
|
||||||
"""Configure tea CLI login from CI_GITEA_API_TOKEN and DEVX_GITEA_API_URL.
|
"""Configure tea CLI login from CI_GITEA_API_TOKEN and DEVX_GITEA_API_URL.
|
||||||
|
|
||||||
@@ -140,6 +154,10 @@ class TeaCLI:
|
|||||||
def _run(self, args: list[str], json_output: bool = True) -> str:
|
def _run(self, args: list[str], json_output: bool = True) -> str:
|
||||||
"""Run a tea command and return stdout.
|
"""Run a tea command and return stdout.
|
||||||
|
|
||||||
|
Retries up to ``MAX_RETRIES`` times on transient HTTP errors
|
||||||
|
(502/503/504/429) detected in stderr/stdout, with exponential
|
||||||
|
backoff. Non-transient errors fail immediately.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
args: Command arguments (without the leading ``tea``).
|
args: Command arguments (without the leading ``tea``).
|
||||||
json_output: If True, append ``--output json`` to the command.
|
json_output: If True, append ``--output json`` to the command.
|
||||||
@@ -148,30 +166,50 @@ class TeaCLI:
|
|||||||
stdout as a string.
|
stdout as a string.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
TeaCLIError: If the command fails.
|
TeaCLIError: If the command fails after retries are exhausted.
|
||||||
"""
|
"""
|
||||||
cmd = [self._tea, *args]
|
cmd = [self._tea, *args]
|
||||||
if json_output:
|
if json_output:
|
||||||
cmd.extend(["--output", "json"])
|
cmd.extend(["--output", "json"])
|
||||||
|
|
||||||
|
def _execute() -> str:
|
||||||
|
try:
|
||||||
|
result = subprocess.run( # nosec B603
|
||||||
|
cmd,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
raise TeaCLIError(f"tea binary not found ('{self._tea}'). Install tea or add it to PATH.") from e
|
||||||
|
if result.returncode != 0:
|
||||||
|
parts = [
|
||||||
|
f"tea command failed (rc={result.returncode}): {' '.join(args)}",
|
||||||
|
f"stdout: {result.stdout.strip()}" if result.stdout.strip() else "",
|
||||||
|
f"stderr: {result.stderr.strip()}" if result.stderr.strip() else "",
|
||||||
|
]
|
||||||
|
msg = "\n".join(p for p in parts if p)
|
||||||
|
combined = f"{result.stdout} {result.stderr}".lower()
|
||||||
|
if any(str(code) in combined for code in RETRY_STATUS_CODES):
|
||||||
|
raise _TransientTeaError(msg)
|
||||||
|
raise TeaCLIError(msg)
|
||||||
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
retry_decorator = retry(
|
||||||
|
stop=stop_after_attempt(MAX_RETRIES),
|
||||||
|
wait=wait_exponential(
|
||||||
|
multiplier=RETRY_BACKOFF_BASE,
|
||||||
|
min=RETRY_BACKOFF_BASE,
|
||||||
|
max=RETRY_BACKOFF_BASE**MAX_RETRIES,
|
||||||
|
),
|
||||||
|
retry=retry_if_exception_type(_TransientTeaError),
|
||||||
|
before_sleep=before_sleep_log(logger, logging.WARNING),
|
||||||
|
reraise=True,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
result = subprocess.run( # nosec B603
|
return retry_decorator(_execute)()
|
||||||
cmd,
|
except _TransientTeaError as e:
|
||||||
capture_output=True,
|
raise TeaCLIError(str(e)) from e
|
||||||
text=True,
|
|
||||||
check=False,
|
|
||||||
)
|
|
||||||
except FileNotFoundError as e:
|
|
||||||
raise TeaCLIError(f"tea binary not found ('{self._tea}'). Install tea or add it to PATH.") from e
|
|
||||||
if result.returncode != 0:
|
|
||||||
# tea writes some errors to stdout (for example, "no available
|
|
||||||
# login"), so include both stdout and stderr for debugging.
|
|
||||||
parts = [
|
|
||||||
f"tea command failed (rc={result.returncode}): {' '.join(args)}",
|
|
||||||
f"stdout: {result.stdout.strip()}" if result.stdout.strip() else "",
|
|
||||||
f"stderr: {result.stderr.strip()}" if result.stderr.strip() else "",
|
|
||||||
]
|
|
||||||
raise TeaCLIError("\n".join(p for p in parts if p))
|
|
||||||
return result.stdout.strip()
|
|
||||||
|
|
||||||
def _run_raw(self, args: list[str]) -> str:
|
def _run_raw(self, args: list[str]) -> str:
|
||||||
"""Run a tea command without JSON output and return stdout."""
|
"""Run a tea command without JSON output and return stdout."""
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ devx-lint: devx-lint-ruff devx-lint-format devx-typecheck devx-lint-bandit devx-
|
|||||||
# ── Testing ───────────────────────────────────────────────────────────────────
|
# ── Testing ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
devx-test-unit:
|
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-pytest-cov:
|
||||||
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -n auto --cov=$(DEVX_COV_PKG) --cov-report=term-missing --cov-fail-under=100
|
@$(DEVX_BIN)/pytest $(DEVX_TEST_PATHS) -n auto --cov=$(DEVX_COV_PKG) --cov-report=term-missing --cov-fail-under=100
|
||||||
|
|||||||
@@ -11,6 +11,18 @@ Usage:
|
|||||||
The module runs ``make test-unit`` with ``PYTEST_ADDOPTS=--durations=0`` so
|
The module runs ``make test-unit`` with ``PYTEST_ADDOPTS=--durations=0`` so
|
||||||
that pytest emits per-test timing lines alongside the summary. Both the
|
that pytest emits per-test timing lines alongside the summary. Both the
|
||||||
total wall-clock time and individual test durations are parsed and validated.
|
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
|
from __future__ import annotations
|
||||||
@@ -27,6 +39,12 @@ DEFAULT_MAX_SECONDS = 10.0
|
|||||||
DEFAULT_MAX_SINGLE_SECONDS = 0.5
|
DEFAULT_MAX_SINGLE_SECONDS = 0.5
|
||||||
TEST_COMMAND = ["make", "test-unit"]
|
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"
|
# Matches pytest summary line: "234 passed in 0.70s"
|
||||||
_TIMING_RE = re.compile(r"(\d+) passed.* in ([0-9.]+)s")
|
_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+(.+)$")
|
_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]:
|
def run_tests() -> tuple[str, str]:
|
||||||
"""Execute the unit-test suite and return (stdout, stderr).
|
"""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:
|
def main(max_seconds: float, max_single_seconds: float) -> None:
|
||||||
"""Run tests, parse timings, and enforce both budgets."""
|
"""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()
|
stdout, stderr = run_tests()
|
||||||
combined = stdout + "\n" + stderr
|
combined = stdout + "\n" + stderr
|
||||||
click.echo(combined, err=False)
|
click.echo(combined, err=False)
|
||||||
|
|
||||||
duration = parse_duration(combined)
|
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)
|
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:
|
if violations:
|
||||||
msg = _(
|
msg = _(
|
||||||
"Per-test speed check FAILED: {count} test(s) exceed {limit}s limit.",
|
"Per-test speed check FAILED: {count} test(s) exceed {limit}s limit.",
|
||||||
count=len(violations),
|
count=len(violations),
|
||||||
limit=max_single_seconds,
|
limit=effective_single,
|
||||||
)
|
)
|
||||||
click.echo(f"\n{msg}", err=True)
|
click.echo(f"\n{msg}", err=True)
|
||||||
for v in violations:
|
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).",
|
"Unit tests passed in {duration:.2f}s (under {max}s limit, all tests under {single}s per-test limit).",
|
||||||
duration=duration,
|
duration=duration,
|
||||||
max=max_seconds,
|
max=effective_max,
|
||||||
single=max_single_seconds,
|
single=effective_single,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,14 @@ def _ensure_target_dir() -> Path:
|
|||||||
|
|
||||||
|
|
||||||
def _download(url: str, dest: Path) -> None:
|
def _download(url: str, dest: Path) -> None:
|
||||||
"""Download a file from ``url`` to ``dest``."""
|
"""Download a file from ``url`` to ``dest`` with a 60s timeout.
|
||||||
urllib.request.urlretrieve(url, dest) # nosec B310
|
|
||||||
|
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:
|
def _download_and_extract_tarball(url: str, binary_name: str) -> Path:
|
||||||
|
|||||||
@@ -81,6 +81,17 @@ def _install_in_image(
|
|||||||
username,
|
username,
|
||||||
token,
|
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 "") + ".")
|
click.echo(f"[setup-image] Linked {opt_venv}" + (f" with [{extras}]" if extras else "") + ".")
|
||||||
subprocess.run(cmd, check=True, env=env) # nosec B603
|
subprocess.run(cmd, check=True, env=env) # nosec B603
|
||||||
|
|||||||
@@ -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.",
|
"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.",
|
"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."
|
"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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ from devx.tools.check_test_speed import (
|
|||||||
DEFAULT_MAX_SECONDS,
|
DEFAULT_MAX_SECONDS,
|
||||||
DEFAULT_MAX_SINGLE_SECONDS,
|
DEFAULT_MAX_SINGLE_SECONDS,
|
||||||
TEST_COMMAND,
|
TEST_COMMAND,
|
||||||
|
_ci_scale_limit,
|
||||||
check_per_test_speed,
|
check_per_test_speed,
|
||||||
check_speed,
|
check_speed,
|
||||||
cli,
|
cli,
|
||||||
@@ -144,7 +145,26 @@ def test_main_module_block() -> None:
|
|||||||
mock_cli.assert_called_once_with([])
|
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:
|
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.run_tests")
|
||||||
@patch("devx.tools.check_test_speed.parse_duration")
|
@patch("devx.tools.check_test_speed.parse_duration")
|
||||||
@patch("devx.tools.check_test_speed.check_speed")
|
@patch("devx.tools.check_test_speed.check_speed")
|
||||||
@@ -174,6 +194,7 @@ class TestMain:
|
|||||||
mock_parse_per.assert_called_once()
|
mock_parse_per.assert_called_once()
|
||||||
mock_check_per.assert_called_once_with([], DEFAULT_MAX_SINGLE_SECONDS)
|
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.run_tests")
|
||||||
@patch("devx.tools.check_test_speed.parse_duration")
|
@patch("devx.tools.check_test_speed.parse_duration")
|
||||||
def test_slow_total_exits(
|
def test_slow_total_exits(
|
||||||
@@ -189,6 +210,7 @@ class TestMain:
|
|||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
assert "too slow" in result.output.lower()
|
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.run_tests")
|
||||||
@patch("devx.tools.check_test_speed.parse_duration")
|
@patch("devx.tools.check_test_speed.parse_duration")
|
||||||
@patch("devx.tools.check_test_speed.check_speed")
|
@patch("devx.tools.check_test_speed.check_speed")
|
||||||
@@ -213,6 +235,7 @@ class TestMain:
|
|||||||
assert "Per-test speed check FAILED" in result.output
|
assert "Per-test speed check FAILED" in result.output
|
||||||
assert "test_slow" 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")
|
@patch("devx.tools.check_test_speed.run_tests")
|
||||||
def test_parse_failure_exits(
|
def test_parse_failure_exits(
|
||||||
self,
|
self,
|
||||||
@@ -225,6 +248,7 @@ class TestMain:
|
|||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
assert "Could not parse" in result.output
|
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.run_tests")
|
||||||
@patch("devx.tools.check_test_speed.parse_duration")
|
@patch("devx.tools.check_test_speed.parse_duration")
|
||||||
@patch("devx.tools.check_test_speed.check_speed")
|
@patch("devx.tools.check_test_speed.check_speed")
|
||||||
@@ -248,6 +272,7 @@ class TestMain:
|
|||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
mock_check.assert_called_once_with(0.5, 1.5)
|
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.run_tests")
|
||||||
@patch("devx.tools.check_test_speed.parse_duration")
|
@patch("devx.tools.check_test_speed.parse_duration")
|
||||||
@patch("devx.tools.check_test_speed.check_speed")
|
@patch("devx.tools.check_test_speed.check_speed")
|
||||||
@@ -270,6 +295,7 @@ class TestMain:
|
|||||||
mock_parse_per.assert_not_called()
|
mock_parse_per.assert_not_called()
|
||||||
mock_check_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.run_tests")
|
||||||
@patch("devx.tools.check_test_speed.parse_duration")
|
@patch("devx.tools.check_test_speed.parse_duration")
|
||||||
@patch("devx.tools.check_test_speed.check_speed")
|
@patch("devx.tools.check_test_speed.check_speed")
|
||||||
@@ -292,3 +318,32 @@ class TestMain:
|
|||||||
result = runner.invoke(cli, ["--max-single-seconds", "1.0"])
|
result = runner.invoke(cli, ["--max-single-seconds", "1.0"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
mock_check_per.assert_called_once_with([], 1.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)
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ from unittest.mock import MagicMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from devx.gitea_cli import TeaCLI, TeaCLIError, _extract_issue_number, _extract_pr_number, configure_tea_login
|
from devx.gitea_cli import (
|
||||||
|
TeaCLI,
|
||||||
|
TeaCLIError,
|
||||||
|
_extract_issue_number,
|
||||||
|
_extract_pr_number,
|
||||||
|
configure_tea_login,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestExtractIssueNumber:
|
class TestExtractIssueNumber:
|
||||||
@@ -119,6 +125,46 @@ class TestTeaCLIRun:
|
|||||||
cmd = mock_run.call_args[0][0]
|
cmd = mock_run.call_args[0][0]
|
||||||
assert "--output" not in cmd
|
assert "--output" not in cmd
|
||||||
|
|
||||||
|
def test_run_retries_on_502(self) -> None:
|
||||||
|
"""Transient 502 errors should be retried, then succeed."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="", stderr="502 Bad Gateway")
|
||||||
|
success_result = MagicMock(returncode=0, stdout='[{"id": 1}]', stderr="")
|
||||||
|
with patch("subprocess.run", side_effect=[fail_result, success_result]) as mock_run:
|
||||||
|
with patch("tenacity.nap.time.sleep"):
|
||||||
|
output = cli._run(["labels", "list"])
|
||||||
|
assert output == '[{"id": 1}]'
|
||||||
|
assert mock_run.call_count == 2
|
||||||
|
|
||||||
|
def test_run_retries_on_503_then_fails(self) -> None:
|
||||||
|
"""If all retries are exhausted on 503, raise TeaCLIError."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="", stderr="503 Service Unavailable")
|
||||||
|
with patch("subprocess.run", return_value=fail_result):
|
||||||
|
with patch("tenacity.nap.time.sleep"):
|
||||||
|
with pytest.raises(TeaCLIError, match="503"):
|
||||||
|
cli._run(["issues", "create"])
|
||||||
|
# MAX_RETRIES=3, so 3 attempts total
|
||||||
|
|
||||||
|
def test_run_no_retry_on_non_transient_error(self) -> None:
|
||||||
|
"""Non-transient errors (e.g. auth) should fail immediately without retry."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="", stderr="auth error")
|
||||||
|
with patch("subprocess.run", return_value=fail_result) as mock_run:
|
||||||
|
with pytest.raises(TeaCLIError, match="auth error"):
|
||||||
|
cli._run(["labels", "list"])
|
||||||
|
assert mock_run.call_count == 1
|
||||||
|
|
||||||
|
def test_run_retries_on_429_in_stdout(self) -> None:
|
||||||
|
"""429 rate limit in stdout should trigger retry."""
|
||||||
|
cli = TeaCLI(tea_bin="/fake/tea")
|
||||||
|
fail_result = MagicMock(returncode=1, stdout="429 Too Many Requests", stderr="")
|
||||||
|
success_result = MagicMock(returncode=0, stdout="ok", stderr="")
|
||||||
|
with patch("subprocess.run", side_effect=[fail_result, success_result]):
|
||||||
|
with patch("tenacity.nap.time.sleep"):
|
||||||
|
output = cli._run(["releases", "create"])
|
||||||
|
assert output == "ok"
|
||||||
|
|
||||||
|
|
||||||
class TestRepoArg:
|
class TestRepoArg:
|
||||||
def test_with_repo_arg(self) -> None:
|
def test_with_repo_arg(self) -> None:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@@ -47,13 +48,29 @@ class TestDownload:
|
|||||||
def test_download(self, tmp_path: Path) -> None:
|
def test_download(self, tmp_path: Path) -> None:
|
||||||
dest = tmp_path / "file.bin"
|
dest = tmp_path / "file.bin"
|
||||||
|
|
||||||
def _write_file(url: str, path: Path) -> tuple[str, None]:
|
class _FakeResponse:
|
||||||
Path(path).write_bytes(b"data")
|
def __init__(self) -> None:
|
||||||
return str(path), 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)
|
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"
|
assert dest.read_bytes() == b"data"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user