This commit is contained in:
1 parent
5583d7b74b
commit
db8472bf28
15 files changed
+2260
-2
No files matched your search
@@ -0,0 +1,78 @@
|
||||
package xlsxtranslate
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// TestValidateBuiltinAgentYAML parses the config YAMLs with plain yaml.v3 to
|
||||
// verify the new SIP translator entries are structurally valid (no internal
|
||||
// packages involved, so no gojieba init on this machine).
|
||||
func TestValidateBuiltinAgentYAML(t *testing.T) {
|
||||
raw, err := os.ReadFile("../../config/builtin_agents.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("read builtin_agents.yaml: %v", err)
|
||||
}
|
||||
var doc struct {
|
||||
BuiltinAgents []map[string]any `yaml:"builtin_agents"`
|
||||
}
|
||||
if err := yaml.Unmarshal(raw, &doc); err != nil {
|
||||
t.Fatalf("builtin_agents.yaml does not parse: %v", err)
|
||||
}
|
||||
var found map[string]any
|
||||
for _, a := range doc.BuiltinAgents {
|
||||
if id, _ := a["id"].(string); id == "builtin-sip-translator" {
|
||||
found = a
|
||||
break
|
||||
}
|
||||
}
|
||||
if found == nil {
|
||||
t.Fatalf("builtin-sip-translator entry not found")
|
||||
}
|
||||
for _, key := range []string{"avatar", "is_builtin", "i18n", "config"} {
|
||||
if _, ok := found[key]; !ok {
|
||||
t.Fatalf("entry missing key %q", key)
|
||||
}
|
||||
}
|
||||
cfg := found["config"].(map[string]any)
|
||||
for _, key := range []string{"agent_mode", "agent_type", "system_prompt_id", "supported_file_types", "allowed_tools"} {
|
||||
if _, ok := cfg[key]; !ok {
|
||||
t.Fatalf("config missing key %q", key)
|
||||
}
|
||||
}
|
||||
tools, _ := cfg["allowed_tools"].([]any)
|
||||
toolNames := map[string]bool{}
|
||||
for _, tl := range tools {
|
||||
if s, ok := tl.(string); ok {
|
||||
toolNames[s] = true
|
||||
}
|
||||
}
|
||||
if !toolNames["xlsx_translate"] {
|
||||
t.Fatalf("allowed_tools does not include xlsx_translate")
|
||||
}
|
||||
|
||||
promptRaw, err := os.ReadFile("../../config/prompt_templates/agent_system_prompt.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("read agent_system_prompt.yaml: %v", err)
|
||||
}
|
||||
var tpl struct {
|
||||
Templates []map[string]any `yaml:"templates"`
|
||||
}
|
||||
if err := yaml.Unmarshal(promptRaw, &tpl); err != nil {
|
||||
t.Fatalf("agent_system_prompt.yaml does not parse: %v", err)
|
||||
}
|
||||
foundTpl := false
|
||||
for _, tp := range tpl.Templates {
|
||||
if id, _ := tp["id"].(string); id == "sip_translator" {
|
||||
foundTpl = true
|
||||
if content, _ := tp["content"].(string); len(content) < 100 {
|
||||
t.Fatalf("sip_translator template content too short")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !foundTpl {
|
||||
t.Fatalf("sip_translator template not found")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user