Skip to content

Accept any 2xx when updating a network policy - #42

Merged
aezell merged 1 commit into
superfly:mainfrom
gkpacker:gkpacker/sprites-network-policy-2xx-pr
Oct 29, 2026
Merged

aezell merged 1 commit into
superfly:mainfrom
gkpacker:gkpacker/sprites-network-policy-2xx-pr

Conversation

@gkpacker

@gkpacker gkpacker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The API returns 200 for POST /v1/sprites/{name}/policy/network, but Sprites.Policy.update_by_name/3 (and so Sprites.update_network_policy/2) only treated 204 as success. A successful update was reported as {:error, {:api_error, 200, body}}.

The published OpenAPI spec (superfly/sprites-docs/api/openapi.json) lists 200 (with the rules as a JSON body), 400, 404 and 500 for this endpoint. It does not list 204.

Fix

Change the success match to status in 200..299. This is the same 2xx handling used everywhere else in the SDK (client.ex, filesystem.ex, Policy.get_by_name/2). Error handling for 400 and other statuses is unchanged.

Tests

Added test/policy_test.exs. HTTP is stubbed with Req.Test through a plug: on the client's req. This adds plug as a test-only dependency.

  • a 200 returns :ok and sends a POST to /v1/sprites/my-sprite/policy/network (this test fails without the fix)
  • a 204 returns :ok
  • a 400 returns {:error, {:invalid_policy, body}}

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T14:47:31.693521Z 6fdafd8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@gkpacker
gkpacker force-pushed the gkpacker/sprites-network-policy-2xx-pr branch 2 times, most recently from f99e87c to 6ca54b8 Compare October 17, 2026 14:52
gkpacker added a commit to gkpacker/sprites-ex that referenced this pull request Oct 17, 2026
…ect (superfly#41)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gkpacker
gkpacker force-pushed the gkpacker/sprites-network-policy-2xx-pr branch from 6ca54b8 to cc2fe3f Compare October 17, 2026 14:55
gkpacker added a commit to gkpacker/sprites-ex that referenced this pull request Oct 17, 2026
…ect (superfly#41)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gkpacker
gkpacker force-pushed the gkpacker/sprites-network-policy-2xx-pr branch from cc2fe3f to e73be58 Compare October 17, 2026 14:56
gkpacker added a commit to gkpacker/sprites-ex that referenced this pull request Oct 17, 2026
…ect (superfly#41)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment thread mix.exs
{:cowlib, "~> 2.19.0"},
{:jason, "~> 1.4"},
{:client_signals, "~> 0.4.4"},
{:plug, "~> 1.0", only: :test},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plug is added as a test-only dependency so the new policy tests can stub HTTP with Req.Test. Req's plug: option, Req.Test.stub/2 and Req.Test.json/2 are only compiled when Plug is available. It is only: :test, so SDK users don't pull it in. Without it, the alternative is a custom Req adapter: module in the test file.

@aezell

aezell commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

@gkpacker This change looks good. Could you double-check the conflict? It looks like there's a newer version of req.

The API returns 200 for POST /v1/sprites/{name}/policy/network, but
update_by_name/3 only treated 204 as success, so successful updates were
reported as {:error, {:api_error, 200, body}}. Match status in 200..299
like the rest of the SDK.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gkpacker
gkpacker force-pushed the gkpacker/sprites-network-policy-2xx-pr branch from e73be58 to 7013c88 Compare October 26, 2026 17:19
gkpacker added a commit to gkpacker/sprites-ex that referenced this pull request Oct 26, 2026
@gkpacker

Copy link
Copy Markdown
Contributor Author

@aezell good to go now

@aezell
aezell merged commit e3332e6 into superfly:main Oct 29, 2026
4 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.

2 participants