Conversation
#4583) Failing test contracts that define the target interface: - Rename sink_url → destination_url, source/sink roles → client/destination - Split channel_auth_methods into has_many :client_auth_methods + has_one :destination_auth_method - destination_credential through association, unique index, auto-set role via cast_assoc with: - Credential swap emits single "auth_method_changed" audit event - Update factories to match new terminology
#4581, #4582, #4583) Phase 1b + Phase 2 of the channel rename spec: - Migration: rename sink_url → destination_url, source/sink → client/destination role enum values, add destination-unique partial index, migrate event types - Schema: has_one :destination_auth_method (on_replace: :delete), has_many :client_auth_methods, has_one :destination_credential through association - Changeset: split cast_assoc with role-injecting :with callbacks - Audit: extract auth method audit helpers into Channels.Audit module - Rename SinkAuth → DestinationAuth module - Rename all sink/source references across proxy plug, handler, LiveView, form component, benchmarking, and tests
…#4581, #4582, #4583) Replace destination credential checkboxes with a single-value <select> dropdown (None + project credentials). Reorder form fields to Name → Destination URL → Destination Credential → Enabled → Client Credentials. Add sublabels, placeholder, empty state for client credentials, and open "Add New" links in a new tab. Update build_destination_auth_param to read destination_credential_id (single value) and handle deletion of existing auth method when "None" is selected. Add :delete action clause to audit_destination_changes.
…4583) Delete three unused public functions (channel_proxy_path/1, DestinationAuth.supported_schemas/0, list_channel_auth_methods/1) and their tests. Refactor get_channel/get_channel! to share a common query with preload support, eliminating the get-then-preload round trip.
…sts (#4581, #4582, #4583) Split channels_test.exs (1390 → 403 lines) into focused files: channel_requests_test, channel_stats_test, channel_audit_test. Split index_test.exs (865 → 296 lines) by extracting form_test. Merged micro-tests with shared setup to reduce 62 → 40 context tests without losing assertion coverage.
…4583) Rename MockSink → MockDestination, --sink → --destination flag, slow_sink/direct_sink → slow_destination/direct_destination scenarios, and all references across config, setup, runner, report, README, and run_all.sh. File renamed mock_sink.exs → mock_destination.exs.
…queries (#4581, #4582, #4583) Add has_many :client_webhook_auth_methods through association to Channel schema (symmetric with existing destination_credential). Include the :through binding in get_channel_with_auth join-preload so it resolves in a single SQL query. Simplify proxy plug to use the :through accessor directly. Refactor get_channel_for_project to build on the shared channel_query/2 with :include support.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4604 +/- ##
==========================================
+ Coverage 89.50% 89.52% +0.02%
==========================================
Files 441 442 +1
Lines 21295 21319 +24
==========================================
+ Hits 19060 19086 +26
+ Misses 2235 2233 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| end | ||
|
|
||
| defp has_string_keys?(attrs) when map_size(attrs) == 0, do: false | ||
| defp has_string_keys?(attrs), do: attrs |> Map.keys() |> hd() |> is_binary() |
There was a problem hiding this comment.
Since map key ordering isn't guaranteed, could hd() give inconsistent results for maps that happen to have mixed key types? Would something like Enum.any?(&is_binary/1) be safer here, or is there a guarantee upstream that keys are always uniform?
There was a problem hiding this comment.
As discussed, we're still protected by Ectos changeset check, so I thing this is find for now.
| include: [ | ||
| :channel_auth_methods, | ||
| :client_auth_methods, | ||
| :destination_auth_method | ||
| ] |
There was a problem hiding this comment.
Just wondering, since :client_auth_methods and :destination_auth_method are both subsets of :channel_auth_methods on the same join table, does preloading all three result in redundant queries? Would it make sense to preload just :channel_auth_methods and filter in memory, or is the clarity worth the extra round trips here?
There was a problem hiding this comment.
You're right, this is a hangover from when I only had :channel_auth_methods - it's supposed to be just the other two, and we don't use the through association to find them. So yeah, I'm still keeping the preloads, it's 2 instead of 3 queries. Not exactly that you are proposing here, but it's super cheap and since it's an on mount concern I'm opting for interface clarity.
| # TODO: Remove this refutation once the old two-event pattern is fully | ||
| # gone — at that point added/removed won't fire for swaps and this | ||
| # negative assertion adds no value. |
There was a problem hiding this comment.
Would it make sense to open a small follow-up issue to track removing these transitional assertions once the migration has been run everywhere? Just so they don't get forgotten.
There was a problem hiding this comment.
I'm in two minds, it's so small, feels weird to make an issue for it. Also I don't think it's actually testing that an actual migration has been run now that I look closer. I'll address this in the next PR.
Description
Standardises channel terminology from Source/Sink to Client/Destination and
enforces that each channel has at most one destination credential (previously
unbounded via has_many).
Closes #4581, closes #4582, closes #4583
What changed
sink_url→destination_url,:source/:sinkroles →:client/:destination,SinkAuth→DestinationAuth, event typesink_response→destination_responsesink_auth_methods(has_many) replaced bydestination_auth_method(has_one, on_replace: :delete) with a partial unique DB index enforcing at-most-one:throughassociations —client_webhook_auth_methodsanddestination_credentialsimplify proxy plug and form codeChannels.Auditwith newauth_method_changedevent for destination credential swapschannels_test.exsintochannel_audit_test.exs,channel_requests_test.exs,channel_stats_test.exs; added dedicatedform_test.exslist_channel_auth_methods/1,channel_proxy_path/1,supported_schemas/0Validation steps
mix test test/lightning/channels_test.exs test/lightning/channels/channel_audit_test.exs test/lightning/channels/channel_requests_test.exs test/lightning/channels/channel_stats_test.exs test/lightning/channels/channel_auth_method_test.exs test/lightning/channels/destination_auth_test.exs test/lightning/channels/handler_test.exs test/lightning_web/live/channel_live/form_test.exs test/lightning_web/live/channel_live/index_test.exs test/lightning_web/plugs/channel_proxy_plug_test.exs— all passmix ecto.migrateandmix ecto.rollback --step 1— verify migration is reversibleAdditional notes for the reviewer
executestatements.benchmarking/channels/also renamed for consistency.AI Usage
Pre-submission checklist
/reviewwith Claude Code):owner,:admin,:editor,:viewer)