Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ func TestAgent_Run_HistoryProvider_ConcurrentConflictClearIsRaceFree(t *testing.
const goroutines = 64
var wg sync.WaitGroup
wg.Add(goroutines)
for i := 0; i < goroutines; i++ {
for range goroutines {
go func() {
defer wg.Done()
// Each goroutine drives a shared *Agent with its own session, so the
Expand Down
2 changes: 1 addition & 1 deletion agent/compaction/compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func TestDefaultToolCallFormatter_DedupsRepeatedNamesWithEmptyResults(t *testing

func TestToolResultStrategy_ZeroValueUsesDefaults(t *testing.T) {
messages := make([]*message.Message, 0, 20)
for i := 0; i < 9; i++ {
for i := range 9 {
callID := "call-" + string(rune('0'+i))
messages = append(messages,
textMessage(message.RoleUser, "u"+string(rune('0'+i))),
Expand Down
4 changes: 2 additions & 2 deletions agent/compaction/contextwindow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (charCounter) CountTokens(text string) int { return len(text) }
// preceded by a user message.
func buildToolCallMessages(n int) []*message.Message {
msgs := make([]*message.Message, 0, n*4)
for i := 0; i < n; i++ {
for i := range n {
callID := "call-" + string(rune('a'+i))
msgs = append(msgs,
textMessage(message.RoleUser, "u"),
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestContextWindowStrategy_TruncatesWhenOverTruncationThreshold(t *testing.T
msgs := []*message.Message{
textMessage(message.RoleSystem, "system"),
}
for i := 0; i < 8; i++ {
for range 8 {
msgs = append(msgs,
textMessage(message.RoleUser, "uuuu"),
textMessage(message.RoleAssistant, "aaaa"),
Expand Down
7 changes: 3 additions & 4 deletions agent/compaction/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func NewMessageIndex(groups []*MessageGroup, tokenCounter TokenCounter) *Message
Groups: groups,
TokenCounter: tokenCounter,
}
for i := len(groups) - 1; i >= 0; i-- {
group := groups[i]
for _, group := range slices.Backward(groups) {
if index.lastProcessedMessage == nil && group.Kind != GroupKindSummary && len(group.Messages) > 0 {
Comment thread
qmuntal marked this conversation as resolved.
index.lastProcessedMessage = group.Messages[len(group.Messages)-1]
}
Expand Down Expand Up @@ -91,8 +90,8 @@ func (index *MessageIndex) Update(messages []*message.Message) {
messageContentEqual(messages[expected], index.lastProcessedMessage) {
foundIndex = expected
} else {
for i := len(messages) - 1; i >= 0; i-- {
if messageContentEqual(messages[i], index.lastProcessedMessage) {
for i, message := range slices.Backward(messages) {
if messageContentEqual(message, index.lastProcessedMessage) {
foundIndex = i
break
}
Expand Down
5 changes: 1 addition & 4 deletions agent/compaction/toolresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ func (strategy *ToolResultStrategy) Compact(_ context.Context, index *MessageInd
nonSystemIncludedIndices = append(nonSystemIncludedIndices, i)
}
}
protectedStart := len(nonSystemIncludedIndices) - minimumPreservedGroups
if protectedStart < 0 {
protectedStart = 0
}
protectedStart := max(len(nonSystemIncludedIndices)-minimumPreservedGroups, 0)
protectedGroupIndices := nonSystemIncludedIndices[protectedStart:]

var eligibleIndices []int
Expand Down
2 changes: 1 addition & 1 deletion agent/harness/agentmode/agentmode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestConcurrentToolInvocations_NoDataRace(t *testing.T) {
// a functional regression (e.g. argument-decode failure) fails the test
// deterministically, independent of the race detector.
errs := make([]error, n*2)
for i := 0; i < n; i++ {
for i := range n {
mode := "plan"
if i%2 == 0 {
mode = "execute"
Expand Down
2 changes: 1 addition & 1 deletion agent/harness/todo/todo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ func TestTodo_ConcurrentSessionAccess_NoDataRace(t *testing.T) {
var wg sync.WaitGroup
wg.Add(n * 2)
errs := make([]error, n*2)
for i := 0; i < n; i++ {
for i := range n {
go func(idx int) {
defer wg.Done()
_, errs[idx] = addTool.Call(context.Background(), fmt.Sprintf(`{"Arg0":[{"title":"item-%d"}]}`, idx))
Expand Down
2 changes: 1 addition & 1 deletion agent/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestNewInMemoryHistoryProvider_ConcurrentStoresOnSameSession_NoDataRace(t *
errs := make(chan error, stores)
var wg sync.WaitGroup
wg.Add(stores)
for i := 0; i < stores; i++ {
for i := range stores {
go func(index int) {
defer wg.Done()
<-start
Expand Down
3 changes: 1 addition & 2 deletions agent/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func (mf MiddlewareFunc) Run(next RunFunc, ctx context.Context, messages []*mess

// compileRunChain applies the given middlewares around fn.
func compileRunChain(fn RunFunc, middlewares []Middleware) RunFunc {
for i := len(middlewares) - 1; i >= 0; i-- {
mw := middlewares[i]
for _, mw := range slices.Backward(middlewares) {
if mw == nil {
Comment thread
qmuntal marked this conversation as resolved.
continue
}
Expand Down
8 changes: 1 addition & 7 deletions agent/skills/fsskills/source_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ func TestFileSource_WithMultipleScriptExtensions_DiscoversAll(t *testing.T) {
if scriptNames[0] == "" {
break
}
found := false
for _, actual := range scriptNames {
if actual == expected {
found = true
break
}
}
found := slices.Contains(scriptNames, expected)
if !found {
t.Fatalf("expected script %q to be discovered, got %#v", expected, scriptNames)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/prfromissue/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func parseCompareURL(raw string) (base, head, title string, ok bool) {
// originalPRBody returns the portion of the issue body that precedes the gh-aw
// fallback note, i.e. the PR description the workflow originally authored.
func originalPRBody(issueBody string) string {
if idx := strings.Index(issueBody, fallbackNoteMarker); idx >= 0 {
return strings.TrimSpace(issueBody[:idx])
if before, _, ok := strings.Cut(issueBody, fallbackNoteMarker); ok {
return strings.TrimSpace(before)
}
return strings.TrimSpace(issueBody)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/verifyexamples/example_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func availableCategories() []string {
func inputLines(values ...string) []*string {
inputs := make([]*string, 0, len(values))
for _, value := range values {
value := value
inputs = append(inputs, &value)
}
return inputs
Expand Down
7 changes: 2 additions & 5 deletions cmd/verifyexamples/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,14 @@ func (o VerificationOrchestrator) RunAll(ctx context.Context, examples []Example
semaphore := make(chan struct{}, maxParallelism)
var wg sync.WaitGroup
for _, example := range runnable {
example := example
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
semaphore <- struct{}{}
defer func() { <-semaphore }()
result := o.runSingle(ctx, example)
resultsLock.Lock()
results[example.Name] = result
resultsLock.Unlock()
}()
})
}
wg.Wait()
return RunAllResult{Results: results, Skipped: skipped, ExampleOrder: exampleOrder}
Expand Down
1 change: 0 additions & 1 deletion examples/02-agents/a2a/as_function_tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func main() {
func createSkillTools(remoteAgent *agent.Agent, skills []a2a.AgentSkill) []tool.Tool {
tools := make([]tool.Tool, 0, len(skills))
for _, skill := range skills {
skill := skill
tools = append(tools, functool.MustNew(functool.Config{
Name: sanitizeToolName(cmp.Or(skill.Name, skill.ID, "a2a_skill")),
Description: formatSkillDescription(skill),
Expand Down
6 changes: 3 additions & 3 deletions examples/03-workflows/concurrent/map_reduce/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func newReducer(id string) workflow.ExecutorBinding {
return err
}
var lines []string
for _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {
for line := range strings.SplitSeq(strings.TrimSpace(string(data)), "\n") {
if strings.TrimSpace(line) == "" {
continue
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func preprocess(text string) []string {
if line == "" {
continue
}
for _, word := range strings.Split(line, " ") {
for word := range strings.SplitSeq(line, " ") {
if strings.TrimSpace(word) != "" {
words = append(words, word)
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func loadMapGroups(results []MapComplete) (map[string][]int, error) {
if err != nil {
return nil, err
}
for _, line := range strings.Split(strings.TrimSpace(string(data)), "\n") {
for line := range strings.SplitSeq(strings.TrimSpace(string(data)), "\n") {
key, value, ok := strings.Cut(line, ": ")
if !ok {
continue
Expand Down
2 changes: 1 addition & 1 deletion examples/03-workflows/shared-states/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {
return FileStats{}, err
}
paragraphs := 0
for _, block := range strings.Split(content, "\n\n") {
for block := range strings.SplitSeq(content, "\n\n") {
if strings.TrimSpace(block) != "" {
paragraphs++
}
Expand Down
3 changes: 0 additions & 3 deletions internal/azaiprojects/toolbox_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ func TestValidateToolboxNamePathSegment(t *testing.T) {
}

for _, endpoint := range endpoints {
endpoint := endpoint
t.Run("endpoint="+endpoint, func(t *testing.T) {
t.Parallel()

for _, name := range validNames {
name := name
t.Run("valid/"+name, func(t *testing.T) {
t.Parallel()

Expand All @@ -55,7 +53,6 @@ func TestValidateToolboxNamePathSegment(t *testing.T) {
}

for _, name := range invalidNames {
name := name
t.Run("invalid/"+name, func(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 2 additions & 4 deletions internal/concurrent/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package concurrent

import (
"maps"
"testing"
)

Expand All @@ -28,10 +29,7 @@ func TestMap_All(t *testing.T) {
m.Store(k, v)
}

got := make(map[string]int)
for k, v := range m.All() {
got[k] = v
}
got := maps.Collect(m.All())

if len(got) != len(items) {
t.Errorf("expected %d items, got %d", len(items), len(got))
Expand Down
6 changes: 2 additions & 4 deletions internal/hashmap/hashmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package hashmap

import (
"hash/maphash"
"maps"
"slices"
"testing"
"unicode"
Expand Down Expand Up @@ -95,10 +96,7 @@ func TestMap(t *testing.T) {
t.Errorf("Values(): got %v", values)
}

entries := make(map[string]int)
for key, value := range m.All() {
entries[key] = value
}
entries := maps.Collect(m.All())
if len(entries) != 2 || entries["Hello"] != 2 || entries["World"] != 3 {
t.Errorf("All(): got %v", entries)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/jsonx/jsonx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestUnmarshalDiscriminatedUnionSliceWithFallback_UsesFallbackForMissingAndU
"Value":"missing"
}]`)
types := map[string]reflect.Type{
"known": reflect.TypeOf(knownUnion{}),
"known": reflect.TypeFor[knownUnion](),
}
fallback := func(raw json.RawMessage) (testUnion, error) {
return &rawUnion{Raw: slices.Clone(raw)}, nil
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestUnmarshalDiscriminatedUnionSliceWithFallback_MissingTypeDoesNotMatchZer
"Value":"missing"
}]`)
types := map[string]reflect.Type{
"": reflect.TypeOf(knownUnion{}),
"": reflect.TypeFor[knownUnion](),
}
fallback := func(raw json.RawMessage) (testUnion, error) {
return &rawUnion{Raw: raw}, nil
Expand Down
2 changes: 1 addition & 1 deletion provider/a2aprovider/a2a_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ func TestRunDeduplicatesTaskIDsAcrossTurns(t *testing.T) {
t.Fatal(err)
}

for i := 0; i < 3; i++ {
for i := range 3 {
if _, err := a.RunText(t.Context(), "Do something", agent.WithSession(session)).Collect(); err != nil {
t.Fatalf("run %d error = %v, want nil", i, err)
}
Expand Down
6 changes: 3 additions & 3 deletions provider/aguiprovider/hosting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func TestHandler_ToolResult_HasDistinctMessageID(t *testing.T) {

// Extract the tool result messageId and the text message start messageId.
var toolResultMsgID, textStartMsgID string
for _, line := range strings.Split(content, "\n") {
for line := range strings.SplitSeq(content, "\n") {
if !strings.HasPrefix(line, "data:") {
continue
}
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestHandler_ParallelToolResults_HaveUniqueMessageIDs(t *testing.T) {
content := rr.Body.String()

var resultMsgIDs []string
for _, line := range strings.Split(content, "\n") {
for line := range strings.SplitSeq(content, "\n") {
if !strings.HasPrefix(line, "data:") {
continue
}
Expand Down Expand Up @@ -503,7 +503,7 @@ func TestHandler_MidStreamError_EmitsRunErrorEvent(t *testing.T) {

var sawRunError bool
var runErrorRunID string
for _, line := range strings.Split(content, "\n") {
for line := range strings.SplitSeq(content, "\n") {
if !strings.HasPrefix(line, "data:") {
continue
}
Expand Down
10 changes: 5 additions & 5 deletions provider/copilotprovider/copilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (p *provider) openSession(

func (p *provider) sessionConfig(streaming bool, eventHandler copilot.SessionEventHandler, options []agent.Option) copilot.SessionConfig {
cfg := copySessionConfig(p.cfg.SessionConfig)
cfg.Streaming = copilot.Bool(streaming)
cfg.Streaming = new(streaming)
cfg.OnEvent = chainSessionEventHandlers(cfg.OnEvent, eventHandler)
cfg.SystemMessage = systemMessageWithInstructions(cfg.SystemMessage, slices.Collect(agent.AllOptions(options, agent.WithInstructions)))
cfg.Tools = append(cfg.Tools, copilotTools(options)...)
Expand All @@ -261,7 +261,7 @@ func (p *provider) sessionConfig(streaming bool, eventHandler copilot.SessionEve

func (p *provider) resumeSessionConfig(streaming bool, eventHandler copilot.SessionEventHandler, options []agent.Option) copilot.ResumeSessionConfig {
cfg := copyResumeSessionConfig(p.cfg.SessionConfig)
cfg.Streaming = copilot.Bool(streaming)
cfg.Streaming = new(streaming)
cfg.OnEvent = chainSessionEventHandlers(cfg.OnEvent, eventHandler)
cfg.SystemMessage = systemMessageWithInstructions(cfg.SystemMessage, slices.Collect(agent.AllOptions(options, agent.WithInstructions)))
cfg.Tools = append(cfg.Tools, copilotTools(options)...)
Expand All @@ -271,7 +271,7 @@ func (p *provider) resumeSessionConfig(streaming bool, eventHandler copilot.Sess

func copySessionConfig(source *copilot.SessionConfig) copilot.SessionConfig {
if source == nil {
return copilot.SessionConfig{Streaming: copilot.Bool(true)}
return copilot.SessionConfig{Streaming: new(true)}
}
clone := *source
clone.Tools = slices.Clone(source.Tools)
Expand All @@ -281,7 +281,7 @@ func copySessionConfig(source *copilot.SessionConfig) copilot.SessionConfig {

func copyResumeSessionConfig(source *copilot.SessionConfig) copilot.ResumeSessionConfig {
if source == nil {
return copilot.ResumeSessionConfig{Streaming: copilot.Bool(true)}
return copilot.ResumeSessionConfig{Streaming: new(true)}
}
return copilot.ResumeSessionConfig{
ClientName: source.ClientName,
Expand Down Expand Up @@ -367,7 +367,7 @@ func chainSessionEventHandlers(existing, added copilot.SessionEventHandler) copi

func copyBoolDefaultTrue(source *bool) *bool {
if source == nil {
return copilot.Bool(true)
return new(true)
}
value := *source
return &value
Expand Down
4 changes: 2 additions & 2 deletions provider/copilotprovider/copilot_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func TestCopyResumeSessionConfig_CopiesRecentSDKFields(t *testing.T) {
managedSettings := &copilot.ManagedSettings{}
source := &copilot.SessionConfig{
AdditionalDirectories: []string{"/shared"},
EnableFileChangeTracking: copilot.Bool(true),
EnableExperimentalMode: copilot.Bool(true),
EnableFileChangeTracking: new(true),
EnableExperimentalMode: new(true),
DisabledMCPServers: []string{"legacy"},
GitHubMCPToolConfig: githubMCPToolConfig,
ManagedSettings: managedSettings,
Expand Down
Loading
Loading