diff --git a/backend/tests/test_env_file.py b/backend/tests/test_env_file.py index dfb333c5d9..aaffd94e4d 100644 --- a/backend/tests/test_env_file.py +++ b/backend/tests/test_env_file.py @@ -19,7 +19,15 @@ ENTRYPOINTS = { def run_startup(tmp_path, entrypoint="config", selector=None, extra_env=None, prelude=""): # Only propagate interpreter necessities, never ambient credentials/config. env = {key: os.environ[key] for key in ("PATH", "SYSTEMROOT") if key in os.environ} - env.update(PYTHONPATH=os.pathsep.join((str(BACKEND), str(BACKEND / "packages/harness"))), AUTH_JWT_SECRET="test-only") + # The stripped env drops the suite's UTF-8 pins (PYTHONUTF8/PYTHONIOENCODING + # from `make test`), so the child's interpreter writes stderr in the host's + # ANSI codepage (cp936 on Chinese Windows) while a UTF-8-mode parent decodes + # it as UTF-8 — the reader thread dies on the first non-ASCII byte and + # stderr comes back None. Pin the child's interpreter to UTF-8 like the + # suite does, and pin the parent's capture explicitly so the round-trip is + # locale-independent even when pytest runs without the Makefile wrapper + # (bare `uv run pytest`, the bug class #6590 eliminated). + env.update(PYTHONPATH=os.pathsep.join((str(BACKEND), str(BACKEND / "packages/harness"))), AUTH_JWT_SECRET="test-only", PYTHONUTF8="1", PYTHONIOENCODING="utf-8") if selector is not None: env["DEER_FLOW_ENV_FILE"] = str(selector) env.update(extra_env or {}) @@ -37,7 +45,7 @@ dotenv.main.find_dotenv = lambda *args, **kwargs: {str(default)!r} {ENTRYPOINTS[entrypoint]} print(json.dumps([os.getenv('ENV_FILE_TEST_VALUE'), os.getenv('ENV_FILE_TEST_DEFAULT_ONLY')])) """ - return subprocess.run([sys.executable, "-c", script], cwd=cwd, env=env, capture_output=True, text=True, timeout=30) + return subprocess.run([sys.executable, "-c", script], cwd=cwd, env=env, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=30) @pytest.mark.parametrize("entrypoint", ENTRYPOINTS) diff --git a/backend/tests/test_jina_retries.py b/backend/tests/test_jina_retries.py index 4a21dad431..9fcdeb18de 100644 --- a/backend/tests/test_jina_retries.py +++ b/backend/tests/test_jina_retries.py @@ -94,7 +94,12 @@ async def test_backoff_jitter_is_capped_by_remaining_budget(requests, monkeypatc assert requests.await_count == 2 sleep.assert_awaited_once() - assert 0 < sleep.await_args.args[0] <= 0.05 + # Tolerance, not an exact bound: deadline = now + budget rounds, so the + # remaining-budget cap can land above the exact 0.05 by ~ulp(loop.time())/4 + # — the error scales with the host's uptime, not with 0.05. A relative + # tolerance covers any realistic uptime while a genuine regression + # overshoots the cap by >= 0.025. + assert 0 < sleep.await_args.args[0] <= 0.05 * (1 + 2**-24) @pytest.mark.parametrize("during_backoff", [False, True])