Repository navigation
build(deps): bump typeguard from 2.13.3 to 4.6.0 #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a195845
build(deps): bump typeguard from 2.13.3 to 4.6.0
dependabot[bot] 49bf44e
test: adapt health check doubles to Typeguard 4 protocols
galacto d2b0364
fix: align shell command results with runtime protocol checks
galacto 38ca2b7
test: isolate subprocess exit status from Slurm child reaper
galacto 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,61 @@ | ||
| # Copyright (c) Last9, Inc. | ||
| import shlex | ||
| import signal | ||
| import subprocess | ||
| import sys | ||
|
|
||
| import pytest | ||
| from typeguard import check_type | ||
|
|
||
| from l9gpu.health_checks.subprocess import ( | ||
| handle_subprocess_exception, | ||
| shell_command, | ||
| ShellCommandOut, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("returncode", [0, 2]) | ||
| def test_shell_command_result_matches_protocol(returncode: int) -> None: | ||
| cmd = shlex.join( | ||
| [ | ||
| sys.executable, | ||
| "-c", | ||
| "import sys; print('output'); print('error', file=sys.stderr); " | ||
| f"sys.exit({returncode})", | ||
| ] | ||
| ) | ||
|
|
||
| # The sacct_backfill CLI installs a child-reaping handler at import time. | ||
| # Let subprocess collect its own exit status, regardless of test order. | ||
| previous_handler = signal.signal(signal.SIGCHLD, signal.SIG_DFL) | ||
| try: | ||
| result = shell_command(cmd, timeout_secs=10) | ||
| finally: | ||
| signal.signal(signal.SIGCHLD, previous_handler) | ||
|
|
||
| check_type(result, ShellCommandOut) | ||
| assert result.args == cmd | ||
| assert result.returncode == returncode | ||
| assert set(result.stdout.splitlines()) == {"output", "error"} | ||
| assert result.stderr is None | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("cmd", ["test-command --flag", ["test-command", "--flag"]]) | ||
| def test_timeout_result_matches_protocol(cmd: str | list[str]) -> None: | ||
| result = handle_subprocess_exception(subprocess.TimeoutExpired(cmd, 10)) | ||
|
|
||
| check_type(result, ShellCommandOut) | ||
| assert result.args == cmd | ||
| assert result.returncode == 128 | ||
| assert "Error command timeout because of timeout setting." in result.stdout | ||
| with pytest.raises(subprocess.CalledProcessError): | ||
| result.check_returncode() | ||
|
|
||
|
|
||
| def test_unknown_exception_result_matches_protocol() -> None: | ||
| result = handle_subprocess_exception(ValueError("unexpected failure")) | ||
|
|
||
| check_type(result, ShellCommandOut) | ||
| assert result.args == [] | ||
| assert result.returncode == 2 | ||
| assert "Unknown subprocess exception" in result.stdout |
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
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.
[P1] Migrate subprocess result contracts before enabling typeguard 4
This upgrade instruments annotated local assignments and validates protocol attributes. The real
DCGMImplreturnsshell_command()results whoseCompletedProcess.argsis a string andstderrisNone(shell=True,stderr=STDOUT), butShellCommandOutrequiresList[str]andstr. Atcheck_dcgmi.py:461, a normal command result now raisesTypeCheckError; the exception recovery result then fails the same protocol'sstderrcheck. The timeout path fails as well.I reproduced this through the actual CLI,
DCGMImpl, shell wrapper and output contexts with only the subprocess boundary replaced. A passing GPU diagnostic, a failing diagnostic, and a timeout all end withWARNING - check did not exit normallyandTypeCheckError, instead of their expected OK/CRITICAL/WARN result and diagnostic message. This breaks the health-check path even for valid command output and can turn a critical result into an unexplained warning.Update the subprocess protocol and recovery values to reflect the real producer contract, and audit the newly enforced annotated assignments and protocol consumers before taking the major upgrade. Keep this dependency at its compatible version until those migrations and the affected tests pass. Do not solve this only by changing test fakes: the production
CompletedProcessshape triggers the failure.Executed regression at
a195845b8c708b44eb5876d1911ec06f074a9908: save the following asl9gpu/tests/test_typeguard_subprocess_review.py. With Python 3.12 and the PR's declared dependencies installed (python -m pip install -e '.[dev,k8s]'), run:Executed on Python 3.12.9: all three cases fail on this head. The identical test passes all three at base
215314527174c7e59743f21fde067be26db5fff1with typeguard 2.13.3 and otherwise identical resolved dependencies. The failure assertions showTypeCheckErroron theShellCommandOutattributes. No GPU, subprocess command, service, or external telemetry endpoint is used by this test.