fix(agent): avoid process exit on exec init failure and add regression test (#1784)

* fix(agent): make exec tool init failure non-fatal

* test(agent): add regression test for invalid exec config fallback
This commit is contained in:
SakoroYou
2026-03-19 21:11:36 +08:00
committed by GitHub
parent 9a25fad20a
commit 844a4eefc7
2 changed files with 46 additions and 8 deletions
+34
View File
@@ -246,3 +246,37 @@ func TestNewAgentInstance_AllowsMediaTempDirForReadListAndExec(t *testing.T) {
t.Fatalf("exec output missing media content: %s", execResult.ForLLM)
}
}
func TestNewAgentInstance_InvalidExecConfigDoesNotExit(t *testing.T) {
workspace := t.TempDir()
cfg := &config.Config{
Agents: config.AgentsConfig{
Defaults: config.AgentDefaults{
Workspace: workspace,
ModelName: "test-model",
},
},
Tools: config.ToolsConfig{
ReadFile: config.ReadFileToolConfig{Enabled: true},
Exec: config.ExecConfig{
ToolConfig: config.ToolConfig{Enabled: true},
EnableDenyPatterns: true,
CustomDenyPatterns: []string{"[invalid-regex"},
},
},
}
agent := NewAgentInstance(nil, &cfg.Agents.Defaults, cfg, &mockProvider{})
if agent == nil {
t.Fatal("expected agent instance, got nil")
}
if _, ok := agent.Tools.Get("exec"); ok {
t.Fatal("exec tool should not be registered when exec config is invalid")
}
if _, ok := agent.Tools.Get("read_file"); !ok {
t.Fatal("read_file tool should still be registered")
}
}