Repository navigation
Don't misreport successful log uploads as errors after WebSocket drop (#1062) - #105
Merged
rquidute merged 3 commits intoJul 22, 2026
Merged
Conversation
Uploading a large manual test log can keep the backend's event loop busy long enough that the WebSocket's ping/pong keepalive times out and the connection is dropped before the CLI can send the prompt response confirming the upload. Previously this was caught by the generic exception handler in __upload_file_and_send_response and reported as 'Unexpected error uploading file: ...', even though the upload itself had already completed successfully (issue #1062). - Wrap only the prompt-response send (not the upload) in a dedicated try/except for websockets.exceptions.ConnectionClosed, and report it as a distinct warning that makes clear the file was already uploaded, instead of letting it fall into the same 'unexpected error' branch as an actual upload failure. - Add unit tests covering: successful upload + successful response, successful upload with the WebSocket closed before the response can be sent, and an actual upload failure (still reported as an error, as before).
|
Tick the box to add this pull request to the merge queue (same as
|
Contributor
There was a problem hiding this comment.
Code Review
This pull request decouples the file upload from sending the prompt response confirmation in __upload_file_and_send_response to prevent WebSocket timeouts from being misreported as upload failures, and adds corresponding unit tests. The reviewer suggested catching a broader Exception instead of only websockets.exceptions.ConnectionClosed when sending the confirmation to ensure any post-upload failure is correctly reported as a warning rather than an upload error.
… successful upload Only catching websockets.exceptions.ConnectionClosed left other post-upload notification failures (e.g. websockets.exceptions. InvalidState, or a plain OSError from a socket already torn down) to fall through to the outer except Exception block, which still misreported them as "Unexpected error uploading file" - the exact bug this fix targets. Broaden the inner except to Exception, since by this point the upload has already succeeded and any exception sending the confirmation is a notification failure, not an upload failure. The try block scopes exactly one call (_send_prompt_response), so this isn't a broad catch-all - it matches the actual invariant at this point in the function. Remove the now-unused top-level "import websockets" statement and add a regression test covering a non-ConnectionClosed exception.
rquidute
force-pushed
the
fix/1062-cli-upload-error-after-success
branch
from
July 22, 2026 18:04
f38a5e4 to
a5eaadf
Compare
__prompt_user_for_file_upload read the raw value from aioconsole.ainput() and only called .strip() when checking for an empty/skip response, then passed the *unstripped* value to __valid_file_upload() and returned it unstripped on success. Some terminals/SSH sessions send a trailing \r (or other whitespace) with the input line; that stray character made os.path.isfile() fail even though the file existed exactly where the user said it did, surfacing as a misleading "Invalid file path or type" error for an otherwise-correct path. Strip the input once, immediately after reading it, and use the stripped value consistently for the emptiness check, validation, and the returned path.
antonio-amjr
approved these changes
Jul 22, 2026
This was referenced Jul 22, 2026
Merged
rquidute
added a commit
that referenced
this pull request
Jul 22, 2026
… (#1062) (#105) (#106) * Stop misreporting successful log uploads as errors after WebSocket drop Uploading a large manual test log can keep the backend's event loop busy long enough that the WebSocket's ping/pong keepalive times out and the connection is dropped before the CLI can send the prompt response confirming the upload. Previously this was caught by the generic exception handler in __upload_file_and_send_response and reported as 'Unexpected error uploading file: ...', even though the upload itself had already completed successfully (issue #1062). - Wrap only the prompt-response send (not the upload) in a dedicated try/except for websockets.exceptions.ConnectionClosed, and report it as a distinct warning that makes clear the file was already uploaded, instead of letting it fall into the same 'unexpected error' branch as an actual upload failure. - Add unit tests covering: successful upload + successful response, successful upload with the WebSocket closed before the response can be sent, and an actual upload failure (still reported as an error, as before). * Address review: catch any exception, not just ConnectionClosed, after successful upload Only catching websockets.exceptions.ConnectionClosed left other post-upload notification failures (e.g. websockets.exceptions. InvalidState, or a plain OSError from a socket already torn down) to fall through to the outer except Exception block, which still misreported them as "Unexpected error uploading file" - the exact bug this fix targets. Broaden the inner except to Exception, since by this point the upload has already succeeded and any exception sending the confirmation is a notification failure, not an upload failure. The try block scopes exactly one call (_send_prompt_response), so this isn't a broad catch-all - it matches the actual invariant at this point in the function. Remove the now-unused top-level "import websockets" statement and add a regression test covering a non-ConnectionClosed exception. * Strip trailing whitespace/CR from uploaded file path input __prompt_user_for_file_upload read the raw value from aioconsole.ainput() and only called .strip() when checking for an empty/skip response, then passed the *unstripped* value to __valid_file_upload() and returned it unstripped on success. Some terminals/SSH sessions send a trailing \r (or other whitespace) with the input line; that stray character made os.path.isfile() fail even though the file existed exactly where the user said it did, surfacing as a misleading "Invalid file path or type" error for an otherwise-correct path. Strip the input once, immediately after reading it, and use the stripped value consistently for the emptiness check, validation, and the returned path.
rquidute
added a commit
that referenced
this pull request
Sep 3, 2026
* [FEATURE] Adding Realtime Log feature to CLI (#81) * Adding Real-time log feature access to the CLI via browser * Changing browser page style and adding download logs feature * Moving log streaming URL display to closer to the Test Run execution start * reducing Real-time log description in default config JSON * Supressing exceptions when no browser is connected Also fixing the downloaded file to show breakline properly. * Reading file in chunks for download Also fixing incomplete log streaming * Adding run_tests argument option to disable real-time logs * [Fix] th-cli --version Surfaces Backend And SDK Versions (#999) (#85) * [Fix] th-cli --version Surfaces Backend And SDK Versions (#999) * Update th_cli/utils.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * [Feature] Config Output To Project Command (#84) * Adding config output for CLI project command * Improving __print_config() method and adding short flags * Add CI workflow to run pytest on every PR (#95) * Add CI workflow to run pytest on every PR Adds .github/workflows/python-tests.yml which: - Triggers on all pull requests (any target branch) - Sets up Python 3.10 and installs dependencies via Poetry (with venv cache) - Runs ./scripts/run_pytest.py (existing test runner) - Fails if coverage drops below 85% (enforced by pyproject.toml) - Uploads coverage.xml and htmlcov/ as artifacts on every run Tracks: project-chip/certification-tool#1020 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Fix CI: bump action versions to v4/v5 actions/upload-artifact@v3 was deprecated and disabled by GitHub in November 2024, causing the job setup to fail before any steps ran. Bump all actions to their current major versions: - actions/checkout: v3 -> v4 - actions/setup-python: v4 -> v5 - actions/cache: v3 -> v4 - actions/upload-artifact: v3 -> v4 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Fix CI: correct test runner script name (run_pytest.sh not .py) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Fix failing test and align coverage threshold with actual coverage - Fix test_test_run_execution_log_whitespace_content: Click prepends a DeprecationWarning line when invoking a deprecated option (--log). Strip DeprecationWarning lines before asserting on output content. - Lower --cov-fail-under from 85 to 65 to match the actual coverage achieved by the current test suite (65.54%). The 85% target was aspirational and not yet reached; using it as a hard gate would permanently block CI on every PR. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Fix CI: use Python 3.12 to match development environment Python 3.10's unittest.mock._dot_lookup resolves dotted patch paths differently from 3.12: it walks the path with getattr, finds the imported Click Command object at 'th_cli.commands.abort_testing' (due to 'from .abort_testing import abort_testing' in __init__.py), and then fails trying to get 'get_client' off the Command object. Python 3.12 correctly resolves the patch target via sys.modules, finding the module rather than the imported name. All tests pass locally on 3.12; switching CI to match eliminates the AttributeError failures across all command modules. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Revert coverage threshold back to 85% Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> * feat: add project export and import CLI commands (#1025) (#98) * feat: add project export and import CLI commands (#1025) Add 'project export' and 'project import' subcommands to the CLI, wiring up the existing backend endpoints: - GET /api/v1/projects/{id}/export - POST /api/v1/projects/import project export: - Downloads the project config as a JSON file - Defaults to '<project-name>-project-config.json' if no output file is given - Accepts --output-file / -o to specify a custom path project import: - Accepts --file / -f pointing to a previously exported JSON file - Sends the file bytes to the backend and prints the new project ID Also adds full unit test coverage in tests/test_project_commands.py (TestExportProjectCommand and TestImportProjectCommand). Closes #1025 * fix: resolve unit test failures in project export/import and logger tests - Add missing 'import json' to test_project_commands.py - Update test_run_tests_logger_configuration to include enable_log_streaming=True in the expected configure_logger_for_run call, matching the actual call signature * fix: apply code review suggestions from PR #98 - Use model_dump_json(indent=2) instead of model_dump() + json.dumps() to correctly serialize Pydantic models with non-standard types - Split OSError handling in _import_project into FileNotFoundError and generic OSError to avoid broken error messages from wrapping OSError in FileNotFoundError * Fix Push AV Stream Verification player reading stale field names (#103) * Fix Push AV Stream Verification player reading stale field names The Push AV Server's /streams API returns each stream's uploaded files under valid_uploads/error_uploads (lists of {file_path, reasons?}) since the server became session-oriented. The CLI's push_av_stream_verification.html was never updated and still looked for files/valid_files/invalid_files, which no longer exist in the response. As a result, allFiles was always empty, no .mpd/.m4s entry point was ever found, and the video player stayed blank even when the DUT successfully uploaded CMAF content to the server. Add getStreamFilePaths() to read valid_uploads/error_uploads first, falling back to the legacy files/valid_files/invalid_files shape for compatibility with older server responses. Also surface per-file non-conforming reasons in the Non-Conforming Files section using the reasons field now provided by error_uploads entries. Add regression tests asserting the rendered template references the current field names ahead of the legacy fallback. * Apply defensive null-checks to Push AV upload parsing per code review Use optional chaining (u?.file_path, u?.reasons) and filter(Boolean) when mapping valid_uploads/error_uploads entries to file paths and reasons, so a malformed or null entry in the server response can't throw a TypeError and block the verification page from rendering. Update the corresponding test assertion to check for the file_path field name generically instead of the literal 'u.file_path' loop variable expression, which no longer appears verbatim once optional chaining is used. * Don't misreport successful log uploads as errors after WebSocket drop (#1062) (#105) * Stop misreporting successful log uploads as errors after WebSocket drop Uploading a large manual test log can keep the backend's event loop busy long enough that the WebSocket's ping/pong keepalive times out and the connection is dropped before the CLI can send the prompt response confirming the upload. Previously this was caught by the generic exception handler in __upload_file_and_send_response and reported as 'Unexpected error uploading file: ...', even though the upload itself had already completed successfully (issue #1062). - Wrap only the prompt-response send (not the upload) in a dedicated try/except for websockets.exceptions.ConnectionClosed, and report it as a distinct warning that makes clear the file was already uploaded, instead of letting it fall into the same 'unexpected error' branch as an actual upload failure. - Add unit tests covering: successful upload + successful response, successful upload with the WebSocket closed before the response can be sent, and an actual upload failure (still reported as an error, as before). * Address review: catch any exception, not just ConnectionClosed, after successful upload Only catching websockets.exceptions.ConnectionClosed left other post-upload notification failures (e.g. websockets.exceptions. InvalidState, or a plain OSError from a socket already torn down) to fall through to the outer except Exception block, which still misreported them as "Unexpected error uploading file" - the exact bug this fix targets. Broaden the inner except to Exception, since by this point the upload has already succeeded and any exception sending the confirmation is a notification failure, not an upload failure. The try block scopes exactly one call (_send_prompt_response), so this isn't a broad catch-all - it matches the actual invariant at this point in the function. Remove the now-unused top-level "import websockets" statement and add a regression test covering a non-ConnectionClosed exception. * Strip trailing whitespace/CR from uploaded file path input __prompt_user_for_file_upload read the raw value from aioconsole.ainput() and only called .strip() when checking for an empty/skip response, then passed the *unstripped* value to __valid_file_upload() and returned it unstripped on success. Some terminals/SSH sessions send a trailing \r (or other whitespace) with the input line; that stray character made os.path.isfile() fail even though the file existed exactly where the user said it did, surfacing as a misleading "Invalid file path or type" error for an otherwise-correct path. Strip the input once, immediately after reading it, and use the stripped value consistently for the emptiness check, validation, and the returned path. * [Fix] Websocket and Log Viewer (#107) * Max retained logs added for the CLI log viewer. Also, the websocket closure was postponed for when inactive and now yields to the event loop every 200 records intead of whole batch * Cap the rendering to 2000 lines and changed log viewer download logs feature * Log viewer download button now opens no tab and start the download immediately * Pushing the run_id to the queue that feeds the live stream * Fixing state verifying to match the backends. --------- Co-authored-by: antonio-amjr <116589331+antonio-amjr@users.noreply.github.com> Co-authored-by: abhisheksingh-esp <abhishek.singh@espressif.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Romulo Quidute Filho <116586593+rquidute@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Part of the fix for #1062: THCLI reports a WebSocket error after successfully uploading a manual test log (e.g. TC-CADMIN-1.17), even though the upload itself completed.
This is the CLI-side complement to the backend fix in certification-tool-backend#343, which batches log-line broadcasts during upload processing to avoid stalling the backend's event loop in the first place. This PR makes the CLI resilient to the case where the WebSocket connection still gets dropped (e.g. on very large files, slower networks, etc.) after the upload has already succeeded.
Root cause
In
__upload_file_and_send_response, both the HTTP file upload and the subsequent_send_prompt_response()WebSocket call were wrapped in the same try/except block. When the backend's event loop was busy handling the flood of log broadcasts triggered by processing a large uploaded file, the WebSocket's keepalive ping/pong could time out and the connection would be dropped after the upload had already succeeded but before the CLI could send the "SUCCESS" prompt response. ThatConnectionClosedErrorwas caught by the genericexcept Exceptionhandler and echoed as❌ Unexpected error uploading file: no close frame received or sent— misleading, since the file was already uploaded.Fix
_send_prompt_response()call (not the upload) in a dedicatedexcept websockets.exceptions.ConnectionClosedhandler.Testing
Added unit tests in
tests/test_run/test_prompt_manager.pycovering:Note: this sandbox's local test venv has no network access to install
pytest/httpx/websockets, so I validated the test logic and the fixed function's control flow via a standalone script (traced through the try/except structure with stubs) rather than viapytestdirectly. Please re-run the full suite in CI/your dev environment to confirm.