Skip to content

refactor(e2e): simplify test helpers and fix redundant HF_HOME env passing - #688

Merged
slin1237 merged 1 commit into
mainfrom
refactor/e2e-simplify-test-helpers
Mar 10, 2026
Merged

slin1237 merged 1 commit into
mainfrom
refactor/e2e-simplify-test-helpers

Conversation

@slin1237

@slin1237 slin1237 commented Mar 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up cleanup to #686. Simplifies e2e test code by extracting a shared helper, fixing a redundant Docker env-var pass, and removing a dead code guard.

What changed

  • e2e_test/realtime/test_realtime_ws.py: Extracted _make_user_message(text) helper to replace 7 identical copy-pasted conversation.item.create dict structures (~70 lines removed).
  • e2e_test/benchmarks/conftest.py:64: Removed "HF_HOME" from the env-var pass-through tuple. The HF cache mount block on line 61 already explicitly passes -e HF_HOME={hf_home} when the directory exists, so the loop entry was redundant and could theoretically set a conflicting value.
  • e2e_test/benchmarks/conftest.py:154: Simplified getattr(p, "proc", p) if hasattr(p, "proc") else p to getattr(p, "proc", p) — the hasattr guard was redundant since getattr with a default already handles the missing attribute case.

Why

Reduces copy-paste boilerplate in the realtime WebSocket tests and fixes a minor correctness issue where HF_HOME could be passed twice to Docker with potentially different values.

How

  • Added a _make_user_message(text) helper that wraps the conversation.item.create event structure, then replaced all 7 inline usages.
  • Narrowed the env-var pass-through tuple from ("HF_TOKEN", "HF_HOME") to ("HF_TOKEN",).
  • Removed the redundant hasattr check before getattr with a default value.

Test plan

  • python3 -c "import ast; ast.parse(open('e2e_test/realtime/test_realtime_ws.py').read())" — syntax OK
  • python3 -c "import ast; ast.parse(open('e2e_test/benchmarks/conftest.py').read())" — syntax OK
  • Realtime WebSocket tests remain functionally identical (helper produces the same JSON)
  • Benchmark container env setup unchanged for HF_TOKEN; HF_HOME still passed via the explicit mount block

Refs: #686

Summary by CodeRabbit

Release Notes

  • Tests
    • Improved benchmark test environment handling for Docker runs (reduced forwarded variables).
    • Reorganized realtime WebSocket tests to use a centralized helper for constructing user message payloads, improving test clarity and maintainability.

@github-actions github-actions Bot added the tests Test changes label Mar 10, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 focuses on refining and simplifying the end-to-end test suite. It streamlines test code by introducing a shared helper function, corrects an issue with redundant environment variable passing in Docker, and removes unnecessary code logic, ultimately improving maintainability and clarity of the test infrastructure.

Highlights

  • Test Helper Extraction: A new _make_user_message helper was extracted in e2e_test/realtime/test_realtime_ws.py to replace repetitive conversation.item.create dict structures, removing approximately 70 lines of boilerplate.
  • Environment Variable Handling: The HF_HOME environment variable was removed from the Docker env-var pass-through in e2e_test/benchmarks/conftest.py as it was redundant and could lead to conflicting values due to an existing explicit mount block.
  • Code Simplification: A redundant hasattr guard was removed from a getattr call in e2e_test/benchmarks/conftest.py, simplifying the code as getattr with a default value already handles missing attributes.
Changelog
  • e2e_test/benchmarks/conftest.py
    • Removed "HF_HOME" from the tuple of environment variables explicitly passed to Docker containers, as it was already handled by a separate mount block.
    • Simplified a getattr call by removing a redundant hasattr check, relying on getattr's default value functionality.
  • e2e_test/realtime/test_realtime_ws.py
    • Added a new helper function _make_user_message to encapsulate the creation of conversation.item.create events for user text messages.
    • Replaced multiple instances of verbose inline _make_event calls with the new _make_user_message helper, significantly reducing code duplication.
Activity
  • No human activity has been recorded on this pull request since its creation.
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. ↩

@coderabbitai

coderabbitai Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6a09493e-faf3-45cd-b44e-620673c4c14f

📥 Commits

Reviewing files that changed from the base of the PR and between b373337 and 7ba8106.

📒 Files selected for processing (2)
  • e2e_test/benchmarks/conftest.py
  • e2e_test/realtime/test_realtime_ws.py

📝 Walkthrough

Walkthrough

HF_HOME is no longer forwarded into the Docker test container and proc cleanup code is simplified in benchmark setup; realtime WebSocket tests consolidate repeated user-message payloads into a new _make_user_message helper.

Changes

Cohort / File(s) Summary
Benchmark Configuration
e2e_test/benchmarks/conftest.py
Stop forwarding HF_HOME into the Docker container while still forwarding HF_TOKEN when present. Simplified _cleanup_procs to use getattr(p, "proc", p) unconditionally.
Realtime WebSocket Tests
e2e_test/realtime/test_realtime_ws.py
Added module-level helper _make_user_message(text: str) and replaced multiple inline conversation.item.create payload constructions with calls to this helper. No change to event structure or handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • CatherineSue
  • key4ng
  • XinyueZhang369

Poem

🐇 I hopped through tests with nimble feet,

Docker homes made tidy, cleanup neat,
One helper now crafts each user line,
Small refactors, oh how they shine,
A rabbit's cheer for tests so sweet.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main refactoring changes: introducing a shared helper function and fixing redundant environment variable passing in e2e tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/e2e-simplify-test-helpers

Comment @coderabbitai help to get the list of available commands and usage tips.

…ssing

- Extract _make_user_message() helper in test_realtime_ws.py to replace
  7 copy-pasted conversation.item.create dict structures, reducing ~70
  lines of boilerplate
- Remove "HF_HOME" from the env-var pass-through tuple in
  benchmarks/conftest.py — it was already explicitly set on line 61 when
  mounting the HF cache directory, causing the variable to be passed
  twice to Docker
- Simplify redundant hasattr+getattr guard in _cleanup_procs() to plain
  getattr with default, since getattr(p, "proc", p) already handles the
  missing attribute case

Refs: #686
Signed-off-by: Simo Lin <linsimo.mark@gmail.com>
@slin1237
slin1237 force-pushed the refactor/e2e-simplify-test-helpers branch from b373337 to 7ba8106 Compare March 10, 2026 00:13

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

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.

Code Review

This pull request introduces several good refactorings that simplify the e2e test code and fix a minor correctness issue. Extracting the _make_user_message helper in test_realtime_ws.py significantly reduces code duplication. The fixes in conftest.py for the redundant HF_HOME environment variable and the unnecessary hasattr check are also clean and correct. I have one suggestion to further improve the new helper function by using constants for protocol strings to enhance maintainability.

Comment thread e2e_test/realtime/test_realtime_ws.py
@slin1237
slin1237 merged commit 1272c6f into main Mar 10, 2026
27 checks passed
@slin1237
slin1237 deleted the refactor/e2e-simplify-test-helpers branch March 10, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant