Files
archie/internal/plugin/pluginextract/pluginextract_test.go
T
sam 71d026feb2 fix(yaegiutil): refuse incomplete Yaegi interface wrappers at load
The generated symbol tables carried 25 hand-added nil guards across three
packages, re-applied by hand after every regeneration because `yaegi extract`
does not emit them. Regeneration silently dropped them, and three package docs
instructed the next agent to put them back.

The guards also answered the wrong way. A nil WResolve returned ("", nil), so a
malformed secret engine served an empty secret and reported success; a nil
WStop reported a clean shutdown for a module that never ran one.

Reject the wrapper where it enters the daemon instead. Yaegi type-checks
"var X Iface = impl{}" and refuses an incomplete impl on its own, but the
wrapper type is exported into the symbol table, so interpreted code can build
one directly and struct-literal semantics leave the omitted method nil.
Resolve now names the missing method and skips the plugin.

Generated tables are used verbatim again. Also names the wanted type on a
failed assertion, which formatted as "want <nil>" for every interface target.
2026-09-20 12:05:39 +10:00

37 lines
1.2 KiB
Go

package pluginextract
import (
"reflect"
"testing"
)
func TestSymbolsContainsExpectedPluginEntries(t *testing.T) {
pkgKey := "github.com/samcharles93/archie-core/internal/plugin/plugin"
pkg, ok := Symbols[pkgKey]
if !ok {
t.Fatalf("Symbols missing key %q", pkgKey)
}
// LoadDir must be a function.
if v, ok := pkg["LoadDir"]; !ok {
t.Error("LoadDir missing from Symbols")
} else if v.Kind() != reflect.Func {
t.Errorf("LoadDir kind = %v, want Func", v.Kind())
}
// Plugin must be a pointer type.
if v, ok := pkg["Plugin"]; !ok {
t.Error("Plugin missing from Symbols")
} else if v.Kind() != reflect.Pointer {
t.Errorf("Plugin kind = %v, want Ptr", v.Kind())
}
}
// The former TestGeneratedWrapperHasNilGuards was retired: it was named for a
// regression Yaegi cannot produce. Yaegi type-checks the assignment to an
// interface before building a wrapper, so a wrapper never reaches Go with a nil
// method field, and the hand-added guards it referred to only survived until the
// next regeneration. That invariant is pinned directly in internal/plugin by
// TestPartialImplementationIsRejectedBeforeWrapping and
// TestCompleteImplementationWrapsWithNoNilMethods.