Skip to content

feat(tests): make integration test providers configurable via env vars#1494

Merged
MuncleUscles merged 3 commits intogenlayerlabs:mainfrom
Ridwannurudeen:fix/340-configurable-test-providers
Mar 27, 2026
Merged

feat(tests): make integration test providers configurable via env vars#1494
MuncleUscles merged 3 commits intogenlayerlabs:mainfrom
Ridwannurudeen:fix/340-configurable-test-providers

Conversation

@Ridwannurudeen
Copy link
Copy Markdown
Contributor

@Ridwannurudeen Ridwannurudeen commented Feb 27, 2026

Summary

Closes #340.

Providers and models in tests/integration/icontracts/conftest.py were hardcoded, making it impossible to run the backend e2e tests against a different LLM provider (e.g. local Ollama) without editing source files.

This PR introduces two helper functions — get_provider_config() and get_mock_provider_config() — that read provider settings from environment variables while preserving the existing defaults:

Non-mock mode (TEST_WITH_MOCK_LLMS not set):

Env var Default
TEST_PROVIDER openai
TEST_PROVIDER_MODEL gpt-4o

Mock mode (TEST_WITH_MOCK_LLMS=true):

Env var Default
TEST_MOCK_PROVIDER openrouter
TEST_MOCK_MODEL @preset/rally-testnet-gpt-5-1
TEST_MOCK_API_KEY_ENV_VAR OPENROUTERAPIKEY
TEST_MOCK_API_URL https://openrouter.ai/api

Example — run tests with local Ollama

TEST_PROVIDER=ollama TEST_PROVIDER_MODEL=llama3 pytest tests/integration/icontracts/

Test plan

  • All existing tests pass unmodified (defaults are identical to the previous hardcoded values)
  • Setting TEST_PROVIDER=ollama TEST_PROVIDER_MODEL=llama3 creates validators with the specified provider
  • Setting TEST_MOCK_PROVIDER / TEST_MOCK_MODEL in mock mode uses the overridden values

Summary by CodeRabbit

  • Tests
    • Integration tests now read provider/model and mock settings from environment variables instead of hardcoded values.
    • Added configurable mock settings (provider, model, API endpoint, API key env var) for mock and non-mock runs.
    • New helper utilities surface configuration for tests.
    • Test setup gained type annotations and docstrings for clarity.
    • Created test resources are tracked during setup and reliably cleaned up after tests.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 27, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds environment-driven provider configuration to integration tests by introducing get_provider_config() and get_mock_provider_config(). setup_validators() now chooses mock vs non-mock flows via these helpers, uses configured provider/model, tracks created validator addresses for cleanup, and adds type annotations and docstrings. (≈34 words)

Changes

Cohort / File(s) Summary
Test Configuration
tests/integration/icontracts/conftest.py
Added get_provider_config() and get_mock_provider_config() to read provider/model/api settings from environment variables; updated setup_validators() to use these helpers for mock and non-mock flows, replaced hardcoded provider/model strings, appended created validator addresses for cleanup, and introduced type annotations and docstrings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

run-tests

Suggested reviewers

  • cristiam86

Poem

🐰 I hopped through envvars, nibbling hardcoded lines,
Now providers dance where configuration shines.
Validators planted, each address I keep,
I tidy the garden before tests go to sleep.
Hooray — a clean run, and then I leap!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: making integration test providers configurable via environment variables, which aligns with the core objective of the PR.
Description check ✅ Passed The PR description comprehensively covers the What, Why, and Testing plan sections with clear examples and environment variable documentation, though formal Checks and Reviewing tips sections are incomplete.
Linked Issues check ✅ Passed The changes fully address issue #340 requirements: providers are no longer hardcoded, configurable defaults are preserved via env vars, and alternative providers like Ollama can be used without editing source files.
Out of Scope Changes check ✅ Passed All changes are directly scoped to making integration test providers configurable; no unrelated modifications are present in the conftest.py file.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Tip

You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting to assertive to make CodeRabbit's nitpick more issues in your PRs.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration/icontracts/conftest.py`:
- Around line 14-15: Replace all EN DASH characters (U+2013) in the docstrings
with standard hyphen-minus '-' to satisfy Ruff RUF002; specifically update the
occurrences in the docstring lines that read "TEST_PROVIDER – provider name 
(default: openai)", "TEST_PROVIDER_MODEL  – model name     (default: gpt-4o)"
and the later docstring lines (the other four instances) so they use "-" instead
of "–". Ensure only the punctuation is changed and spacing remains consistent so
tests and linting pass.
- Around line 9-23: Add explicit return type annotations to the config helper
functions: annotate get_provider_config and get_mock_provider_config to return a
mapping of string keys to string values (e.g., Dict[str, str] or Mapping[str,
str]); also add the necessary typing import (from typing import Dict or Mapping)
at the top of the file so the annotations are valid. Ensure the function
signatures (get_provider_config and get_mock_provider_config) include these
return types and that the returned dict shapes remain unchanged.
- Around line 79-87: The test currently always requests creation of 5 validators
via post_request_localhost(payload("sim_createRandomValidators", 5, ...)) even
when existing_validators already has some entries; change the logic to compute
missing = max(0, 5 - len(existing_validators)) and only call
post_request_localhost when missing > 0, passing missing instead of the
hardcoded 5; update any surrounding non-mock check so this applies only in the
non-mock branch and keep references to existing_validators,
post_request_localhost, payload, and "sim_createRandomValidators" to locate the
code.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2beab08 and b771000.

