- Introduce `-config-overlay` flag and `config.LoadOverlay()` to merge a base config with an overlay file, only overriding fields the overlay sets. This enables docker-compose to mount the base config from the host and apply only deployment-specific overrides. - Create `internal/natsrpc` package with reusable NATS request/reply primitives (Envelope, Client, Call, RegisterAll, Respond). Migrate storerpc, worktreerpc, and forgerpc to use it, eliminating duplicated marshal/unmarshal and error handling. - Create `internal/yaegiutil` package with shared interpreter construction (stdlib + extra symbols), generic export resolution (Resolve), and panic recovery (Safe). Migrate all Yaegi-based surfaces (gate scripts, daemon plugins, skill plugins, workflow stages, skill scripts) to use it, reducing boilerplate and centralizing panic safety. - Simplify `config.docker.toml` to contain only overlay fields (paths, container config) and remove the duplicated repos list – the base config is now the single source of truth. - Update docker-compose.yml to pass both -config and -config-overlay flags and mount the base config from the host. - Add tests for LoadOverlay, DockerConfigOverlaysExampleConfig, Envelope, and yaegiutil utilities.
74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package yaegiutil_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/traefik/yaegi/interp"
|
|
|
|
"github.com/samcharles93/archie-core/internal/yaegiutil"
|
|
)
|
|
|
|
func TestResolve(t *testing.T) {
|
|
i, err := yaegiutil.New(interp.Options{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fn, err := yaegiutil.Resolve[func() string](i, `package main
|
|
func Greet() string { return "hi" }`, "main.Greet")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := fn(); got != "hi" {
|
|
t.Errorf("got %q, want %q", got, "hi")
|
|
}
|
|
}
|
|
|
|
func TestResolveWrongType(t *testing.T) {
|
|
i, err := yaegiutil.New(interp.Options{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = yaegiutil.Resolve[func() int](i, `package main
|
|
func Greet() string { return "hi" }`, "main.Greet")
|
|
if err == nil {
|
|
t.Fatal("want error for wrong type, got nil")
|
|
}
|
|
}
|
|
|
|
func TestResolveMissingExport(t *testing.T) {
|
|
i, err := yaegiutil.New(interp.Options{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = yaegiutil.Resolve[func() string](i, `package main
|
|
func Other() string { return "hi" }`, "main.Greet")
|
|
if err == nil {
|
|
t.Fatal("want error for missing export, got nil")
|
|
}
|
|
}
|
|
|
|
func TestSafeRecoversPanic(t *testing.T) {
|
|
_, err := yaegiutil.Safe("test", func() (string, error) {
|
|
panic("boom")
|
|
})
|
|
if err == nil {
|
|
t.Fatal("want error from recovered panic, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), "boom") {
|
|
t.Errorf("error %q does not mention panic value", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestSafePassesThroughResult(t *testing.T) {
|
|
got, err := yaegiutil.Safe("test", func() (int, error) {
|
|
return 42, nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != 42 {
|
|
t.Errorf("got %d, want 42", got)
|
|
}
|
|
}
|