Two bugs found by adversarial tests: 1. _Plugin wrapper panicked on nil WName/WVersion — the daemon calls Name()/Version() at startup to log loaded plugins, so a plugin with nil func fields would crash the daemon. Fixed with nil guards returning empty strings. 2. LoadDir returned nil for empty directories instead of an empty slice — inconsistent with the contract (nil means 'no plugin dir configured', empty means 'no plugins found'). Added 9 adversarial tests that attempt to break LoadDir: - Nil function fields (must not panic on load or call) - Empty name/version (valid per interface contract) - Wrong export type (int instead of Plugin — must skip) - Partial interface implementation (missing method — must skip) - Empty directory (returns empty slice, not nil) - Nested subdirectories (must not be traversed) - Panic in Name() function (deferred to call time, loader survives) - Unused import (must not crash eval) - Go build tags (must be ignored in Yaegi) Why: per test-first-build skill, every build/test failure results in a test that would have caught it. Adversarial tests alongside confirmation tests prevent silent breakage.
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Code generated by 'yaegi extract github.com/samcharles93/archie-core/internal/plugin'. DO NOT EDIT.
|
|
|
|
package pluginextract
|
|
|
|
import (
|
|
"github.com/samcharles93/archie-core/internal/plugin"
|
|
"reflect"
|
|
)
|
|
|
|
func init() {
|
|
Symbols["github.com/samcharles93/archie-core/internal/plugin/plugin"] = map[string]reflect.Value{
|
|
// function, constant and variable definitions
|
|
"LoadDir": reflect.ValueOf(plugin.LoadDir),
|
|
|
|
// type definitions
|
|
"Plugin": reflect.ValueOf((*plugin.Plugin)(nil)),
|
|
"Registry": reflect.ValueOf((*plugin.Registry)(nil)),
|
|
|
|
// interface wrapper definitions
|
|
"_Plugin": reflect.ValueOf((*_github_com_samcharles93_archie_core_internal_plugin_Plugin)(nil)),
|
|
}
|
|
}
|
|
|
|
// _github_com_samcharles93_archie_core_internal_plugin_Plugin is an interface wrapper for Plugin type
|
|
type _github_com_samcharles93_archie_core_internal_plugin_Plugin struct {
|
|
IValue interface{}
|
|
WName func() string
|
|
WVersion func() string
|
|
}
|
|
|
|
func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Name() string {
|
|
if W.WName == nil {
|
|
return ""
|
|
}
|
|
return W.WName()
|
|
}
|
|
func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Version() string {
|
|
if W.WVersion == nil {
|
|
return ""
|
|
}
|
|
return W.WVersion()
|
|
}
|