From 6eda0c74d1043607b333fc6cadd915ef3c1b7a80 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:07:27 +0000 Subject: [PATCH 1/4] Initial plan From 144932183990f77cf2ef879c1689e46e4d248ea5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:20:48 +0000 Subject: [PATCH 2/4] refactor(tests): parametrize and use focused call_args assertions in test_main.py Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- tests/unit/test_main.py | 105 +++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 49 deletions(-) diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 08350eef..b662c288 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -1,54 +1,61 @@ -import pytest -from unittest.mock import patch +# SPDX-FileCopyrightText: 2025 Knitli Inc. +# SPDX-FileContributor: Adam Poulemanos +# +# SPDX-License-Identifier: MIT OR Apache-2.0 +"""Tests for the conditional transport branching in codeweaver.main.run().""" + +from __future__ import annotations + from pathlib import Path +from unittest.mock import AsyncMock, patch + +import pytest + from codeweaver.main import run -@pytest.mark.asyncio -@patch("codeweaver.main._run_stdio_server") -@patch("codeweaver.main._run_http_server") -async def test_run_stdio_transport(mock_run_http_server, mock_run_stdio_server): - """Test that run() calls _run_stdio_server when transport is 'stdio'.""" - await run( - config_file=Path("/fake/config.yaml"), - project_path=Path("/fake/project"), - host="127.0.0.1", - port=8080, - transport="stdio", - verbose=True, - debug=False, - ) - - mock_run_stdio_server.assert_called_once_with( - config_file=Path("/fake/config.yaml"), - project_path=Path("/fake/project"), - host="127.0.0.1", - port=8080, - verbose=True, - debug=False, - ) - mock_run_http_server.assert_not_called() + +pytestmark = [pytest.mark.unit] + +_TRANSPORT_CASES = [ + pytest.param( + "stdio", "codeweaver.main._run_stdio_server", "codeweaver.main._run_http_server", id="stdio" + ), + pytest.param( + "streamable-http", + "codeweaver.main._run_http_server", + "codeweaver.main._run_stdio_server", + id="streamable-http", + ), +] + @pytest.mark.asyncio -@patch("codeweaver.main._run_stdio_server") -@patch("codeweaver.main._run_http_server") -async def test_run_streamable_http_transport(mock_run_http_server, mock_run_stdio_server): - """Test that run() calls _run_http_server when transport is 'streamable-http'.""" - await run( - config_file=None, - project_path=None, - host="0.0.0.0", - port=9090, - transport="streamable-http", - verbose=False, - debug=True, - ) - - mock_run_http_server.assert_called_once_with( - config_file=None, - project_path=None, - host="0.0.0.0", - port=9090, - verbose=False, - debug=True, - ) - mock_run_stdio_server.assert_not_called() +@pytest.mark.parametrize(("transport", "expected_patch", "other_patch"), _TRANSPORT_CASES) +async def test_run_dispatches_to_correct_server( + transport: str, expected_patch: str, other_patch: str +) -> None: + """Test that run() calls the correct server helper for each transport value.""" + config_file = Path("/fake/config.yaml") + project_path = Path("/fake/project") + host = "127.0.0.1" + port = 8080 + + with ( + patch(expected_patch, new_callable=AsyncMock) as mock_expected, + patch(other_patch, new_callable=AsyncMock) as mock_other, + ): + await run( + config_file=config_file, + project_path=project_path, + host=host, + port=port, + transport=transport, # type: ignore[arg-type] + verbose=False, + debug=False, + ) + + mock_expected.assert_called_once() + kwargs = mock_expected.call_args.kwargs + assert kwargs.get("host") == host + assert kwargs.get("port") == port + mock_other.assert_not_called() From d44408578b517bbcccfc9aa243ef2a297d5a7b40 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:21:49 +0000 Subject: [PATCH 3/4] chore(tests): remove unused type-ignore comment in test_main.py Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- tests/unit/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index b662c288..77514324 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -49,7 +49,7 @@ async def test_run_dispatches_to_correct_server( project_path=project_path, host=host, port=port, - transport=transport, # type: ignore[arg-type] + transport=transport, verbose=False, debug=False, ) From 6b68ddb5cc36f4d9352c5eb9a087857bdaf609e6 Mon Sep 17 00:00:00 2001 From: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com> Date: Mon, 16 Mar 2026 11:30:59 -0400 Subject: [PATCH 4/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com> --- tests/unit/test_main.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 77514324..2d1df19d 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -30,13 +30,22 @@ @pytest.mark.asyncio +@pytest.mark.parametrize( + ("config_file", "project_path"), + [ + pytest.param(Path("/fake/config.yaml"), Path("/fake/project"), id="with-paths"), + pytest.param(None, None, id="none-paths"), + ], +) @pytest.mark.parametrize(("transport", "expected_patch", "other_patch"), _TRANSPORT_CASES) async def test_run_dispatches_to_correct_server( - transport: str, expected_patch: str, other_patch: str + transport: str, + expected_patch: str, + other_patch: str, + config_file: Path | None, + project_path: Path | None, ) -> None: """Test that run() calls the correct server helper for each transport value.""" - config_file = Path("/fake/config.yaml") - project_path = Path("/fake/project") host = "127.0.0.1" port = 8080 @@ -54,8 +63,13 @@ async def test_run_dispatches_to_correct_server( debug=False, ) - mock_expected.assert_called_once() - kwargs = mock_expected.call_args.kwargs - assert kwargs.get("host") == host - assert kwargs.get("port") == port - mock_other.assert_not_called() + mock_expected.assert_awaited_once_with( + config_file=config_file, + project_path=project_path, + host=host, + port=port, + transport=transport, + verbose=False, + debug=False, + ) + mock_other.assert_not_awaited()