Amazon Ergo 1.0 · 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 Opus 5.5.

Gold bugs found
5 of 10
Comments published
12
Comments matching a bug
5
Comments not matching
7
Cost of this PR
$5.270

Published comments (12)

highbugapp/assets/javascripts/discourse/models/store.js.es6:196-200

Hydration crashes when a *_ids payload value is not an array — A null or non-array `*_ids` value makes `obj[k].map` throw inside `_hydrateEmbedded`, aborting hydration for the entire payload. Use `Array.isArray(obj[k])` and fall back to an empty array before mapping.

highbugapp/models/embeddable_host.rb:2

Embeddable host validation rejects valid TLDs longer than five characters — Hostnames such as `example.museum` and `example.technology` cannot be configured because `validates_format_of :host` caps TLDs at five letters. Accept DNS labels up to 63 characters, including digits and hyphens for punycode.

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

Migration stores embeddable hosts without normalizing URLs — Raw SQL bypasses `EmbeddableHost` normalization, so migrated values like `http://eviltrout.com` never match the bare host from `URI(referer).host` and embedding silently stops. Normalize `h` before the `INSERT`, stripping the scheme and path.

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

Migration crashes when embed_category has no matching category — An unsaved or blank `embed_category` setting makes the `SELECT` return no rows, so `[0]['id']` dereferences nil and aborts the upgrade with `NoMethodError`. Fetch with `first` and fall back to `category_id = 0`, matching the later uncategorized handling.

highbugapp/models/embeddable_host.rb:14-17

Lookup key drops the port, so host:port records never match — A saved `example.com:3000` never matches, while `example.com` matches referers on any port because `URI#host` omits the port. Append `uri.port` when it differs from `uri.default_port`, or reject/normalize ports in `validates_format_of :host` so storage and lookup agree.

mediumbugapp/models/topic_embed.rb:36-43

TopicEmbed.import derives category from embeddable-host allowlist — Feed URLs from `Jobs::PollFeed#import_topic` in `app/jobs/scheduled/poll_feed.rb` can lack an `EmbeddableHost` record, so `record_for_host(url)` silently sends imports to the default category instead of the configured `embed_category`. Pass `SiteSetting.embed_category` to `PostCreator`.

mediumbugapp/models/topic.rb:869

expandable_first_post? no longer requires an embeddable host — With no embeddable hosts, `expandable_first_post?` can now return true whenever `SiteSetting.embed_truncate?` and `has_topic_embed?` are true, breaking its callers' contract. Restore `EmbeddableHost.exists?`, and update the blank-host spec in `spec/models/topic_spec.rb` to set `embed_truncate` and stub `has_topic_embed?` so it exercises that path.

mediumbugtest/javascripts/models/store-test.js.es6:111-117

Embedded-color test requests fruit 2 but asserts fruit 1's colors — Because the `/fruits/:id` pretender always returns `fruits[0]`, the assertions never verify the requested record and could pass if `find` ignored its id. Use `store.find('fruit', 1)` to match the fixture, or return the requested fruit and assert banana's color id 3.

mediumbugspec/models/topic_spec.rb:1407

Misspelled context name hides embeddable-host tests from name-filtered runs — The misspelling makes `rspec -e "embeddable host"` skip the only examples exercising that path, leaving the vacuous blank-host example. Rename `with an emeddable host` to `with an embeddable host`.

mediumbugapp/models/embeddable_host.rb:5-8

Nil host causes NoMethodError before validation — A missing `embeddable_host[host]` parameter leaves `self.host` nil, so calling `sub!` raises `NoMethodError` and turns a routine validation failure into a 500. Normalize through `self.host.to_s` or guard the `before_validation` callback.

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

Stale embeddable host IDs cause nil dereferences and 500s — A stale or concurrently deleted id makes `EmbeddableHost.where(id: params[:id]).first` return nil, so `save_host` or `destroy` dereferences it and returns a 500. Use `EmbeddableHost.find(params[:id])` or handle the missing record explicitly.

mediumbugspec/models/topic_spec.rb:1403-1405

Stale embeddable-host test passes without exercising the behavior — The implementation in `app/models/topic.rb` no longer checks embeddable hosts, and this example leaves `embed_truncate` false and `has_topic_embed?` unstubbed, so it passes without exercising the behavior it names. Rewrite it with `SiteSetting.embed_truncate = true` and a `has_topic_embed?` stub, asserting the intended result, or remove the stale case.

Gold bugs found (5)

mediumupdate and destroy in Admin::EmbeddableHostsController fetch the host with where(id:).first and never check for nil, so an unknown id raises NoMethodError and returns a 500 instead of not-found.
highThe migration copies the legacy embeddable_hosts values into the new table without stripping scheme and path, so hosts stored as http://example.com no longer match the bare-host lookup and previously allowed embeds are rejected after upgrade.
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.
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.
highEmbeddableHost's host format validation only accepts TLDs of 2-5 letters, so admins cannot add embeddable hosts on longer TLDs like example.technology.

Gold bugs missed (5)

highrecord_for_host compares lower(host) against the un-lowercased URI host, so mixed-case referer hosts fail to match allowed hosts and embedding is rejected.
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.
mediumEmbeddableHost has no (case-insensitive) uniqueness validation or unique index, so the same host can be saved twice with different categories and record_for_host silently picks whichever row comes first.
mediumThe embeddable-host component's delete action has no .catch(popupAjaxError) on destroyRecord(), so a failed host deletion is silently swallowed and the row stays with no feedback to the admin.
mediumThe 'raises an error with a missing host' spec sends no referer, so the request fails on the nil referer regardless of the empty embeddable_hosts table; the missing-host behaviour is not actually tested.