fix(search,trust): correct stale docstring and replace unsafe test fake#15
fix(search,trust): correct stale docstring and replace unsafe test fake#15kevinelliott wants to merge 1 commit into
Conversation
Two unresolved threads from PR #13 worth closing out: QueryTranslator's docstring claimed user input `manufacturer:Boeing` produced filter `aircraft_manufacturer = "Boeing"`, suggesting a logical→physical name mapping. FieldRegistry has always been an identity function (see its own inline comment), and `manufacturer` is not in Aircraft's filterable_attributes — so the example was misleading. Updated to use `aircraft_manufacturer:` directly and added a note that this class does not alias names. TrustCalculatorTest's `fake_source` helper overrode `Object#class` via `define_singleton_method(:class)`. It works today because TrustCalculator only calls `.class.name.demodulize`, but the override silently breaks `is_a?`, `case..when`, and pattern matching on the fake — a footgun for future code. Replaced with an anonymous class whose own `.name` returns the desired string, so the fake behaves correctly under all class introspection. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Cleans up two leftover items from PR #13: corrects a misleading docstring in QueryTranslator that suggested a non-existent field-name mapping, and replaces a fragile test fake that overrode Object#class with an anonymous class that exposes the desired .name instead.
Changes:
- Update
QueryTranslatordocstring examples to use the realaircraft_manufacturerattribute and note that no aliasing exists. - Replace
fake_sourceimplementation inTrustCalculatorTestto avoid overriding#class, preservingis_a?/pattern-matching behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app/services/search/query_translator.rb | Corrects docstring examples to use the actual filterable attribute name and clarifies no aliasing is performed. |
| test/services/trust_calculator_test.rb | Replaces Struct-based class override with an anonymous class whose .name returns the desired string. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Adversarial review finding:
I could not run the Rails test command locally because PostgreSQL is not listening at |
|
@kevinelliott need to fix linting and review Shorty's comments. |
Summary
Closes out two unresolved threads from PR #13.
1.
QueryTranslatordocstringThe class docstring showed user input
manufacturer:Boeingproducing filteraircraft_manufacturer = "Boeing", implying a logical→physical name mapping. There is no such mapping:FieldRegistry.meilisearch_attribute_for/2is an identity function (per its own inline comment "Since we use the same names, this just validates and returns the field"), andmanufactureris not in Aircraft'sfilterable_attributes. The example as written would have produced a silently dropped filter, not the documented output.Updated the docstring to use
aircraft_manufacturer:directly and added a note that this class does not alias user-friendly names to physical attributes. The test was already correct.2.
TrustCalculatorTestfakefake_sourceoverrodeObject#classviasource.define_singleton_method(:class) { FakeClass.new(...) }. It works today becauseTrustCalculatoronly reaches for.class.name.demodulize, but the override silently breaksis_a?,case..when, and pattern matching on the fake — a future footgun.Replaced with an anonymous class whose
.namereturns the desired string.source.class.name.demodulizestill works, and class introspection now behaves correctly.Not changing
The trust score expectations in
source_config_test.rb(40 → 85/95) — verified these matchSourceConfig'sHIGH_TRUST = 85andVERY_HIGH_TRUST = 95forCASAAircraftSource. No drift; no change needed.Test plan
./bin/rails test test/services/trust_calculator_test.rb test/services/search/query_translator_test.rb— 18 runs, 0 failures.bundle exec rubocopclean on touched files (the one pre-existing offence is on untouched code atquery_translator.rb:111).🤖 Generated with Claude Code