项目文件夹

文件
Asim Aslam c7657f73f4
goreleaser / goreleaser (push) Has been cancelled
Refactor agent plan storage, update docs, and release v6 (#2977)
* 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>
2026-06-18 11:55:35 +01:00

101 行
2.9 KiB
Go

package main
import (
"testing"
"time"
"go-micro.dev/v6/agent"
"go-micro.dev/v6/ai"
"go-micro.dev/v6/broker"
"go-micro.dev/v6/client"
"go-micro.dev/v6/flow"
"go-micro.dev/v6/registry"
"go-micro.dev/v6/selector"
"go-micro.dev/v6/service"
"go-micro.dev/v6/store"
)
// TestEventTriggersAgentNoPrompt proves "the event is the prompt": a
// broker event drives a Flow that hands off to a registered agent, which
// reasons and acts through its services — workspace created, welcome
// sent — with no human prompt anywhere. Real services, registry, RPC,
// broker, agent loop, store; only the LLM is mocked. No mDNS, no sleeps
// beyond polling for the asynchronous side effect.
func TestEventTriggersAgentNoPrompt(t *testing.T) {
ai.Register("mock", newMock)
reg := registry.NewMemoryRegistry()
br := broker.NewMemoryBroker()
if err := br.Connect(); err != nil {
t.Fatalf("broker connect: %v", err)
}
cl := client.NewClient(
client.Registry(reg),
client.Selector(selector.NewSelector(selector.Registry(reg))),
)
mem := store.NewMemoryStore()
wsSvc := new(WorkspaceService)
ws := service.New(service.Name("workspace"), service.Registry(reg), service.Client(cl))
if err := ws.Handle(wsSvc); err != nil {
t.Fatalf("handle workspace: %v", err)
}
go ws.Run()
ntSvc := new(NotifyService)
nt := service.New(service.Name("notify"), service.Registry(reg), service.Client(cl))
if err := nt.Handle(ntSvc); err != nil {
t.Fatalf("handle notify: %v", err)
}
go nt.Run()
onboarder := agent.New(
agent.Name("onboarder"),
agent.Services("workspace", "notify"),
agent.Prompt("You onboard new users. Create their workspace and send a welcome message."),
agent.Provider("mock"),
agent.WithRegistry(reg), agent.WithClient(cl), agent.WithStore(mem),
)
go onboarder.Run()
defer onboarder.Stop()
waitFor(reg, "workspace")
waitFor(reg, "notify")
waitFor(reg, "onboarder")
f := flow.New("onboard",
flow.Trigger("events.user.created"),
flow.Agent("onboarder"),
flow.Prompt("A new user signed up: {{.Data}}. Get them set up."),
)
if err := f.Register(reg, br, cl); err != nil {
t.Fatalf("flow register: %v", err)
}
// The event — nobody typed a prompt.
if err := br.Publish("events.user.created", &broker.Message{
Body: []byte(`{"email":"alice@acme.com"}`),
}); err != nil {
t.Fatalf("publish: %v", err)
}
// Wait for the agent to act (delivery is asynchronous).
deadline := time.Now().Add(10 * time.Second)
for time.Now().Before(deadline) {
if wsSvc.count() >= 1 && ntSvc.count() >= 1 {
break
}
time.Sleep(20 * time.Millisecond)
}
if got := wsSvc.count(); got != 1 {
t.Errorf("workspace created %d times, want 1", got)
}
if got := ntSvc.count(); got != 1 {
t.Errorf("notify sent %d times, want 1 (event->flow->agent chain broken)", got)
}
if rs := f.Results(); len(rs) == 0 || rs[len(rs)-1].Reply == "" {
t.Errorf("flow recorded no result for the event")
}
}