Skip to content

Commit c49816f

Browse files
committed
feat: added definition source to sub flow
1 parent 29822fd commit c49816f

5 files changed

Lines changed: 65 additions & 14 deletions

File tree

app/models/sub_flow.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ def function_identifier
1414
end
1515

1616
def to_grpc
17-
Tucana::Shared::SubFlow.new(
17+
grpc_sub_flow = Tucana::Shared::SubFlow.new(
1818
starting_node_id: starting_node_id,
19-
function_identifier: function_identifier,
2019
signature: signature,
2120
settings: sub_flow_settings.map(&:to_grpc)
2221
)
22+
if function_definition.present?
23+
function_args = { function_identifier: function_identifier }
24+
definition_source = function_definition.runtime_function_definition.definition_source
25+
function_args[:definition_source] = definition_source if definition_source.present?
26+
27+
grpc_sub_flow.function = Tucana::Shared::SubFlow::SubFlowFunction.new(**function_args)
28+
end
29+
30+
grpc_sub_flow
2331
end
2432

2533
private

app/services/velorum/generation_flow_serializer.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ def prepare_definition_ids
7575
runtime_name = if definition.respond_to?(:runtime_function_definition)
7676
definition.runtime_function_definition&.runtime_name
7777
end
78+
definition_source = definition.runtime_function_definition&.definition_source
7879
function_definitions_by_runtime_id[runtime_name] ||= definition if runtime_name.present?
80+
if definition_source.present?
81+
function_definitions_by_runtime_id[[definition.identifier, definition_source]] ||= definition
82+
function_definitions_by_runtime_id[[runtime_name, definition_source]] ||= definition if runtime_name.present?
83+
end
7984
end
8085
end
8186

@@ -176,11 +181,15 @@ def reference_path_to_h(path)
176181
end
177182

178183
def sub_flow_to_h(sub_flow)
179-
function_definition = function_definition_for_identifier(sub_flow.function_identifier)
180-
if runtime.present? && sub_flow.function_identifier.present? && function_definition.nil?
184+
sub_flow_function = sub_flow.function if sub_flow.execution_reference == :function
185+
function_identifier = sub_flow_function&.function_identifier
186+
definition_source = sub_flow_function.definition_source if sub_flow_function&.has_definition_source?
187+
function_definition = function_definition_for_identifier(function_identifier, definition_source)
188+
if runtime.present? && function_identifier.present? && function_definition.nil?
181189
raise_unresolved_definition(
182190
'Generated sub-flow function definition is unknown',
183-
function_identifier: sub_flow.function_identifier
191+
function_identifier: function_identifier,
192+
definition_source: definition_source
184193
)
185194
end
186195

@@ -251,7 +260,11 @@ def function_definition_for(node)
251260
function_definition_for_identifier(node.runtime_function_id)
252261
end
253262

254-
def function_definition_for_identifier(identifier)
263+
def function_definition_for_identifier(identifier, definition_source = nil)
264+
return if identifier.blank?
265+
266+
return function_definitions_by_runtime_id[[identifier, definition_source]] if definition_source.present?
267+
255268
function_definitions_by_runtime_id[identifier]
256269
end
257270

spec/models/sub_flow_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,24 @@
2020
expect(sub_flow.errors[:base]).to include('Exactly one of starting_node or function_definition must be present')
2121
end
2222
end
23+
24+
describe '#to_grpc' do
25+
it 'serializes a function reference with its definition source' do
26+
runtime_function_definition = create(:runtime_function_definition, definition_source: 'taurus')
27+
function_definition = create(
28+
:function_definition,
29+
runtime: runtime_function_definition.runtime,
30+
runtime_function_definition: runtime_function_definition
31+
)
32+
sub_flow = create(:sub_flow, starting_node: nil, function_definition: function_definition)
33+
34+
grpc_sub_flow = sub_flow.to_grpc
35+
36+
expect(grpc_sub_flow.function).to have_attributes(
37+
function_identifier: function_definition.identifier,
38+
definition_source: 'taurus'
39+
)
40+
expect(grpc_sub_flow.function.has_definition_source?).to be(true)
41+
end
42+
end
2343
end

spec/services/velorum/generate_flow_service_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
parameter_definitions: [parameter_definition]
3737
)
3838
end
39-
let(:runtime_function_definition) { instance_double(RuntimeFunctionDefinition, runtime_name: 'sum') }
39+
let(:runtime_function_definition) do
40+
instance_double(RuntimeFunctionDefinition, runtime_name: 'sum', definition_source: 'taurus')
41+
end
4042
let(:parameter_definition) do
4143
instance_double(ParameterDefinition, runtime_parameter_definition: runtime_parameter_definition)
4244
end

spec/services/velorum/generation_flow_serializer_spec.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@
150150
)
151151
end
152152

153-
it 'maps gRPC reference variants and sub-flow values to flow-shaped objects',
154-
skip: 'Temporarily disabled until the Tucana 0.0.76 SubFlow schema is supported' do
153+
it 'maps gRPC reference variants and sub-flow values to flow-shaped objects' do
155154
flow = Tucana::Shared::GenerationFlow.new(
156155
node_functions: [
157156
Tucana::Shared::NodeFunction.new(
@@ -184,7 +183,7 @@
184183
runtime_parameter_id: 'sub-flow',
185184
value: Tucana::Shared::NodeValue.new(
186185
sub_flow: Tucana::Shared::SubFlow.new(
187-
function_identifier: 'helper',
186+
function: Tucana::Shared::SubFlow::SubFlowFunction.new(function_identifier: 'helper'),
188187
signature: '(): undefined'
189188
)
190189
)
@@ -223,9 +222,13 @@
223222
)
224223
end
225224

226-
it 'resolves generated sub-flow function identifiers to function definitions',
227-
skip: 'Temporarily disabled until the Tucana 0.0.76 SubFlow schema is supported' do
228-
runtime_function_definition = create(:runtime_function_definition, runtime: runtime, runtime_name: 'helper')
225+
it 'resolves generated sub-flow functions by identifier and definition source' do
226+
runtime_function_definition = create(
227+
:runtime_function_definition,
228+
runtime: runtime,
229+
runtime_name: 'helper',
230+
definition_source: 'taurus'
231+
)
229232
function_definition = create(
230233
:function_definition,
231234
runtime: runtime,
@@ -250,7 +253,12 @@
250253
parameters: [
251254
Tucana::Shared::NodeParameter.new(
252255
value: Tucana::Shared::NodeValue.new(
253-
sub_flow: Tucana::Shared::SubFlow.new(function_identifier: 'helper')
256+
sub_flow: Tucana::Shared::SubFlow.new(
257+
function: Tucana::Shared::SubFlow::SubFlowFunction.new(
258+
function_identifier: 'helper',
259+
definition_source: 'taurus'
260+
)
261+
)
254262
)
255263
)
256264
]

0 commit comments

Comments
 (0)