micro--go-micro
c7657f73f4
goreleaser / goreleaser (push) Has been cancelled
* test(harness): read agent plan from the scoped store
The store-scoping change moved an agent's plan from the default table
key agent/{name}/plan to its own table (database "agent", table {name},
key "plan"). The plan-delegate harness tests still read the old key and
failed with 'not found'; read through store.Scope(mem, "agent", name)
like the agent does.
* docs: orient agents-first across README, landing, and docs overview
Lead with agents (then services and flows), surface MCP + A2A as the
interop story, and frame agents as services. Landing hero and feature
grid reordered agents-first with an A2A gateway card.
* v6: module path go-micro.dev/v6, TLS secure by default, NewService
Cut v6. Three breaking changes, bundled so the major bump is paid once:
- Module path go-micro.dev/v5 -> go-micro.dev/v6 across all imports + go.mod.
- TLS verification on by default (was off). MICRO_TLS_SECURE removed;
MICRO_TLS_INSECURE=true opts out for self-signed/dev.
- micro.NewService(name, opts...) is the canonical service constructor,
symmetric with NewAgent/NewFlow; micro.New kept as a deprecated alias;
the old name-less NewService(opts...) removed. Generators emit NewService.
Also ports the JWT auth token provider in-module (go-micro.dev/v6/auth/jwt/token
on golang-jwt/jwt/v5), dropping the v5-pinned github.com/micro/plugins/v5/auth/jwt
and the deprecated dgrijalva/jwt-go.
Docs/README/landing updated to v6 and @latest; v5->v6 migration guide added;
CHANGELOG cut as [6.0.0]. Blog posts left at their historical versions.
---------
Co-authored-by: Claude <noreply@anthropic.com>
93 行
2.8 KiB
Go
93 行
2.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"go-micro.dev/v6/ai"
|
|
"go-micro.dev/v6/registry"
|
|
"go-micro.dev/v6/store"
|
|
)
|
|
|
|
// toolContent runs a tool call through a handler and returns the content
|
|
// shown to the model — the part these tests assert on.
|
|
func toolContent(h ai.ToolHandler, name string, input map[string]any) string {
|
|
return h(context.Background(), ai.ToolCall{Name: name, Input: input}).Content
|
|
}
|
|
|
|
// MaxSteps refuses tool calls once the per-Ask limit is exceeded; plan
|
|
// is bookkeeping and is never counted.
|
|
func TestMaxStepsStopsActions(t *testing.T) {
|
|
a := newTestAgent(Name("limited"), MaxSteps(2))
|
|
|
|
h := a.toolHandler()
|
|
|
|
// plan must not consume a step.
|
|
a.steps = 0
|
|
toolContent(h, toolPlan, map[string]any{"steps": []any{}})
|
|
if a.steps != 0 {
|
|
t.Fatalf("plan consumed a step: steps=%d", a.steps)
|
|
}
|
|
|
|
// First two actions are allowed (they fall through to RPC, which
|
|
// fails harmlessly — we only care they weren't refused by the limit).
|
|
for i := 1; i <= 2; i++ {
|
|
content := toolContent(h, "demo_Svc_Do", map[string]any{})
|
|
if strings.Contains(content, "step limit") {
|
|
t.Fatalf("action %d wrongly hit the step limit", i)
|
|
}
|
|
}
|
|
|
|
// Third action exceeds MaxSteps(2) and must be refused.
|
|
content := toolContent(h, "demo_Svc_Do", map[string]any{})
|
|
if !strings.Contains(content, "step limit") {
|
|
t.Errorf("third action should hit the step limit; got %q", content)
|
|
}
|
|
}
|
|
|
|
// ApproveTool blocks an action when the hook denies it, and the denial
|
|
// reason is surfaced to the model.
|
|
func TestApproveToolBlocks(t *testing.T) {
|
|
var sawTool string
|
|
a := newTestAgent(Name("gated"),
|
|
ApproveTool(func(tool string, input map[string]any) (bool, string) {
|
|
sawTool = tool
|
|
return false, "needs sign-off"
|
|
}),
|
|
)
|
|
|
|
content := toolContent(a.toolHandler(), "demo_Svc_Do", map[string]any{})
|
|
if sawTool != "demo_Svc_Do" {
|
|
t.Errorf("approver saw %q, want demo_Svc_Do", sawTool)
|
|
}
|
|
if !strings.Contains(content, "not approved") || !strings.Contains(content, "needs sign-off") {
|
|
t.Errorf("blocked call should surface the reason; got %q", content)
|
|
}
|
|
}
|
|
|
|
// A denying approver must not gate the internal plan tool.
|
|
func TestApproveToolDoesNotGatePlan(t *testing.T) {
|
|
mem := store.NewMemoryStore()
|
|
a := New(
|
|
Name("gated"),
|
|
Provider("fake"),
|
|
WithRegistry(registry.NewMemoryRegistry()),
|
|
WithStore(mem),
|
|
ApproveTool(func(tool string, input map[string]any) (bool, string) {
|
|
return false, "deny everything"
|
|
}),
|
|
).(*agentImpl)
|
|
a.setup()
|
|
|
|
content := toolContent(a.toolHandler(), toolPlan, map[string]any{
|
|
"steps": []any{map[string]any{"task": "x", "status": "pending"}},
|
|
})
|
|
if strings.Contains(content, "not approved") {
|
|
t.Errorf("plan must not be gated by ApproveTool; got %q", content)
|
|
}
|
|
if recs, _ := store.Scope(mem, "agent", "gated").Read(planKey); len(recs) == 0 {
|
|
t.Error("plan should have been persisted despite the denying approver")
|
|
}
|
|
}
|