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: 5 additions & 1 deletion bough/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ def _find_direct_packages(
directly_affected = set()
strip_prefix = self.workspace_root.relative_to(self.repo_root)
for file_path in changed_files:
file_path_obj = Path(file_path).relative_to(strip_prefix)
if Path(file_path).is_relative_to(strip_prefix):
file_path_obj = Path(file_path).relative_to(strip_prefix)
else:
logger.debug(f"Ignoring file {file_path} outside of workspace")
continue

if self._matches_patterns(file_path, self.config.ignore):
logger.debug(f"Ignoring file {file_path} (matches ignore patterns)")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dev = [
"pytest-cov>=7.0.0",
"ruff>=0.12.11",
"tomli-w>=1.0.0",
"ty>=0.0.1a25",
"ty>=0.0.15",
]

[tool.ruff]
Expand Down
27 changes: 27 additions & 0 deletions tests/test_complex_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from unittest.mock import Mock, patch

import pytest
import tomli_w

from bough.analyzer import BoughAnalyzer
Expand Down Expand Up @@ -409,3 +410,29 @@ def test_divergent_git_vs_workspace_roots(mock_repo_class, tmp_path):
affected, _ = analyzer.find_affected()

assert affected == {"web"}


@pytest.mark.parametrize(
"changed_file",
["frontend/foo", "Dockerfile", ".github/workflows/ci.yaml"],
)
@patch("git.Repo")
def test_changed_files_outside_workspace(mock_repo_class, tmp_path, changed_file):
"""Test that files outside the workspace do not trigger any builds."""
structure = {
"tools/cli": {"dependencies": []},
}

create_workspace_structure(tmp_path / "backend", structure)

config_path = tmp_path / ".bough.yml"
config_path.write_text("""
buildable:
- "tools/*"
""")
Comment on lines +428 to +432
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

write_text("""...""") includes a leading newline and relies on indentation/formatting of a triple-quoted string for YAML. Consider writing the YAML without the leading newline (or using textwrap.dedent(...).lstrip()), which makes the test fixture less fragile and easier to read.

Copilot uses AI. Check for mistakes.

mock_repo_class.return_value = mock_git_changes([changed_file])
analyzer = BoughAnalyzer.from_workspace(tmp_path, tmp_path / "backend", config_path)
affected, _ = analyzer.find_affected()

assert affected == set()
2 changes: 1 addition & 1 deletion tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def package_graph(draw):
return packages


@given(package_graph())
@given(package_graph()) # ty: ignore[missing-argument]
def test_dependency_graph_contains_all_packages(packages):
"""All package names must appear in dependency graph output."""
analyzer = Mock()
Expand Down
Loading