Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/rai_core/rai/messages/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def store_artifacts(
tool_call_id: str, artifacts: List[Any], db_path="artifact_database.pkl"
):
# TODO(boczekbartek): refactor
if not isinstance(tool_call_id, str) or not tool_call_id.strip():
raise ValueError(
f"tool_call_id must be a non-empty string, got {tool_call_id!r}"
)
path = Path(db_path)
if not path.is_file():
artifact_database: dict = {}
Expand All @@ -45,6 +49,10 @@ def get_stored_artifacts(
tool_call_id: str, db_path="artifact_database.pkl"
) -> List[Any]:
# TODO(boczekbartek): refactor
if not isinstance(tool_call_id, str) or not tool_call_id.strip():
raise ValueError(
f"tool_call_id must be a non-empty string, got {tool_call_id!r}"
)
db_path = Path(db_path)
if not db_path.is_file():
return []
Expand Down
13 changes: 13 additions & 0 deletions tests/communication/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2025 Robotec.AI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
6 changes: 3 additions & 3 deletions tests/communication/ros2/test_ros2_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ def cancel_future():

# Edge case timeout tests
def test_get_future_result_zero_timeout():
"""Test with zero timeout."""
"""Test that a zero timeout is rejected as non-positive."""
future = Future()
result = get_future_result(future, timeout_sec=0.0)
assert result is None
with pytest.raises(ValueError, match="timeout_sec must be positive"):
get_future_result(future, timeout_sec=0.0)


def test_get_future_result_very_short_timeout():
Expand Down
11 changes: 11 additions & 0 deletions tests/messages/test_artifacts_db_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ def test_store_artifacts_creates_file_at_path(tmp_path: Path):
db.parent.mkdir(parents=True)
store_artifacts("x", [1], db_path=str(db))
assert get_stored_artifacts("x", db_path=str(db)) == [1]


def test_store_artifacts_rejects_empty_tool_call_id(tmp_path: Path):
import pytest

db = tmp_path / "db.pkl"
for bad in ("", " ", None, 123):
with pytest.raises(ValueError, match="tool_call_id must be a non-empty string"):
store_artifacts(bad, ["a"], db_path=str(db)) # type: ignore[arg-type]
with pytest.raises(ValueError, match="tool_call_id must be a non-empty string"):
get_stored_artifacts(bad, db_path=str(db)) # type: ignore[arg-type]