📒 Files selected for processing (1)
  • tests/integration/icontracts/conftest.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration/icontracts/conftest.py`:
- Around line 129-131: In pytest_configure
(tests/integration/icontracts/conftest.py) change the load_dotenv call to not
overwrite existing environment variables: replace load_dotenv(override=True)
with load_dotenv(override=False) so CLI/CI-provided TEST_* and other env vars
keep precedence; verify the pytest_configure function still runs at session
start and loads .env only for missing keys.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f31e52 and b13775a.

📒 Files selected for processing (1)
  • tests/integration/icontracts/conftest.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration/icontracts/conftest.py`:
- Around line 48-50: Update the docstring for the pytest fixture in conftest.py
that currently says "exactly 5 validators" to accurately reflect its behavior:
indicate it tops up to 5 validators (e.g., "ensures at least 5 validators by
topping up to 5" or "provisions up to 5 additional validators to reach 5 total")
rather than guaranteeing exactly five; modify the text surrounding the phrase
"exactly 5 validators" in that fixture's docstring to match the topping-up logic
implemented in the fixture.
- Around line 81-82: The code currently replaces any falsy mock_response with {}
by using "mock_response if mock_response else {}", which discards intentional
falsy values like "", 0, False, or [], so change the conditional to only treat
None as missing (e.g., use "mock_response if mock_response is not None else {}")
so that explicit falsy responses are preserved; update the expression that
builds the dict entry for "mock_response" accordingly where the dict is created.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b13775a and b33511b.

📒 Files selected for processing (1)
  • tests/integration/icontracts/conftest.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/integration/icontracts/conftest.py (1)

123-126: Consider case-insensitive comparison for the mock mode check.

The current check requires exactly "true" (lowercase). Users might set TEST_WITH_MOCK_LLMS=True or TRUE, which would unexpectedly disable mock mode.

♻️ Suggested improvement
 def mock_llms() -> bool:
     """Return True when mock LLM mode is enabled via TEST_WITH_MOCK_LLMS=true."""
     env_var = os.getenv("TEST_WITH_MOCK_LLMS", "false")  # default no mocking
-    return env_var == "true"
+    return env_var.lower() == "true"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/icontracts/conftest.py` around lines 123 - 126, The
mock_llms function currently compares os.getenv("TEST_WITH_MOCK_LLMS", "false")
to the literal "true" which is case-sensitive; change the comparison to be
case-insensitive (e.g., call .lower() or .casefold() on the env_var before
comparing) so values like "True", "TRUE", or "true" enable mock mode; update the
mock_llms function to use the case-normalized env var when returning the
boolean.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/integration/icontracts/conftest.py`:
- Around line 123-126: The mock_llms function currently compares
os.getenv("TEST_WITH_MOCK_LLMS", "false") to the literal "true" which is
case-sensitive; change the comparison to be case-insensitive (e.g., call
.lower() or .casefold() on the env_var before comparing) so values like "True",
"TRUE", or "true" enable mock mode; update the mock_llms function to use the
case-normalized env var when returning the boolean.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b33511b and 9c6876e.

📒 Files selected for processing (1)
  • tests/integration/icontracts/conftest.py

Providers and models were hardcoded in conftest.py, making it
impossible to run the backend e2e tests against a different LLM
provider (e.g. local Ollama) without editing source files.

Introduces two helper functions that read provider settings from
environment variables with the same defaults that were previously
hardcoded:

  Non-mock mode (TEST_WITH_MOCK_LLMS != true):
    TEST_PROVIDER        – provider name  (default: openai)
    TEST_PROVIDER_MODEL  – model name     (default: gpt-4o)

  Mock mode (TEST_WITH_MOCK_LLMS=true):
    TEST_MOCK_PROVIDER         (default: openrouter)
    TEST_MOCK_MODEL            (default: @preset/rally-testnet-gpt-5-1)
    TEST_MOCK_API_KEY_ENV_VAR  (default: OPENROUTERAPIKEY)
    TEST_MOCK_API_URL          (default: https://openrouter.ai/api)

Closes genlayerlabs#340
- Add return type annotations to all functions (dict[str, str], bool,
  None) and import Any for dynamic-typed parameters
- Replace EN dash characters with hyphen-minus in docstrings (Ruff RUF002)
- Create only the missing validators in non-mock mode instead of always
  requesting 5, preventing over-provisioning
@Ridwannurudeen Ridwannurudeen force-pushed the fix/340-configurable-test-providers branch from 7e840a8 to 34d75ab Compare March 16, 2026 12:01
@Ridwannurudeen
Copy link
Copy Markdown
Contributor Author

Rebased on latest main to resolve the merge conflict — no code changes, just a rebase. Could you re-approve when you get a chance? Thanks!

- mock_llms(): use .lower() so TRUE/True/true all work
- mock_response: use `is not None` to preserve intentional falsy values
@MuncleUscles MuncleUscles merged commit 29a7223 into genlayerlabs:main Mar 27, 2026
1 check passed
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.112.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIM-BE-Allow configuring backend e2e tests with different providers

3 participants