Skip to content

Commit 14cd09e

Browse files
aditik0303claude
andcommitted
test(google-adk): cover swallow/extraction branches (Sonar coverage)
New-code coverage ~89% -> over the 90% gate. Added non-block swallow on the model/tool callbacks and _content_text / _cap_args / _stringify helper edges. governance/callbacks.py: 89% -> 96%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6a42ec7 commit 14cd09e

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

packages/uipath-google-adk/tests/governance/test_callbacks.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,56 @@ def test_callbacks_return_none():
448448
assert cb.after_model(None, SimpleNamespace(partial=False, content=None)) is None # type: ignore[func-returns-value]
449449
assert cb.before_tool(FakeTool("t"), {}, None) is None # type: ignore[func-returns-value]
450450
assert cb.after_tool(FakeTool("t"), {}, None, {}) is None # type: ignore[func-returns-value]
451+
452+
453+
# --------------------------------------------------------------------------
454+
# coverage: swallow on model/tool callbacks + extraction / helper edges
455+
# --------------------------------------------------------------------------
456+
457+
458+
class _Boom:
459+
"""Evaluator whose every evaluate_* raises a non-block error."""
460+
461+
def __getattr__(self, _name: str) -> Any:
462+
def _raise(*_a: Any, **_k: Any) -> None:
463+
raise RuntimeError("evaluator bug")
464+
465+
return _raise
466+
467+
468+
@pytest.mark.parametrize(
469+
"invoke",
470+
[
471+
lambda cb: cb.after_model(None, SimpleNamespace(partial=False, content=None)),
472+
lambda cb: cb.before_tool(FakeTool("t"), {}, None),
473+
lambda cb: cb.after_tool(FakeTool("t"), {}, None, {"r": 1}),
474+
],
475+
)
476+
def test_model_tool_callbacks_swallow_non_block_errors(invoke, caplog):
477+
cb = GovernanceCallbacks(evaluator=_Boom(), agent_name="a", session_id="s")
478+
with caplog.at_level(logging.WARNING):
479+
invoke(cb) # must NOT raise — a governance bug can't break the run
480+
assert any("governance check failed" in r.message for r in caplog.records)
481+
482+
483+
def test_content_text_and_helper_edges():
484+
G = GovernanceCallbacks
485+
# _content_text: None / bare str / list-of-parts / unsupported object
486+
assert G._content_text(None) == ""
487+
assert G._content_text("bare") == "bare"
488+
assert G._content_text(123) == ""
489+
fc = SimpleNamespace(name="lookup", args={"q": "x"})
490+
fr = SimpleNamespace(response={"ok": 1})
491+
out = G._content_text(
492+
_content(
493+
[_part(text="hi"), _part(function_call=fc), _part(function_response=fr)]
494+
)
495+
)
496+
assert "hi" in out and "lookup" in out and "ok" in out
497+
# _cap_args: non-dict passes through untouched
498+
assert G._cap_args("notdict") == "notdict" # type: ignore[arg-type]
499+
# _stringify: str passthrough + circular-ref fallback (no crash)
500+
assert G._stringify("hi") == "hi"
501+
circular: dict[str, Any] = {}
502+
circular["self"] = circular
503+
assert isinstance(G._stringify(circular), str)

0 commit comments

Comments
 (0)