From 88513136fd92224be59668fc3aae3db6094e1170 Mon Sep 17 00:00:00 2001 From: paoloanzn Date: Wed, 18 Mar 2026 13:02:16 +0100 Subject: [PATCH] fix(tools): fix cron_test build error and add TTL clone test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix cron_test.go:229 — replace non-existent SubscribeOutbound(ctx) with select on OutboundChan(), matching the MessageBus channel API - Add TestToolRegistry_Clone_PreservesTTLValue per reviewer feedback - Add version reset note to Clone() doc comment Co-Authored-By: Claude Opus 4.6 --- pkg/tools/cron_test.go | 13 +++++++------ pkg/tools/registry.go | 1 + pkg/tools/registry_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/pkg/tools/cron_test.go b/pkg/tools/cron_test.go index 09d29b6fa..b09e332ff 100644 --- a/pkg/tools/cron_test.go +++ b/pkg/tools/cron_test.go @@ -226,11 +226,12 @@ func TestCronTool_ExecuteJobPublishesErrorWhenExecDisabled(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - msg, ok := tool.msgBus.SubscribeOutbound(ctx) - if !ok { - t.Fatal("expected outbound message") - } - if !strings.Contains(msg.Content, "command execution is disabled") { - t.Fatalf("expected exec disabled message, got: %s", msg.Content) + select { + case msg := <-tool.msgBus.OutboundChan(): + if !strings.Contains(msg.Content, "command execution is disabled") { + t.Fatalf("expected exec disabled message, got: %s", msg.Content) + } + case <-ctx.Done(): + t.Fatal("timeout waiting for outbound message") } } diff --git a/pkg/tools/registry.go b/pkg/tools/registry.go index 74319d7ef..064f77ec4 100644 --- a/pkg/tools/registry.go +++ b/pkg/tools/registry.go @@ -308,6 +308,7 @@ func (r *ToolRegistry) List() []string { // snapshot of the parent agent's tools without sharing the same registry — // tools registered on the parent after cloning (e.g. spawn, spawn_status) // will NOT be visible to the clone, preventing recursive subagent spawning. +// The version counter is reset to 0 in the clone as it's a new independent registry. func (r *ToolRegistry) Clone() *ToolRegistry { r.mu.RLock() defer r.mu.RUnlock() diff --git a/pkg/tools/registry_test.go b/pkg/tools/registry_test.go index b3162ae5f..9f9890d8f 100644 --- a/pkg/tools/registry_test.go +++ b/pkg/tools/registry_test.go @@ -400,6 +400,31 @@ func TestToolRegistry_Clone_PreservesHiddenToolState(t *testing.T) { } } +func TestToolRegistry_Clone_PreservesTTLValue(t *testing.T) { + r := NewToolRegistry() + r.RegisterHidden(newMockTool("ttl_tool", "tool with TTL")) + + // Manually set a non-zero TTL on the entry + r.mu.RLock() + if entry, ok := r.tools["ttl_tool"]; ok { + entry.TTL = 5 + } + r.mu.RUnlock() + + clone := r.Clone() + + // Verify TTL value is preserved in the clone + clone.mu.RLock() + defer clone.mu.RUnlock() + entry, ok := clone.tools["ttl_tool"] + if !ok { + t.Fatal("expected ttl_tool to exist in clone") + } + if entry.TTL != 5 { + t.Errorf("expected TTL=5 in clone, got %d", entry.TTL) + } +} + func TestToolRegistry_ConcurrentAccess(t *testing.T) { r := NewToolRegistry() var wg sync.WaitGroup