Skip to content

refactor(e2e): unify RouterInstance into Gateway class, split conftest.py into modular fixtures#16671

Merged
slin1237 merged 1 commit intomainfrom
smg-ci-n/18
Jan 7, 2026
Merged

refactor(e2e): unify RouterInstance into Gateway class, split conftest.py into modular fixtures#16671
slin1237 merged 1 commit intomainfrom
smg-ci-n/18

Conversation

@slin1237
Copy link
Copy Markdown
Collaborator

@slin1237 slin1237 commented Jan 7, 2026

Add cloud mode support to Gateway class and remove the duplicate RouterInstance dataclass from backends.py. The Gateway class now supports four modes:

  1. Regular mode: worker URLs + model path
  2. PD mode: prefill/decode workers
  3. IGW mode: empty start, add workers via API
  4. Cloud mode: OpenAI/xAI runtimes

Also clarify the distinction between:

  • Cloud runtimes: Where models run (openai, xai)
  • History backends: Gateway plugin for storage (memory, oracle)

Backward compatibility maintained for e2e_response_api migration.

Split the 1056-line conftest.py into focused modules:

  • conftest.py (192 lines): Path setup, logging, imports
  • fixtures/hooks.py (358 lines): Pytest collection hooks, GPU validation
  • fixtures/pool.py (194 lines): Model pool fixtures
  • fixtures/setup_backend.py (401 lines): Backend setup fixtures
  • fixtures/markers.py (57 lines): Marker helper utilities

Also marked legacy fixtures (ports.py, router_manager.py) as deprecated for removal during e2e_response_api migration.

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments (/tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci) or contact authorized users to do so.
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @slin1237, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the end-to-end (e2e) testing infrastructure by centralizing router management within an enhanced Gateway class and modularizing pytest fixtures. The changes aim to improve the clarity, maintainability, and extensibility of the test suite, particularly in how different backend types, including new cloud-based runtimes, are configured and managed. This sets a clearer architectural foundation for future development and testing efforts.

Highlights

  • Gateway Class Unification: The RouterInstance dataclass has been removed, and its functionality, including support for cloud API backends (OpenAI, xAI), has been integrated directly into the Gateway class. This centralizes router management and simplifies the e2e testing infrastructure.
  • Modularization of Pytest Fixtures: The monolithic conftest.py file (previously 1056 lines) has been refactored and split into several focused modules within a new fixtures/ package. This improves organization, readability, and maintainability of e2e test setup.
  • Enhanced Gateway Modes: The Gateway class now explicitly supports four operational modes: Regular, PD (Prefill/Decode), IGW (empty start, add workers via API), and a newly added Cloud mode for OpenAI/xAI runtimes.
  • Clarified Backend Terminology: The distinction between 'Cloud runtimes' (where models execute, e.g., OpenAI, xAI) and 'History backends' (for conversation storage, e.g., memory, Oracle) has been clarified, emphasizing their orthogonal nature.
  • Deprecation of Legacy Fixtures: Legacy fixture modules ports.py and router_manager.py have been marked as deprecated, with plans for their removal during the ongoing e2e_response_api migration, promoting the use of the new infra.Gateway and infra.get_open_port().

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that significantly refactors and improves the e2e test infrastructure. Unifying RouterInstance into the Gateway class and splitting the large conftest.py into modular fixtures are great steps towards better maintainability and readability. The addition of cloud mode to the Gateway class is also a valuable enhancement. I've provided a couple of suggestions to further improve the code. One addresses repetitive logic in the Gateway class for handling cloud providers, and the other fixes an inconsistency in the return value of the setup_backend fixture, which could cause test failures. Overall, this is a high-quality contribution.

Comment thread sgl-model-gateway/e2e_test/fixtures/setup_backend.py Outdated
Comment on lines +229 to +244
if cloud_backend == "openai":
worker_url = "https://api.openai.com"
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
raise ValueError("OPENAI_API_KEY environment variable required")
self._env = os.environ.copy()
self._env["OPENAI_API_KEY"] = api_key
elif cloud_backend == "xai":
worker_url = "https://api.x.ai"
api_key = os.environ.get("XAI_API_KEY")
if not api_key:
raise ValueError("XAI_API_KEY environment variable required")
self._env = os.environ.copy()
self._env["XAI_API_KEY"] = api_key
else:
raise ValueError(f"Unsupported cloud backend: {cloud_backend}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This block contains repetitive logic for handling different cloud backends. It can be refactored to be more DRY by using a configuration dictionary. This will make it easier to add or modify cloud backends in the future.

            provider_configs = {
                "openai": {
                    "worker_url": "https://api.openai.com",
                    "api_key_env": "OPENAI_API_KEY",
                },
                "xai": {
                    "worker_url": "https://api.x.ai",
                    "api_key_env": "XAI_API_KEY",
                },
            }

            if cloud_backend not in provider_configs:
                raise ValueError(f"Unsupported cloud backend: {cloud_backend}")

            config = provider_configs[cloud_backend]
            worker_url = config["worker_url"]
            api_key_env = config["api_key_env"]

            api_key = os.environ.get(api_key_env)
            if not api_key:
                raise ValueError(f"{api_key_env} environment variable required")

            self._env = os.environ.copy()
            self._env[api_key_env] = api_key

…t.py into modular fixtures

Add cloud mode support to Gateway class and remove the duplicate
RouterInstance dataclass from backends.py. The Gateway class now
supports four modes:
1. Regular mode: worker URLs + model path
2. PD mode: prefill/decode workers
3. IGW mode: empty start, add workers via API
4. Cloud mode: OpenAI/xAI runtimes

Also clarify the distinction between:
- Cloud runtimes: Where models run (openai, xai)
- History backends: Gateway plugin for storage (memory, oracle)

Backward compatibility maintained for e2e_response_api migration.

Split the 1056-line conftest.py into focused modules:
- conftest.py (192 lines): Path setup, logging, imports
- fixtures/hooks.py (358 lines): Pytest collection hooks, GPU validation
- fixtures/pool.py (194 lines): Model pool fixtures
- fixtures/setup_backend.py (401 lines): Backend setup fixtures
- fixtures/markers.py (57 lines): Marker helper utilities

Also marked legacy fixtures (ports.py, router_manager.py) as deprecated
for removal during e2e_response_api migration.
@slin1237 slin1237 merged commit c356ed0 into main Jan 7, 2026
63 checks passed
@slin1237 slin1237 deleted the smg-ci-n/18 branch January 7, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant