Files
yhh 12b5ba6279 refactor(usecap): the use_capability proxy leaves the agent package
UseCapabilityTool, the MCP capability runtime, on-demand connects,
capability listing and search, and the argument-contract reading they
share move from internal/runtime/agent to internal/runtime/usecap. They
were already their own types rather than agent methods, and they need
nothing from the agent. usecap depends on the agent not at all; the
agent imports it.

- The two MCP checks both sides make are now tool.HasMCPDestructiveHint
  and tool.IsMCPServerAuthorized. They live in contract/tool/mcp_server.go
  beside the interfaces they read.
- The agent's call-contract gate and the proxy's hints share
  usecap.ReadArgumentContract, with its Hint and Broken.
- FilterCapabilityListResult, FilterCapabilitySearchResult,
  ParseMCPServerCapabilityID and WithContractHint are exported for the
  child registry and the dispatch path.

The integration tests that drive a real agent through the proxy stay in
agent. The runtime's own tests move to usecap. Tests that check the
proxy's judgements against agent or delegation types run as usecap_test
through export_test.go. No test was added or removed.

Baseline: usecapability.go carries its debt unchanged under the new path,
and delegation/task.go and control/controller.go each gain one import
line (-allow-widen).
2026-09-24 00:51:59 -07:00

31 lines
1014 B
Go

package usecap
import (
"strings"
"testing"
"unicode/utf8"
)
func TestALeadIsPickableAndWhole(t *testing.T) {
long := "Dispatch 2-64 sub-agent tasks as a small dependency graph. Each item may select a profile, model, effort, tools, write_paths, or read_only."
lead := capabilityLead(long)
if lead != "Dispatch 2-64 sub-agent tasks as a small dependency graph." {
t.Fatalf("lead = %q, want the first sentence", lead)
}
// No sentence break: bounded on a word, and never mid-character.
cjk := strings.Repeat("在隔离的子代理里探索代码库", 30)
got := capabilityLead(cjk)
if len(got) > capabilityLeadBytes+4 {
t.Fatalf("lead is %d bytes, over the bound", len(got))
}
if !utf8.ValidString(got) {
t.Fatalf("lead cut a character in half: %q", got)
}
if capabilityLead("") != "" || capabilityLead(" ") != "" {
t.Fatal("an absent description became text")
}
if got := capabilityLead("Short one."); got != "Short one." {
t.Fatalf("a short description was rewritten: %q", got)
}
}