style: fix lint errors and update test assertions for CI

Fix 9 lint issues (predeclared min shadow, golines, gofmt, gci) and
2 test failures (spawn error message assertions).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-03-01 03:36:11 +09:00
parent fc70169a7b
commit ce7845ed60
8 changed files with 37 additions and 21 deletions

View file

@ -880,12 +880,12 @@ func formatDurationMs(ms int64) string {
tenths := (ms % 1000) / 100
return fmt.Sprintf("%d.%ds", totalSec, tenths)
}
min := totalSec / 60
mins := totalSec / 60
sec := totalSec % 60
if sec == 0 {
return fmt.Sprintf("%dm", min)
return fmt.Sprintf("%dm", mins)
}
return fmt.Sprintf("%dm%ds", min, sec)
return fmt.Sprintf("%dm%ds", mins, sec)
}
// acquireSessionLock gets or creates a per-session semaphore and acquires it.
@ -1153,7 +1153,10 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt
)
messages = append(messages, providers.Message{
Role: "user",
Content: fmt.Sprintf("[System] Phase %d is now active. Continue working on the next steps.", agent.ContextBuilder.GetCurrentPhase()),
Content: fmt.Sprintf(
"[System] Phase %d is now active. Continue working on the next steps.",
agent.ContextBuilder.GetCurrentPhase(),
),
})
if len(messages) > 0 {
al.lastSystemPrompt.Store(messages[0].Content)
@ -1240,7 +1243,7 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt
if agent.ContextBuilder.IsCurrentPhaseComplete() {
if phaseLoop >= maxPhaseTransitions {
logger.WarnCF("agent", "Max phase transitions reached, stopping",
map[string]interface{}{"agent_id": agent.ID, "transitions": phaseLoop})
map[string]any{"agent_id": agent.ID, "transitions": phaseLoop})
break
}
prev := agent.ContextBuilder.GetCurrentPhase()

View file

@ -903,7 +903,11 @@ func checkCurlLocalNet(command string) string {
}
host := u.Hostname()
if !isLocalHost(host) {
return fmt.Sprintf("Command blocked by safety guard (curl/wget is restricted to localhost and private network; %q is a public address)", host)
return fmt.Sprintf(
"Command blocked by safety guard "+
"(curl/wget is restricted to localhost and private network; %q is a public address)",
host,
)
}
}
return ""

View file

@ -73,7 +73,10 @@ func (t *SpawnTool) SetAllowlistChecker(check func(targetAgentID string) bool) {
func (t *SpawnTool) Execute(ctx context.Context, args map[string]any) *ToolResult {
task, ok := args["task"].(string)
if !ok || strings.TrimSpace(task) == "" {
return ErrorResult(`Required parameter "task" (string) is missing. Example: {"task": "describe what you need done", "preset": "scout"}`)
return ErrorResult(
`Required parameter "task" (string) is missing. ` +
`Example: {"task": "describe what you need done", "preset": "scout"}`,
)
}
label, _ := args["label"].(string)

View file

@ -33,8 +33,8 @@ func TestSpawnTool_Execute_EmptyTask(t *testing.T) {
if !result.IsError {
t.Error("Expected error for invalid task parameter")
}
if !strings.Contains(result.ForLLM, "task is required") {
t.Errorf("Error message should mention 'task is required', got: %s", result.ForLLM)
if !strings.Contains(result.ForLLM, `"task"`) {
t.Errorf("Error message should mention '\"task\"', got: %s", result.ForLLM)
}
})
}
@ -73,7 +73,7 @@ func TestSpawnTool_Execute_NilManager(t *testing.T) {
if !result.IsError {
t.Error("Expected error for nil manager")
}
if !strings.Contains(result.ForLLM, "Subagent manager not configured") {
t.Errorf("Error message should mention manager not configured, got: %s", result.ForLLM)
if !strings.Contains(result.ForLLM, "spawn tool is not available") {
t.Errorf("Error message should mention spawn tool not available, got: %s", result.ForLLM)
}
}

View file

@ -434,8 +434,10 @@ func (t *SubagentTool) SetContext(channel, chatID string) {
func (t *SubagentTool) Execute(ctx context.Context, args map[string]any) *ToolResult {
task, ok := args["task"].(string)
if !ok {
return ErrorResult(`Required parameter "task" (string) is missing. Example: {"task": "describe what you need done"}`).
WithError(fmt.Errorf("task parameter is required"))
return ErrorResult(
`Required parameter "task" (string) is missing. ` +
`Example: {"task": "describe what you need done"}`,
).WithError(fmt.Errorf("task parameter is required"))
}
label, _ := args["label"].(string)

View file

@ -365,7 +365,11 @@ func TestFormatToolStats(t *testing.T) {
}{
{"empty", map[string]int{}, ""},
{"single", map[string]int{"exec": 3}, "exec:3"},
{"multiple sorted", map[string]int{"read_file": 5, "exec": 3, "write_file": 1}, "exec:3,read_file:5,write_file:1"},
{
"multiple sorted",
map[string]int{"read_file": 5, "exec": 3, "write_file": 1},
"exec:3,read_file:5,write_file:1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {