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)
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.
Blank categoryId overwrites the saved category with undefined — Resolve the category from `host.get('category_id')` after the save response instead.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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`
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.