Repository navigation
test(python): add direct unit tests for decorator_metadata - #1234
Open
OpenLucasKaka wants to merge 1 commit into
Open
OpenLucasKaka wants to merge 1 commit into
OpenLucasKaka wants to merge 1 commit into
Conversation
Cover code_origin, split_direct_registration_arg, stage_trigger and every accepts_webhook branch of resolve_reasoner_metadata, plus trigger merging, _pending_triggers cleanup and code_origin preservation. Fixes Agent-Field#1228
|
|
This branch has not been deployed
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
Adds
sdk/python/tests/test_decorator_metadata.py, a set of direct unit tests foragentfield/decorator_metadata.py. Before this, the module was only covered indirectly through the decorator tests. There are no production code changes.Fixes #1228
The new tests cover:
code_origin: it returns"path:line"for a plain function andNonefor the builtinlen.split_direct_registration_arg: it returns(fn, None)for a function and(None, value)for a string, a list andNone.stage_trigger: repeated calls append to_pending_triggers.accepts_webhookbranch ofresolve_reasoner_metadata: an explicit value wins;"warn"is upgraded toTruewhen triggers are passed or staged; an existing value is kept; triggers present giveTrue; nothing gives"warn"._pending_triggersis deleted afterwards. A trigger with a pre-setcode_originkeeps it, and a trigger without one gets the function's origin.delattrfallback (lines 57–58): a staged trigger reached through a bound method is still merged, and theAttributeErrorfrom deleting the attribute on the method is swallowed. Without this case the coverage report still shows those two lines as missing.Triggers are plain
types.SimpleNamespace()stand-ins, as the issue suggests.Type of change
Test plan
cd sdk/python && ./scripts/run_pytest.sh tests/test_decorator_metadata.py -q: 16 passedcd sdk/python && ./scripts/run_pytest.sh tests/test_decorator_metadata.py --cov=agentfield.decorator_metadata --cov-report=term-missing:agentfield/decorator_metadata.py 52 0 100%(no missing lines)Neighboring decorator tests still pass:
./scripts/run_pytest.sh tests/test_decorator_metadata.py tests/test_accepts_webhook.py tests/test_decorator_code_origin.py tests/test_decorator_typing.py --no-cov: 58 passedMutation check: I made each of these one-line changes to
decorator_metadata.pyin turn, and each one makes at least one new test fail: default"warn"→True; the"warn"upgrade disabled; thecode_originoverwritten unconditionally; thedelattrremoved;stage_triggerreplacing instead of appending;split_direct_registration_argswapped; explicit triggers not merged; explicitaccepts_webhookignored.All runs used Python 3.10.12 and pytest 9.2.0.
Lint: I couldn't download the pinned
ruff==0.15.22wheel in my environment because the network was too slow. Instead I checked the new file against ruff's default rule set usingpyflakes(F rules) andpycodestyle --select=E4,E7,E9, plus a fullpycodestyle --max-line-length=88pass. All of them are clean. The file has no async code, so the ASYNC rules don't apply. CI'sruff check .remains the authoritative check.Test coverage
decorator_metadata.pyis now at 100% line coverage.coverage-baseline.jsonin this PR. (Not applicable: nothing was removed.)Checklist
test(python): …. The commit itself is not GPG-signed.)Related issues / PRs
#1228