Skip to content

Commit 154042a

Browse files
authored
feat(pyamber): reject invalid port booleans (apache#8240)
### What changes were proposed in this PR? The Python GlobalPortIdentity decoder now rejects invalid boolean tokens instead of silently treating them as false. Valid mixed-case true and false values remain supported. ### Any related issues, documentation, discussions? Closes apache#8239 ### How was this PR tested? Retested with Python 3.12 on Windows in a fresh detached worktree from upstream main at `7426431337`, which includes the merged loop-completion change apache#8938. Regression before implementation: 2 failed, 48 passed. After implementation: 50 passed. Generate protobufs with `bash bin/python-proto-gen.sh`, then run from `amber`: ```text python -m pytest src/test/python/core/util/test_virtual_identity.py src/test/python/core/storage/test_vfs_uri_factory.py -q --tb=line -p no:cacheprovider python -m ruff check src/main/python src/test/python python -m ruff format --check src/main/python src/test/python ``` Ruff lint and formatting pass for all 217 Python files. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Codex
1 parent 707849a commit 154042a

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎amber/src/main/python/core/util/virtual_identity.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ def deserialize_global_port_identity(encoded_str: str) -> GlobalPortIdentity:
111111
port_id = int(port_id_str)
112112
if port_id < 0:
113113
raise ValueError(f"portId must be non-negative: {port_id}")
114+
for field, value in (("isInternal", is_internal_str), ("isInput", is_input_str)):
115+
if value.lower() not in ("true", "false"):
116+
raise ValueError(
117+
f"Invalid {field}: {value}. Expected true/false in GlobalPortIdentity "
118+
f"encoding: {encoded_str}"
119+
)
114120
is_internal = is_internal_str.lower() == "true"
115121
is_input_port = is_input_str.lower() == "true"
116122
op_id = PhysicalOpIdentity(

‎amber/src/test/python/core/util/test_virtual_identity.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ def test_treats_boolean_capitalization_case_insensitively(self):
195195
assert result.port_id.internal is True
196196
assert result.input is False
197197

198+
@pytest.mark.parametrize(
199+
("field", "valid"), [("isInternal", "false"), ("isInput", "true")]
200+
)
201+
def test_rejects_invalid_boolean_value(self, field, valid):
202+
encoded = (
203+
"(logicalOpId=op,layerName=l,portId=0,isInternal=false,isInput=true)"
204+
).replace(f"{field}={valid}", f"{field}=maybe")
205+
with pytest.raises(ValueError, match=f"Invalid {field}"):
206+
deserialize_global_port_identity(encoded)
207+
198208
def test_raises_value_error_on_malformed_input(self):
199209
with pytest.raises(ValueError, match="Invalid GlobalPortIdentity format"):
200210
deserialize_global_port_identity("not-a-port-id")

0 commit comments

Comments
 (0)