Skip to content

Commit 490b1b3

Browse files
olivermeyerclaude
andcommitted
fix(settings): use explicit None/empty guard for Path serializer
`Path` has no `__bool__`, making all instances truthy. The previous `if not input_value:` guard was therefore never entered for any `Path`, so `Path("")` silently resolved to the current working directory. Replace the falsy check with an explicit guard: if input_value is None or not input_value.parts: This correctly returns `None` for both `None` and empty/no-parts paths (e.g. `Path("")` / `Path()`), while resolving all other paths as before. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 11f72b1 commit 490b1b3

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/aignostics_foundry_core/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ def serialize_path_resolve(input_value: Path | None, _info: FieldSerializationIn
6363
_info: Pydantic serialization info (unused).
6464
6565
Returns:
66-
None if input is falsy, otherwise the resolved absolute path string.
66+
None if input is `None` or has no path components (e.g. empty string),
67+
otherwise the resolved absolute path string.
6768
"""
68-
if not input_value:
69+
if input_value is None or not input_value.parts:
6970
return None
7071
return str(input_value.resolve())
7172

tests/aignostics_foundry_core/settings_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ def test_serialize_path_resolve_none(self) -> None:
117117
result = OpaqueSettings.serialize_path_resolve(cast("Path", None), _make_info(None))
118118
assert result is None
119119

120+
@pytest.mark.unit
121+
def test_serialize_path_resolve_empty_path(self) -> None:
122+
"""Test that None is returned for Path("") rather than resolving to CWD."""
123+
result = OpaqueSettings.serialize_path_resolve(Path(), _make_info(None))
124+
assert result is None
125+
120126

121127
class TestLoadSettings:
122128
"""Tests for load_settings."""

0 commit comments

Comments
 (0)