DeepSeek V4.1 Flash · 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
- 1 of 4
- Comments published
- 13
- Comments matching a bug
- 1
- Comments not matching
- 12
- Cost of this PR
- $0.450
Published comments (13)
Migration dereferences nil when embed_category or uncategorized row is missing — Forums that never overrode `embed_category` have no such `SiteSetting` row, so `execute(...)[0]['id']` raises `NoMethodError` and the migration cannot run. Guard with `.first` and fall back to `SiteSetting.uncategorized_category_id`.
Migration inserts embeddable hosts without normalization or SQL escaping — Legacy values with a scheme or path survive verbatim, so `record_for_host` never matches the bare host and embedding silently breaks after upgrade. Normalize each value like the model does and use a quoted insert so a host containing a quote cannot abort the migration.
EmbeddableHost lookup fails when referer host has uppercase letters — A referer such as `http://EvilTrout.com/page` keeps its case, so `where("lower(host) = ?", host)` never matches the configured host and the embed frame is rejected. Downcase the argument too.
Guard `_hydrateEmbedded` against non-array `_ids` values — The regex now matches every `_ids` key, so a null or non-array value makes `obj[k].map` throw and breaks the whole `store.find`/`findAll` for that type. Guard with `Array.isArray(obj[k])` and leave the key untouched otherwise.
Missing nil check on embeddable host lookup returns 500 — A stale or already-deleted id (double-click on delete, two admins editing) makes `host.host = ...` or `host.destroy` raise `NoMethodError` and answer 500. Use `find_by!` or raise `Discourse::NotFound` so a missing record returns 404.
Uncached embeddable host lookup runs on every embed request — Each embedded page view now adds an uncached SQL round trip, and the `lower(host) = ?` predicate blocks any index on `host`. Cache the host list and compare in Ruby, or store hosts downcased in an indexed column.
Migration resolves numeric embed_category by name, losing category — A stored numeric id fails the name join, so `category_id` resolves to 0 and every host falls back to `uncategorized_category_id`, losing the category. Resolve by id when the value is numeric and by name otherwise, mirroring `TopicCreator#find_category`.
Embedded posts lose category when EmbeddableHost lookup misses — When `record_for_host` returns `false` for an unparseable URL or `nil` for no match, the embedded topic is created with `category: nil` and lands in uncategorized, where it previously went to the configured category. Fall back to `SiteSetting.embed_category`, and downcase the argument in `record_for_host`.
Vacuous expandable_first_post? test no longer exercises embeddable host — `expandable_first_post?` no longer consults embeddable hosts, and this example sets neither `embed_truncate` nor the `has_topic_embed?` stub, so it passes on defaults and cannot fail for the reason its name claims. Delete it; the no-embed case is already covered in the nested block.
before_validation crashes on nil host instead of failing validation — A nil host from a missing `params[:embeddable_host][:host]` makes `self.host.sub!` raise `NoMethodError` and answer 500, so `validates_format_of :host` never reports it. Assign through `self.host.to_s.sub(...)` to return a 422 instead.
Plural embedded hydration drops unresolved ids and maps null — When the side-loaded key does not match `pluralize(subType)` or is missing, every `_lookupSubType` returns undefined, the raw ids are lost, and the property becomes `[undefined, ...]`. Delete and replace the ids key only when the lookup resolved, otherwise keep the original.
Plural `*_ids` hydration stores undefined for missing records — `_lookupSubType` returns undefined for ids missing from the side-loaded collection, so `[undefined, ...]` is stored and consumers like `embeddable-host`'s `host.category.id` throw a TypeError. Filter unresolved ids before assigning.
Test requests fruit 2 but pretender fixture returns fruit 1's data — The pretender handler for `/fruits/:id` in `create-pretender.js.es6` hardcodes `fruits[0]` and ignores the requested id, so these assertions verify apple's fixture and would pass even if the store mangled the id. Look the record up by `request.params.id` or request fruit 1.