Claude Sonnet 5.5 · Balanced
feature-can-edit-category-host-relationships-for-embedding-discourse-cursor
Discourse · Ruby · M · 100–299 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Haiku 5.5.
- Gold bugs found
- 3 of 4
- Comments published
- 7
- Comments matching a bug
- 3
- Comments not matching
- 4
- Cost of this PR
- $0.636
Published comments (7)
Migration crashes when embed_category or uncategorized_category_id row is missing — On a default install the `embed_category` row is absent, so `[0]` is nil and the migration raises NoMethodError, blocking the deploy. Fetch `.first` into a variable and fall back to 0 when nil, for both the `embed_category` and `uncategorized_category_id` lookups.
Migration inserts unnormalized embeddable hosts with unescaped raw SQL — The raw INSERT bypasses the model's `before_validation`, so legacy values like `http://discourse.org` are stored with scheme or path and `record_for_host` never matches them, breaking embedding after upgrade. Normalize each value (strip scheme and path, downcase, skip blanks) and quote it before inserting.
before_validation callback raises NoMethodError when host is nil — A request with a missing `host` raises NoMethodError and returns a 500 instead of a validation error. Skip the `sub!` calls when `host` is blank, or assign a non-mutating `sub` result, so `validates_format_of` reports the problem.
update and destroy raise NoMethodError (500) for unknown host ids — An unknown or already-deleted id makes `update` and `destroy` dereference nil, returning a 500 instead of a 404. Use `EmbeddableHost.find` or raise `Discourse::NotFound` when nil, and check that the nested `params[:embeddable_host]` exists in `save_host`.
record_for_host fails to downcase host, rejecting registered hosts with uppercase — Registered hosts are rejected when the incoming URL has uppercase characters, because `record_for_host` compares `lower(host)` against a non-downcased `uri.host`. Compare with `host.downcase` instead.
Host validation accepts ports that record_for_host can never match — A host saved with a port can never match, because `record_for_host` compares only `uri.host`, so embedding silently fails for it. Remove the port from the validation regex, or match `host:port` when `uri.port` is non-default.
Host category set from local categoryId instead of server-saved category_id — For a new host with no chosen category, the local `categoryId` is null while the server stores the uncategorized category, so the badge is empty until reload. Set `category` from the `category_id` in the saved response instead of `categoryId`.