package engine import ( "strings" "testing" "github.com/loyaly/behavision-agent/pkg/paths" ) // The engine must be told where THIS process keeps state, or a pip-installed // engine decides on site-packages and the two halves never find each other. func TestTheEngineIsToldWhereStateLives(t *testing.T) { t.Setenv("BEHAVISION_DATA_DIR", t.TempDir()) env := ChildEnv("http://127.0.0.1:5555/events") want := "BEHAVISION_DATA_DIR=" + paths.StateRoot() if !contains(env, want) { t.Fatalf("engine env lacks %q - a source-installed engine would put its "+ "database and credential somewhere this process never looks", want) } if !contains(env, "BEHAVISION_WEBHOOK_URL=http://127.0.0.1:5555/events") { t.Fatal("webhook url not passed to the engine") } } // Before the bridge has a port there is no webhook. An empty variable would be // read by the engine as a webhook at "", which is not the same as none. func TestNoWebhookMeansNoVariable(t *testing.T) { for _, v := range ChildEnv("") { if strings.HasPrefix(v, "BEHAVISION_WEBHOOK_URL=") { t.Fatalf("empty hook still exported: %q", v) } } } func contains(env []string, want string) bool { for _, v := range env { if v == want { return true } } return false }