fix(tools): fix cron_test build error and add TTL clone test
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
cec74fe73a
commit
88513136fd
3 changed files with 33 additions and 6 deletions
|
|
@ -226,11 +226,12 @@ func TestCronTool_ExecuteJobPublishesErrorWhenExecDisabled(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
msg, ok := tool.msgBus.SubscribeOutbound(ctx)
|
select {
|
||||||
if !ok {
|
case msg := <-tool.msgBus.OutboundChan():
|
||||||
t.Fatal("expected outbound message")
|
if !strings.Contains(msg.Content, "command execution is disabled") {
|
||||||
}
|
t.Fatalf("expected exec disabled message, got: %s", msg.Content)
|
||||||
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,7 @@ func (r *ToolRegistry) List() []string {
|
||||||
// snapshot of the parent agent's tools without sharing the same registry —
|
// snapshot of the parent agent's tools without sharing the same registry —
|
||||||
// tools registered on the parent after cloning (e.g. spawn, spawn_status)
|
// tools registered on the parent after cloning (e.g. spawn, spawn_status)
|
||||||
// will NOT be visible to the clone, preventing recursive subagent spawning.
|
// 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 {
|
func (r *ToolRegistry) Clone() *ToolRegistry {
|
||||||
r.mu.RLock()
|
r.mu.RLock()
|
||||||
defer r.mu.RUnlock()
|
defer r.mu.RUnlock()
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func TestToolRegistry_ConcurrentAccess(t *testing.T) {
|
||||||
r := NewToolRegistry()
|
r := NewToolRegistry()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue