You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updates to the 'init' and 'logs' actions in the VISOR CLI tool:
init
Add option to start a session in the same command as starting a new VISOR instance. We currently have an action to spin up a new VISOR instance (init) and a separate action to start the visualizer (start). It makes sense to have a dedicated start action for cases where we are loading a dataset and/or metadata into the scene. But for the case where a user wants to spin up a VISOR instance with an empty scene and start it immediately (e.g. where they will be loading a saved state into it), this PR adds a --start flag.
logs
Current functionality is maintained but the 'logs' action is given its own parser to take three actions: tail (which is the current default behaviour), list, and a new action, clear (which removes the logs directory). It also selects the visor.log file as a default log to display, which previously a user would need to specify explicitly.
Old behaviour -> New behaviour (defaults to 'visor.log'): visor-cli logs visor -f -> visor-cli logs tail -f
New functionality (optional -f flag to remove without prompting; default asks for confirmation) visor-cli logs clear -f
Copilot summary
This pull request introduces several improvements and new features to the Visor CLI, focusing on enhanced log management capabilities and server initialization flexibility. The most significant changes include the addition of a new logs subcommand structure with support for listing, tailing, and clearing log files, as well as an option to start the viewer instance immediately after initialization. Extensive tests have been added and updated to cover these new features and changes.
Log management enhancements:
Added a new logs subcommand structure with three actions: list (list available logs), tail (tail a log file, with support for -f/--follow and -n/--lines), and clear (delete the log directory with optional confirmation via -f/--force). The corresponding methods (list_logs, tail_log, clear_logs) were implemented in LogsAPI, replacing the previous single log display method. [1][2][3][4]
Improved log listing output to include the log directory path in messages for better clarity.
Comprehensive unit tests were added for all new log management features, including confirmation prompts, error handling, and force deletion. [1][2][3][4][5]
Server initialization improvements:
Added a --start flag to the server init command, allowing users to optionally start the viewer instance immediately after initialization. This is reflected in argument parsing, the ServerAPI.initialize method signature, and the main CLI logic. [1][2][3][4][5]
Updated and added tests to verify that the --start flag is correctly parsed, forwarded, and triggers the expected API calls. [1][2][3]
General CLI improvements:
The CLI now allows log-related commands to run even if the server is not running, improving usability for log inspection and cleanup.
These changes collectively make the CLI more robust, user-friendly, and testable, especially for log management and server initialization workflows.
If the new /start request returns an HTTP error, initialize(..., start=True) still returns normally, so the CLI reports success even though the requested session was not started. Check the second response status just as the initialization response is checked.
Return nonzero when log deletion fails
src/ansys/visor/viewer/cli/apis.py:313
A failed rmtree is only printed and then swallowed, causing visor-cli logs clear to exit with status 0 even though nothing was cleared. This makes the force form unsafe for scripts and cleanup automation. Propagate the failure (or return a failure result that main() converts to a nonzero exit code) after reporting it.
The new --start path never calls raise_for_status() on the /start response. If initialization succeeds but starting returns 4xx/5xx, the command exits successfully even though the requested instance was not started. Validate this response just as the initialization response is validated.
Propagate log removal errors to the command exit status
src/ansys/visor/viewer/cli/apis.py:313
A removal error is printed and then swallowed, so visor-cli logs clear -f exits with status 0 even when the directory was not cleared. Re-raise the filesystem error (or propagate a failure result to main) so scripts can detect that this destructive operation failed.
Check /start response before reporting successful viewer startup
src/ansys/visor/viewer/cli/apis.py:91
A 4xx/5xx response from /start is printed but never checked, so visor-cli server init --start can exit successfully even though the viewer failed to start. Check the start response before reporting success.
Propagate log deletion failures and return a nonzero exit status
src/ansys/visor/viewer/cli/apis.py:313
Deletion failures are swallowed and the method returns normally, causing visor-cli logs clear to exit with status 0 after permission errors or locked files. Propagate a failure status and have the CLI exit nonzero so scripts can reliably detect that logs were not cleared.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
The start request can fail while the CLI exits successfully, and the PR references an unrelated issue.
Review effort: Balanced Findings: None
Previously missed (1)
In code that hasn't changed since last review
Check /start HTTP status before reporting successful startup
src/ansys/visor/viewer/cli/apis.py:91
The new --start request does not check the HTTP status. If /start returns a 4xx/5xx response, the body is printed and visor-cli server init --start still exits successfully even though the requested instance was not started. Call raise_for_status() for this response as is already done for /initialize.
The reason will be displayed to describe this comment to others. Learn more.
@margalva@ansBAkula this copilot comment is a valid point. I think the server check here at the CLI layer is likely sufficient though; the visor-cli logs clear action is for convenience (instead of running rm -r logs manually). Its current server check is not a guarantee it's safe, it's a best-effort guard. But, let me know what you think.
@ansBAkula Good question, the main reason I kept the default False is to, by default, keep the Visor class instance instantiation separate from starting the Trame server itself (the original design). The normal workflow is
# Create the new instance on a new port
visor-cli server init --port 8082
# Start the instance with a dataset
visor-cli instance start examples/assets/vtk_scene_sphere_l2_b3_r32_v3_c1_z0.vtm --metadata-path examples/assets/vtk_scene_sphere_l2_b3_r32_v3_c1_z0.json
The use case I was picturing for the --start flag was the case where we want to load a state into a blank visualizer. Right now that requires:
# Create the new instance on a new port
visor-cli server init --port 8083
# Start the instance with no dataset
visor-cli instance start
# Load the saved state
visor-cli instance load <saved_state_dir>
So it's more like a convenience helper to optionally start the server in the simple case where no dataset is being loaded into the scene on the 'start' API call, but the default usage would keep init separate from start.
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
maintenanceOperation not directly changing the production code - e.g., updating a devops pipelinetestWork associated with testing
4 participants
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.
Addresses #155
Description
Updates to the 'init' and 'logs' actions in the VISOR CLI tool:
Add option to start a session in the same command as starting a new VISOR instance. We currently have an action to spin up a new VISOR instance (
init) and a separate action to start the visualizer (start). It makes sense to have a dedicatedstartaction for cases where we are loading a dataset and/or metadata into the scene. But for the case where a user wants to spin up a VISOR instance with an empty scene and start it immediately (e.g. where they will be loading a saved state into it), this PR adds a--startflag.Current functionality is maintained but the 'logs' action is given its own parser to take three actions:
tail(which is the current default behaviour),list, and a new action,clear(which removes the logs directory). It also selects thevisor.logfile as a default log to display, which previously a user would need to specify explicitly.Old behaviour -> New behaviour (defaults to 'visor.log'):
visor-cli logs visor -f->visor-cli logs tail -fNew functionality (optional -f flag to remove without prompting; default asks for confirmation)
visor-cli logs clear -fCopilot summary
This pull request introduces several improvements and new features to the Visor CLI, focusing on enhanced log management capabilities and server initialization flexibility. The most significant changes include the addition of a new
logssubcommand structure with support for listing, tailing, and clearing log files, as well as an option to start the viewer instance immediately after initialization. Extensive tests have been added and updated to cover these new features and changes.Log management enhancements:
logssubcommand structure with three actions:list(list available logs),tail(tail a log file, with support for-f/--followand-n/--lines), andclear(delete the log directory with optional confirmation via-f/--force). The corresponding methods (list_logs,tail_log,clear_logs) were implemented inLogsAPI, replacing the previous single log display method. [1] [2] [3] [4]Server initialization improvements:
--startflag to theserver initcommand, allowing users to optionally start the viewer instance immediately after initialization. This is reflected in argument parsing, theServerAPI.initializemethod signature, and the main CLI logic. [1] [2] [3] [4] [5]--startflag is correctly parsed, forwarded, and triggers the expected API calls. [1] [2] [3]General CLI improvements:
These changes collectively make the CLI more robust, user-friendly, and testable, especially for log management and server initialization workflows.