mirror of
https://github.com/esengine/DeepSeek-Reasonix.git
synced 2026-11-07 10:45:59 -10:00
* refactor(go): adopt modern stdlib idioms across kernel and desktop Mechanical sweep with golangci-lint's modernize/intrange/copyloopvar/ usestdlibvars fixers plus hand-fixes for what they could not rewrite: slices.Contains, min/max, slices.Backward, WaitGroup.Go, reflect.TypeFor, maps.Copy, strings.Cut/CutPrefix/SplitSeq, strings.Builder, range-over-int. Net -549 lines with no behavior change. Three loops in session.go stay index-based: slices.Backward yields element copies, so the fixer's rewrite silently dropped writes to DecisionReceipts and ToolCalls (caught by TestDelivery* and TestDependentSameBatch*). All 49 slices.Backward sites were audited for that shape; only these three write through the index, and they carry a nolint with the reason. CaptureAfter's scan loop had an empty body and never ran any logic, so the fixer could not express it. Drop it and the accessor it was the only caller of. omitzero is deliberately untouched: turning omitempty into omitzero changes the JSON written for nested structs, which is a wire-format change to session files and the extension protocol. * build(lint): gate the modern-idiom linters Nothing stopped the codebase from drifting back to pre-1.22 idioms. Both modules are now clean for modernize, intrange, copyloopvar, and usestdlibvars, so enable them rather than leaving the sweep as a one-off. omitzero stays disabled with the reason inline; usetesting, perfsprint, and errorlint still have residue and land separately.
114 lines
2.8 KiB
Go
114 lines
2.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSchedulerTotalConcurrencyQueues(t *testing.T) {
|
|
s := NewSubagentScheduler(2, 2)
|
|
root := t.TempDir()
|
|
var started atomic.Int32
|
|
var max atomic.Int32
|
|
var wg sync.WaitGroup
|
|
barrier := make(chan struct{})
|
|
|
|
for range 4 {
|
|
wg.Go(func() {
|
|
release, err := s.Acquire(context.Background(), AcquireRequest{Writer: false})
|
|
if err != nil {
|
|
t.Errorf("acquire: %v", err)
|
|
return
|
|
}
|
|
cur := started.Add(1)
|
|
for {
|
|
old := max.Load()
|
|
if cur <= old || max.CompareAndSwap(old, cur) {
|
|
break
|
|
}
|
|
}
|
|
<-barrier
|
|
started.Add(-1)
|
|
release()
|
|
})
|
|
}
|
|
|
|
// Wait until at least 2 are running, then release them.
|
|
deadline := time.Now().Add(2 * time.Second)
|
|
for time.Now().Before(deadline) {
|
|
if max.Load() >= 2 {
|
|
break
|
|
}
|
|
time.Sleep(5 * time.Millisecond)
|
|
}
|
|
if got := max.Load(); got > 2 {
|
|
t.Fatalf("max concurrent = %d, want <= 2", got)
|
|
}
|
|
close(barrier)
|
|
wg.Wait()
|
|
_ = root
|
|
}
|
|
|
|
func TestSchedulerNestedFailsFast(t *testing.T) {
|
|
s := NewSubagentScheduler(1, 1)
|
|
release, err := s.Acquire(context.Background(), AcquireRequest{Writer: false})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer release()
|
|
_, err = s.Acquire(context.Background(), AcquireRequest{Writer: false, Nested: true})
|
|
if err == nil {
|
|
t.Fatal("nested acquire should fail fast at limit")
|
|
}
|
|
}
|
|
|
|
func TestSchedulerWriterPathConflictQueues(t *testing.T) {
|
|
s := NewSubagentScheduler(4, 2)
|
|
root := t.TempDir()
|
|
claim, err := NormalizeWritePaths(root, []string{"a.md"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
release, err := s.Acquire(context.Background(), AcquireRequest{Writer: true, WritePaths: claim})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
|
|
defer cancel()
|
|
// Same path cannot start while the first claim is held — with Nested it fails.
|
|
_, err = s.Acquire(ctx, AcquireRequest{Writer: true, WritePaths: claim, Nested: true})
|
|
if err == nil {
|
|
t.Fatal("expected path conflict for nested acquire")
|
|
}
|
|
release()
|
|
|
|
// After release, same path is free.
|
|
release2, err := s.Acquire(context.Background(), AcquireRequest{Writer: true, WritePaths: claim})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
release2()
|
|
}
|
|
|
|
func TestSchedulerTryClaimWritePaths(t *testing.T) {
|
|
s := NewSubagentScheduler(4, 2)
|
|
root := t.TempDir()
|
|
claim, _ := NormalizeWritePaths(root, []string{"a.md"})
|
|
release, err := s.Acquire(context.Background(), AcquireRequest{Writer: true, WritePaths: claim})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer release()
|
|
if err := s.TryClaimWritePaths(claim); err == nil {
|
|
t.Fatal("parent should see active claim")
|
|
}
|
|
other, _ := NormalizeWritePaths(root, []string{"b.md"})
|
|
if err := s.TryClaimWritePaths(other); err != nil {
|
|
t.Fatalf("disjoint claim should be free: %v", err)
|
|
}
|
|
}
|