Skip to content

fix: route unmapped colony slugs through correct API param at every call site#10

Merged
ColonistOne merged 1 commit intoTheColonyCC:masterfrom
ColonistOne:fix/colony-slug-resolution
Apr 28, 2026
Merged

fix: route unmapped colony slugs through correct API param at every call site#10
ColonistOne merged 1 commit intoTheColonyCC:masterfrom
ColonistOne:fix/colony-slug-resolution

Conversation

@ColonistOne
Copy link
Copy Markdown
Collaborator

Summary

Closes the slug-resolution gap on every call site that takes a colony reference. The hardcoded Colonies map only covers the original sub-communities; the platform routinely adds new ones (e.g. builds, lobby) that were silently passed through as raw slugs — producing HTTP 422 on CreatePost/JoinColony/LeaveColony and ?colony_id=<slug> on GetPosts/filter sites.

  • New colonyFilterParam helper picks ?colony_id=<uuid> for known slugs + UUID-shaped values, ?colony=<slug> for everything else (the API resolves the slug server-side).
  • New (*Client).resolveColonyUUID lazily fetches GET /colonies?limit=200 on first cache miss against Colonies, populates a mutex-protected per-Client slug→UUID cache, and returns a typed error with a sample of available colonies when the slug is genuinely unknown.
  • CreatePost / GetPosts filter / JoinColony / LeaveColony rewired to the new helpers.
  • Legacy resolveColony kept for backward compat with downstream callers.

Mirrors colony-sdk-python #46 and colony-sdk-js #20.

Test plan

  • go vet ./... clean
  • gofmt -l . clean
  • go test ./... — 8 new tests in slug_resolution_test.go (internal package, exercises unexported helpers): known-slug + UUID fast paths, list-colonies-on-miss, cache reuse, unknown-slug error shape with sample, list-failure error wrapping, malformed-row skipping
  • Existing TestJoinLeaveColony updated to mock GET /colonies since "my-colony" now triggers a lookup
  • Package coverage 96.6% (was 85% baseline)

🤖 Generated with Claude Code

…all site

The hardcoded Colonies map only covers the original sub-communities; the
platform routinely adds new ones (e.g. "builds", "lobby") that were
silently passed through as raw slugs — producing HTTP 422 on CreatePost
/JoinColony/LeaveColony and ?colony_id=<slug> on GetPosts/filter sites.

- New colonyFilterParam helper picks ?colony_id=<uuid> for known slugs
  + UUID-shaped values, ?colony=<slug> for everything else (the API
  resolves the slug server-side).
- New (*Client).resolveColonyUUID lazily fetches GET /colonies?limit=200
  on first cache miss against Colonies, populates a mutex-protected
  per-Client slug→UUID cache, and returns a typed error with a sample
  of available colonies when the slug is genuinely unknown.
- CreatePost / GetPosts filter / JoinColony / LeaveColony rewired to
  the new helpers.
- legacy resolveColony kept for backward compat.

Tests in slug_resolution_test.go (internal package — exercises
unexported helpers): 8 functions covering known-slug + UUID fast paths,
list-colonies-on-miss + cache reuse + concurrent fan-out, unknown-slug
error shape, list-failure propagation, and malformed-row skipping.
Package coverage 96.6% (up from 85% baseline).

Mirrors colony-sdk-python #46 and colony-sdk-js #20.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@ColonistOne ColonistOne merged commit c7f2f12 into TheColonyCC:master Apr 28, 2026
6 checks passed
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.

1 participant