Skip to content

Commit e8552b1

Browse files
Copilotintel352
andauthored
fix: tighten engine_module_bridge and mockApplication based on review feedback (#148)
* Initial plan * refactor: address code review feedback on engine_module_bridge and engine_test Co-authored-by: intel352 <77607+intel352@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
1 parent 769bf3c commit e8552b1

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

engine_module_bridge.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ func (e *StdEngine) registerPluginSteps(typeName string, stepFactory func(name s
8686
// uses the canonical interface type.
8787
func (e *StdEngine) registerPluginTrigger(triggerType string, factory func() any) {
8888
result := factory()
89-
if trigger, ok := result.(interfaces.Trigger); ok {
90-
e.triggerTypeMap[triggerType] = trigger.Name()
91-
e.RegisterTrigger(trigger)
89+
trigger, ok := result.(interfaces.Trigger)
90+
if !ok {
91+
// Fail fast with a clear warning when a plugin misconfigures its trigger factory.
92+
// This avoids silent failures that later surface as "no handler found" errors.
93+
e.logger.Error(fmt.Sprintf("workflow: plugin trigger factory for %q returned non-Trigger type %T; trigger not registered", triggerType, result))
94+
return
9295
}
96+
e.triggerTypeMap[triggerType] = trigger.Name()
97+
e.RegisterTrigger(trigger)
9398
}

engine_test.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,15 @@ func (a *mockApplication) GetService(name string, out any) error {
281281

282282
// If out is provided, try to assign the service to it using reflection
283283
if out != nil {
284+
// Guard: nil service value would make reflect.ValueOf(svc).Type() panic.
285+
if svc == nil {
286+
return fmt.Errorf("service %s has a nil value", name)
287+
}
288+
284289
// Get reflect values
285290
outVal := reflect.ValueOf(out)
286-
if outVal.Kind() != reflect.Pointer {
287-
return fmt.Errorf("out parameter must be a pointer")
291+
if outVal.Kind() != reflect.Pointer || outVal.IsNil() {
292+
return fmt.Errorf("out parameter must be a non-nil pointer")
288293
}
289294

290295
// Dereference the pointer
@@ -1544,14 +1549,6 @@ func TestEngine_BuildFromConfig_RequiresPlugins_EmptyPluginsList(t *testing.T) {
15441549
// TestEngine_BuildFromConfig_RequiresPlugins_ExactVersionMatch verifies
15451550
// exact version matching (=1.2.3 constraint).
15461551
func TestEngine_BuildFromConfig_RequiresPlugins_ExactVersionMatch(t *testing.T) {
1547-
app := newMockApplication()
1548-
engine := NewStdEngine(app, app.Logger())
1549-
1550-
p := newMinimalPlugin("exact-plugin", "1.2.3")
1551-
if err := engine.LoadPlugin(p); err != nil {
1552-
t.Fatalf("LoadPlugin failed: %v", err)
1553-
}
1554-
15551552
tests := []struct {
15561553
constraint string
15571554
wantOK bool
@@ -1577,10 +1574,8 @@ func TestEngine_BuildFromConfig_RequiresPlugins_ExactVersionMatch(t *testing.T)
15771574
},
15781575
}
15791576

1580-
// Use a fresh engine for each sub-test to avoid state contamination.
1581-
// We re-use the same app since plugins are already registered in the
1582-
// PluginLoader (which we recreate by calling LoadPlugin again on a
1583-
// fresh engine but referencing the same plugin instance).
1577+
// Use a fresh app and engine (with a freshly loaded plugin) for each
1578+
// sub-test to avoid state contamination.
15841579
subApp := newMockApplication()
15851580
subEngine := NewStdEngine(subApp, subApp.Logger())
15861581
subP := newMinimalPlugin("exact-plugin", "1.2.3")

0 commit comments

Comments
 (0)