Skip to content

Commit 55df0d7

Browse files
committed
Share the example scalar coercion adapter across suites
The whole-repo CI run failed coverage because two identical copies of `ExampleScalarCoercionAdapter` (one per gem suite) shared the same relative require path, so only one of them ever loaded and the other reported 0% coverage. Moving the adapter into `spec_support/lib` leaves a single copy that every suite loads from the same require path, which also preserves the extension loader's same-path guarantee that the prior commit relied on.
1 parent de462ca commit 55df0d7

5 files changed

Lines changed: 33 additions & 42 deletions

File tree

elasticgraph-json_ingestion/spec/support/example_extensions/scalar_coercion_adapter.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

elasticgraph-json_ingestion/spec/unit/elastic_graph/json_ingestion/schema_definition/schema_elements/scalar_type_extension_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ def grouping_missing_value_placeholder_for(mapping_type, **json_schema_options)
209209
end
210210

211211
def scalar_coercion_adapter_path
212-
# Must match the `defined_at` path used by other specs (e.g. in `elasticgraph-schema_definition`)
213-
# that load this adapter: the extension loader raises if the same extension is loaded from two
214-
# different paths within one process, as can happen when one worker runs both suites.
215-
"support/example_extensions/scalar_coercion_adapter"
212+
# The adapter lives in `spec_support` so that every suite which loads it (e.g. this one and
213+
# `elasticgraph-schema_definition`) uses the same require path: the extension loader raises
214+
# if the same extension is loaded from two different paths within one process, as can happen
215+
# when one worker runs multiple suites.
216+
"elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
216217
end
217218

218219
def build_api

elasticgraph-schema_definition/spec/support/example_extensions/scalar_coercion_adapter.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/runtime_metadata/scalar_types_by_name_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ module SchemaDefinition
2121
metadata = scalar_type_metadata_for "BigInt" do |s|
2222
s.scalar_type "BigInt" do |t|
2323
t.mapping type: "long"
24-
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "support/example_extensions/scalar_coercion_adapter"
24+
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
2525
end
2626
end
2727

2828
expect(metadata).to eq scalar_type_with(coercion_adapter_ref: {
2929
"name" => "ExampleScalarCoercionAdapter",
30-
"require_path" => "support/example_extensions/scalar_coercion_adapter"
30+
"require_path" => "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
3131
})
3232
end
3333

@@ -51,7 +51,7 @@ module SchemaDefinition
5151
t.mapping type: "long"
5252

5353
expect {
54-
t.coerce_with "NotAValidConstant", defined_at: "support/example_extensions/scalar_coercion_adapter"
54+
t.coerce_with "NotAValidConstant", defined_at: "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
5555
}.to raise_error NameError, a_string_including("NotAValidConstant")
5656
end
5757
end
@@ -79,14 +79,14 @@ module SchemaDefinition
7979
metadata = scalar_type_metadata_for "Int" do |s|
8080
s.on_built_in_types do |t|
8181
if t.is_a?(SchemaElements::ScalarType)
82-
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "support/example_extensions/scalar_coercion_adapter"
82+
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
8383
end
8484
end
8585
end
8686

8787
expect(metadata.coercion_adapter_ref).to eq({
8888
"name" => "ExampleScalarCoercionAdapter",
89-
"require_path" => "support/example_extensions/scalar_coercion_adapter"
89+
"require_path" => "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
9090
})
9191
end
9292

@@ -191,7 +191,7 @@ module SchemaDefinition
191191

192192
it "infers 'NaN' for safe integer type #{int_type} with custom coercion adapter" do
193193
grouping_missing_value_placeholder = grouping_missing_value_placeholder_for(int_type) do |t|
194-
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "support/example_extensions/scalar_coercion_adapter"
194+
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
195195
end
196196

197197
expect(grouping_missing_value_placeholder).to eq(MISSING_NUMERIC_PLACEHOLDER)
@@ -200,15 +200,15 @@ module SchemaDefinition
200200

201201
it "does not infer a placeholder for `long` types since core ElasticGraph cannot know their range is float-safe" do
202202
grouping_missing_value_placeholder = grouping_missing_value_placeholder_for("long") do |t|
203-
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "support/example_extensions/scalar_coercion_adapter"
203+
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
204204
end
205205

206206
expect(grouping_missing_value_placeholder).to be_nil
207207
end
208208

209209
it "does not infer a placeholder for `unsigned_long` types since core ElasticGraph cannot know their range is float-safe" do
210210
grouping_missing_value_placeholder = grouping_missing_value_placeholder_for("unsigned_long") do |t|
211-
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "support/example_extensions/scalar_coercion_adapter"
211+
t.coerce_with "ExampleScalarCoercionAdapter", defined_at: "elastic_graph/spec_support/example_extensions/scalar_coercion_adapter"
212212
end
213213

214214
expect(grouping_missing_value_placeholder).to be_nil
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2024 - 2026 Block, Inc.
2+
#
3+
# Use of this source code is governed by an MIT-style
4+
# license that can be found in the LICENSE file or at
5+
# https://opensource.org/licenses/MIT.
6+
#
7+
# frozen_string_literal: true
8+
9+
# This example adapter is shared by multiple gem suites (e.g. `elasticgraph-schema_definition`
10+
# and `elasticgraph-json_ingestion`). It must live in `spec_support` (rather than being
11+
# duplicated under each gem's `spec/support`) so that every suite loads it from the same
12+
# require path: the extension loader raises if the same extension is loaded from two
13+
# different paths within one process, as can happen when one worker runs multiple suites.
14+
class ExampleScalarCoercionAdapter
15+
def self.coerce_input(value, ctx)
16+
end
17+
18+
def self.coerce_result(value, ctx)
19+
end
20+
end

0 commit comments

Comments
 (0)