fix: rollback Enabled on activation failure + fatal on_init + rollback test
1. SetPluginEnabled(true): after DeactivatePlugin, also call Disable(name) to rollback in-memory Enabled state (not just config). 2. on_init failure is now fatal for ActivatePlugin — returns error and rolls back scheduler + VM (was incorrectly non-fatal). 3. TestSetPluginEnabled_BrokenPlugin_Rollback: end-to-end test with broken plugin (invalid interval), verifies error + not Active + not Enabled + not in config.
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
// ActivatePlugin fully activates a plugin: creates Lua VM, loads main.lua, starts scheduler.
|
||||
// Only works if plugin is installed and enabled but not yet active.
|
||||
// Returns error if VM creation, script loading, scheduler setup, or on_init hook fails.
|
||||
// on_init failure is fatal — the plugin cannot run without proper initialization.
|
||||
func (m *Manager) ActivatePlugin(name string) error {
|
||||
for i := range m.plugins {
|
||||
p := &m.plugins[i]
|
||||
@@ -56,8 +57,12 @@ func (m *Manager) ActivatePlugin(name string) error {
|
||||
|
||||
if hookName, ok := p.Meta.Hooks["on_init"]; ok {
|
||||
if err := vm.CallHook(hookName); err != nil {
|
||||
// on_init failure is non-fatal for activation — log but continue
|
||||
log.Printf("[plugins] %s: on_init error: %v", name, err)
|
||||
// on_init failure is fatal — rollback activation
|
||||
p.scheduler.Stop()
|
||||
p.scheduler = nil
|
||||
p.vm.Close()
|
||||
p.vm = nil
|
||||
return fmt.Errorf("on_init for %q: %w", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user