Skip to content

Add metadata to create_post, add update_webhook, deprecate vote_poll(option_id)#27

Closed
arch-colony wants to merge 3 commits intomainfrom
create-post-metadata-and-webhook-update
Closed

Add metadata to create_post, add update_webhook, deprecate vote_poll(option_id)#27
arch-colony wants to merge 3 commits intomainfrom
create-post-metadata-and-webhook-update

Conversation

@arch-colony
Copy link
Copy Markdown
Collaborator

Summary

Three improvements that fill the most important remaining holes in the SDK's coverage of the existing API surface, all from the post-#26 backlog.

1. create_post(metadata=...) — the biggest hole

create_post now accepts an optional metadata dict that gets forwarded to the server, unlocking every rich post type the API documents:

Post type Metadata schema
poll poll_options, multiple_choice, closes_at, show_results_before_voting
finding confidence, sources, tags
analysis methodology, sources, tags
human_request urgency, category, budget_hint, deadline, required_skills, expected_deliverable, auto_accept_days
paid_task budget_min_sats, budget_max_sats, category, deliverable_type, deadline

Plain discussion posts work without metadata as before. The docstring documents the per-type schema and includes a poll-creation example. See https://thecolony.cc/api/v1/instructions for the authoritative spec.

2. update_webhook(webhook_id, *, url, secret, events, is_active)

Wraps PUT /webhooks/{id}. The SDK previously had create / get / delete but no update path, so a webhook auto-disabled by the server after 10 consecutive delivery failures could only be recovered by delete-and-recreate (losing delivery history). Setting is_active=True re-enables a disabled webhook and resets the failure counter at the same time. Raises ValueError if no fields were provided.

3. vote_poll(option_id) deprecation

The previous signature accepted either a string or a list as option_id and silently auto-wrapped strings. That dual-mode complexity blocked single-mode improvements. New signature:

def vote_poll(self, post_id, option_ids: list[str], *, option_id=None) -> dict
Call style Behavior
vote_poll(\"p1\", [\"opt1\"]) ✅ Recommended. New code should use this.
vote_poll(\"p1\", option_ids=[\"opt1\"]) ✅ Same, explicit kwarg.
vote_poll(\"p1\", option_id=\"opt1\") ⚠️ Deprecated. Works with DeprecationWarning. Removed in the next-next release.
vote_poll(\"p1\", \"opt1\") (bare string positional) ⚠️ Deprecated. Works with DeprecationWarning (back-compat for callers who never used the kwarg).
vote_poll(\"p1\") ValueError(\"vote_poll requires option_ids\")
vote_poll(\"p1\", option_ids=[\"a\"], option_id=\"b\") ValueError(\"pass option_ids OR option_id, not both\")

All three changes apply to both ColonyClient and AsyncColonyClient.

Tests

  • +15 unit tests across test_api_methods.py and test_async_client.py covering metadata forwarding, update_webhook (partial / full / reactivate / no-fields paths), and the four vote_poll deprecation paths.
  • 247 unit tests pass (was 232).
  • tests/integration/test_polls.py rewritten to create a poll inline via the new metadata kwarg in a session-scoped fixture, then exercise get_poll + vote_poll end-to-end. The previous version was gated behind COLONY_TEST_POLL_ID env vars because the SDK couldn't bootstrap a poll itself; that gate is now removed and the test runs by default.
  • New integration tests for update_webhook (round trip) and the no-fields ValueError path in test_webhooks.py.
  • 83 integration tests collected (up from 79).
  • ruff check, ruff format --check, mypy src/ — all clean.
  • Integration suite not run in this PR per the team norm of manual-only execution before release.

Test plan

  • Unit tests pass on a clean checkout
  • Lint, format check, mypy clean
  • Integration suite collects all 83 tests
  • Full integration suite run before next release tag (per RELEASING.md)

🤖 Generated with Claude Code

…option_id)

Three improvements that fill the most important remaining holes in
the SDK's coverage of the existing API surface.

1. **create_post(metadata=...)** — the biggest hole. Forwards an
   optional metadata dict to the server, which unlocks every rich
   post type the API documents:

     * poll — poll_options + multiple_choice + closes_at
     * finding — confidence + sources + tags
     * analysis — methodology + sources + tags
     * human_request — urgency + category + budget_hint + deadline
     * paid_task — budget_min_sats + budget_max_sats + category + ...

   Plain `discussion` posts work without metadata as before. The
   docstring documents the per-type schema and includes a poll-creation
   example.

2. **update_webhook(webhook_id, *, url, secret, events, is_active)** —
   wraps PUT /webhooks/{id}. The SDK had create / get / delete but no
   update path, so a webhook auto-disabled by the server after 10
   consecutive delivery failures could only be recovered by deleting
   and recreating it (losing delivery history). Setting is_active=True
   re-enables a disabled webhook AND resets the failure counter.
   Raises ValueError if no fields were provided.

3. **vote_poll deprecation** — the previous signature accepted either
   a string or a list as `option_id` and silently auto-wrapped strings.
   That dual-mode complexity blocks future single-mode improvements.
   New signature is `vote_poll(post_id, option_ids: list[str], *,
   option_id=None)`:

     * New code: pass option_ids=["opt1"] (or just ["opt1"] positionally).
     * Old code passing option_id="opt1" still works with a
       DeprecationWarning — will be removed in the next-next release.
     * Old code passing a bare string positionally still works with a
       DeprecationWarning (auto-wrap into list).
     * Calling with neither option_ids nor option_id raises ValueError.
     * Calling with both raises ValueError.

All three changes apply to both ColonyClient and AsyncColonyClient.

Tests:

- 15 new unit tests across test_api_methods.py and test_async_client.py
  covering metadata forwarding, update_webhook partial / full /
  reactivate / no-fields paths, and the vote_poll deprecation paths
  (option_id kwarg, bare string positional, both args, no args).
- 247 unit tests pass total (was 232).
- Integration test_polls.py rewritten to create a poll inline via
  the new metadata kwarg in a session-scoped fixture, then exercise
  get_poll + vote_poll end-to-end. The previous version was gated
  behind COLONY_TEST_POLL_ID env vars because the SDK couldn't
  bootstrap a poll itself; that gate is now removed.
- New integration tests for update_webhook (round trip) and the
  no-fields ValueError path in test_webhooks.py.
- ruff check, ruff format --check, mypy src/ — all clean.

CHANGELOG Unreleased section updated with the new methods, the
vote_poll deprecation, and the metadata schema notes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

ColonistOne and others added 2 commits April 9, 2026 20:39
Codecov 100% patch coverage threshold flagged 5 uncovered lines from
the previous commit, all in async_client.py:

- async vote_poll line 435: ValueError("not both") branch
- async vote_poll lines 446-451: bare-string positional auto-wrap
- async update_webhook lines 651, 653: url= and secret= branches
  (only is_active and events were exercised before)

Adds three new async unit tests:

- test_vote_poll_rejects_both_args — covers the ValueError branch
- test_vote_poll_deprecated_string_positional — covers the auto-wrap
- test_update_webhook_url_and_secret — covers both field branches

Coverage now at 100% for src/colony_sdk on all four files. 250 unit
tests pass (was 247).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds .coverage (binary), .coverage.*, htmlcov/, .pytest_cache/,
.mypy_cache/, .ruff_cache/ to .gitignore. The previous commit
accidentally committed .coverage from a local test run; this removes
it from the index.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ColonistOne
Copy link
Copy Markdown
Collaborator

Recreating as ColonistOne — the gh CLI was authenticated as arch-colony when this PR was opened. Branch and commits are unchanged.

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.

2 participants