Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughCentralizes base URL validation into a new utility Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
c870461 to
b7097fe
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@mpt_api_client/http/client_utils.py`:
- Around line 11-16: The inline multi-line error message used in the ValueError
when validating base_url should be moved to a module-level constant to satisfy
TRY003; create a descriptive constant (e.g. BASE_URL_ERROR_MSG) at the top of
the module and replace the inline string in the raise ValueError(...) (the check
that inspects base_url before constructing MPTClient) with that constant so the
ValueError is raised with the constant variable instead of a raw multi-line
literal.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@mpt_api_client/http/client_utils.py`:
- Around line 17-24: The code accesses split_result.port which can raise
ValueError for malformed ports and bypass the standard INVALID_ENV_URL_MESSAGE;
update the logic around port handling in the function that builds the sanitized
base URL (the block using split_result, host, port, PATH_TO_REMOVE_RE, and
urlunparse) to guard access to split_result.port with a try/except ValueError,
normalize the exception by raising or returning the same INVALID_ENV_URL_MESSAGE
path/validation flow, and then continue to construct host/port/path and call
urlunparse as before so malformed ports produce the consistent validation error.
f6b3fb9 to
09a0762
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@mpt_api_client/http/client_utils.py`:
- Around line 13-29: The validate_base_url function is over the complexity
limit; extract the URL reconstruction logic into a small helper (e.g.,
build_normalized_url or format_host_port_path) that takes the urlsplit result
and PATH_TO_REMOVE_RE and returns the normalized URL string; leave
validate_base_url responsible only for input validation, calling urlsplit,
delegating host/port/path formatting to the helper, keeping the existing
try/except for split_result.port and re-raising ValueError as before, and ensure
you still use urlsplit, urlunparse, split_result.hostname/port/scheme and
PATH_TO_REMOVE_RE so behavior is unchanged.
🧹 Nitpick comments (1)
tests/unit/http/test_client_utils.py (1)
30-42: Good error case coverage; consider adding malformed port tests.The test cases cover empty and malformed URL structures well. Given that
validate_base_urlincludes atry/exceptblock specifically for port parsing errors (lines 22-25 in client_utils.py), consider adding test cases for malformed ports to verify the error handling:"http://example.com:abc", # Non-numeric port "http://example.com:99999", # Port out of range
09a0762 to
f6a8076
Compare
mpt_api_client/http/client_utils.py
Outdated
| return f"[{hostname}]" if ":" in hostname else hostname | ||
|
|
||
|
|
||
| def _format_port(split_result: Any) -> str: |
There was a problem hiding this comment.
Could you pls try to avoid using Any here, I'm pretty sure there should be a proper type of url here
0341992 to
c6caa2c
Compare
c6caa2c to
2de5b67
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@mpt_api_client/http/client_utils.py`:
- Around line 35-44: Update the validate_base_url function signature to accept
an optional URL by changing its parameter type to Optional[str] (import Optional
from typing) so callers like base_url or os.getenv("MPT_URL") have a compatible
type; keep the return type as str and leave the internal runtime checks (raising
ValueError for None/invalid) unchanged; update any related type hints/usages of
validate_base_url if necessary to reflect Optional[str] input.
- Around line 1-32: The type annotations for _format_port and
_build_sanitized_base_url are incorrect: import SplitResult from urllib.parse
and change their parameter types from str to SplitResult; in
_build_sanitized_base_url, guard against split_result.hostname being None (e.g.,
raise ValueError(INVALID_ENV_URL_MESSAGE) or handle it) before calling
_format_host, and keep accessing split_result.port, .path and .scheme as before
so mypy/type checkers accept the code.
|



Closes MPT-17614