agentfield icon indicating copy to clipboard operation
agentfield copied to clipboard

[Python SDK] Expand verification.py tests — did:key, constraints, refresh

Open santoshkumarradha opened this issue 7 months ago • 8 comments

Test coverage: Python SDK verification.py — did:key resolution, constraint operators, refresh

sdk/python/agentfield/verification.py already has test_verification.py, but several public methods of LocalVerifier are uncovered — and they are security-critical (policy evaluation + signature verification).

Scope

Extend sdk/python/tests/test_verification.py.

Uncovered callables:

  • _resolve_public_key — did:key:z... parsing + admin-key fallback
  • _evaluate_constraints — operator logic
  • refresh() — success and partial-failure paths

Test cases

did:key resolution:

  • test_resolve_did_key_z_success — valid did:key:z6Mkp..., assert correct 32-byte public key returned
  • test_resolve_did_key_invalid_multicodec — did:key:z with wrong prefix, assert None
  • test_resolve_fallback_to_admin_key — set admin_public_key_jwk with valid x, call with did:web:example.com, assert admin key bytes returned
  • test_resolve_no_key_available — call with did:web:... when no admin key set, assert None

Constraints:

  • test_constraint_equality — {"operator": "==", "value": 10}, input 10 (allow) vs 11 (deny)
  • test_constraint_greater_than — {"operator": ">", "value": 10}, input 11 (allow) vs 10 (deny)
  • test_constraint_invalid_float — input "not-a-number" for a numeric constraint, assert False (fail-closed)
  • test_constraint_missing_param — skip parameter required by constraint, assert True (silently skipped per current behavior)

Refresh:

  • test_refresh_success_populates_caches — mock aiohttp.ClientSession.get to return JSON for policies, revocations, and keys; assert verifier attributes updated
  • test_refresh_sets_initialized_and_timestamp — assert _initialized is True and _last_refresh > 0
  • test_refresh_partial_failure — one endpoint 500s; assert refresh() returns False but other caches still update

Fixture / mock strategy

  • Pre-calculated Ed25519 public keys + their did:key representation
  • respx or unittest.mock.AsyncMock for aiohttp
  • pytest-asyncio for refresh

Acceptance criteria

  • [ ] ≥11 new tests across the three concerns
  • [ ] uv run pytest sdk/python/tests/test_verification.py passes
  • [ ] Coverage on verification.py ≥90%

Size: M · Difficulty: intermediate · Language: Python


Part of epic #387 — parent tracker.


How to work on this

Setup

git clone https://github.com/Agent-Field/agentfield.git
cd agentfield
make install        # installs Go, Python (via uv), and Node deps
make build          # optional — builds the control plane binary

Run the baseline test suite

Before you change anything, run the tests for the language this issue targets so you know what "green" looks like:

  • Go control plane: cd control-plane && go test ./... -count=1
  • Go SDK: cd sdk/go && go test ./... -count=1
  • Python SDK: cd sdk/python && uv run pytest -q
  • TypeScript SDK: cd sdk/typescript && bun test

Package coverage baseline (so you can show improvement in the PR):

  • go test -cover ./control-plane/internal/...
  • uv run pytest --cov=agentfield sdk/python/tests
  • bun test --coverage (TypeScript)

Using Claude Code or another AI coding agent

