Files
ai_academy/internal/agent/grounding_prompt_test.go
T
runny 9058149576
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
refactor: 项目更名 WeKnora → Academy
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名)
- 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块)
- docreader proto 描述符采用等长替换,保持序列化字节布局有效
- Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像
- 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
2026-11-13 20:52:51 +08:00

125 lines
4.5 KiB
Go

package agent
import (
"context"
"os"
"strings"
"testing"
"academy/internal/agent/tools"
"academy/internal/config"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
func TestGroundingGuidanceSurvivesTemplateSelection(t *testing.T) {
data, err := os.ReadFile("../../config/prompt_templates/agent_system_prompt.yaml")
require.NoError(t, err)
var file struct {
Templates []config.PromptTemplate `yaml:"templates"`
}
require.NoError(t, yaml.Unmarshal(data, &file))
cfg := &config.Config{PromptTemplates: &config.PromptTemplatesConfig{AgentSystemPrompt: file.Templates}}
for _, tc := range []struct {
name string
kbs []*KnowledgeBaseInfo
custom string
}{
{name: "pure"},
{name: "rag", kbs: []*KnowledgeBaseInfo{{ID: "kb", Capabilities: []string{"chunks"}}}},
{name: "saved custom", custom: "Create the requested slides using the selected skill."},
} {
t.Run(tc.name, func(t *testing.T) {
prompt := BuildSystemPromptWithOptions(tc.kbs, false, &BuildSystemPromptOptions{Config: cfg}, tc.custom)
require.Contains(t, prompt, "consult relevant available sources before drafting unsupported content")
require.Contains(t, prompt, "presentations, reports, tutorials, and technical instructions")
require.Contains(t, prompt, "Reading a generator's instructions or successfully running its script does not verify the subject matter")
require.Contains(t, prompt, "translation or formatting of supplied content do not require research")
require.Contains(t, prompt, "If relevant sources are unavailable or searches leave gaps")
if tc.custom != "" {
require.True(t, strings.HasPrefix(prompt, tc.custom))
}
})
}
// The legacy builder cannot infer tools, but still needs the evidence policy.
require.Contains(t, BuildSystemPrompt(nil, false, "Custom"), "Content grounding")
}
func TestGroundingUsesRegistryInsteadOfConfiguration(t *testing.T) {
for _, tc := range []struct {
name string
registered []string
webFlag bool
want []string
absent []string
}{
{
"skill only with stale flags",
[]string{tools.ToolReadFile, tools.ToolShellExec},
true,
nil,
[]string{
"Available knowledge tools:", "web_search is available", "web_fetch is available",
"search them before answering",
},
},
{
"rag",
[]string{tools.ToolSearchKnowledge, tools.ToolReadDocument},
false,
[]string{
"Available knowledge tools: search_knowledge, read_document",
"search them before answering a question about a topic, even one that reads like general knowledge",
},
[]string{"wiki_search", "web_search is available"},
},
{
"wiki",
[]string{tools.ToolWikiReadPage, tools.ToolWikiSearch},
false,
[]string{"Available knowledge tools: wiki_search, wiki_read_page"},
[]string{"search_knowledge", "web_search is available"},
},
{
"registered web",
[]string{tools.ToolWebSearch, tools.ToolWebFetch},
false,
[]string{"web_search is available", "web_fetch is available"},
[]string{"Available knowledge tools:"},
},
{
"no tools", nil, false, nil,
[]string{"Available knowledge tools:", "web_search is available", "web_fetch is available"},
},
} {
t.Run(tc.name, func(t *testing.T) {
engine := newTestEngine(t, &mockChat{})
engine.config.WebSearchEnabled = tc.webFlag
engine.config.AllowedTools = []string{tools.ToolSearchKnowledge, tools.ToolWebSearch}
engine.toolRegistry = tools.NewToolRegistry()
for _, name := range tc.registered {
engine.toolRegistry.RegisterTool(newCountingTool(name))
}
prompt := engine.buildSystemPrompt(context.Background())
require.Contains(t, prompt, "Content grounding")
for _, want := range tc.want {
require.Contains(t, prompt, want)
}
for _, absent := range tc.absent {
require.NotContains(t, prompt, absent)
}
})
}
}
func TestPinnedGenerationSkillKeepsResearchAndKnowledgeScope(t *testing.T) {
engine := newTestEngine(t, &mockChat{})
engine.knowledgeBasesInfo = []*KnowledgeBaseInfo{{ID: "kb", Name: "Server operations", Capabilities: []string{"chunks"}}}
engine.SetPinnedMentions(nil, []*PinnedSkillInfo{{Name: "pptx-generator"}})
prompt := engine.RenderUserTurnContent("session", "如何在 Windows Server 2008 上连接 WiFi 网络?制作相关 PPT")
require.Contains(t, prompt, "Server operations")
require.Contains(t, prompt, `read_file(path="skill://pptx-generator/SKILL.md")`)
require.Contains(t, prompt, "do not replace research into the task's factual content")
require.Contains(t, prompt, "unless the user explicitly restricts them")
}