litellm/tests/e2e_harness/cli_harness/test_lockdown.py
ryan-crabbe-berri 3af23024bc
test(e2e): share the coding-CLI harness between suites (#49370)
* test(e2e): share the CLI version rule, env lockdown and rate limiter in tests/e2e/cli_harness

Moves the npm release rule (now taking the package name), the env allowlist plus fresh HOME, and the per-upstream rate limiter out of claude_code so the Codex suite can reuse them. Claude Code behavior is unchanged, its CI, cron and Dockerfile paths now call the shared resolver with @anthropic-ai/claude-code

* test(e2e): freeze the packument map and note the rate limiter self-test

* test(e2e): race real processes on one rate limiter bucket so a missing lock fails

Eight spawned processes start together and drain a bucket that never refills. With the flock they get exactly its burst between them, without it every attempt is granted

* test(e2e): keep the old Claude Code version resolver path for the Buildkite runner images

The runner Dockerfiles still run tests/e2e/claude_code/pr_gate_version_resolver.py and silently install @latest when it is missing, which drops the three day review window. The old path now forwards to cli_harness/npm_version_resolver.py
2026-11-02 13:50:56 -08:00

32 lines
1,022 B
Python

from __future__ import annotations
from pathlib import Path
from typing import Final
from cli_harness.lockdown import isolated_home, locked_down_env
RUNNER_ENV: Final = {
"PATH": "/usr/bin",
"LANG": "C.UTF-8",
"HOME": "/home/runner",
"OPENAI_API_KEY": "sk-runner-secret",
"AWS_SECRET_ACCESS_KEY": "runner-aws-secret",
"DATABASE_URL": "postgresql://runner",
}
def test_cli_sees_runtime_vars_and_its_overrides_but_no_runner_credentials(tmp_path: Path) -> None:
env: Final = locked_down_env(home=tmp_path, overrides={"OPENAI_BASE_URL": "http://gateway"}, source=RUNNER_ENV)
assert dict(env) == {
"PATH": "/usr/bin",
"LANG": "C.UTF-8",
"HOME": str(tmp_path),
"OPENAI_BASE_URL": "http://gateway",
}
def test_isolated_home_starts_empty_and_is_gone_after_the_cli_exits() -> None:
with isolated_home("cli-harness-test-") as home:
assert home.is_dir() and not any(home.iterdir())
(home / ".config").mkdir()
assert not home.exists()