Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ymir/agents/tests/e2e/backport_agent/test_backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _load_test_cases(fixtures_dir: str | Path) -> list[BackportAgentTestCase]:
return cases


test_cases = _load_test_cases(os.getenv("BACKPORT_MOCK_REPOS_DIR", str(DEFAULT_FIXTURES_DIR)))
test_cases = _load_test_cases(os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR))

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

Instead of repeating the environment variable lookup and fallback logic across multiple functions, define a single module-level FIXTURES_DIR constant. Additionally, add a defensive check to ensure the directory exists, preventing silent test collection failures or empty test runs if the environment variable is misconfigured.

FIXTURES_DIR = Path(os.getenv("BACKPORT_MOCK_REPOS_DIR") or DEFAULT_FIXTURES_DIR)
if not FIXTURES_DIR.is_dir():
    raise FileNotFoundError(f"Fixtures directory not found: {FIXTURES_DIR}")

test_cases = _load_test_cases(FIXTURES_DIR)

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

Since _load_test_cases accepts both str and Path objects, and DEFAULT_FIXTURES_DIR is already defined as a Path object, the str() conversion is redundant. We can simplify this expression by passing DEFAULT_FIXTURES_DIR directly.

Suggested change
test_cases = _load_test_cases(os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR))
test_cases = _load_test_cases(os.getenv("BACKPORT_MOCK_REPOS_DIR") or DEFAULT_FIXTURES_DIR)



_span_processor = None
Expand Down Expand Up @@ -131,7 +131,7 @@ def mock_centos_stream_repos():
Yields:
Control to the test session after repos are prepared.
"""
fixtures_dir = os.getenv("BACKPORT_MOCK_REPOS_DIR", str(DEFAULT_FIXTURES_DIR))
fixtures_dir = os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR)

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

Use the module-level FIXTURES_DIR constant to avoid redundant environment variable lookups and ensure consistency.

Suggested change
fixtures_dir = os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR)
fixtures_dir = FIXTURES_DIR

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

Similarly, fixtures_dir is passed to load_all_fixture_configs, which accepts str | Path. Since DEFAULT_FIXTURES_DIR is already a Path object, we can avoid the redundant str() conversion here as well.

Suggested change
fixtures_dir = os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR)
fixtures_dir = os.getenv("BACKPORT_MOCK_REPOS_DIR") or DEFAULT_FIXTURES_DIR

configs = load_all_fixture_configs(fixtures_dir)

if SHARED_BARE_REPOS_DIR.exists():
Expand Down Expand Up @@ -166,7 +166,7 @@ def _load_reference_patch(test_case: "BackportAgentTestCase") -> str | None:
ref_patch_rel = test_case.expected.get("reference_patch")
if not ref_patch_rel:
return None
fixtures_dir = Path(os.getenv("BACKPORT_MOCK_REPOS_DIR", str(DEFAULT_FIXTURES_DIR)))
fixtures_dir = Path(os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR))

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

Use the module-level FIXTURES_DIR constant to avoid redundant environment variable lookups and ensure consistency.

Suggested change
fixtures_dir = Path(os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR))
fixtures_dir = FIXTURES_DIR

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

Here, converting DEFAULT_FIXTURES_DIR (which is already a Path object) to a string only to wrap it back in Path() is redundant. We can pass DEFAULT_FIXTURES_DIR directly to Path().

Suggested change
fixtures_dir = Path(os.getenv("BACKPORT_MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR))
fixtures_dir = Path(os.getenv("BACKPORT_MOCK_REPOS_DIR") or DEFAULT_FIXTURES_DIR)

ref_patch_path = fixtures_dir / ref_patch_rel
if ref_patch_path.is_file():
return ref_patch_path.read_text()
Expand Down
12 changes: 12 additions & 0 deletions ymir/agents/tests/e2e/mock_repos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ Clone the repository and set `MOCK_REPOS_HOST` in your `.env`:
MOCK_REPOS_HOST=/path/to/testing-jiras/mock_data
```

It is recommended to run the E2E tests via compose.

You can also symlink the `mock_data/` subdirectories here for running tests on the host:

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

The instruction says "symlink the mock_data/ subdirectories here", but the commands provided use relative paths from the repository root (e.g., ymir/agents/tests/e2e/mock_repos/triage). If a user runs these commands while inside this directory, the symlinks will be created incorrectly or fail.\n\nIt would be clearer to specify that these commands should be run from the repository root.

Suggested change
You can also symlink the `mock_data/` subdirectories here for running tests on the host:
You can also symlink the `mock_data/` subdirectories to this directory (run from the repository root) for running tests on the host:

```bash
ln -s /path/to/testing-jiras/mock_data/triage ymir/agents/tests/e2e/mock_repos/triage
ln -s /path/to/testing-jiras/mock_data/backport ymir/agents/tests/e2e/mock_repos/backport
```

> **Note:** Symlinks only work when running tests on the host. Podman bind
> mounts do not follow symlinks pointing outside the mounted tree, so
> containerized e2e tests require the compose-based approach.

This mounts the fixture data into E2E test containers at `/home/beeai/mock_repos/`.
The compose services set `MOCK_REPOS_DIR` and `BACKPORT_MOCK_REPOS_DIR` to point
at the `triage/` and `backport/` subdirectories respectively.
Expand Down
2 changes: 1 addition & 1 deletion ymir/agents/tests/e2e/test_triage.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def mock_centos_stream_repos(tmp_path_factory):
Yields:
Control to the test session after repos are prepared.
"""
fixtures_dir = os.getenv("MOCK_REPOS_DIR", str(DEFAULT_FIXTURES_DIR))
fixtures_dir = os.getenv("MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR)

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

Add a defensive check to ensure the fixtures directory exists. This prevents confusing downstream errors (like git clone/fetch failures) if MOCK_REPOS_DIR is misconfigured.

Suggested change
fixtures_dir = os.getenv("MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR)
fixtures_dir = Path(os.getenv("MOCK_REPOS_DIR") or DEFAULT_FIXTURES_DIR)
if not fixtures_dir.is_dir():
raise FileNotFoundError(f"Fixtures directory not found: {fixtures_dir}")

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

Since load_all_fixture_configs accepts str | Path, and DEFAULT_FIXTURES_DIR is already a Path object, we can simplify this by removing the redundant str() conversion.

Suggested change
fixtures_dir = os.getenv("MOCK_REPOS_DIR") or str(DEFAULT_FIXTURES_DIR)
fixtures_dir = os.getenv("MOCK_REPOS_DIR") or DEFAULT_FIXTURES_DIR

configs = load_all_fixture_configs(fixtures_dir)

if git_repo_basepath := os.getenv("GIT_REPO_BASEPATH"):
Expand Down
Loading