Files
sam f92c5b4536
ci/woodpecker/pr/quality Pipeline was successful
Quality / check (pull_request) Canceled after 7m39s
chore(runtime): delete Kit and external agent harness support (#1877)
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.
2026-11-12 21:29:05 +11:00

204 lines
6.1 KiB
Go

package webui
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"google.golang.org/grpc"
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/secret"
)
type setupStore struct {
storecontract.TaskStore
}
func (setupStore) StatusCounts(context.Context) (map[string]int, error) {
return map[string]int{"done": 1}, nil
}
type setupModels struct {
aliases map[string]string
err error
}
func (m setupModels) CallerModels(context.Context) (string, map[string]string, error) {
return "org", m.aliases, m.err
}
// setupControl answers provider-settings and credential-bindings queries from
// fixed documents, the way the State Store would for one org.
type setupControl struct {
controlpb.ControlPlaneServiceClient
providers string
bindings string
}
func (c setupControl) Query(_ context.Context, r *controlpb.QueryRequest, _ ...grpc.CallOption) (*controlpb.QueryResponse, error) {
var value string
switch r.Kind {
case providerSettingsKind:
value = c.providers
case credentialBindingsKind:
value = c.bindings
default:
value = "null"
}
return &controlpb.QueryResponse{Resource: &controlpb.Resource{Kind: r.Kind, ValueJson: []byte(value)}}, nil
}
func setupRequest(t *testing.T, srv *Server) []SetupStep {
t.Helper()
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/setup", nil)
response := httptest.NewRecorder()
srv.handleSetup(response, req)
if response.Code != http.StatusOK {
t.Fatalf("response = %d %s", response.Code, response.Body.String())
}
var body struct {
Steps []SetupStep `json:"steps"`
}
if err := json.Unmarshal(response.Body.Bytes(), &body); err != nil {
t.Fatalf("decode response %q: %v", response.Body.String(), err)
}
return body.Steps
}
func modelStep(steps []SetupStep) *SetupStep {
for i := range steps {
if steps[i].Title == "Model" {
return &steps[i]
}
}
return nil
}
func TestHandleSetupModelStep(t *testing.T) {
resolving := func(_ context.Context, ref secret.SecretRef) (bool, error) {
return ref == (secret.SecretRef{Engine: "env", Key: "GOOD_KEY"}), nil
}
for _, tt := range []struct {
name string
aliases map[string]string
providers string
bindings string
check func(context.Context, secret.SecretRef) (bool, error)
open bool
detail string
}{
{
name: "no aliases leaves the step open",
aliases: map[string]string{},
open: true,
detail: "no model alias configured",
},
{
name: "resolving api_key_ref completes the step",
aliases: map[string]string{"default": "openai/gpt-5"},
providers: `{"openai":{"class":"openai","api_key_ref":{"engine":"env","key":"GOOD_KEY"}}}`,
check: resolving,
open: false,
},
{
name: "unresolving api_key_ref keeps the step open and names it",
aliases: map[string]string{"default": "openai/gpt-5"},
providers: `{"openai":{"class":"openai","api_key_ref":{"engine":"env","key":"BAD_KEY"}}}`,
check: resolving,
open: true,
detail: `provider "openai" credential env:BAD_KEY does not resolve`,
},
{
name: "provider declaring no credential keeps the step open",
aliases: map[string]string{"default": "openai/gpt-5"},
providers: `{"openai":{"class":"openai"}}`,
check: resolving,
open: true,
detail: `provider "openai" declares no credential`,
},
{
name: "credential binding secret resolves for an org provider",
aliases: map[string]string{"default": "acme/gpt-5"},
providers: `{"acme":{"class":"openai"}}`,
bindings: `[{"service":"acme","secret":{"engine":"env","key":"GOOD_KEY"}}]`,
check: resolving,
open: false,
},
{
name: "credential binding secret that does not resolve keeps the step open",
aliases: map[string]string{"default": "acme/gpt-5"},
providers: `{"acme":{"class":"openai"}}`,
bindings: `[{"service":"acme","secret":{"engine":"env","key":"BAD_KEY"}}]`,
check: resolving,
open: true,
detail: `provider "acme" credential env:BAD_KEY does not resolve`,
},
{
name: "org provider without a binding keeps the step open",
aliases: map[string]string{"default": "acme/gpt-5"},
providers: `{"acme":{"class":"openai"}}`,
check: resolving,
open: true,
detail: `provider "acme" declares no credential`,
},
{
name: "instance provider is not the org's credential to configure",
aliases: map[string]string{"default": "shared/gpt-5"},
providers: `{}`,
check: resolving,
open: false,
},
{
name: "binding without a secret keeps the step open",
aliases: map[string]string{"default": "acme/gpt-5"},
providers: `{"acme":{"class":"openai"}}`,
bindings: `[{"service":"acme"}]`,
check: resolving,
open: true,
detail: `credential binding "acme" names no secret`,
},
{
name: "api_key_env resolves through the env engine",
aliases: map[string]string{"default": "openai/gpt-5"},
providers: `{"openai":{"class":"openai","api_key_env":"GOOD_KEY"}}`,
check: resolving,
open: false,
},
{
name: "without the control plane the aliases alone decide",
aliases: map[string]string{"default": "openai/gpt-5"},
check: resolving,
open: false,
},
} {
t.Run(tt.name, func(t *testing.T) {
srv := &Server{Store: setupStore{}, Models: setupModels{aliases: tt.aliases}}
if tt.providers != "" || tt.bindings != "" {
srv.ControlPlane = setupControl{providers: tt.providers, bindings: tt.bindings}
}
srv.CheckSecret = tt.check
step := modelStep(setupRequest(t, srv))
if !tt.open {
if step != nil {
t.Fatalf("Model step = %+v, want it complete (absent)", *step)
}
return
}
if step == nil {
t.Fatalf("Model step absent, want it open with detail %q", tt.detail)
}
if step.Done {
t.Fatalf("Model step done, want it open")
}
if !strings.Contains(step.Detail, tt.detail) {
t.Fatalf("Model step detail = %q, want it to contain %q", step.Detail, tt.detail)
}
})
}
}