Archie runs its own agent loop only. Removes Kit resolution and launch, the harness runner and adapters, the setup terminal and sandbox view, harness secrets and OAuth capture (table dropped in migration 0075), the task-tools contract that only Kit containers reached, and the sandbox-kit-spec dependency. Agent profiles carry image and tools only. The egress proxy keeps the model-session path; the sandbox relay code stays for #1867.
78 lines
3.4 KiB
Go
78 lines
3.4 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/identity"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
|
)
|
|
|
|
type runsByToken map[string]*workflow.Task
|
|
|
|
func (r runsByToken) TaskForCredential(_ context.Context, token string) (*workflow.Task, error) {
|
|
if task, ok := r[token]; ok {
|
|
return task, nil
|
|
}
|
|
return nil, errors.New("unknown")
|
|
}
|
|
|
|
type secretValues map[string]string
|
|
|
|
func (s secretValues) Resolve(ref config.SecretRef) (string, error) { return s[ref.Key], nil }
|
|
|
|
// TestEgressResolvesOnlyGrantedCredentials pins that the proxy hands a run
|
|
// only a secret its identity is granted and bound for in its own org.
|
|
func TestEgressResolvesOnlyGrantedCredentials(t *testing.T) {
|
|
own := []string{"anthropic"}
|
|
cfg := config.Config{
|
|
GrantedCredentials: []string{"github"},
|
|
Providers: map[string]config.Provider{"openai": {Class: "openai"}, "deepseek": {Class: "deepseek"}},
|
|
Identities: []config.IdentityConfig{{Name: "acme-bot", Org: "acme", GrantedCredentials: &own}},
|
|
Containers: config.ContainerConfig{Credentials: []config.CredentialBinding{
|
|
{Service: "github", Secret: config.SecretRef{Engine: "env", Key: "GH"}},
|
|
{Service: "anthropic", Secret: config.SecretRef{Engine: "env", Key: "ROOT_AI"}},
|
|
{Service: "anthropic", Org: "acme", Secret: config.SecretRef{Engine: "env", Key: "ACME_AI"}},
|
|
{Service: "openai", Secret: config.SecretRef{Engine: "env", Key: "ROOT_OPENAI"}},
|
|
{Service: "openai", Org: "acme", Secret: config.SecretRef{Engine: "env", Key: "ACME_OPENAI"}},
|
|
{Service: "deepseek", Secret: config.SecretRef{Engine: "env", Key: "ROOT_DEEPSEEK"}},
|
|
}},
|
|
}
|
|
r := runCredentialResolver{
|
|
runs: runsByToken{"dashboard-run": {ID: 9, Identity: "new-agent"}, "root-run": {ID: 1, Identity: string(identity.SystemID)}, "acme-run": {ID: 2, Identity: "acme-bot", Org: "acme"}, "acme-row-run": {ID: 3, Org: "acme"}},
|
|
config: config.NewHolder(cfg),
|
|
secrets: secretValues{"GH": "gh-secret", "ROOT_AI": "root-ai", "ACME_AI": "acme-ai", "ROOT_OPENAI": "root-openai", "ACME_OPENAI": "acme-openai", "ROOT_DEEPSEEK": "root-deepseek"},
|
|
}
|
|
tests := []struct {
|
|
name, credential, service, want string
|
|
}{
|
|
{"new database agent does not inherit root grants", "dashboard-run", "github", ""},
|
|
{"root run, granted", "root-run", "github", "gh-secret"},
|
|
{"root run, not granted", "root-run", "anthropic", ""},
|
|
{"identity run gets its own org's binding", "acme-run", "anthropic", "acme-ai"},
|
|
{"identity grants replace the root's", "acme-run", "github", ""},
|
|
{"unknown credential", "gone", "github", ""},
|
|
{"a model provider key needs no grant", "root-run", "openai", "root-openai"},
|
|
{"a model provider key is the run's own org's", "acme-run", "openai", "acme-openai"},
|
|
{"another org's model provider key is unbound", "acme-run", "deepseek", ""},
|
|
{"the task's own org decides, not the identity mapping", "acme-row-run", "openai", "acme-openai"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := r.Resolve(context.Background(), tt.credential, tt.service)
|
|
if tt.want == "" {
|
|
if !errors.Is(err, egress.ErrUnbound) {
|
|
t.Fatalf("got %q, %v; want ErrUnbound", got, err)
|
|
}
|
|
return
|
|
}
|
|
if err != nil || got != tt.want {
|
|
t.Fatalf("got %q, %v; want %q", got, err, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|