Skip to content

Conversation

@dearlordylord
Copy link
Contributor

@dearlordylord dearlordylord commented Aug 14, 2025

User description

https://www.loom.com/share/4dcfb2729e4a4a308a7d09f5a5e064c0?sid=c4139292-4f51-4876-9aac-fa0325215b69

  • explicit env vars to let tests see docker networks
  • subnets cleanup (tests create many subnets not cleaning it up)
  • gitignore pnpm technical files

PR Type

Bug fix, Tests


Description

  • Fixed Docker network cleanup in tests

  • Added explicit environment variables for Mac tests

  • Improved test reliability with better error handling

  • Added consistent Docker project naming


Changes walkthrough 📝

Relevant files
Bug fix
conftest.py
Improve Docker test reliability with cleanup and error handling

server/tests/conftest.py

  • Added Docker network cleanup before and after test sessions
  • Implemented consistent Docker project naming to prevent network
    proliferation
  • Added error handling for Docker service failures with retry mechanism
  • Added automatic cleanup of orphaned Docker networks
  • +51/-2   
    Documentation
    CLAUDE.md
    Update test documentation with required environment variables

    CLAUDE.md

  • Added explicit environment variables to test commands
  • Updated documentation to include Redis and Celery connection
    parameters
  • Ensured test commands work properly on Mac environments
  • +3/-3     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @vercel
    Copy link

    vercel bot commented Aug 14, 2025

    The latest updates on your projects. Learn more about Vercel for GitHub.

    Project Deployment Preview Comments Updated (UTC)
    reflector Ready Ready Preview Comment Aug 28, 2025 9:19pm
    reflector-media Ready Ready Preview Comment Aug 28, 2025 9:19pm

    @pr-agent-monadical
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The error handling in the postgres_service fixture catches all exceptions, which might mask specific Docker-related issues. Consider catching more specific exceptions related to Docker connectivity.

    except Exception as e:
        # If Docker services fail to start, clean up and retry
        subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
        subprocess.run(
            ["docker", "compose", "-p", "reflector_test", "down", "-v"],
            capture_output=True,
        )
        raise pytest.skip(f"Docker services failed to start: {e}")
    Subprocess Security

    The subprocess calls don't set shell=False explicitly, and while it's the default, it's a good practice to be explicit for security and clarity when running external commands.

    subprocess.run(
        [
            "docker",
            "compose",
            "-p",
            "reflector_test",
            "down",
            "-v",
            "--remove-orphans",
        ],
        capture_output=True,
        cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
    )
    # Clean up any unused networks (includes orphaned pytest networks)
    # This is safe - only removes networks with no attached containers
    subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)

    Comment on lines +42 to +43
    # This is safe - only removes networks with no attached containers
    subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Check the return code of the subprocess call to ensure the Docker command executed successfully. If the command fails, it could silently fail and cause test issues. [general, importance: 7]

    Suggested change
    # This is safe - only removes networks with no attached containers
    subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
    # Clean up any unused networks (includes orphaned pytest networks)
    # This is safe - only removes networks with no attached containers
    result = subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
    if result.returncode != 0:
    print(f"Warning: Docker network prune failed: {result.stderr.decode()}")

    Copy link
    Member

    Choose a reason for hiding this comment

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

    No, i don't want the project to prune my network, some network can be created without being attached to a container, does not mean you want to prune. Filter to pytest then

    Comment on lines +61 to +66
    subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
    subprocess.run(
    ["docker", "compose", "-p", "reflector_test", "down", "-v"],
    capture_output=True,
    )
    raise pytest.skip(f"Docker services failed to start: {e}")
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Add error handling for the cleanup commands in the exception handler. If these cleanup commands fail, they could mask the original error and make debugging more difficult. [general, importance: 8]

    Suggested change
    subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
    subprocess.run(
    ["docker", "compose", "-p", "reflector_test", "down", "-v"],
    capture_output=True,
    )
    raise pytest.skip(f"Docker services failed to start: {e}")
    # If Docker services fail to start, clean up and retry
    try:
    subprocess.run(["docker", "network", "prune", "-f"], capture_output=True, check=False)
    subprocess.run(
    ["docker", "compose", "-p", "reflector_test", "down", "-v"],
    capture_output=True,
    check=False,
    )
    except Exception as cleanup_error:
    print(f"Warning: Cleanup after Docker failure also failed: {cleanup_error}")
    raise pytest.skip(f"Docker services failed to start: {e}")

    Comment on lines +28 to +40
    subprocess.run(
    [
    "docker",
    "compose",
    "-p",
    "reflector_test",
    "down",
    "-v",
    "--remove-orphans",
    ],
    capture_output=True,
    cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
    )
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Add a timeout parameter to the subprocess call to prevent tests from hanging indefinitely if Docker operations take too long or get stuck. [general, importance: 7]

    Suggested change
    subprocess.run(
    [
    "docker",
    "compose",
    "-p",
    "reflector_test",
    "down",
    "-v",
    "--remove-orphans",
    ],
    capture_output=True,
    cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
    )
    subprocess.run(
    [
    "docker",
    "compose",
    "-p",
    "reflector_test",
    "down",
    "-v",
    "--remove-orphans",
    ],
    capture_output=True,
    cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
    timeout=60, # Add timeout to prevent hanging
    )

    Comment on lines +42 to +43
    # This is safe - only removes networks with no attached containers
    subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
    Copy link
    Member

    Choose a reason for hiding this comment

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

    No, i don't want the project to prune my network, some network can be created without being attached to a container, does not mean you want to prune. Filter to pytest then

    Comment on lines +45 to +51
    REDIS_HOST=localhost CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/1 uv run pytest

    # Run specific test file
    uv run pytest tests/test_transcripts.py
    REDIS_HOST=localhost CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/1 uv run pytest tests/test_transcripts.py

    # Run tests with verbose output
    uv run pytest -v
    REDIS_HOST=localhost CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/1 uv run pytest -v
    Copy link
    Member

    Choose a reason for hiding this comment

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

    No, again this is specific to you because you change your env to have stuff running in a docker, then add stuff about how to run without your env again.

    We could do the same way for REDIS_HOST to be populated with pytest-docker the same way as postgres.

    @deardarlingoose deardarlingoose changed the title fix pending issue with tests on mac fix: pending issue with tests on mac Aug 28, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants