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
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
84 lines
2.8 KiB
Go
84 lines
2.8 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
|
|
"academy/internal/types"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type outcomeTool struct {
|
|
BaseTool
|
|
result *types.ToolResult
|
|
err error
|
|
}
|
|
|
|
func (t *outcomeTool) Execute(context.Context, json.RawMessage) (*types.ToolResult, error) {
|
|
return t.result, t.err
|
|
}
|
|
|
|
func TestRegistryPreservesFailureWithoutEncouragingToolHopping(t *testing.T) {
|
|
registry := NewToolRegistry()
|
|
registry.RegisterTool(&outcomeTool{
|
|
BaseTool: NewBaseTool("denied", "", json.RawMessage(`{"type":"object"}`)),
|
|
result: &types.ToolResult{Success: false, Error: "permission denied"},
|
|
})
|
|
result, err := registry.ExecuteTool(context.Background(), "denied", json.RawMessage(`{}`))
|
|
require.NoError(t, err)
|
|
require.False(t, result.Success)
|
|
require.Equal(t, "permission denied", result.Error)
|
|
}
|
|
|
|
func TestRegistryRedirectsRetiredSkillTools(t *testing.T) {
|
|
registry := NewToolRegistry()
|
|
for _, name := range []string{LegacyToolExecuteSkillScript, LegacyToolReadSkill, LegacyToolReadSandboxFile} {
|
|
result, err := registry.ExecuteTool(context.Background(), name, json.RawMessage(`{}`))
|
|
require.NoError(t, err)
|
|
require.False(t, result.Success)
|
|
require.Equal(t, RetiredToolReplacement(name), result.Error)
|
|
require.NotContains(t, result.Error, "tool not found")
|
|
}
|
|
result, err := registry.ExecuteTool(context.Background(), "not_a_tool", json.RawMessage(`{}`))
|
|
require.Error(t, err)
|
|
require.False(t, result.Success)
|
|
require.Contains(t, result.Error, "tool not found")
|
|
}
|
|
|
|
func TestRegistryNormalizesMissingAndContradictoryResults(t *testing.T) {
|
|
for _, outcome := range []*outcomeTool{
|
|
{result: nil},
|
|
{result: &types.ToolResult{Success: true}, err: errors.New("transport failed")},
|
|
} {
|
|
outcome.BaseTool = NewBaseTool("test", "", json.RawMessage(`{"type":"object"}`))
|
|
registry := NewToolRegistry()
|
|
registry.RegisterTool(outcome)
|
|
result, _ := registry.ExecuteTool(context.Background(), "test", json.RawMessage(`{}`))
|
|
require.NotNil(t, result)
|
|
require.False(t, result.Success)
|
|
require.NotEmpty(t, result.Error)
|
|
}
|
|
}
|
|
|
|
type panickingTool struct{ BaseTool }
|
|
|
|
func (t *panickingTool) Execute(context.Context, json.RawMessage) (*types.ToolResult, error) {
|
|
var items []int
|
|
_ = items[len(items)] // index out of range: a runtime panic like a buggy tool would raise
|
|
return nil, nil
|
|
}
|
|
|
|
func TestRegistryRecoversToolPanic(t *testing.T) {
|
|
registry := NewToolRegistry()
|
|
registry.RegisterTool(&panickingTool{BaseTool: NewBaseTool("crashy", "", json.RawMessage(`{"type":"object"}`))})
|
|
|
|
result, err := registry.ExecuteTool(context.Background(), "crashy", json.RawMessage(`{}`))
|
|
require.Error(t, err)
|
|
require.NotNil(t, result)
|
|
require.False(t, result.Success)
|
|
require.Equal(t, "tool crashy failed with an internal error", result.Error)
|
|
require.NotContains(t, result.Error, "index out of range")
|
|
}
|