-
Notifications
You must be signed in to change notification settings - Fork 0
📝 CodeRabbit Chat: Implement requested code changes #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coderabbitai
wants to merge
4
commits into
main
Choose a base branch
from
coderabbitai/chat/f5ab030
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b0dca3f
Stop double-logging external command invocations
leynos 95a3496
Harden subprocess logging regression test assertions
leynos f5ab030
Log cmd-mox passthrough command invocations
leynos fb8a583
📝 CodeRabbit Chat: Implement requested code changes
coderabbitai[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """Regression tests for subprocess runner invocation logging. | ||
|
|
||
| Issue #104: every external command used to be logged twice — once at INFO | ||
| by ``subprocess_runner`` and once at DEBUG by ``invoke_via_subprocess``. | ||
| These tests pin the single-log contract. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import typing as typ | ||
|
|
||
| from lading.runtime.subprocess_runner import subprocess_runner | ||
|
|
||
| if typ.TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| LogCaptureFixture = pytest.LogCaptureFixture | ||
| else: # pragma: no cover - typing helpers | ||
| Path = typ.Any | ||
| LogCaptureFixture = typ.Any | ||
|
|
||
| _RUNNER_LOGGER = "lading.runtime.subprocess_runner" | ||
|
|
||
|
|
||
| def _invocation_records( | ||
| caplog: LogCaptureFixture, | ||
| ) -> list[logging.LogRecord]: | ||
| """Return records that render the external command line.""" | ||
| return [ | ||
| record | ||
| for record in caplog.records | ||
| if "Running external command" in record.getMessage() | ||
| ] | ||
|
|
||
|
|
||
| def _assert_no_spawn_record(caplog: LogCaptureFixture) -> None: | ||
| """Assert the removed DEBUG spawn log is absent (regression for #104).""" | ||
| assert all( | ||
| "Spawning subprocess:" not in record.getMessage() for record in caplog.records | ||
| ) | ||
|
|
||
|
|
||
| def test_command_logged_exactly_once(caplog: LogCaptureFixture) -> None: | ||
| """A command produces a single invocation log record at INFO.""" | ||
| caplog.set_level(logging.DEBUG, logger=_RUNNER_LOGGER) | ||
|
|
||
| exit_code, stdout, stderr = subprocess_runner(("echo", "hello"), echo_stdout=False) | ||
|
|
||
| assert exit_code == 0 | ||
| assert stdout.strip() == "hello" | ||
| assert stderr == "" | ||
| records = _invocation_records(caplog) | ||
| assert len(records) == 1 | ||
| assert records[0].levelno == logging.INFO | ||
| message = records[0].getMessage() | ||
| assert "Running external command" in message | ||
| assert "echo hello" in message | ||
| _assert_no_spawn_record(caplog) | ||
|
|
||
|
|
||
| def test_command_logged_exactly_once_with_cwd( | ||
| caplog: LogCaptureFixture, tmp_path: Path | ||
| ) -> None: | ||
| """The single invocation record includes the working directory.""" | ||
| caplog.set_level(logging.DEBUG, logger=_RUNNER_LOGGER) | ||
|
|
||
| exit_code, _, _ = subprocess_runner( | ||
| ("echo", "hello"), cwd=tmp_path, echo_stdout=False | ||
| ) | ||
|
|
||
| assert exit_code == 0 | ||
| records = _invocation_records(caplog) | ||
| assert len(records) == 1 | ||
| assert records[0].levelno == logging.INFO | ||
| assert f"(cwd={tmp_path})" in records[0].getMessage() | ||
| _assert_no_spawn_record(caplog) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (testing): The test no longer invokes
cmd_mox, so it may not validate passthrough behavior anymore.With the removal of
cmd_mox.spy(sys.executable).with_args("-c", script).passthrough()and no replacement,test_cmd_mox_passthrough_streams_outputno longer appears to trigger the passthrough/streaming behavior it’s supposed to verify. This risks making the test effectively a no-op. Please reintroduce an explicitcmd_moxinvocation (adapted if needed) or add a new call that actually exercises passthrough so the test still confirms that subprocess output is streamed and logged.