Completes the objective deletion gate for the UI Service (archie-core-8cda.5.6): go list -deps ./cmd/archie-ui now links zero banned packages -- no modernc.org/sqlite, no internal/store, gateway, channels, memory, secret, agentexec, tools, skill, yaegiutil, curator, or the workflow engine. The closure shrinks from 68 to 26 archie-core packages. Each cut is a producer-side move; no consumer-side defensive shims. - Store contracts (TaskStore family, value types, sentinels) moved from internal/store to internal/domain/storecontract -- the approved contract location per state-store-contract rev. 2d, and NOT internal/contracts: that tree is buf generate output and tools/proto.sh check deletes hand-written files there. internal/store keeps aliases; sentinel message strings are byte-identical and remain the wire contract. - Chat contracts (ChatContract, sessions, turns, streaming, commands) moved from internal/gateway to internal/domain/messaging; gateway keeps aliases. ToolCallEvent rendering helpers become gateway functions (methods cannot live on alias types). - Task vocabulary (Task, statuses, mid-run Store, Definition) split into internal/domain/workflow/task; the pipeline engine stays in package workflow with aliases, so daemon-side callers are unchanged. - overlay.DeniedKeys moved to internal/infrastructure/configuration: webui referenced the constant and that dragged the overlay SQLite store in. - webui.Server's concrete runtime handles become webui-owned view interfaces with daemon-side bootstrap adapters: channel lifecycle (internal/channels/status), MemoryStatus, CuratorStatus, and a SkillCatalog seam replacing the direct skill.DefaultRoots/CatalogRoots calls. Each degrades to an empty page when unwired. - config.SecretRef moved into internal/config (config vocabulary); internal/secret keeps an alias and Registry.Resolve absorbs the zero-value short-circuit. Docs: state-store-contract rev. 2d relocation record; ui-service-boundary deletion gate marked satisfied; ARCHITECTURE.md package map rows.
170 lines
3.7 KiB
Go
170 lines
3.7 KiB
Go
package secret
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestEnvEngineResolve(t *testing.T) {
|
|
t.Setenv("TEST_SECRET_KEY", "test-value")
|
|
|
|
e := &envEngine{}
|
|
if e.Name() != "env" {
|
|
t.Errorf("Name = %q", e.Name())
|
|
}
|
|
if e.Version() != "1.0.0" {
|
|
t.Errorf("Version = %q", e.Version())
|
|
}
|
|
v, err := e.Resolve("TEST_SECRET_KEY")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v != "test-value" {
|
|
t.Errorf("got %q, want test-value", v)
|
|
}
|
|
}
|
|
|
|
func TestEnvEngineResolveMissing(t *testing.T) {
|
|
e := &envEngine{}
|
|
_, err := e.Resolve("NONEXISTENT_VAR_12345")
|
|
if err == nil {
|
|
t.Error("expected error for missing env var")
|
|
}
|
|
}
|
|
|
|
func TestSecretRefZeroValue(t *testing.T) {
|
|
r := NewRegistry()
|
|
var s SecretRef
|
|
v, err := r.Resolve(s)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if v != "" {
|
|
t.Errorf("zero-value SecretRef should return empty string, got %q", v)
|
|
}
|
|
}
|
|
|
|
func TestRegistryRegisterAndGet(t *testing.T) {
|
|
r := NewRegistry()
|
|
e, ok := r.Get("env")
|
|
if !ok {
|
|
t.Fatal("env engine should be registered by default")
|
|
}
|
|
if e.Name() != "env" {
|
|
t.Errorf("Name = %q", e.Name())
|
|
}
|
|
}
|
|
|
|
func TestRegistryGetMissing(t *testing.T) {
|
|
r := NewRegistry()
|
|
_, ok := r.Get("nonexistent")
|
|
if ok {
|
|
t.Error("should not find nonexistent engine")
|
|
}
|
|
}
|
|
|
|
func TestRegistryResolve(t *testing.T) {
|
|
t.Setenv("TEST_SECRET", "resolved")
|
|
|
|
r := NewRegistry()
|
|
v, err := r.Resolve(SecretRef{Engine: "env", Key: "TEST_SECRET"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v != "resolved" {
|
|
t.Errorf("got %q, want resolved", v)
|
|
}
|
|
}
|
|
|
|
func TestRegistryResolveUnknownEngine(t *testing.T) {
|
|
r := NewRegistry()
|
|
_, err := r.Resolve(SecretRef{Engine: "unknown", Key: "x"})
|
|
if err == nil {
|
|
t.Error("expected error for unknown engine")
|
|
}
|
|
}
|
|
|
|
func TestRegistryGetenvFallsBackToNonEnvEngine(t *testing.T) {
|
|
t.Setenv("ARCHIE_TEST_BWS_PROVIDER_KEY", "")
|
|
r := NewRegistry()
|
|
r.Register(testEngine{name: "test-source", values: map[string]string{
|
|
"ARCHIE_TEST_BWS_PROVIDER_KEY": "resolved-value",
|
|
}})
|
|
|
|
if got := r.Getenv("ARCHIE_TEST_BWS_PROVIDER_KEY"); got != "resolved-value" {
|
|
t.Fatalf("Getenv() = %q, want resolved value", got)
|
|
}
|
|
if got := os.Getenv("ARCHIE_TEST_BWS_PROVIDER_KEY"); got != "resolved-value" {
|
|
t.Fatalf("resolved value was not exported for SDK/container consumers")
|
|
}
|
|
}
|
|
|
|
type testEngine struct {
|
|
name string
|
|
values map[string]string
|
|
}
|
|
|
|
func TestBWSEngineLoadsNamedSecretsOnce(t *testing.T) {
|
|
dir := t.TempDir()
|
|
command := filepath.Join(dir, "bws")
|
|
countPath := filepath.Join(dir, "count")
|
|
script := fmt.Sprintf(`#!/bin/sh
|
|
echo x >> %q
|
|
printf '%%s' '[{"key":"OPENAI_API_KEY","value":"from-bws"}]'
|
|
`, countPath)
|
|
if err := os.WriteFile(command, []byte(script), 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("PATH", dir)
|
|
|
|
engine := newBWSEngine()
|
|
got, err := engine.Resolve("OPENAI_API_KEY")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "from-bws" {
|
|
t.Fatalf("Resolve() = %q", got)
|
|
}
|
|
if _, err := engine.Resolve("OPENAI_API_KEY"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
count, err := os.ReadFile(countPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := strings.Count(string(count), "x"); got != 1 {
|
|
t.Fatalf("bws invocation count = %d, want 1", got)
|
|
}
|
|
}
|
|
|
|
func (e testEngine) Name() string { return e.name }
|
|
func (e testEngine) Version() string { return "test" }
|
|
func (e testEngine) Resolve(key string) (string, error) {
|
|
value, ok := e.values[key]
|
|
if !ok {
|
|
return "", fmt.Errorf("not found")
|
|
}
|
|
return value, nil
|
|
}
|
|
|
|
func TestLoadDirNonexistent(t *testing.T) {
|
|
r := NewRegistry()
|
|
n, err := r.LoadDir("/nonexistent/path/12345")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n != 0 {
|
|
t.Errorf("expected 0 loaded, got %d", n)
|
|
}
|
|
}
|
|
|
|
func TestNewRegistryHasEnv(t *testing.T) {
|
|
r := NewRegistry()
|
|
if _, ok := r.Get("env"); !ok {
|
|
t.Error("NewRegistry must pre-register env engine")
|
|
}
|
|
}
|