mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-06 20:32:12 +00:00
fix: stop eval modules leaking .env into the test process (#1482)
evals/reviewer/{target,run_eval,build_dataset} called load_dotenv() at
import time, so importing them in tests injected the real .env (live
LANGGRAPH_URL, tokens) into the whole pytest process. The slack-context
default-repo tests then reached the real LangGraph store via
get_team_default_repo() and picked up the developer's actual team
default repo, failing in full-suite runs while passing in isolation.
Move load_dotenv() into the CLI entrypoints (all env reads were already
lazy), and patch get_team_default_repo in the two affected tests so they
stay hermetic regardless of environment.
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This commit is contained in:
parent
f539962c73
commit
a9653ca758
4 changed files with 8 additions and 7 deletions
|
|
@ -21,8 +21,6 @@ from pathlib import Path
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from langsmith import Client
|
from langsmith import Client
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
GOLDENS_DIR = Path(__file__).parent / "golden_comments"
|
GOLDENS_DIR = Path(__file__).parent / "golden_comments"
|
||||||
PR_URL_RE = re.compile(r"github\.com/([^/]+)/([^/]+)/pull/(\d+)")
|
PR_URL_RE = re.compile(r"github\.com/([^/]+)/([^/]+)/pull/(\d+)")
|
||||||
|
|
||||||
|
|
@ -115,6 +113,7 @@ def upload(dataset_name: str, examples: list[dict]) -> None:
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
load_dotenv()
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument("--dataset-name", default="openswe-reviewer-v1")
|
ap.add_argument("--dataset-name", default="openswe-reviewer-v1")
|
||||||
ap.add_argument("--dry-run", action="store_true", help="Build examples but don't upload.")
|
ap.add_argument("--dry-run", action="store_true", help="Build examples but don't upload.")
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ from langsmith.schemas import Example
|
||||||
from evals.reviewer.judge import aggregate_pr, judge_match
|
from evals.reviewer.judge import aggregate_pr, judge_match
|
||||||
from evals.reviewer.target import drain_thread_ids, get_langgraph_url, review_pr
|
from evals.reviewer.target import drain_thread_ids, get_langgraph_url, review_pr
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONFIG_PATH = Path(__file__).with_name("config.toml")
|
CONFIG_PATH = Path(__file__).with_name("config.toml")
|
||||||
|
|
@ -127,6 +125,7 @@ async def _cleanup_threads(thread_ids: Iterable[str]) -> None:
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
|
load_dotenv()
|
||||||
config = _load_config()
|
config = _load_config()
|
||||||
_apply_config_to_env(config)
|
_apply_config_to_env(config)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,10 @@ import os
|
||||||
import threading
|
import threading
|
||||||
from typing import Any, Literal, cast
|
from typing import Any, Literal, cast
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
from langgraph_sdk import get_client
|
from langgraph_sdk import get_client
|
||||||
|
|
||||||
from agent.reviewer_findings import Finding, Severity, filter_findings_for_publish
|
from agent.reviewer_findings import Finding, Severity, filter_findings_for_publish
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
DEFAULT_REVIEWER_ASSISTANT_ID = "reviewer"
|
DEFAULT_REVIEWER_ASSISTANT_ID = "reviewer"
|
||||||
DEFAULT_LANGGRAPH_URL = "http://localhost:2024"
|
DEFAULT_LANGGRAPH_URL = "http://localhost:2024"
|
||||||
ScoreMode = Literal["all_findings", "surfaced_findings"]
|
ScoreMode = Literal["all_findings", "surfaced_findings"]
|
||||||
|
|
|
||||||
|
|
@ -323,12 +323,17 @@ def test_get_slack_repo_config_uses_existing_thread_repo(
|
||||||
assert not posted
|
assert not posted
|
||||||
|
|
||||||
|
|
||||||
|
async def _no_team_default_repo() -> dict[str, str] | None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def test_get_slack_repo_config_new_thread_uses_default(
|
def test_get_slack_repo_config_new_thread_uses_default(
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
) -> None:
|
) -> None:
|
||||||
threads_client = _FakeThreadsClient(raise_not_found=True)
|
threads_client = _FakeThreadsClient(raise_not_found=True)
|
||||||
monkeypatch.setattr(webapp, "SLACK_REPO_OWNER", "default-owner")
|
monkeypatch.setattr(webapp, "SLACK_REPO_OWNER", "default-owner")
|
||||||
monkeypatch.setattr(webapp, "SLACK_REPO_NAME", "default-repo")
|
monkeypatch.setattr(webapp, "SLACK_REPO_NAME", "default-repo")
|
||||||
|
monkeypatch.setattr(webapp, "get_team_default_repo", _no_team_default_repo)
|
||||||
|
|
||||||
monkeypatch.setattr(webapp, "get_client", lambda url: _FakeClient(threads_client))
|
monkeypatch.setattr(webapp, "get_client", lambda url: _FakeClient(threads_client))
|
||||||
|
|
||||||
|
|
@ -343,6 +348,7 @@ def test_get_slack_repo_config_existing_thread_without_repo_uses_default(
|
||||||
threads_client = _FakeThreadsClient(thread={"metadata": {}})
|
threads_client = _FakeThreadsClient(thread={"metadata": {}})
|
||||||
monkeypatch.setattr(webapp, "SLACK_REPO_OWNER", "default-owner")
|
monkeypatch.setattr(webapp, "SLACK_REPO_OWNER", "default-owner")
|
||||||
monkeypatch.setattr(webapp, "SLACK_REPO_NAME", "default-repo")
|
monkeypatch.setattr(webapp, "SLACK_REPO_NAME", "default-repo")
|
||||||
|
monkeypatch.setattr(webapp, "get_team_default_repo", _no_team_default_repo)
|
||||||
|
|
||||||
monkeypatch.setattr(webapp, "get_client", lambda url: _FakeClient(threads_client))
|
monkeypatch.setattr(webapp, "get_client", lambda url: _FakeClient(threads_client))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue