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)
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.
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.
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.
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.
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.
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`.
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.
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.
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`.
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.
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.
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.