Skip to content

🧪 [testing improvement] Add comprehensive tests for headless environment detection - #44

Closed
b3nw wants to merge 12 commits into
devfrom
dev-12968995087421801627
Closed

b3nw wants to merge 12 commits into
devfrom
dev-12968995087421801627

Conversation

@b3nw

@b3nw b3nw commented Apr 25, 2026

Copy link
Copy Markdown
Owner

🎯 What: Added a comprehensive test suite for is_headless_environment to address the testing gap.
📊 Coverage: Covered Linux/Unix (DISPLAY), macOS/Windows ignored variables, SSH detection, typical CI environments, specific Windows sessions (SESSIONNAME), and Container environment scenarios. Also tests proper GUI detection logic.
Result: Improved test coverage and enhanced reliability of headless environment detection.


PR created automatically by Jules for task 12968995087421801627 started by @b3nw

b3nw and others added 10 commits April 24, 2026 19:40
…ardization, and utilities

Core infrastructure improvements:
- Smart 'latest' model alias resolution with cost-based tiebreaking
- Standardized error responses with proper HTTP status codes and error.code field
- ProxyExhaustionError for structured credential exhaustion reporting
- TerminalRequestError for non-rotatable errors (404, model not found)
- Per-provider retry count override via MAX_RETRIES_{PROVIDER} env var
- Retry 429 rate_limit errors with backoff instead of rotating
- Cached token pricing in streaming cost calculation
- Split quota stats into current_period and global/lifetime views
- Log rotation for proxy.log and proxy_debug.log (RotatingFileHandler)
- Include latest virtual models in /v1/models endpoint
- Resolve singleton cache pollution for dynamic providers
- Fork-specific README and .gitignore updates
…ased model filtering, and enhanced X-Initiator heuristic
Test suite designed to catch breakage from branch re-organization without
sending queries to real LLM providers. Covers all critical integration
points that previously broke silently during deployment.

Coverage:
- Anthropic↔OpenAI format translation & streaming
- Error classification (determines retry/rotation behavior)
- Request sanitization (prevents 400s from invalid params)
- Provider-specific request transforms
- Model alias & latest registry parsing
- Usage tracking (windows, quota groups, custom caps)
- Credential discovery, deduplication, env:// URI
- Provider plugin registration & singleton pattern
- Proxy endpoint routing & auth

All tests use synthetic credentials and mocked HTTP.
Runs in ~2.3s. Zero API cost.
…flow

Replaces the old manifest-driven multi-branch replay system with a
simpler linear commit stack. Changes are made via fixup!/autosquash.
Upstream syncs are a single git rebase.

Includes:
- AGENTS.md: entry point for all AI coding agents
- .agent/rules/claude.md: Claude-specific SSH/deployment notes
- .agent/rules/llm-proxy.md: container layout and deployment pipeline
- .agent/skills/upstream-sync/SKILL.md: sync workflow reference
Custom provider for Google Vertex AI Express Mode API keys that uses
x-goog-api-key header authentication against the Vertex AI
OpenAI-compatible endpoint. Supports non-streaming and streaming
chat completions with automatic model discovery.

Models are prefixed as vertex/ (e.g. vertex/gemini-3.1-flash-lite-preview).
Env vars: VERTEX_PROJECT, VERTEX_LOCATION, VERTEX_API_KEY_N
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive test suite for the is_headless_environment utility, covering Linux, macOS, Windows, SSH, CI, and container environments. The review feedback focuses on improving maintainability by centralizing environment variable lists into constants and refactoring repetitive Windows session tests into a single parametrized test.

Comment thread tests/test_headless_detection.py Outdated
Comment on lines +13 to +17
for var in [
"DISPLAY", "SSH_CONNECTION", "SSH_CLIENT", "SSH_TTY", "SESSIONNAME",
"CI", "GITHUB_ACTIONS", "GITLAB_CI", "JENKINS_URL", "CIRCLECI",
"TRAVIS", "BUILDKITE", "DRONE", "TEAMCITY_VERSION", "TF_BUILD", "CODEBUILD_BUILD_ID"
]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The list of environment variables is duplicated in multiple places (the clean_env fixture and the parametrization of test_ssh_detection and test_ci_environments). This increases maintenance effort and the risk of tests becoming out of sync with the implementation. Consider defining these lists as constants at the module level and reusing them.

Comment thread tests/test_headless_detection.py Outdated
Comment on lines +57 to +75
def test_windows_headless_services(clean_env):
"""Test Windows with SESSIONNAME=services (headless)."""
with patch("os.name", "nt"), patch("sys.platform", "win32"):
clean_env.setenv("SESSIONNAME", "services")
assert is_headless_environment() is True


def test_windows_headless_rdp(clean_env):
"""Test Windows with SESSIONNAME=rdp-tcp (headless)."""
with patch("os.name", "nt"), patch("sys.platform", "win32"):
clean_env.setenv("SESSIONNAME", "rdp-tcp")
assert is_headless_environment() is True