This repo has a CLAUDE.md at the root that Claude Code and compatible agents will read automatically. A working flow:

  1. cd into the repo and run claude (or open in your IDE's agent).
  2. Paste this issue URL and say: "Please implement this issue, following every acceptance-criteria checkbox. Do not change source files — only add tests under the target path in the issue. When you're done, run the test suite command from the issue and paste the result."
  3. Let the agent read existing tests in the same package as a model for style / fixtures — we point to them in the issue.
  4. Run make lint before opening the PR.

See the AI-Assisted Contributions guide for testing requirements. Tag your PR with ai-assisted if you used an AI agent.

Claiming this issue

Comment I'd like to work on this and a maintainer will assign it to you. If you're new to open source, issues labelled good first issue or first-timers-only are hand-picked for a smooth first PR — we'll guide you if you get stuck.

Opening the PR

  • Branch name: tests/<short-description> or refactor/<short-description>
  • Link this issue in the PR description with Closes #<number>
  • Paste the before/after test output or coverage delta in the PR body
  • Keep the diff to the scope in this issue — no drive-by cleanups

Help & questions

  • Comment on this issue — we monitor all assigned issues.
  • Join the community Discord: run /gsd-join-discord or check the README for the invite.
  • For repo-wide questions, open a discussion with the help tag.

santoshkumarradha avatar Apr 11 '26 18:04 santoshkumarradha

I would like to work on this

Luffy2208 avatar Apr 17 '26 04:04 Luffy2208

Hi! I’d like to work on this.

The scope and acceptance criteria are clear: add focused Python tests for LocalVerifier did:key/admin-key resolution, constraint operator behavior, and async refresh() success/partial-failure paths, without changing source files.

Rough estimate:

  • Timeline: 1–2 days
  • Quote: $250–$400

I’d follow the existing sdk/python/tests/test_verification.py style, use precomputed Ed25519/did:key fixtures, mock aiohttp.ClientSession.get with async-compatible mocks, and verify both the specific new test cases and the coverage target with:

uv run pytest sdk/python/tests/test_verification.py
uv run pytest --cov=agentfield sdk/python/tests

One quick clarification before starting:

  • For the refresh_partial_failure case, should the expected behavior be “best-effort cache updates from successful endpoints + return False,” even if the failing endpoint is encountered before later endpoints?

Happy to take this on and submit a clean PR.

tradego579 avatar Apr 17 '26 04:04 tradego579

Hi! I’d like to work on this.

The scope and acceptance criteria are clear: add focused Python tests for LocalVerifier did:key/admin-key resolution, constraint operator behavior, and async refresh() success/partial-failure paths, without changing source files.

Rough estimate:

  • Timeline: 1–2 days
  • Quote: $250–$400

I’d follow the existing sdk/python/tests/test_verification.py style, use precomputed Ed25519/did:key fixtures, mock aiohttp.ClientSession.get with async-compatible mocks, and verify both the specific new test cases and the coverage target with:

uv run pytest sdk/python/tests/test_verification.py uv run pytest --cov=agentfield sdk/python/tests One quick clarification before starting:

  • For the refresh_partial_failure case, should the expected behavior be “best-effort cache updates from successful endpoints + return False,” even if the failing endpoint is encountered before later endpoints?

Happy to take this on and submit a clean PR.

go for it!

AbirAbbas avatar Apr 17 '26 12:04 AbirAbbas

Thanks for picking this up, @tradego579! :tada:

Here's what to expect:

  • We'll check in after 7 days if we haven't heard an update
  • After 14 days, we'll send a second reminder
  • After 21 days without activity, we'll unassign to let others contribute

Tips for success:

  • Drop a comment when you start working on it
  • Share any blockers - we're here to help!
  • Link your PR with Fixes #398 in the description

Happy coding! :rocket:

github-actions[bot] avatar Apr 17 '26 12:04 github-actions[bot]

Hey @tradego579! :wave:

Just a friendly reminder that you're assigned to this issue. It's been about a week since assignment.

How's it going? We'd love to hear:

  • Any progress updates?
  • Running into any blockers we can help with?
  • Need more time? (Totally fine!)

A quick comment helps us know you're still interested. If your plans have changed, no worries at all - just let us know and we can find another contributor.

Thanks for contributing to AgentField! :rocket:

github-actions[bot] avatar Apr 24 '26 10:04 github-actions[bot]

Hi @tradego579,

Just checking in again! It's been 14 days since we last heard from you on this issue.

Quick options:

  • :speech_balloon: Drop a comment with a progress update
  • :link: Link a draft PR if you've started working on it
  • :wave: Let us know if you'd like to be unassigned (no judgment!)

If we don't hear back in 7 days, we'll unassign this issue to give other contributors a chance to help.

Thanks for understanding!

github-actions[bot] avatar May 01 '26 10:05 github-actions[bot]

Hi @tradego579,

It's been 21 days since the last update on this issue. To keep the project moving, we've unassigned this issue so other contributors can pick it up.

No worries at all! Life happens, and we totally understand. If you'd like to continue working on this, just comment here and we'll reassign it to you.

This issue is now available for anyone who'd like to contribute. Check out our contribution guidelines if you're interested!

Thanks for your interest in AgentField! :heart:

github-actions[bot] avatar May 08 '26 10:05 github-actions[bot]

Hi, I would like to work on this test-only task. I plan to add the requested LocalVerifier coverage for did:key resolution, constraint evaluation, and refresh success/partial-failure paths, then report focused test and coverage results. I will use AI assistance transparently, review every change myself, and keep the diff within the issue scope.

Donyes avatar Aug 30 '26 16:08 Donyes