@@ -62,6 +62,8 @@ func (m *mockDataProducerP) Consumes() map[fwkplugin.DataKey]any {
6262 return m .consumes
6363}
6464
65+ func (m * mockDataProducerP ) OptionalConsumes () map [fwkplugin.DataKey ]any { return nil }
66+
6567func (m * mockDataProducerP ) Produce (ctx context.Context , request * fwksched.InferenceRequest , endpoints []fwksched.Endpoint ) error {
6668 endpoints [0 ].Put (mockProducedDataKey , & mockProducedDataType {value : 42 })
6769 return nil
@@ -92,6 +94,8 @@ func (m *MockConsumerFairnessPolicy) Consumes() map[fwkplugin.DataKey]any {
9294 return m .consumes
9395}
9496
97+ func (m * MockConsumerFairnessPolicy ) OptionalConsumes () map [fwkplugin.DataKey ]any { return nil }
98+
9599type MockSchedulingPlugin struct {
96100 fwksched.Scorer
97101 consumes map [fwkplugin.DataKey ]any
@@ -105,6 +109,8 @@ func (m *MockSchedulingPlugin) Consumes() map[fwkplugin.DataKey]any {
105109 return m .consumes
106110}
107111
112+ func (m * MockSchedulingPlugin ) OptionalConsumes () map [fwkplugin.DataKey ]any { return nil }
113+
108114func TestValidatePluginExecutionOrder (t * testing.T ) {
109115 dkA := fwkplugin .NewDataKey ("keyA" , "mock" )
110116 // Request control plugin that produces data.
@@ -429,27 +435,29 @@ func TestCreateMissingDataProducers(t *testing.T) {
429435 }
430436}
431437
432- // mockMayConsumerPlugin is a plugin that optionally consumes certain data keys.
438+ // mockMayConsumerPlugin is a plugin that only optionally consumes certain data keys.
433439type mockMayConsumerPlugin struct {
434- name string
435- mayConsume map [fwkplugin.DataKey ]any
440+ name string
441+ optionalConsumes map [fwkplugin.DataKey ]any
436442}
437443
438444func (m * mockMayConsumerPlugin ) TypedName () fwkplugin.TypedName {
439445 return fwkplugin.TypedName {Name : m .name , Type : "mock" }
440446}
441447
442- func (m * mockMayConsumerPlugin ) MayConsume () map [fwkplugin.DataKey ]any {
443- return m .mayConsume
448+ func (m * mockMayConsumerPlugin ) Consumes () map [fwkplugin.DataKey ]any { return nil }
449+
450+ func (m * mockMayConsumerPlugin ) OptionalConsumes () map [fwkplugin.DataKey ]any {
451+ return m .optionalConsumes
444452}
445453
446- // mockMixedConsumerPlugin is a plugin that has both required Consumes and optional MayConsume .
454+ // mockMixedConsumerPlugin is a plugin that has both required Consumes and optional OptionalConsumes .
447455// This models a real plugin like prefix cache scorer — requires prefix-match data,
448456// but optionally uses tokenized input and falls back to raw text if unavailable.
449457type mockMixedConsumerPlugin struct {
450- name string
451- consumes map [fwkplugin.DataKey ]any
452- mayConsume map [fwkplugin.DataKey ]any
458+ name string
459+ consumes map [fwkplugin.DataKey ]any
460+ optionalConsumes map [fwkplugin.DataKey ]any
453461}
454462
455463func (m * mockMixedConsumerPlugin ) TypedName () fwkplugin.TypedName {
@@ -460,15 +468,15 @@ func (m *mockMixedConsumerPlugin) Consumes() map[fwkplugin.DataKey]any {
460468 return m .consumes
461469}
462470
463- func (m * mockMixedConsumerPlugin ) MayConsume () map [fwkplugin.DataKey ]any {
464- return m .mayConsume
471+ func (m * mockMixedConsumerPlugin ) OptionalConsumes () map [fwkplugin.DataKey ]any {
472+ return m .optionalConsumes
465473}
466474
467475func TestCreateMissingDataProducers_MayConsume (t * testing.T ) {
468476 producerTypeA := "producer-a"
469477 keyA := fwkplugin .NewDataKey ("keyA" , producerTypeA )
470478
471- producerAFactory := fwkplugin .FactoryFunc (func (name string , _ json.RawMessage , handle fwkplugin.Handle ) (fwkplugin.Plugin , error ) {
479+ producerAFactory := fwkplugin .FactoryFunc (func (name string , _ * json.Decoder , handle fwkplugin.Handle ) (fwkplugin.Plugin , error ) {
472480 return & mockDataProducerP {name : name , produces : map [fwkplugin.DataKey ]any {keyA : nil }}, nil
473481 })
474482
@@ -479,40 +487,40 @@ func TestCreateMissingDataProducers_MayConsume(t *testing.T) {
479487 wantErr bool
480488 }{
481489 {
482- name : "MayConsume key with no producer — warning only, no error" ,
490+ name : "OptionalConsumes key with no producer — warning only, no error" ,
483491 existingPlugins : []fwkplugin.Plugin {
484492 & mockMayConsumerPlugin {
485- name : "optional-consumer" ,
486- mayConsume : map [fwkplugin.DataKey ]any {keyA : nil },
493+ name : "optional-consumer" ,
494+ optionalConsumes : map [fwkplugin.DataKey ]any {keyA : nil },
487495 },
488496 },
489497 factoryRegistry : map [string ]fwkplugin.FactoryFunc {},
490498 wantErr : false , // must NOT error
491499 },
492500 {
493- name : "MayConsume key with a producer present — no warning, no error" ,
501+ name : "OptionalConsumes key with a producer present — no warning, no error" ,
494502 existingPlugins : []fwkplugin.Plugin {
495503 & mockDataProducerP {name : "producer" , produces : map [fwkplugin.DataKey ]any {keyA : nil }},
496504 & mockMayConsumerPlugin {
497- name : "optional-consumer" ,
498- mayConsume : map [fwkplugin.DataKey ]any {keyA : nil },
505+ name : "optional-consumer" ,
506+ optionalConsumes : map [fwkplugin.DataKey ]any {keyA : nil },
499507 },
500508 },
501509 factoryRegistry : map [string ]fwkplugin.FactoryFunc {producerTypeA : producerAFactory },
502510 wantErr : false ,
503511 },
504512 {
505513 // Models the real prefix cache scorer — it requires prefix-match data (Consumes)
506- // but optionally uses tokenized input (MayConsume ), falling back to raw text.
514+ // but optionally uses tokenized input (OptionalConsumes ), falling back to raw text.
507515 // The required key has a producer. The optional key does not.
508516 // Result: no error. Warning logged for the missing optional key.
509- name : "plugin with both Consumes and MayConsume — required key has producer, optional does not" ,
517+ name : "plugin with both Consumes and OptionalConsumes — required key has producer, optional does not" ,
510518 existingPlugins : []fwkplugin.Plugin {
511519 & mockDataProducerP {name : "required-producer" , produces : map [fwkplugin.DataKey ]any {keyA : nil }},
512520 & mockMixedConsumerPlugin {
513- name : "prefix-cache-scorer" ,
514- consumes : map [fwkplugin.DataKey ]any {keyA : nil },
515- mayConsume : map [fwkplugin.DataKey ]any {fwkplugin .NewDataKey ("tokenized-input" , "tokenizer" ): nil },
521+ name : "prefix-cache-scorer" ,
522+ consumes : map [fwkplugin.DataKey ]any {keyA : nil },
523+ optionalConsumes : map [fwkplugin.DataKey ]any {fwkplugin .NewDataKey ("tokenized-input" , "tokenizer" ): nil },
516524 },
517525 },
518526 factoryRegistry : map [string ]fwkplugin.FactoryFunc {},
0 commit comments