def test_windows_headless_caps_sessionname(clean_env):
"""Test Windows with capitalized SESSIONNAME=Services (headless)."""
with patch("os.name", "nt"), patch("sys.platform", "win32"):
clean_env.setenv("SESSIONNAME", "Services")
assert is_headless_environment() is True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These three tests for Windows headless sessions can be refactored into a single parametrized test to improve maintainability and readability. Additionally, consider that Windows RDP sessions often include a numeric suffix (e.g., rdp-tcp#0); while the current implementation may not handle this yet, it would be a valuable scenario to support and test in the future.

Suggested change
def test_windows_headless_services(clean_env):
"""Test Windows with SESSIONNAME=services (headless)."""
with patch("os.name", "nt"), patch("sys.platform", "win32"):
clean_env.setenv("SESSIONNAME", "services")
assert is_headless_environment() is True
def test_windows_headless_rdp(clean_env):
"""Test Windows with SESSIONNAME=rdp-tcp (headless)."""
with patch("os.name", "nt"), patch("sys.platform", "win32"):
clean_env.setenv("SESSIONNAME", "rdp-tcp")
assert is_headless_environment() is True
def test_windows_headless_caps_sessionname(clean_env):
"""Test Windows with capitalized SESSIONNAME=Services (headless)."""
with patch("os.name", "nt"), patch("sys.platform", "win32"):
clean_env.setenv("SESSIONNAME", "Services")
assert is_headless_environment() is True
@pytest.mark.parametrize("session", ["services", "Services", "rdp-tcp"])
def test_windows_headless_sessions(clean_env, session):
"""Test Windows headless session detection."""
with patch("os.name", "nt"), patch("sys.platform", "win32"):
clean_env.setenv("SESSIONNAME", session)
assert is_headless_environment() is True

@b3nw

b3nw commented Apr 26, 2026

Copy link
Copy Markdown
Owner Author

[Gemini-CLI Review Skill] @jules Reviewing this PR against the checklist and Gemini Code Assist feedback:

  1. [Gemini Code Assist] Maintainability: Please centralize the list of environment variables used in the clean_env fixture into a module-level constant (e.g., HEADLESS_ENV_VARS). This makes it easier to update if new headless-related variables are added to the implementation.
  2. [Gemini Code Assist] Parametrization: Refactor the repetitive Windows session tests (test_windows_headless_services, test_windows_headless_rdp, test_windows_headless_caps_sessionname) into a single test using @pytest.mark.parametrize.
  3. [Boundary/Edge] OS Name Validation: The test test_ssh_detection patches sys.platform to darwin to avoid the DISPLAY check, but it should also explicitly verify behavior on other platforms if the logic differs (e.g., ensuring SSH_TTY still triggers headless on Linux even if DISPLAY is set).

@google-labs-jules

Copy link
Copy Markdown

[Gemini-CLI Review Skill] @jules Reviewing this PR against the checklist and Gemini Code Assist feedback:

  1. [Gemini Code Assist] Maintainability: Please centralize the list of environment variables used in the clean_env fixture into a module-level constant (e.g., HEADLESS_ENV_VARS). This makes it easier to update if new headless-related variables are added to the implementation.
  2. [Gemini Code Assist] Parametrization: Refactor the repetitive Windows session tests (test_windows_headless_services, test_windows_headless_rdp, test_windows_headless_caps_sessionname) into a single test using @pytest.mark.parametrize.
  3. [Boundary/Edge] OS Name Validation: The test test_ssh_detection patches sys.platform to darwin to avoid the DISPLAY check, but it should also explicitly verify behavior on other platforms if the logic differs (e.g., ensuring SSH_TTY still triggers headless on Linux even if DISPLAY is set).

Thank you for the excellent feedback. I have implemented all three points:

  1. Centralized the environment variables into a HEADLESS_ENV_VARS list.
  2. Refactored the Windows headless session tests into a single parameterized test (test_windows_headless_session).
  3. Updated test_ssh_detection to test Linux where DISPLAY is set, confirming SSH variables override the GUI check, and also explicit macOS testing where DISPLAY is ignored.

@b3nw
b3nw marked this pull request as ready for review April 26, 2026 03:23
@kilo-code-bot

kilo-code-bot Bot commented Apr 26, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

The test suite for is_headless_environment is comprehensive and well-structured.

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0
Files Reviewed (1 file)
  • tests/test_headless_detection.py - No issues found
Test Coverage Summary
Scenario Covered
Linux GUI (DISPLAY set)
Linux headless (no DISPLAY)
Linux headless (empty DISPLAY)
macOS GUI (ignores DISPLAY)
Windows GUI (ignores DISPLAY)
Windows headless sessions
SSH detection (Linux + macOS)
CI environment detection
Container detection

Note: Prior review comments about duplicated environment variables and test parametrization have been addressed in the current version.


Reviewed by minimax-m2.7-20260318 · 200,853 tokens

@b3nw

b3nw commented Apr 26, 2026

Copy link
Copy Markdown
Owner Author

[Gemini-CLI Review Skill] Consolidated into the linear commit stack on dev.

@b3nw b3nw closed this Apr 26, 2026
@google-labs-jules

Copy link
Copy Markdown

[Gemini-CLI Review Skill] Consolidated into the linear commit stack on dev.

Acknowledged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant