Files
tutti/services/tuttid/service/agentstatus/provider_resolution_managed_runtime_test.go
agent-radar 2ed3415fb7
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
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

76 lines
2.3 KiB
Go

package agentstatus
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"github.com/tutti-os/tutti/services/tuttid/service/managedruntime"
)
func TestResolvedExistingManagedNodeRuntimeRejectsBrokenCorepack(t *testing.T) {
root := fakeManagedRuntimeRoot(t)
writeExecutable(
t,
filepath.Join(root, "node", "bin", corepackBinaryNameForTest()),
"#!/bin/sh\nexit 0\n",
)
if runtime, ok := resolvedExistingManagedNodeRuntime(root, func() []string {
return []string{"PATH=/usr/bin:/bin"}
}); ok {
t.Fatalf("resolvedExistingManagedNodeRuntime() = %#v, want incompatible cache rejected", runtime)
}
}
func TestResolveManagedNodeRuntimeForProviderDoesNotUseBrokenOptionalCache(t *testing.T) {
root := fakeManagedRuntimeRoot(t)
writeExecutable(
t,
filepath.Join(root, "node", "bin", corepackBinaryNameForTest()),
"#!/bin/sh\nexit 0\n",
)
service := Service{
Environ: func() []string {
return []string{"PATH=/usr/bin:/bin"}
},
ManagedRuntime: managedruntime.DefaultResolver{RuntimeRoot: root},
}
if runtime, ok := service.resolveManagedNodeRuntimeForProvider(context.Background(), false); ok {
t.Fatalf("resolveManagedNodeRuntimeForProvider() = %#v, want incompatible optional cache skipped", runtime)
}
}
func TestResolvedExistingManagedNodeRuntimeAcceptsCompatibleCorepack(t *testing.T) {
root := fakeManagedRuntimeRoot(t)
runtime, ok := resolvedExistingManagedNodeRuntime(root, func() []string {
return []string{"PATH=/usr/bin:/bin"}
})
if !ok {
t.Fatal("resolvedExistingManagedNodeRuntime() rejected compatible cache")
}
wantNode := filepath.Join(root, "node", "bin", nodeBinaryNameForTest())
if runtime.Node != wantNode {
t.Fatalf("Node = %q, want %q", runtime.Node, wantNode)
}
}
func TestResolvedExistingManagedNodeRuntimeInheritsProcessPath(t *testing.T) {
root := fakeManagedRuntimeRoot(t)
inheritedPath := strings.Join([]string{t.TempDir(), t.TempDir()}, string(os.PathListSeparator))
t.Setenv("PATH", inheritedPath)
resolved, ok := resolvedExistingManagedNodeRuntime(root, nil)
if !ok {
t.Fatal("resolvedExistingManagedNodeRuntime() rejected compatible cache")
}
wantPath := filepath.Join(root, "node", "bin") + string(os.PathListSeparator) + inheritedPath
if got := managedruntime.EnvValue(resolved.EnvOverrides, "PATH"); got != wantPath {
t.Fatalf("PATH = %q, want %q", got, wantPath)
}
}