Files
tutti/services/tuttid/service/agent/composer_capabilities_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

123 lines
5.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package agent
import (
"context"
"path/filepath"
"reflect"
"testing"
)
// TestServiceResolveExtensionSkillRootsPicksWorkspaceScope 确认 service 只取
// extension composer profile 里 workspace scope 的 skill root 路径填入
// PrepareInput.ExtensionSkillRoots,user scope 不物化(per-session prepare 不该
// 每次重写用户级目录)。
func TestServiceResolveExtensionSkillRootsPicksWorkspaceScope(t *testing.T) {
service := newTestService(newFakeRuntime())
service.ExtensionComposerProfiles = extensionComposerProfileResolverStub{profile: ExtensionComposerProfile{
Skills: &ExtensionComposerSkillProfile{
Invocation: "textTrigger",
TriggerPrefix: "/",
Roots: []ExtensionComposerSkillRoot{
{Scope: "workspace", Path: ".agent_context/skills"},
{Scope: "workspace", Path: ".agent_context/../.agent_context/other-skills"},
{Scope: "workspace", Path: "../outside"},
{Scope: "workspace", Path: "."},
{Scope: "workspace", Path: filepath.Join(t.TempDir(), "skills")},
{Scope: "user", Path: ".agents/skills"},
},
},
}}
ref := map[string]any{
"kind": "agent_extension",
"extensionInstallationId": "hermes@1.0.0",
}
roots := service.resolveExtensionSkillRoots(context.Background(), ref)
if want := []string{".agent_context/skills", ".agent_context/other-skills"}; !reflect.DeepEqual(roots, want) {
t.Fatalf("resolveExtensionSkillRoots() = %#v, want %#v (workspace scope only)", roots, want)
}
}
// TestServiceResolveExtensionSkillRootsEmptyWhenNoSkills 确认非 extension
// provider 或 profile 无 skills 时返回空,不物化 skill。
func TestServiceResolveExtensionSkillRootsEmptyWhenNoSkills(t *testing.T) {
service := newTestService(newFakeRuntime())
service.ExtensionComposerProfiles = extensionComposerProfileResolverStub{profile: ExtensionComposerProfile{}}
if roots := service.resolveExtensionSkillRoots(context.Background(), map[string]any{"kind": "builtin"}); len(roots) != 0 {
t.Fatalf("non-extension roots = %#v, want empty", roots)
}
ref := map[string]any{"kind": "agent_extension", "extensionInstallationId": "hermes@1.0.0"}
if roots := service.resolveExtensionSkillRoots(context.Background(), ref); len(roots) != 0 {
t.Fatalf("no-skills roots = %#v, want empty", roots)
}
}
func TestServiceClampExtensionBrowserUseRequiresDeclaredCapability(t *testing.T) {
t.Setenv("TUTTI_BROWSER_USE", "1")
truePtr := true
ref := map[string]any{"kind": "agent_extension", "extensionInstallationId": "hermes@1.0.0"}
service := newTestService(newFakeRuntime())
service.ExtensionComposerProfiles = extensionComposerProfileResolverStub{profile: ExtensionComposerProfile{
Capabilities: []string{"compact"},
}}
if service.clampComposerBrowserUseForLaunch(context.Background(), "acp:hermes", ref, &truePtr) {
t.Fatal("extension without browserUse declaration should clamp browserUse off")
}
service.ExtensionComposerProfiles = extensionComposerProfileResolverStub{profile: ExtensionComposerProfile{
Capabilities: []string{"browserUse"},
}}
if !service.clampComposerBrowserUseForLaunch(context.Background(), "acp:hermes", ref, nil) {
t.Fatal("extension with browserUse declaration should default browserUse on")
}
t.Setenv("TUTTI_BROWSER_USE", "0")
if service.clampComposerBrowserUseForLaunch(context.Background(), "acp:hermes", ref, &truePtr) {
t.Fatal("operator browserUse master switch should clamp extension browserUse off")
}
}
func TestServiceClampExtensionComputerUseRequiresDeclaredCapability(t *testing.T) {
t.Setenv("TUTTI_COMPUTER_USE", "1")
truePtr := true
ref := map[string]any{"kind": "agent_extension", "extensionInstallationId": "hermes@1.0.0"}
service := newTestService(newFakeRuntime())
service.ComputerUseAvailable = func() bool { return true }
service.ExtensionComposerProfiles = extensionComposerProfileResolverStub{profile: ExtensionComposerProfile{
Capabilities: []string{"browserUse"},
}}
if service.clampComposerComputerUseForLaunch(context.Background(), "acp:hermes", ref, &truePtr) {
t.Fatal("extension without computerUse declaration should clamp computerUse off")
}
service.ExtensionComposerProfiles = extensionComposerProfileResolverStub{profile: ExtensionComposerProfile{
Capabilities: []string{"computerUse"},
}}
if !service.clampComposerComputerUseForLaunch(context.Background(), "acp:hermes", ref, nil) {
t.Fatal("extension with computerUse declaration should default computerUse on")
}
service.ComputerUseAvailable = func() bool { return false }
if service.clampComposerComputerUseForLaunch(context.Background(), "acp:hermes", ref, &truePtr) {
t.Fatal("unavailable computerUse runtime should clamp extension computerUse off")
}
}
func TestServiceClampBuiltinComputerUseRequiresHostAvailability(t *testing.T) {
t.Setenv("TUTTI_COMPUTER_USE", "1")
truePtr := true
service := newTestService(newFakeRuntime())
service.ComputerUseAvailable = func() bool { return false }
if service.clampComposerComputerUseForLaunch(context.Background(), "codex", nil, &truePtr) {
t.Fatal("unavailable built-in computerUse should clamp off")
}
}
func TestEffectiveCapabilitySettingPersistsOnlyClampedDefaults(t *testing.T) {
truePtr := true
if got := effectiveCapabilitySetting(nil, true); got != nil {
t.Fatalf("available nil default = %#v, want nil", got)
}
if got := effectiveCapabilitySetting(nil, false); got == nil || *got {
t.Fatalf("unavailable nil default = %#v, want explicit false", got)
}
if got := effectiveCapabilitySetting(&truePtr, false); got == nil || *got {
t.Fatalf("clamped explicit true = %#v, want explicit false", got)
}
}