mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-16 06:16:55 +00:00
- Add enrich_auto_linking.go: deterministic auto-link logic for task/delegation contexts - Add team_task_siblings.go (PG + SQLite): find all tasks in same delegation for batch link - Update enrich_worker.go: call enrich_auto_linking Phase 2 hook + skip re-embed for binary - Update team_store.go: add TaskSiblings interface method + TeamStore binding - Add context_keys.go + test: define ContextDelegationIDKey + ContextTaskIDKey for propagation - Update vault_interceptor.go: extract + inject delegation ID from request - Update run_context.go: propagate DelegationID from request - Update loop_context.go: inject DelegationID from run context - Update teams_tasks.go: DeleteTask(s) → cleanup auto-links via vault_source_cleanup - Update teams_tasks_activity.go: DetachFileFromTask → cleanup related auto-links - Update vault_documents_enrichment.go: populate summary from media_summary - Update cmd/gateway.go: wire TeamStore to handler bootstrap
134 lines
3.6 KiB
Go
134 lines
3.6 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/nextlevelbuilder/goclaw/internal/store"
|
|
)
|
|
|
|
func TestWithDelegationID_RoundTrip(t *testing.T) {
|
|
ctx := context.Background()
|
|
if got := DelegationIDFromCtx(ctx); got != "" {
|
|
t.Errorf("empty context: want empty, got %q", got)
|
|
}
|
|
|
|
ctx = WithDelegationID(ctx, "deleg-123")
|
|
if got := DelegationIDFromCtx(ctx); got != "deleg-123" {
|
|
t.Errorf("round-trip: want deleg-123, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestDelegationIDFromCtx_RunContextFallback(t *testing.T) {
|
|
// When ctxDelegationID is NOT set but RunContext has the ID,
|
|
// DelegationIDFromCtx should return the RunContext value.
|
|
ctx := context.Background()
|
|
rc := &store.RunContext{DelegationID: "from-runcontext"}
|
|
ctx = store.WithRunContext(ctx, rc)
|
|
|
|
if got := DelegationIDFromCtx(ctx); got != "from-runcontext" {
|
|
t.Errorf("fallback: want from-runcontext, got %q", got)
|
|
}
|
|
|
|
// Explicit value wins over RunContext fallback.
|
|
ctx = WithDelegationID(ctx, "explicit")
|
|
if got := DelegationIDFromCtx(ctx); got != "explicit" {
|
|
t.Errorf("explicit-wins: want explicit, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestToolContextKeys_Channel(t *testing.T) {
|
|
ctx := context.Background()
|
|
if v := ToolChannelFromCtx(ctx); v != "" {
|
|
t.Errorf("expected empty, got %q", v)
|
|
}
|
|
|
|
ctx = WithToolChannel(ctx, "telegram")
|
|
if v := ToolChannelFromCtx(ctx); v != "telegram" {
|
|
t.Errorf("expected telegram, got %q", v)
|
|
}
|
|
}
|
|
|
|
func TestToolContextKeys_ChatID(t *testing.T) {
|
|
ctx := context.Background()
|
|
if v := ToolChatIDFromCtx(ctx); v != "" {
|
|
t.Errorf("expected empty, got %q", v)
|
|
}
|
|
|
|
ctx = WithToolChatID(ctx, "chat-123")
|
|
if v := ToolChatIDFromCtx(ctx); v != "chat-123" {
|
|
t.Errorf("expected chat-123, got %q", v)
|
|
}
|
|
}
|
|
|
|
func TestToolContextKeys_PeerKind(t *testing.T) {
|
|
ctx := context.Background()
|
|
ctx = WithToolPeerKind(ctx, "group")
|
|
if v := ToolPeerKindFromCtx(ctx); v != "group" {
|
|
t.Errorf("expected group, got %q", v)
|
|
}
|
|
}
|
|
|
|
func TestToolContextKeys_SandboxKey(t *testing.T) {
|
|
ctx := context.Background()
|
|
ctx = WithToolSandboxKey(ctx, "agent:main:telegram:direct:123")
|
|
if v := ToolSandboxKeyFromCtx(ctx); v != "agent:main:telegram:direct:123" {
|
|
t.Errorf("expected sandbox key, got %q", v)
|
|
}
|
|
}
|
|
|
|
func TestToolContextKeys_AsyncCB(t *testing.T) {
|
|
ctx := context.Background()
|
|
if v := ToolAsyncCBFromCtx(ctx); v != nil {
|
|
t.Error("expected nil callback")
|
|
}
|
|
|
|
called := false
|
|
cb := AsyncCallback(func(ctx context.Context, result *Result) {
|
|
called = true
|
|
})
|
|
|
|
ctx = WithToolAsyncCB(ctx, cb)
|
|
got := ToolAsyncCBFromCtx(ctx)
|
|
if got == nil {
|
|
t.Fatal("expected non-nil callback")
|
|
}
|
|
got(ctx, nil)
|
|
if !called {
|
|
t.Error("callback was not invoked")
|
|
}
|
|
}
|
|
|
|
func TestToolContextKeys_LeaderAgentID(t *testing.T) {
|
|
ctx := context.Background()
|
|
if v := LeaderAgentIDFromCtx(ctx); v != "" {
|
|
t.Errorf("expected empty, got %q", v)
|
|
}
|
|
|
|
ctx = WithLeaderAgentID(ctx, "leader-uuid-123")
|
|
if v := LeaderAgentIDFromCtx(ctx); v != "leader-uuid-123" {
|
|
t.Errorf("expected leader-uuid-123, got %q", v)
|
|
}
|
|
}
|
|
|
|
func TestToolContextKeys_MultipleValues(t *testing.T) {
|
|
ctx := context.Background()
|
|
ctx = WithToolChannel(ctx, "slack")
|
|
ctx = WithToolChatID(ctx, "C123")
|
|
ctx = WithToolPeerKind(ctx, "direct")
|
|
ctx = WithToolSandboxKey(ctx, "sandbox-1")
|
|
|
|
if v := ToolChannelFromCtx(ctx); v != "slack" {
|
|
t.Errorf("channel: expected slack, got %q", v)
|
|
}
|
|
if v := ToolChatIDFromCtx(ctx); v != "C123" {
|
|
t.Errorf("chatID: expected C123, got %q", v)
|
|
}
|
|
if v := ToolPeerKindFromCtx(ctx); v != "direct" {
|
|
t.Errorf("peerKind: expected direct, got %q", v)
|
|
}
|
|
if v := ToolSandboxKeyFromCtx(ctx); v != "sandbox-1" {
|
|
t.Errorf("sandboxKey: expected sandbox-1, got %q", v)
|
|
}
|
|
}
|