2026-04-10 08:17:38 +00:00
|
|
|
package cli
|
|
|
|
|
|
2026-04-14 10:48:36 +00:00
|
|
|
import (
|
2026-04-14 15:09:46 +00:00
|
|
|
"strings"
|
2026-04-14 10:48:36 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2026-05-11 09:16:37 +00:00
|
|
|
frameworkmanifest "forge.lclr.dev/AI/mcp-framework/manifest"
|
2026-04-14 10:48:36 +00:00
|
|
|
)
|
2026-04-10 10:21:58 +00:00
|
|
|
|
2026-04-13 16:01:28 +00:00
|
|
|
func TestBuildAppReturnsConfiguredApp(t *testing.T) {
|
|
|
|
|
app := BuildApp("dev")
|
|
|
|
|
if app == nil {
|
|
|
|
|
t.Fatal("expected app instance")
|
2026-04-10 08:17:38 +00:00
|
|
|
}
|
2026-04-13 16:01:28 +00:00
|
|
|
if app.prompter == nil {
|
|
|
|
|
t.Fatal("expected config prompter to be configured")
|
2026-04-10 10:21:58 +00:00
|
|
|
}
|
2026-04-13 16:01:28 +00:00
|
|
|
if app.configStore == nil {
|
|
|
|
|
t.Fatal("expected config store to be configured")
|
2026-04-10 10:21:58 +00:00
|
|
|
}
|
2026-04-13 16:01:28 +00:00
|
|
|
if app.openSecretStore == nil {
|
|
|
|
|
t.Fatal("expected secret store opener to be configured")
|
2026-04-10 08:17:38 +00:00
|
|
|
}
|
2026-04-13 16:01:28 +00:00
|
|
|
if app.newMailService == nil {
|
|
|
|
|
t.Fatal("expected mail service factory to be configured")
|
2026-04-10 10:21:58 +00:00
|
|
|
}
|
2026-04-13 16:01:28 +00:00
|
|
|
if app.newRunner == nil {
|
|
|
|
|
t.Fatal("expected runner factory to be configured")
|
2026-04-10 10:21:58 +00:00
|
|
|
}
|
2026-04-13 16:01:28 +00:00
|
|
|
if app.loadManifest == nil {
|
|
|
|
|
t.Fatal("expected manifest loader to be configured")
|
2026-04-10 08:17:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-14 10:48:36 +00:00
|
|
|
|
2026-04-14 13:54:17 +00:00
|
|
|
func TestBuildAppOpenSecretStoreMapsProfilePasswordToEnvironment(t *testing.T) {
|
|
|
|
|
t.Setenv(passwordEnv, "env-secret")
|
|
|
|
|
|
|
|
|
|
app := buildApp(nil, nil, nil, "dev", runtimeFactories{
|
|
|
|
|
loadManifest: func(string) (frameworkmanifest.File, string, error) {
|
|
|
|
|
return frameworkmanifest.File{
|
|
|
|
|
SecretStore: frameworkmanifest.SecretStore{
|
|
|
|
|
BackendPolicy: "env-only",
|
|
|
|
|
},
|
|
|
|
|
}, "/tmp/mcp.toml", nil
|
|
|
|
|
},
|
|
|
|
|
resolveExecutable: func() (string, error) { return "/tmp/bin/email-mcp", nil },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
store, err := app.openSecretStore()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("openSecretStore returned error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value, err := store.GetSecret("imap-password/work")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("GetSecret returned error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if value != "env-secret" {
|
|
|
|
|
t.Fatalf("GetSecret = %q, want %q", value, "env-secret")
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-14 15:09:46 +00:00
|
|
|
|
|
|
|
|
func TestBuildAppOpenSecretStoreReturnsErrorOnInvalidManifestPolicy(t *testing.T) {
|
|
|
|
|
app := buildApp(nil, nil, nil, "dev", runtimeFactories{
|
|
|
|
|
loadManifest: func(string) (frameworkmanifest.File, string, error) {
|
|
|
|
|
return frameworkmanifest.File{
|
|
|
|
|
SecretStore: frameworkmanifest.SecretStore{
|
|
|
|
|
BackendPolicy: "invalid-policy",
|
|
|
|
|
},
|
|
|
|
|
}, "/tmp/mcp.toml", nil
|
|
|
|
|
},
|
|
|
|
|
resolveExecutable: func() (string, error) { return "/tmp/bin/email-mcp", nil },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
_, err := app.openSecretStore()
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("expected invalid secret store policy error")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(err.Error(), "invalid secret_store.backend_policy") {
|
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|