fix(adapters): harden native hooks — edge-case tests + CHANGELOG [v2]#1608
Closed
miyannishar wants to merge 2 commits into
Closed
fix(adapters): harden native hooks — edge-case tests + CHANGELOG [v2]#1608miyannishar wants to merge 2 commits into
miyannishar wants to merge 2 commits into
Conversation
added 2 commits
April 29, 2026 20:56
Fixes 5 issues raised by @imran-siddique: BLOCKING: - SK wrap_kernel(), PydanticAI wrap(): remove contextlib.suppress(Exception) which was silently swallowing ALL exceptions (not just DeprecationWarning). Now uses warnings.catch_warnings() alone to suppress only the nested DeprecationWarning, so real errors (invalid kernel, policy validation failures) propagate correctly. BUG: - test_smolagents_hooks: test_blocks_pattern_in_observation incorrectly assumed a step with no tool calls but a blocked observation would pass. GovernanceStepCallback scans observations unconditionally; the test now correctly asserts PolicyViolationError is raised in both cases (no-tool- call step and allowed-tool-call step with blocked observation). WARNINGS: - Anthropic wrap_client(): suppress nested DeprecationWarning from kernel.wrap() so callers see only one warning instead of two. - Anthropic wrap()/as_message_hook(), SK GovernanceFunctionFilter: replace int(time.time()) session IDs with uuid.uuid4().hex[:12] to prevent same-second session ID collisions in audit trails. - SK GovernanceFunctionFilter: use the uuid-based ID as the _contexts dict key so calling as_filter() multiple times no longer overwrites the first filter's context entry. Part of: microsoft#1593
…CHANGELOG Bot-flagged issues resolved: ## Test coverage (docs-sync + test-generator bot) - anthropic: add UUID session-ID format tests, empty messages list, assistant-message blocked-pattern scan, client exception propagation, cumulative token tracking, exact-one-deprecation assertion - semantic_kernel: fix context key lookup (now UUID-keyed, not 'sk-filter'), add cross-filter isolation, wildcard scope, nested blocked-arg, None-args, correct call_count assertions (increments by 2: filter + pre_execute) - pydantic_ai: add empty/long prompt edge cases, multiple-tool sequence, call_number monotonicity, audit-log immutability (returns copy), full lifecycle integration test, repr-updates-after-calls - conftest: pre-stub llama_index tree so all four suites run on Python 3.9 ## CHANGELOG (docs-sync bot) - Added native hooks entry under [Unreleased] detailing new factory methods - Added Deprecated section for all wrap() variants with migration notes All 98 hook tests now pass locally. Relates to microsoft#1571
🤖 AI Agent: code-reviewer — Action Items:TL;DR: 0 blockers, 1 warning. Solid improvements; minor follow-up suggested.
Action Items:
|
🤖 AI Agent: breaking-change-detector — API CompatibilityAPI Compatibility
|
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
🤖 AI Agent: test-generator — View detailsTest coverage looks good. No gaps identified. |
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
PR Review Summary
Verdict: ❌ Changes needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is the successor to #1593, rebased on
mainand addressing every issue raised in that review.Closes / relates to #1571 (deprecate
wrap()API in favour of native hooks).What changed
🧪 Test coverage
All four adapter test suites now cover the edge cases flagged by the
test-generatoranddocs-syncbots in #1593:Anthropic (
test_anthropic_hooks.py)ant-hook-<hex12>)emptymessages list does not raiseDeprecationWarningassertion for bothwrap()andwrap_client()Semantic Kernel (
test_semantic_kernel_hooks.py)_ctx(was hardcoded'sk-filter')f1does not affectf2Plugin.*allowlist scopedict/Nonearguments handled without crashcall_countassertions corrected (filter +pre_executeeach increment → ×2 per invocation)PydanticAI (
test_pydantic_ai_hooks.py)before_tool_execute× 3 with distinct call_number audit entries.audit_logreturns a copy — mutation does not affect internal stateNonetool result returned unchangedconftest.pyllama_indexmodule tree so all four suites can be collected on Python 3.9 (CI uses 3.10+, where the real package is available)📖 CHANGELOG
Added
[Unreleased]entries for:wrap()variants with migration guidanceChecklist
mainDeprecationWarningemits exactly once perwrap()calluuid.uuid4()— no time-collision riskBot notes addressed:
test-generator: missing edge cases,docs-sync: no CHANGELOG entry