Skip to content

test(python): add direct unit tests for decorator_metadata - #1234

Open
OpenLucasKaka wants to merge 1 commit into
Agent-Field:mainfrom
OpenLucasKaka:test/issue-1228-decorator-metadata-tests
Open

OpenLucasKaka wants to merge 1 commit into
Agent-Field:mainfrom
OpenLucasKaka:test/issue-1228-decorator-metadata-tests

Conversation

@OpenLucasKaka

Copy link
Copy Markdown

Summary

Adds sdk/python/tests/test_decorator_metadata.py, a set of direct unit tests for agentfield/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 and None for the builtin len.
  • split_direct_registration_arg: it returns (fn, None) for a function and (None, value) for a string, a list and None.
  • stage_trigger: repeated calls append to _pending_triggers.
  • Each accepts_webhook branch of resolve_reasoner_metadata: an explicit value wins; "warn" is upgraded to True when triggers are passed or staged; an existing value is kept; triggers present give True; nothing gives "warn".
  • Merging: existing, explicit and staged triggers are merged in that order, and _pending_triggers is deleted afterwards. A trigger with a pre-set code_origin keeps it, and a trigger without one gets the function's origin.
  • The delattr fallback (lines 57–58): a staged trigger reached through a bound method is still merged, and the AttributeError from 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

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs only
  • Tests only
  • CI / tooling
  • Breaking change

Test plan

  • cd sdk/python && ./scripts/run_pytest.sh tests/test_decorator_metadata.py -q: 16 passed

  • cd 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 passed

  • Mutation check: I made each of these one-line changes to decorator_metadata.py in turn, and each one makes at least one new test fail: default "warn" → True; the "warn" upgrade disabled; the code_origin overwritten unconditionally; the delattr removed; stage_trigger replacing instead of appending; split_direct_registration_arg swapped; explicit triggers not merged; explicit accepts_webhook ignored.

All runs used Python 3.10.12 and pytest 9.2.0.

Lint: I couldn't download the pinned ruff==0.15.22 wheel in my environment because the network was too slow. Instead I checked the new file against ruff's default rule set using pyflakes (F rules) and pycodestyle --select=E4,E7,E9, plus a full pycodestyle --max-line-length=88 pass. All of them are clean. The file has no async code, so the ASYNC rules don't apply. CI's ruff check . remains the authoritative check.

Test coverage

  • I ran tests for the surface(s) I changed locally.
  • New code paths are covered by tests in this PR (no bare additions). This PR only adds tests; decorator_metadata.py is now at 100% line coverage.
  • If I removed code, I updated coverage-baseline.json in this PR. (Not applicable: nothing was removed.)
  • The coverage gate check is green in CI before requesting review. (Waiting for CI.)

Checklist

Related issues / PRs

#1228

This PR was prepared with the help of an AI coding assistant (Claude); the change and tests were verified locally before submission.

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
@OpenLucasKaka
OpenLucasKaka requested review from a team and AbirAbbas as code owners November 23, 2026 02:20
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python SDK] Add direct unit tests for decorator_metadata.py

2 participants