Refactor implementation and add unit tests. #107
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 489 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.371
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #107"
general
weight: 0.35
fujitatomoya
Refactoring of the implementation with no change in capabilities, command line arguments, options or printed output.
ros2 ai -h,status -h,query -handexec -hare byte-identical before and after.Code changes
| Before | After |
| :-- | :-- |
|
ros2ai/api/__init__.pyheldadd_global_arguments(),curl_get_request()and the unusedollama_get_models()|ros2ai/api/arguments.pyholdsadd_global_arguments()and the newadd_role_argument()shared byquery/exec. Model listing uses the OpenAI python client (client.models.list()) instead of spawningcurl, so thecurlexec dependency is dropped. ||
ros2ai/api/openai.py(name shadowed theopenaipackage),ChatCompletionClientinheritedOpenAiConfig,ChatCompletionParameterswas a hand written property class with a mutable default |ros2ai/api/client.py:ChatCompletionClient(config)takes the config by composition,call()returns success,list_models()added,ChatCompletionParametersis adataclass,chat_messages()builds the system/user messages. ||
OpenAiConfighad unusedset_value()/remove_key(), andis_api_key_valid()duplicated the client code |OpenAiConfigis configuration only.resolve_role_system()implements the argument > env > default role resolution thatqueryandexecduplicated. The availability check lives instatusand uses the client. ||
utils.pyhad the unusedrun_command()and unusedargv/prefixparameters | removed,extract_ros2_command()composestruncate_before_substring()/remove_backticks()/ros2_single_command()forexec. || verbs duplicated role handling, message building and the
-r/--roleargument | verbs are thin: parse, resolve role, build parameters, call client, print. |Whole code base now passes
ament_flake8,ament_pep257,ament_copyrightandament_xmllint.Behavior notes (intentional, error path only)
queryandexecused to printFailed to call OpenAI API: ...and then crash with anAttributeError/TypeErrortraceback. They now print the same message and return 1.execgets a completion that did not finish (finish_reason != 'stop') it used to crash with a traceback, it now printsFailed chat completion with: <reason>and returns 1.status -lmodel listing failures printFailed to list models: <error>instead of the raw curl/json error, the[FAILURE] Could not retrieved list of models.line is unchanged.Tests
New
test/directory, 43 tests, no network access required:test_utils.py,test_config.py: pure helpers and env/argument precedence.test_cli.py: every option of every verb andros2 ai -hthrough ros2cli entry points.test_verbs.py:status/query/execend to end against a fake OpenAI client, asserting the exact printed output and the arguments passed to the API.test_flake8.py,test_pep257.py,test_copyright.py,test_xmllint.py.The behavior tests were written first and pass against the original code on
rollingas well, so they lock the existing behavior.scripts/github_workflows.shnow installs the test dependencies and runscolcon test+colcon test-result, so the suite runs for every distribution on each PR. Verified locally by running that script in theros:humble,ros:jazzy,ros:kilted,ros:lyricalandros:rollingcontainers: 43 passed on each.Other files
pytest.ini: disables theanyiopytest plugin pulled in byopenai, it requires pytest >= 7 and breaks test collection on humble (pytest 6.2.5). Also registers the lint markers.CONTRIBUTING.md: standard Apache 2.0 text generated byament_copyright, which requires it next toLICENSE.package.xml:curlexec dependency removed. README/CHANGELOG untouched.🤖 Generated with Claude Code