Skip to content

Commit bb13b05

Browse files
fix: address PR review comments
Signed-off-by: Matthew Grigsby <38010437+MatthewGrigsby@users.noreply.github.com>
1 parent 8b0e346 commit bb13b05

4 files changed

Lines changed: 12 additions & 41 deletions

File tree

cforge/common/prompting.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,6 @@ def _prompt_string_value(
108108
return typer.prompt("", type=str, default=default, show_default=show_default)
109109

110110

111-
def _unwrap_optional_annotation(annotation: Any) -> Any:
112-
"""Unwrap Optional[T] and Annotated[Optional[T], ...] into T."""
113-
origin = get_origin(annotation)
114-
if origin is Annotated:
115-
args = get_args(annotation)
116-
if args:
117-
return _unwrap_optional_annotation(args[0])
118-
119-
args = get_args(annotation)
120-
if origin is Union and type(None) in args:
121-
non_none_args = [arg for arg in args if arg is not type(None)]
122-
if non_none_args:
123-
return non_none_args[0]
124-
return annotation
125-
126-
127111
def _validate_pydantic_schema_dict_key_types(schema_class: type[BaseModel]) -> None:
128112
"""Reject dict fields with non-string keys (JSON object keys are always strings)."""
129113
visited_models: set[type[BaseModel]] = set()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ maintainers = [
4747
# ----------------------------------------------------------------
4848
dependencies = [
4949
"rich>=13.9.4",
50-
"typer>=0.23.1",
50+
"typer>=0.20.0",
5151
"mcp-contextforge-gateway==1.0.0b2",
5252
"cryptography>=44.0.0",
5353
"jsonschema>=4.23.0",

tests/commands/resources/test_tools.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,16 @@ def test_tools_update_interactive(self, mock_console) -> None:
156156
"""Test tools update interactive mode."""
157157
mock_result = {"id": "tool-1", "name": "updated"}
158158

159-
with patch("cforge.commands.resources.tools.get_console", return_value=mock_console):
160-
with patch("cforge.commands.resources.tools.prompt_for_schema", return_value={"description": "updated"}):
161-
with patch("cforge.commands.resources.tools.make_authenticated_request", return_value=mock_result):
162-
with patch("cforge.commands.resources.tools.print_json"):
163-
tools_update(tool_id="tool-1", data_file=None)
159+
with patch_functions(
160+
"cforge.commands.resources.tools",
161+
get_console=mock_console,
162+
prompt_for_schema={"return_value": {"description": "updated"}},
163+
make_authenticated_request={"return_value": mock_result},
164+
print_json=None,
165+
) as mocks:
166+
tools_update(tool_id="tool-1", data_file=None)
167+
mocks.make_authenticated_request.assert_called_once_with("PUT", "/tools/tool-1", json_data={"description": "updated"})
168+
mocks.print_json.assert_called_once()
164169

165170
def test_tools_delete_with_confirmation(self, mock_console) -> None:
166171
"""Test tools delete with confirmation."""

tests/common/test_prompting.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Standard
55
from datetime import datetime
6-
from typing import Annotated, Any, Dict, List, Optional, Union
6+
from typing import Annotated, Any, Dict, List, Optional
77
from unittest.mock import patch
88

99
# Third-Party
@@ -23,7 +23,6 @@
2323
_resolve_schema_type,
2424
_schema_contains_ref,
2525
_strip_schema_internal_properties,
26-
_unwrap_optional_annotation,
2726
)
2827

2928

@@ -1766,23 +1765,6 @@ def test_resolve_ref_schema_non_dict_input_returns_empty_schema(self) -> None:
17661765
result = _resolve_ref_schema({}, "not-a-dict") # type: ignore[arg-type]
17671766
assert result == {}
17681767

1769-
def test_unwrap_optional_annotation_union_only_none_returns_annotation(self) -> None:
1770-
"""Test Optional unwrapping keeps annotation when union has no non-None members."""
1771-
marker: object = object()
1772-
with patch("cforge.common.prompting.get_origin", return_value=Union), patch("cforge.common.prompting.get_args", return_value=(type(None),)):
1773-
assert _unwrap_optional_annotation(marker) is marker
1774-
1775-
def test_unwrap_optional_annotation_annotated_without_args_returns_annotation(self) -> None:
1776-
"""Annotated branches should handle empty arg tuples defensively."""
1777-
marker: object = object()
1778-
with patch("cforge.common.prompting.get_origin", return_value=Annotated), patch("cforge.common.prompting.get_args", return_value=()):
1779-
assert _unwrap_optional_annotation(marker) is marker
1780-
1781-
def test_unwrap_optional_annotation_annotated_optional_unwraps(self) -> None:
1782-
"""Annotated optional annotations should unwrap to the inner type."""
1783-
annotation = Annotated[Optional[int], "meta"]
1784-
assert _unwrap_optional_annotation(annotation) is int
1785-
17861768
def test_resolve_schema_type_any_of_all_null_returns_null(self) -> None:
17871769
"""Test schema type resolver returns null when all anyOf variants are null."""
17881770
schema = {"anyOf": [{"type": "null"}, {"type": "null"}]}

0 commit comments

Comments
 (0)