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:
parent
b8220102c9
commit
27130f7226
8 changed files with 37 additions and 21 deletions
|
|
@ -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.
|
||||
|
|
@ -1152,8 +1152,11 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt
|
|||
"", nil, opts.Channel, opts.ChatID,
|
||||
)
|
||||
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()),
|
||||
Role: "user",
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ type AgentReporter interface {
|
|||
|
||||
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) ReportConversation(from, to, text string) {}
|
||||
func (n *noopReporter) ReportGC(id, reason string) {}
|
||||
func (n *noopReporter) ReportConversation(from, to, text string) {}
|
||||
func (n *noopReporter) ReportGC(id, reason string) {}
|
||||
|
||||
// Noop is the AgentReporter to use when orchestration is disabled.
|
||||
// Allows nil-free code in callers.
|
||||
|
|
|
|||
|
|
@ -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 ""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ type spyCall struct {
|
|||
tool string
|
||||
}
|
||||
|
||||
func (r *reporterSpy) ReportSpawn(id, label, task string) {}
|
||||
func (r *reporterSpy) ReportConversation(from, to, text string) {}
|
||||
func (r *reporterSpy) ReportGC(id, reason string) {}
|
||||
func (r *reporterSpy) ReportSpawn(id, label, task string) {}
|
||||
func (r *reporterSpy) ReportConversation(from, to, text string) {}
|
||||
func (r *reporterSpy) ReportGC(id, reason string) {}
|
||||
func (r *reporterSpy) ReportStateChange(id string, state orch.AgentState, tool string) {
|
||||
r.mu.Lock()
|
||||
r.calls = append(r.calls, spyCall{state, tool})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue