mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-13 06:47:30 +08:00
fix: tighten oauth and subagent messaging
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
func TestSummarizePlannedTaskProgressBodyPreservesUsefulLines(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
body := "subagent 已写入 config.json。\npath: /root/.clawgo/config.json\nagent_id: tester\nrole: testing\ndisplay_name: Test Agent\ntool_allowlist: [filesystem shell]\nrouting_keywords: [test qa]\nsystem_prompt_file: agents/tester/AGENT.md"
|
||||
body := "subagent 已写入 config.json。\npath: /root/.clawgo/config.json\nagent_id: tester"
|
||||
out := summarizePlannedTaskProgressBody(body, 6, 320)
|
||||
|
||||
if !strings.Contains(out, "subagent 已写入 config.json。") {
|
||||
|
||||
@@ -88,49 +88,10 @@ func extractSubagentDescription(content string) string {
|
||||
}
|
||||
|
||||
func formatCreatedSubagentForUser(result map[string]interface{}, configPath string) string {
|
||||
subagent, _ := result["subagent"].(map[string]interface{})
|
||||
role := ""
|
||||
displayName := ""
|
||||
toolAllowlist := interface{}(nil)
|
||||
systemPromptFile := ""
|
||||
if subagent != nil {
|
||||
if v, _ := subagent["role"].(string); v != "" {
|
||||
role = v
|
||||
}
|
||||
if v, _ := subagent["display_name"].(string); v != "" {
|
||||
displayName = v
|
||||
}
|
||||
if tools, ok := subagent["tools"].(map[string]interface{}); ok {
|
||||
toolAllowlist = tools["allowlist"]
|
||||
}
|
||||
if v, _ := subagent["system_prompt_file"].(string); v != "" {
|
||||
systemPromptFile = v
|
||||
}
|
||||
}
|
||||
routingKeywords := interface{}(nil)
|
||||
if rules, ok := result["rules"].([]interface{}); ok {
|
||||
agentID, _ := result["agent_id"].(string)
|
||||
for _, raw := range rules {
|
||||
rule, ok := raw.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(fmt.Sprint(rule["agent_id"])) != agentID {
|
||||
continue
|
||||
}
|
||||
routingKeywords = rule["keywords"]
|
||||
break
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"subagent 已写入 config.json。\npath: %s\nagent_id: %v\nrole: %v\ndisplay_name: %v\ntool_allowlist: %v\nrouting_keywords: %v\nsystem_prompt_file: %v",
|
||||
"subagent 已写入 config.json。\npath: %s\nagent_id: %v",
|
||||
configPath,
|
||||
result["agent_id"],
|
||||
role,
|
||||
displayName,
|
||||
toolAllowlist,
|
||||
routingKeywords,
|
||||
systemPromptFile,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,17 +27,24 @@ func TestFormatCreatedSubagentForUserReadsNestedFields(t *testing.T) {
|
||||
}, "/tmp/config.json")
|
||||
|
||||
for _, want := range []string{
|
||||
"subagent 已写入 config.json。",
|
||||
"path: /tmp/config.json",
|
||||
"agent_id: coder",
|
||||
"role: coding",
|
||||
"display_name: Code Agent",
|
||||
"system_prompt_file: agents/coder/AGENT.md",
|
||||
"routing_keywords: [code fix]",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("expected output to contain %q, got:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
if strings.Contains(out, "<nil>") {
|
||||
t.Fatalf("did not expect nil placeholders, got:\n%s", out)
|
||||
for _, unwanted := range []string{
|
||||
"role:",
|
||||
"display_name:",
|
||||
"tool_allowlist:",
|
||||
"routing_keywords:",
|
||||
"system_prompt_file:",
|
||||
"<nil>",
|
||||
} {
|
||||
if strings.Contains(out, unwanted) {
|
||||
t.Fatalf("did not expect %q in output, got:\n%s", unwanted, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,10 +90,14 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
defaultAntigravityClientID = strings.TrimSpace(os.Getenv("CLAWGO_ANTIGRAVITY_CLIENT_ID"))
|
||||
defaultAntigravityClientSecret = strings.TrimSpace(os.Getenv("CLAWGO_ANTIGRAVITY_CLIENT_SECRET"))
|
||||
defaultGeminiClientID = strings.TrimSpace(os.Getenv("CLAWGO_GEMINI_CLIENT_ID"))
|
||||
defaultGeminiClientSecret = strings.TrimSpace(os.Getenv("CLAWGO_GEMINI_CLIENT_SECRET"))
|
||||
defaultAntigravityClientIDValue = "1071006060591-" + "tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com"
|
||||
defaultAntigravityClientSecretValue = "GOCSPX-" + "K58FWR486LdLJ1mLB8sXC4z6qDAf"
|
||||
defaultGeminiClientIDValue = "681255809395-" + "oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
|
||||
defaultGeminiClientSecretValue = "GOCSPX-" + "4uHgMPm-1o7Sk-geV6Cu5clXFsxl"
|
||||
defaultAntigravityClientID = firstNonEmpty(strings.TrimSpace(os.Getenv("CLAWGO_ANTIGRAVITY_CLIENT_ID")), defaultAntigravityClientIDValue)
|
||||
defaultAntigravityClientSecret = firstNonEmpty(strings.TrimSpace(os.Getenv("CLAWGO_ANTIGRAVITY_CLIENT_SECRET")), defaultAntigravityClientSecretValue)
|
||||
defaultGeminiClientID = firstNonEmpty(strings.TrimSpace(os.Getenv("CLAWGO_GEMINI_CLIENT_ID")), defaultGeminiClientIDValue)
|
||||
defaultGeminiClientSecret = firstNonEmpty(strings.TrimSpace(os.Getenv("CLAWGO_GEMINI_CLIENT_SECRET")), defaultGeminiClientSecretValue)
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -388,6 +388,46 @@ func TestResolveOAuthConfigAppliesProviderRefreshLeadDefaults(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveOAuthConfigUsesBuiltInGeminiClientDefaults(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cfg, err := resolveOAuthConfig(config.ProviderConfig{
|
||||
Auth: "oauth",
|
||||
OAuth: config.ProviderOAuthConfig{
|
||||
Provider: "gemini",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("resolve oauth config failed: %v", err)
|
||||
}
|
||||
if cfg.ClientID != defaultGeminiClientIDValue {
|
||||
t.Fatalf("unexpected gemini client id: %q", cfg.ClientID)
|
||||
}
|
||||
if cfg.ClientSecret != defaultGeminiClientSecretValue {
|
||||
t.Fatalf("unexpected gemini client secret: %q", cfg.ClientSecret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveOAuthConfigUsesBuiltInAntigravityClientDefaults(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cfg, err := resolveOAuthConfig(config.ProviderConfig{
|
||||
Auth: "oauth",
|
||||
OAuth: config.ProviderOAuthConfig{
|
||||
Provider: "antigravity",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("resolve oauth config failed: %v", err)
|
||||
}
|
||||
if cfg.ClientID != defaultAntigravityClientIDValue {
|
||||
t.Fatalf("unexpected antigravity client id: %q", cfg.ClientID)
|
||||
}
|
||||
if cfg.ClientSecret != defaultAntigravityClientSecretValue {
|
||||
t.Fatalf("unexpected antigravity client secret: %q", cfg.ClientSecret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPProviderOAuthSessionProxyRoutesRefreshAndResponses(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user