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.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package secretextract
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestEngineWrapperDelegatesToFields(t *testing.T) {
|
|
w := _github_com_samcharles93_archie_core_internal_secret_Engine{
|
|
WName: func() string { return "vault" },
|
|
WVersion: func() string { return "1.0" },
|
|
WResolve: func(key string) (string, error) { return "resolved:" + key, nil },
|
|
}
|
|
|
|
if got, want := w.Name(), "vault"; got != want {
|
|
t.Errorf("Name() = %q, want %q", got, want)
|
|
}
|
|
if got, want := w.Version(), "1.0"; got != want {
|
|
t.Errorf("Version() = %q, want %q", got, want)
|
|
}
|
|
got, err := w.Resolve("key")
|
|
if err != nil {
|
|
t.Fatalf("Resolve() error = %v, want nil", err)
|
|
}
|
|
if want := "resolved:key"; got != want {
|
|
t.Errorf("Resolve() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestEngineWrapperResolvePropagatesError(t *testing.T) {
|
|
wantErr := errors.New("boom")
|
|
w := _github_com_samcharles93_archie_core_internal_secret_Engine{
|
|
WResolve: func(key string) (string, error) { return "", wantErr },
|
|
}
|
|
_, err := w.Resolve("key")
|
|
if !errors.Is(err, wantErr) {
|
|
t.Fatalf("Resolve() error = %v, want %v", err, wantErr)
|
|
}
|
|
}
|
|
|
|
// The former TestEngineWrapperNilGuards was retired along with the hand-added
|
|
// nil guards it pinned. A wrapper missing a method is now refused where it
|
|
// enters the daemon, in yaegiutil.Resolve, so it never reaches a call site.
|