docs: crear issues 0036-0041 — nuevas features del sistema
Issues planificados: - 0036: Claude Code streaming de progreso en Matrix - 0037: Agente que crea otros agentes/bots via Matrix - 0038: Webapps y dashboards embebidos en Element via widgets - 0039: Recordatorios dinámicos y crons que invocan agentes - 0040: Soporte para mensajes de voz (audio → STT) - 0041: Videollamadas con agentes via LiveKit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package agents
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestAgentStopAndDone verifies that Stop() cancels Run and Done() closes.
|
||||
// Uses a minimal Agent (no Matrix, no LLM) via direct struct init so the test
|
||||
// doesn't require network or external dependencies.
|
||||
func TestAgentStopAndDone(t *testing.T) {
|
||||
a := &Agent{
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
|
||||
// Simulate Run: create the cancel, then immediately block on ctx.
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
a.cancel = cancel
|
||||
|
||||
started := make(chan struct{})
|
||||
go func() {
|
||||
close(started)
|
||||
// Mimic what Run does: block on ctx, then close done.
|
||||
<-ctx.Done()
|
||||
close(a.done)
|
||||
}()
|
||||
|
||||
<-started
|
||||
|
||||
// Stop must unblock the goroutine above.
|
||||
a.Stop()
|
||||
|
||||
select {
|
||||
case <-a.Done():
|
||||
// ok
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("Done() did not close within 2s after Stop()")
|
||||
}
|
||||
}
|
||||
|
||||
// TestAgentStopIdempotent verifies that calling Stop() multiple times is safe.
|
||||
func TestAgentStopIdempotent(t *testing.T) {
|
||||
a := &Agent{
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
_, cancel := context.WithCancel(context.Background())
|
||||
a.cancel = cancel
|
||||
defer cancel()
|
||||
|
||||
// Should not panic when called multiple times.
|
||||
a.Stop()
|
||||
a.Stop()
|
||||
a.Stop()
|
||||
}
|
||||
|
||||
// TestAgentStopNilCancel verifies Stop() is safe when cancel is nil.
|
||||
func TestAgentStopNilCancel(t *testing.T) {
|
||||
a := &Agent{
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
// cancel is nil — must not panic.
|
||||
a.Stop()
|
||||
}
|
||||
Reference in New Issue
Block a user