Skip to content

Add environment context detection utility for Breeze (GSoC PoC)#64753

Draft
Mayankaggarwal8055 wants to merge 2 commits intoapache:mainfrom
Mayankaggarwal8055:feat/execution-manager-env-detection
Draft

Add environment context detection utility for Breeze (GSoC PoC)#64753
Mayankaggarwal8055 wants to merge 2 commits intoapache:mainfrom
Mayankaggarwal8055:feat/execution-manager-env-detection

Conversation

@Mayankaggarwal8055
Copy link
Copy Markdown
Contributor

This PR introduces a utility for detecting execution context (WSL, host, Docker container) and providing environment-aware command recommendations for Breeze workflows.

Why is this important?

This work aligns with the GSoC 2026 project:
"Airflow Contribution & Verification Agent Skills" (#62500)

A key requirement of the project is enabling AI agents to:

  • Detect whether they are running on host or inside Breeze
  • Choose appropriate commands based on environment

This PR implements a foundational step toward that goal by providing:

  • A consistent environment detection mechanism
  • A simple API for retrieving recommended commands

Key Features

  • Detect WSL using:

    • environment variables
    • /proc/version
    • kernel release
  • Detect container execution via /.dockerenv

  • Detect Docker availability using docker info

  • Provide recommended command:

    • pytest (inside container)
    • breeze shell (host)

Tests

  • Added comprehensive unit tests with proper mocking
  • Ensured isolation of system-dependent behavior (e.g. /proc/version, subprocess calls)

Notes

This is an initial PoC toward environment-awareness for AI-assisted workflows and can be extended to support broader agent skill integration.

Related Issue

Related to #62500

- Detect WSL environment
- Detect Docker availability
- Recommend appropriate command (pytest or breeze shell)
- Add comprehensive unit tests with proper mocking
Copy link
Copy Markdown
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

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

I’ll mark it as a draft, according to the timeline, we’re still reviewing all the proposals. In the meantime, please feel free to contribute to any open issue (perhaps issues labeled ‎good first issue would be a good starting point).

Thanks and welcome to the community.

@jason810496 jason810496 marked this pull request as draft April 6, 2026 08:41
@Mayankaggarwal8055
Copy link
Copy Markdown
Contributor Author

Thanks for the guidance!

I created this as a small PoC aligned with the GSoC “Agent Skills” idea to explore environment detection and how it could integrate with Breeze workflows.

I’ll continue working on relevant open issues as well to contribute more directly.

Appreciate the feedback!

@kaxil kaxil requested a review from Copilot April 10, 2026 19:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a small Breeze-side utility to detect the current execution context (WSL vs non-WSL, inside Docker container vs host, Docker availability) and to return an environment-aware recommended command for common workflows.

Changes:

  • Added airflow_breeze.utils.environment_context with WSL/container/Docker detection and a simple EnvironmentContext return type.
  • Added unit tests covering WSL detection paths, Docker availability probing, and the resulting recommended command.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
dev/breeze/src/airflow_breeze/utils/environment_context.py Introduces the environment context detection API and supporting helpers.
dev/breeze/tests/utils/test_environment_context.py Adds unit tests validating detection behavior via mocking.

Comment on lines +27 to +31
from pathlib import Path
from unittest.mock import MagicMock, patch

import pytest

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

Path and pytest are imported but unused in this test module, which will fail linting (unused imports). Remove the unused imports or use them as intended.

Suggested change
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from unittest.mock import MagicMock, patch

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +53
def test_detect_wsl_not_present_env_var(self, monkeypatch):
"""Test when WSL_DISTRO_NAME is not set but on non-WSL system."""
monkeypatch.delenv("WSL_DISTRO_NAME", raising=False)

# Mock all detection methods to return non-WSL values
with patch("builtins.open", side_effect=OSError): # /proc/version not available
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

There are whitespace-only/trailing spaces on otherwise blank lines (e.g. the blank line after monkeypatch.delenv(...)). This violates the repo's trailing-whitespace checks and should be cleaned up.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +5
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This file appears to be using CRLF (Windows-style) line endings. The repository's .editorconfig requires end_of_line = lf, so please normalize the file to LF to match project conventions.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +5
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This module also appears to be using CRLF line endings; .editorconfig specifies end_of_line = lf. Please convert the file to LF to align with repository conventions and avoid noisy diffs/tooling issues.

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +63
def _detect_wsl() -> bool:
"""
Detect whether we are running under Windows Subsystem for Linux (WSL).

Uses multiple detection methods:
1. Check WSL_DISTRO_NAME environment variable (WSL 2 specific)
2. Check /proc/version for Microsoft/WSL markers (WSL 1 & 2)
3. Check uname release for microsoft marker (WSL 2)

Returns:
True if running under WSL, False otherwise.
"""
# Method 1: Environment variable (WSL 2 specific)
if "WSL_DISTRO_NAME" in os.environ:
return True

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

WSL detection in _detect_wsl() duplicates existing logic in airflow_breeze/commands/developer_commands.py:is_wsl() and uses a different implementation. To avoid divergence/bugs over time, consider reusing a shared helper (or moving WSL detection into a common utils module and importing it from both places).

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +68
version = version_file.read()
if "Microsoft" in version or "WSL" in version:
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

/proc/version detection is currently case-sensitive ("Microsoft" / "WSL"). Elsewhere in Breeze (e.g. developer_commands.is_wsl) the content is normalized with .lower() before checking, which is more robust. Consider lowercasing the file contents and checking for "microsoft"/"wsl" to avoid false negatives.

Suggested change
version = version_file.read()
if "Microsoft" in version or "WSL" in version:
version = version_file.read().lower()
if "microsoft" in version or "wsl" in version:

Copilot uses AI. Check for mistakes.
Comment on lines +130 to +131
# Check Docker availability
docker_available = _is_docker_available()
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

detect_environment_context() always runs _is_docker_available() (which shells out to docker info with a 5s timeout) even when inside_container is True and the result doesn't affect recommended_command. Consider skipping the Docker availability check when running inside the container, or making the availability probe opt-in, to keep context detection fast and predictable.

Suggested change
# Check Docker availability
docker_available = _is_docker_available()
# Check Docker availability only when running outside the container.
docker_available = False if inside_container else _is_docker_available()

Copilot uses AI. Check for mistakes.
Comment on lines +83 to +89
def test_docker_available_success(self):
"""Test when Docker is available and running."""
with patch("subprocess.run") as mock_run:
mock_result = MagicMock()
mock_result.returncode = 0
mock_run.return_value = mock_result

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

Tests create MagicMock() instances without a spec/autospec (e.g. for the subprocess.run result). Using spec/autospec (or a real subprocess.CompletedProcess) helps catch attribute typos and keeps mocks aligned with the real API.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants