Kimi K3.1 Pro · Heavy

feature-can-edit-category-host-relationships-for-embedding-discourse-cursor

Discourse · Ruby · M · 100–299 lines · 6 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.

Gold bugs found
3 of 4
Comments published
13
Comments matching a bug
3
Comments not matching
10
Cost of this PR
$3.190

Published comments (13)

mediumbugapp/assets/javascripts/discourse/models/store.js.es6:197-201

Failed plural hydration deletes ids and leaves undefined entries — If an id has no matching side-loaded collection, `_lookupSubType` returns undefined, but this still stores an array of undefined entries and deletes the original `*_ids`; `hydrated || []` cannot help because `map` always returns an array. Preserve the original ids unless hydration resolves them, matching the singular branch's behavior.

mediumbugapp/assets/javascripts/admin/components/embeddable-host.js.es6:38

Blank categoryId overwrites the saved category with undefined — Resolve the category from `host.get('category_id')` after the save response instead.

mediumbugapp/models/topic.rb:869

expandable_first_post? ignores missing embeddable hosts — An embedded topic with `embed_truncate` enabled now returns true even after the last allowed host is deleted, whereas the previous host-presence guard returned false. Restore an `EmbeddableHost` presence check so disabling embedding also disables the full-post expansion control.

mediumbugapp/models/topic_embed.rb:36-43

Feed imports lose embed_category when no EmbeddableHost matches — Feed polling calls `TopicEmbed.import` directly, so a feed entry without a matching `EmbeddableHost` now passes a nil category and is filed under Uncategorized instead of the previously configured `embed_category`. Provide an explicit feed-category fallback or migration rather than relying exclusively on a matching host record.

mediumbugspec/controllers/embed_controller_spec.rb:13-15

Missing-host spec also lacks a referer, so it does not isolate the host guard — The 'missing host' example also supplies no referer. Since the new guard checks `EmbeddableHost.host_allowed?(request.referer)`, the nil referer independently produces a non-success response; the test would still pass if a valid referer were incorrectly accepted when no host records exist.

mediumbugdb/migrate/20150818190757_create_embeddable_hosts.rb:9-11

Missing embed_category site setting crashes the migration — `embed_category` can have no row in `site_settings` when it has never been overridden. The query then returns zero rows, `[0]` is `nil`, and `['id']` raises, aborting the migration before the intended `category_id == 0` fallback can run.

mediumbugdb/migrate/20150818190757_create_embeddable_hosts.rb:24-25

Legacy hosts are inserted without stripping URL schemes and paths — Legacy settings accepted values such as `https://example.com/1234`, but this inserts them verbatim while `record_for_host` later queries only `example.com`, disabling those existing embeds after upgrade. Normalize each legacy value with the same scheme/path trimming as the model before inserting it.

mediumbugapp/models/embeddable_host.rb:5-7

Saving without a host crashes in normalization before validation — Saving a record with an omitted `host` parameter calls `sub!` on `nil`, producing a 500 instead of a validation error. Guard the normalization when `host` is blank, or convert it to a string, before running validation.

mediumbugapp/models/embeddable_host.rb:14-17

The model accepts and preserves an optional port such as `example.com:3000`, but `uri.host`… — The lookup therefore searches for `example.com`, so the port-specific record does not match its own referer. Compare a consistently normalized host-and-port authority, or reject ports when writing.

mediumbugapp/models/embeddable_host.rb:17

Mixed-case URLs can fail the embeddable host lookup — `lower(host)` normalizes only the database column; the bind value from `uri.host` retains its input case. Uppercase or mixed-case URLs can therefore fail the exact comparison despite hostnames being case-insensitive and the validator accepting them.

mediumbugapp/controllers/admin/embeddable_hosts_controller.rb:9-16

Update and destroy crash when the embeddable host no longer exists — Both actions immediately dereference the nullable `where(...).first` result. A stale update or delete after another admin removes the host causes `save_host(nil)` to fail at `host.host=` or destroy to fail at `host.destroy`, producing an unhandled 500.

mediumbugdb/migrate/20150818190757_create_embeddable_hosts.rb:3-7

Embeddable hosts lack case-insensitive uniqueness enforcement — The new host-to-category mapping has no uniqueness enforcement: the model validates only format and the table has no unique index. Concurrent admin creates can therefore both commit the same normalized host, potentially with different categories, after which `record_for_host(...).first` silently chooses one mapping for access and topic categorization. **Also found in:** - `app/models/embeddable_host.rb:2-3`

mediumbugspec/models/topic_spec.rb:1403-1404

Blank-host example no longer isolates blank-host behavior — The setup enabling `embed_truncate` and stubbing `has_topic_embed?` was moved into the nested context, so this example returns false because truncation is false by default and the topic has no embed. It passes whether blank-host handling is correct or broken.

Gold bugs found (3)

highThe migration reads execute(...)[0]['id'] for embed_category without checking for an empty result, so installs without that setting stored crash the migration instead of falling back to the uncategorized category.
mediumAfter saving a host, the component overwrites its category with findById(categoryId); when no category was chosen this is null even though the server saved the uncategorized category, so the row shows no category until reload.
highHosts saved with a port (allowed by the validation regex) are stored as host:port, but lookup compares only URI.host, so those configured hosts never match and embedding fails for them.

Gold bugs missed (1)

highEmbeddableHost's host format validation only accepts TLDs of 2-5 letters, so admins cannot add embeddable hosts on longer TLDs like example.technology.