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 f239720aa0
commit c1b370e132
8 changed files with 37 additions and 21 deletions

View file

@ -880,12 +880,12 @@ func formatDurationMs(ms int64) string {
tenths := (ms % 1000) / 100 tenths := (ms % 1000) / 100
return fmt.Sprintf("%d.%ds", totalSec, tenths) return fmt.Sprintf("%d.%ds", totalSec, tenths)
} }
min := totalSec / 60 mins := totalSec / 60
sec := totalSec % 60 sec := totalSec % 60
if sec == 0 { 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. // acquireSessionLock gets or creates a per-session semaphore and acquires it.
@ -1152,8 +1152,11 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt
"", nil, opts.Channel, opts.ChatID, "", nil, opts.Channel, opts.ChatID,
) )
messages = append(messages, providers.Message{ messages = append(messages, providers.Message{
Role: "user", 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 { if len(messages) > 0 {
al.lastSystemPrompt.Store(messages[0].Content) 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 agent.ContextBuilder.IsCurrentPhaseComplete() {
if phaseLoop >= maxPhaseTransitions { if phaseLoop >= maxPhaseTransitions {
logger.WarnCF("agent", "Max phase transitions reached, stopping", 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 break
} }
prev := agent.ContextBuilder.GetCurrentPhase() prev := agent.ContextBuilder.GetCurrentPhase()

View file

@ -11,10 +11,10 @@ type AgentReporter interface {
type noopReporter struct{} type noopReporter struct{}
func (n *noopReporter) ReportSpawn(id, label, task string) {} func (n *noopReporter) ReportSpawn(id, label, task string) {}
func (n *noopReporter) ReportStateChange(id string, state AgentState, tool string) {} func (n *noopReporter) ReportStateChange(id string, state AgentState, tool string) {}
func (n *noopReporter) ReportConversation(from, to, text string) {} func (n *noopReporter) ReportConversation(from, to, text string) {}
func (n *noopReporter) ReportGC(id, reason string) {} func (n *noopReporter) ReportGC(id, reason string) {}
// Noop is the AgentReporter to use when orchestration is disabled. // Noop is the AgentReporter to use when orchestration is disabled.
// Allows nil-free code in callers. // Allows nil-free code in callers.

View file

@ -903,7 +903,11 @@ func checkCurlLocalNet(command string) string {
} }
host := u.Hostname() host := u.Hostname()
if !isLocalHost(host) { 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 "" 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 { func (t *SpawnTool) Execute(ctx context.Context, args map[string]any) *ToolResult {
task, ok := args["task"].(string) task, ok := args["task"].(string)
if !ok || strings.TrimSpace(task) == "" { 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) label, _ := args["label"].(string)

View file

@ -33,8 +33,8 @@ func TestSpawnTool_Execute_EmptyTask(t *testing.T) {
if !result.IsError { if !result.IsError {
t.Error("Expected error for invalid task parameter") t.Error("Expected error for invalid task parameter")
} }
if !strings.Contains(result.ForLLM, "task is required") { if !strings.Contains(result.ForLLM, `"task"`) {
t.Errorf("Error message should mention 'task is required', got: %s", result.ForLLM) 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 { if !result.IsError {
t.Error("Expected error for nil manager") t.Error("Expected error for nil manager")
} }
if !strings.Contains(result.ForLLM, "Subagent manager not configured") { if !strings.Contains(result.ForLLM, "spawn tool is not available") {
t.Errorf("Error message should mention manager not configured, got: %s", result.ForLLM) 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 { func (t *SubagentTool) Execute(ctx context.Context, args map[string]any) *ToolResult {
task, ok := args["task"].(string) task, ok := args["task"].(string)
if !ok { if !ok {
return ErrorResult(`Required parameter "task" (string) is missing. Example: {"task": "describe what you need done"}`). return ErrorResult(
WithError(fmt.Errorf("task parameter is required")) `Required parameter "task" (string) is missing. ` +
`Example: {"task": "describe what you need done"}`,
).WithError(fmt.Errorf("task parameter is required"))
} }
label, _ := args["label"].(string) label, _ := args["label"].(string)

View file

@ -365,7 +365,11 @@ func TestFormatToolStats(t *testing.T) {
}{ }{
{"empty", map[string]int{}, ""}, {"empty", map[string]int{}, ""},
{"single", map[string]int{"exec": 3}, "exec:3"}, {"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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View file

@ -21,9 +21,9 @@ type spyCall struct {
tool string tool string
} }
func (r *reporterSpy) ReportSpawn(id, label, task string) {} func (r *reporterSpy) ReportSpawn(id, label, task string) {}
func (r *reporterSpy) ReportConversation(from, to, text string) {} func (r *reporterSpy) ReportConversation(from, to, text string) {}
func (r *reporterSpy) ReportGC(id, reason string) {} func (r *reporterSpy) ReportGC(id, reason string) {}
func (r *reporterSpy) ReportStateChange(id string, state orch.AgentState, tool string) { func (r *reporterSpy) ReportStateChange(id string, state orch.AgentState, tool string) {
r.mu.Lock() r.mu.Lock()
r.calls = append(r.calls, spyCall{state, tool}) r.calls = append(r.calls, spyCall{state, tool})