refactor: adopt Go 1.26+ standard library modernizations

- Use maps.Copy in hooks dispatcher instead of manual map loop
- Remove implicit loop variable capture in router_abort_test (Go 1.26 semantics)
- Use range without index in http_test where index unused
- Use min() builtin in script_test instead of manual min computation
This commit is contained in:
viettranx committed 2026-04-23 19:16:08 +07:00
1 parent bb49b87810
commit b676ee1351
4 files changed
+5 -12

No files matched your search

-1
View File
@@ -138,7 +138,6 @@ func TestAbortRun_AlreadyAborting(t *testing.T) {
var wg sync.WaitGroup
wg.Add(n)
for i := range n {
i := i
go func() {
defer wg.Done()
results[i] = r.AbortRun(runID, sessionKey)
+3 -6
View File
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log/slog"
"maps"
"sync"
"sync/atomic"
"time"
@@ -276,9 +277,7 @@ func (d *stdDispatcher) runSync(ctx context.Context, ev Event, chain []HookConfi
// blocks or the chain aborts.
func cloneMap(m map[string]any) map[string]any {
out := make(map[string]any, len(m))
for k, v := range m {
out[k] = v
}
maps.Copy(out, m)
return out
}
@@ -303,9 +302,7 @@ func applyBuiltinMutation(ev *Event, updated map[string]any, allowlist []string)
if ev.ToolInput == nil {
ev.ToolInput = map[string]any{}
}
for k, v := range m {
ev.ToolInput[k] = v
}
maps.Copy(ev.ToolInput, m)
} else {
for k, v := range m {
if _, ok := allowSet["toolInput."+k]; ok {
+1 -1
View File
@@ -236,7 +236,7 @@ func TestHTTP_ResponseBodyCappedAt1MiB(t *testing.T) {
for i := range chunk {
chunk[i] = 'x'
}
for i := 0; i < 32; i++ { // 32 × 64 KiB = 2 MiB
for range 32 { // 32 × 64 KiB = 2 MiB
w.Write(chunk)
}
}))
+1 -4
View File
@@ -214,10 +214,7 @@ func TestStdoutCapTruncates(t *testing.T) {
t.Fatalf("stdout exceeded cap: %d bytes", len(res.Stdout))
}
if !strings.Contains(res.Stdout, "truncated") {
end := 200
if end > len(res.Stdout) {
end = len(res.Stdout)
}
end := min(200, len(res.Stdout))
t.Fatalf("truncation marker missing: %q", res.Stdout[:end])
}
}