Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
295 lines
12 KiB
Go
295 lines
12 KiB
Go
package agentstatus
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/tutti-os/tutti/packages/agent/daemon/providerregistry"
|
|
"github.com/tutti-os/tutti/packages/agent/daemon/providerstatus"
|
|
"github.com/tutti-os/tutti/services/tuttid/biz/agentprovider"
|
|
)
|
|
|
|
func TestResolveProviderCommandPrefersCompleteManagedNPMPackageOverStaleShim(t *testing.T) {
|
|
if runtime.GOOS != "windows" {
|
|
t.Skip("managed npm fallback is Windows-only")
|
|
}
|
|
home := t.TempDir()
|
|
legacyShim := filepath.Join(home, ".local", "bin", "opencode.cmd")
|
|
if err := os.MkdirAll(filepath.Dir(legacyShim), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(legacyShim, []byte("@echo off\r\nmissing.exe %*\r\n"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
prefix := filepath.Join(home, ".local")
|
|
packageDir, ok := managedNPMGlobalPackageDir(prefix, "opencode-ai")
|
|
if !ok {
|
|
t.Fatal("managed npm package path rejected")
|
|
}
|
|
managedBinary := filepath.Join(packageDir, "bin", "opencode.exe")
|
|
if err := os.MkdirAll(filepath.Dir(managedBinary), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(packageDir, "package.json"), []byte(`{"name":"opencode-ai","bin":{"opencode":"./bin/opencode.exe"}}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(managedBinary, []byte("test binary"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
service := Service{
|
|
HomeDir: func() (string, error) { return home, nil },
|
|
Environ: func() []string { return []string{"PATH=" + filepath.Dir(legacyShim)} },
|
|
LookPath: func(string) (string, error) { return legacyShim, nil },
|
|
IsExecutableFile: func(path string) bool {
|
|
info, err := os.Stat(path)
|
|
return err == nil && !info.IsDir()
|
|
},
|
|
}
|
|
resolved, err := service.ResolveProviderCommand(context.Background(), agentprovider.OpenCode)
|
|
if err != nil {
|
|
t.Fatalf("ResolveProviderCommand() error = %v", err)
|
|
}
|
|
if !reflect.DeepEqual(resolved.Command, []string{managedBinary, "acp"}) {
|
|
t.Fatalf("Command = %#v, want managed package binary", resolved.Command)
|
|
}
|
|
}
|
|
|
|
func TestResolveStaticGenericProviderDoesNotRewriteClaudeSDKSidecar(t *testing.T) {
|
|
specs, err := DefaultRegistry().Select([]string{agentprovider.ClaudeCode})
|
|
if err != nil || len(specs) != 1 {
|
|
t.Fatalf("Select(claude-code) = %#v, %v", specs, err)
|
|
}
|
|
spec := specs[0]
|
|
spec.AdapterCommand = []string{"node", "--experimental-strip-types", "sidecar.ts"}
|
|
service := Service{
|
|
LookPath: func(string) (string, error) { return "/usr/local/bin/claude", nil },
|
|
IsExecutableFile: func(string) bool { return true },
|
|
}
|
|
resolved := service.resolveStaticProviderSpec(context.Background(), spec, false)
|
|
if !reflect.DeepEqual(resolved.AdapterCommand, spec.AdapterCommand) {
|
|
t.Fatalf("AdapterCommand = %#v, want sidecar command %#v", resolved.AdapterCommand, spec.AdapterCommand)
|
|
}
|
|
}
|
|
|
|
func TestResolveStaticGenericProviderUsesSeparateAdapterBinary(t *testing.T) {
|
|
specs, err := DefaultRegistry().Select([]string{providerregistry.NexightProviderID})
|
|
if err != nil || len(specs) != 1 {
|
|
t.Fatalf("Select(nexight) = %#v, %v", specs, err)
|
|
}
|
|
spec := specs[0]
|
|
service := Service{
|
|
LookPath: func(name string) (string, error) {
|
|
return filepath.Join(t.TempDir(), name), nil
|
|
},
|
|
IsExecutableFile: func(string) bool { return true },
|
|
}
|
|
resolved := service.resolveStaticProviderSpec(context.Background(), spec, false)
|
|
got := filepath.Base(resolved.AdapterCommand[0])
|
|
got = strings.TrimSuffix(got, filepath.Ext(got))
|
|
if !strings.EqualFold(got, spec.AdapterBinaryNames[0]) {
|
|
t.Fatalf("AdapterCommand[0] = %q, want resolved %q adapter", resolved.AdapterCommand[0], spec.AdapterBinaryNames[0])
|
|
}
|
|
}
|
|
|
|
func TestCodexStatusSpecComesFromProviderDescriptor(t *testing.T) {
|
|
specs, err := DefaultRegistry().Select([]string{agentprovider.Codex})
|
|
if err != nil {
|
|
t.Fatalf("Select(codex) error = %v", err)
|
|
}
|
|
if len(specs) != 1 {
|
|
t.Fatalf("len(specs) = %d", len(specs))
|
|
}
|
|
spec := specs[0]
|
|
if !reflect.DeepEqual(spec.AdapterCommand, []string{"codex", "app-server"}) {
|
|
t.Fatalf("AdapterCommand = %#v", spec.AdapterCommand)
|
|
}
|
|
if !reflect.DeepEqual(spec.AuthStatusCommand, []string{"-c", `service_tier="fast"`, "app-server"}) ||
|
|
spec.AuthCommandRunnerKind != providerregistry.AuthCommandRunnerKindCodexAppServerAccount ||
|
|
spec.AuthStatusCommandTimeout != 10*time.Second {
|
|
t.Fatalf("Codex auth status command = %#v, runner = %q, timeout = %s", spec.AuthStatusCommand, spec.AuthCommandRunnerKind, spec.AuthStatusCommandTimeout)
|
|
}
|
|
if spec.Install.Kind != InstallerKindCodexCLILatest || spec.Install.CodexCLI == nil {
|
|
t.Fatalf("Install = %#v", spec.Install)
|
|
}
|
|
if spec.MinVersion != providerregistry.CodexMinVersion || spec.NPMRegistryPackage != "@openai/codex" {
|
|
t.Fatalf("status registration = %#v", spec)
|
|
}
|
|
if spec.Install.CodexCLI.PackageName != "@openai/codex" || spec.Install.CodexCLI.BinaryName != "codex" || !spec.Install.CodexCLI.IncludeOptional {
|
|
t.Fatalf("codex installer registration = %#v", spec.Install.CodexCLI)
|
|
}
|
|
if spec.Update.Capability != UpdateCapabilitySupported || spec.Update.Source != UpdateSourceNPM ||
|
|
spec.Update.Strategy != ProviderUpdateStrategyManagedNPM || spec.Update.PackageName != "@openai/codex" ||
|
|
spec.Update.BinaryName != "codex" || !spec.Update.IncludeOptional {
|
|
t.Fatalf("codex update registration = %#v", spec.Update)
|
|
}
|
|
}
|
|
|
|
func TestClaudeCodeStatusSpecComesFromProviderDescriptor(t *testing.T) {
|
|
specs, err := DefaultRegistry().Select([]string{agentprovider.ClaudeCode})
|
|
if err != nil || len(specs) != 1 {
|
|
t.Fatalf("Select(claude-code) = %#v, %v", specs, err)
|
|
}
|
|
spec := specs[0]
|
|
if spec.Kind != providerregistry.StatusKindClaudeCLI ||
|
|
spec.AuthStatusCommandTimeout != 10*time.Minute {
|
|
t.Fatalf("claude status registration = %#v", spec)
|
|
}
|
|
if spec.Install.Kind != InstallerKindOfficialScript ||
|
|
spec.Install.ScriptURL != "https://claude.ai/install.sh" ||
|
|
spec.Install.ScriptShell != "bash" ||
|
|
spec.Install.WindowsFallback != providerregistry.InstallerWindowsFallbackManagedRuntime {
|
|
t.Fatalf("claude installer = %#v", spec.Install)
|
|
}
|
|
}
|
|
|
|
func TestTuttiAgentStatusSpecComesFromProviderDescriptor(t *testing.T) {
|
|
specs, err := DefaultRegistry().Select([]string{agentprovider.TuttiAgent})
|
|
if err != nil || len(specs) != 1 {
|
|
t.Fatalf("Select(tutti-agent) = %#v, %v", specs, err)
|
|
}
|
|
if specs[0].MinVersion != providerregistry.TuttiAgentMinVersion {
|
|
t.Fatalf("MinVersion = %q, want %q", specs[0].MinVersion, providerregistry.TuttiAgentMinVersion)
|
|
}
|
|
}
|
|
|
|
func TestProviderStatusAdapterConsumesDescriptorInstallerData(t *testing.T) {
|
|
descriptor, ok := providerregistry.Find(providerregistry.CodexProviderID)
|
|
if !ok {
|
|
t.Fatal("codex descriptor missing")
|
|
}
|
|
descriptor.Status.MinVersion = "9.9.9"
|
|
descriptor.Status.NPMRegistryPackage = "@poison/codex"
|
|
descriptor.Status.Install.PackageName = "@poison/codex"
|
|
descriptor.Status.Install.BinaryName = "poison-codex"
|
|
descriptor.Status.Install.IncludeOptional = false
|
|
descriptor.Status.Update.PackageName = "@poison/codex"
|
|
descriptor.Status.Update.BinaryName = "poison-codex"
|
|
descriptor.Status.Update.IncludeOptional = false
|
|
|
|
spec, err := providerSpecFromDescriptor(descriptor)
|
|
if err != nil {
|
|
t.Fatalf("providerSpecFromDescriptor() error = %v", err)
|
|
}
|
|
if spec.MinVersion != "9.9.9" || spec.NPMRegistryPackage != "@poison/codex" {
|
|
t.Fatalf("status descriptor values = %#v", spec)
|
|
}
|
|
if spec.Install.CodexCLI == nil || spec.Install.CodexCLI.PackageName != "@poison/codex" ||
|
|
spec.Install.CodexCLI.BinaryName != "poison-codex" || spec.Install.CodexCLI.IncludeOptional {
|
|
t.Fatalf("installer descriptor values = %#v", spec.Install.CodexCLI)
|
|
}
|
|
if spec.Update.PackageName != "@poison/codex" || spec.Update.BinaryName != "poison-codex" || spec.Update.IncludeOptional {
|
|
t.Fatalf("update descriptor values = %#v", spec.Update)
|
|
}
|
|
}
|
|
|
|
func TestOpenCodeStatusSpecComesFromProviderDescriptor(t *testing.T) {
|
|
specs, err := DefaultRegistry().Select([]string{agentprovider.OpenCode})
|
|
if err != nil {
|
|
t.Fatalf("Select(opencode) error = %v", err)
|
|
}
|
|
if len(specs) != 1 {
|
|
t.Fatalf("len(specs) = %d", len(specs))
|
|
}
|
|
spec := specs[0]
|
|
if !reflect.DeepEqual(spec.AdapterCommand, []string{"opencode", "acp"}) ||
|
|
!reflect.DeepEqual(spec.AuthStatusCommand, []string{"auth", "list"}) {
|
|
t.Fatalf("status commands = %#v %#v", spec.AdapterCommand, spec.AuthStatusCommand)
|
|
}
|
|
if spec.AuthMarkerParserKind != providerregistry.AuthMarkerParserKindOpenCode {
|
|
t.Fatalf("AuthMarkerParserKind = %q, want opencode", spec.AuthMarkerParserKind)
|
|
}
|
|
if spec.Install.Kind != InstallerKindOfficialScript ||
|
|
spec.Install.ScriptURL != "https://opencode.ai/install" ||
|
|
spec.Install.ScriptShell != "bash" ||
|
|
spec.Install.WindowsFallback != providerregistry.InstallerWindowsFallbackManagedNPM ||
|
|
spec.Install.ManagedNPM == nil ||
|
|
spec.Install.ManagedNPM.PackageName != "opencode-ai" ||
|
|
spec.Install.ManagedNPM.BinaryName != "opencode" {
|
|
t.Fatalf("Install = %#v", spec.Install)
|
|
}
|
|
}
|
|
|
|
func TestOpenCodeStatusAdapterConsumesDescriptorInstallerData(t *testing.T) {
|
|
descriptor, ok := providerregistry.Find(providerregistry.OpenCodeProviderID)
|
|
if !ok {
|
|
t.Fatal("opencode descriptor missing")
|
|
}
|
|
descriptor.Runtime.Command = []string{"poison-opencode", "descriptor-acp"}
|
|
descriptor.Status.Install.DisplayCommand = "descriptor install"
|
|
descriptor.Status.Install.ScriptURL = "https://example.invalid/install"
|
|
descriptor.Status.Install.ScriptShell = "zsh"
|
|
|
|
spec, err := providerSpecFromDescriptor(descriptor)
|
|
if err != nil {
|
|
t.Fatalf("providerSpecFromDescriptor() error = %v", err)
|
|
}
|
|
if !reflect.DeepEqual(spec.AdapterCommand, descriptor.Runtime.Command) ||
|
|
spec.Install.DisplayCommand != "descriptor install" ||
|
|
spec.Install.ScriptURL != "https://example.invalid/install" ||
|
|
spec.Install.ScriptShell != "zsh" {
|
|
t.Fatalf("status descriptor values = %#v", spec)
|
|
}
|
|
}
|
|
|
|
func TestOpenCodeStatusHelpersDispatchFromDescriptorStrategy(t *testing.T) {
|
|
descriptor, ok := providerregistry.Find(providerregistry.OpenCodeProviderID)
|
|
if !ok {
|
|
t.Fatal("opencode descriptor missing")
|
|
}
|
|
if got := providerCustomConfigEnvVars("open-code"); !reflect.DeepEqual(got, descriptor.Status.CustomConfigEnvVars) {
|
|
t.Fatalf("custom config env vars = %#v, want %#v", got, descriptor.Status.CustomConfigEnvVars)
|
|
}
|
|
auth, ok := providerstatus.ParseAuthStatusOutput(
|
|
descriptor.Status.AuthOutputParserKind,
|
|
[]byte("Not authenticated. Run opencode auth login."),
|
|
)
|
|
if !ok || auth.Status != AuthRequired {
|
|
t.Fatalf("ParseAuthStatusOutput() = %#v, %v", auth, ok)
|
|
}
|
|
}
|
|
|
|
func TestAuthStrategiesProjectFromProviderDescriptor(t *testing.T) {
|
|
for _, provider := range []string{
|
|
providerregistry.CodexProviderID,
|
|
providerregistry.ClaudeCodeProviderID,
|
|
providerregistry.CursorProviderID,
|
|
providerregistry.OpenCodeProviderID,
|
|
providerregistry.TuttiAgentProviderID,
|
|
} {
|
|
descriptor, ok := providerregistry.Find(provider)
|
|
if !ok {
|
|
t.Fatalf("provider %q descriptor missing", provider)
|
|
}
|
|
spec, err := providerSpecFromDescriptor(descriptor)
|
|
if err != nil {
|
|
t.Fatalf("providerSpecFromDescriptor(%q) error = %v", provider, err)
|
|
}
|
|
if spec.AuthOutputParserKind != descriptor.Status.AuthOutputParserKind || spec.AuthMarkerParserKind != descriptor.Status.AuthMarkerParserKind || spec.AuthCommandRunnerKind != descriptor.Status.AuthCommandRunnerKind || spec.StaticSpecResolverKind != descriptor.Status.StaticSpecResolverKind {
|
|
t.Fatalf("provider %q auth strategies = %#v, want %#v", provider, spec, descriptor.Status)
|
|
}
|
|
if spec.RemoteAuthProbe.Kind != descriptor.Status.RemoteAuthProbe.Kind ||
|
|
spec.RemoteAuthProbe.CredentialKind != descriptor.Status.RemoteAuthProbe.CredentialKind ||
|
|
spec.RemoteAuthProbe.Endpoint != descriptor.Status.RemoteAuthProbe.Endpoint {
|
|
t.Fatalf("provider %q remote auth probe = %#v, want %#v", provider, spec.RemoteAuthProbe, descriptor.Status.RemoteAuthProbe)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestProviderStatusAdapterRejectsUnknownInstallerKind(t *testing.T) {
|
|
descriptor, ok := providerregistry.Find(providerregistry.CodexProviderID)
|
|
if !ok {
|
|
t.Fatal("codex descriptor missing")
|
|
}
|
|
descriptor.Status.Install.Kind = providerregistry.InstallerKind("poison")
|
|
if _, err := providerSpecFromDescriptor(descriptor); err == nil {
|
|
t.Fatal("providerSpecFromDescriptor() error = nil, want unsupported installer kind")
|
|
}
|
|
}
|