封堵鉴权旁路与导出 IDOR,DocGov 改服务端身份;对话层 PendingAction 接真实 docgov/taskrun;修复流式租约假死与会话级任务流;加固配置/doc_id/NULL;补齐 slog 与测试;前端 ErrorBoundary 与受控文档重试。 Co-authored-by: Cursor <cursoragent@cursor.com>
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package taskrun
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"chat-agent-system/internal/bizdev"
|
|
)
|
|
|
|
func TestManager_EvictStaleRuns(t *testing.T) {
|
|
m := &Manager{runs: make(map[string]*activeRun)}
|
|
stale := &activeRun{
|
|
record: &RunRecord{
|
|
RunID: "run_stale",
|
|
Status: "completed",
|
|
UpdatedAt: time.Now().Add(-2 * time.Hour),
|
|
},
|
|
done: make(chan struct{}),
|
|
}
|
|
fresh := &activeRun{
|
|
record: &RunRecord{
|
|
RunID: "run_fresh",
|
|
Status: "completed",
|
|
UpdatedAt: time.Now(),
|
|
},
|
|
done: make(chan struct{}),
|
|
}
|
|
m.runs["run_stale"] = stale
|
|
m.runs["run_fresh"] = fresh
|
|
|
|
m.evictStaleRuns()
|
|
|
|
if _, ok := m.runs["run_stale"]; ok {
|
|
t.Fatal("expected stale run to be evicted")
|
|
}
|
|
if _, ok := m.runs["run_fresh"]; !ok {
|
|
t.Fatal("expected fresh run to remain")
|
|
}
|
|
}
|
|
|
|
func TestManager_CancelUnknownRun(t *testing.T) {
|
|
m := NewManager(nil, nil)
|
|
if err := m.Cancel("missing"); err == nil {
|
|
t.Fatal("expected error for unknown run")
|
|
}
|
|
}
|
|
|
|
func TestManager_CreateAndStartWithoutExecutorFails(t *testing.T) {
|
|
m := NewManager(nil, nil)
|
|
ctx := context.Background()
|
|
rec := &RunRecord{RunID: "run_test", Status: "running"}
|
|
_, err := m.CreateAndStart(ctx, "run_test", rec, bizdev.TaskRunRequest{}, bizdev.StageRunRequest{}, "")
|
|
if err != nil {
|
|
t.Fatalf("CreateAndStart returned error: %v", err)
|
|
}
|
|
|
|
deadline := time.After(3 * time.Second)
|
|
for {
|
|
got, getErr := m.GetRun("run_test")
|
|
if getErr == nil && got.Status == "failed" {
|
|
return
|
|
}
|
|
select {
|
|
case <-deadline:
|
|
t.Fatalf("timed out waiting for failed status, last=%+v err=%v", got, getErr)
|
|
case <-time.After(50 * time.Millisecond):
|
|
}
|
|
}
|
|
}
|