chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,141 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"academy/internal/sandbox"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDeploymentCapabilityKeysMatchFrontend(t *testing.T) {
|
||||
frontendKeys, err := readFrontendDeploymentCapabilityKeys()
|
||||
if err != nil {
|
||||
t.Fatalf("read frontend capability keys: %v", err)
|
||||
}
|
||||
|
||||
if !slices.Equal(DeploymentCapabilityKeys, frontendKeys) {
|
||||
t.Fatalf("backend keys = %#v, frontend keys = %#v", DeploymentCapabilityKeys, frontendKeys)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildDeploymentCapabilitiesIncludesAllKeys(t *testing.T) {
|
||||
result := BuildDeploymentCapabilities("standard", DeploymentFeatureAvailability{
|
||||
Organizations: true,
|
||||
Agents: true,
|
||||
IM: true,
|
||||
Embed: true,
|
||||
API: true,
|
||||
MCP: true,
|
||||
WebSearch: true,
|
||||
VectorStore: true,
|
||||
Storage: true,
|
||||
Sandbox: true,
|
||||
})
|
||||
|
||||
for _, key := range DeploymentCapabilityKeys {
|
||||
if _, ok := result.Capabilities[key]; !ok {
|
||||
t.Fatalf("missing capability key %q", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverlayLiveDockerSandboxCapabilityIgnoresStartupSnapshot(t *testing.T) {
|
||||
sandbox.ClearDockerBackendEnabledOverride()
|
||||
t.Cleanup(sandbox.ClearDockerBackendEnabledOverride)
|
||||
t.Setenv(sandbox.DockerBackendEnabledEnv, "")
|
||||
|
||||
snapshot := BuildDeploymentCapabilities("standard", DeploymentFeatureAvailability{
|
||||
Sandbox: true,
|
||||
SandboxDocker: true,
|
||||
})
|
||||
live := overlayLiveDockerSandboxCapability(snapshot)
|
||||
docker := live.Capabilities["settings.sandbox.docker"]
|
||||
if docker.Supported {
|
||||
t.Fatal("live env off must hide docker even if the startup snapshot was on")
|
||||
}
|
||||
if docker.Reason != "docker_backend_disabled" {
|
||||
t.Fatalf("reason = %q, want docker_backend_disabled", docker.Reason)
|
||||
}
|
||||
|
||||
t.Setenv(sandbox.DockerBackendEnabledEnv, "true")
|
||||
enabled := overlayLiveDockerSandboxCapability(snapshot)
|
||||
if !enabled.Capabilities["settings.sandbox.docker"].Supported {
|
||||
t.Fatal("live env true must expose docker")
|
||||
}
|
||||
}
|
||||
|
||||
func readFrontendDeploymentCapabilityKeys() ([]string, error) {
|
||||
_, thisFile, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
repoRoot := filepath.Clean(filepath.Join(filepath.Dir(thisFile), "..", ".."))
|
||||
frontendPath := filepath.Join(repoRoot, "frontend", "src", "config", "deploymentCapabilities.ts")
|
||||
content, err := os.ReadFile(frontendPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`(?s)export const DEPLOYMENT_CAPABILITY_KEYS = \[(.*?)\]`)
|
||||
match := re.FindSubmatch(content)
|
||||
if len(match) < 2 {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
|
||||
var keys []string
|
||||
for _, line := range strings.Split(string(match[1]), "\n") {
|
||||
line = strings.TrimSpace(strings.TrimRight(line, ","))
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
line = strings.Trim(line, `'`)
|
||||
keys = append(keys, line)
|
||||
}
|
||||
return keys, nil
|
||||
}
|
||||
|
||||
func TestHostSandboxCapabilityFollowsAvailability(t *testing.T) {
|
||||
data := BuildDeploymentCapabilities("lite", DeploymentFeatureAvailability{
|
||||
Sandbox: true,
|
||||
SandboxHost: true,
|
||||
})
|
||||
require.True(t, data.Capabilities["settings.sandbox.host"].Supported)
|
||||
|
||||
off := BuildDeploymentCapabilities("lite", DeploymentFeatureAvailability{
|
||||
Sandbox: true,
|
||||
})
|
||||
require.False(t, off.Capabilities["settings.sandbox.host"].Supported)
|
||||
require.Equal(t, "platform_unsupported",
|
||||
off.Capabilities["settings.sandbox.host"].Reason)
|
||||
}
|
||||
|
||||
func TestRemoteSandboxCapabilityIsOffOnLiteDesktop(t *testing.T) {
|
||||
on := BuildDeploymentCapabilities("standard", DeploymentFeatureAvailability{Sandbox: true, SandboxRemote: true})
|
||||
require.True(t, on.Capabilities["settings.sandbox.remote"].Supported)
|
||||
|
||||
off := BuildDeploymentCapabilities("lite", DeploymentFeatureAvailability{
|
||||
Sandbox: true, SandboxRemote: false, SandboxHost: true,
|
||||
})
|
||||
require.False(t, off.Capabilities["settings.sandbox.remote"].Supported)
|
||||
require.Equal(t, "not_supported_in_lite", off.Capabilities["settings.sandbox.remote"].Reason)
|
||||
|
||||
none := BuildDeploymentCapabilities("standard", DeploymentFeatureAvailability{})
|
||||
require.Equal(t, "route_not_registered", none.Capabilities["settings.sandbox.remote"].Reason)
|
||||
}
|
||||
|
||||
func TestBuildDeploymentCapabilitiesUserAllocation(t *testing.T) {
|
||||
off := BuildDeploymentCapabilities("standard", DeploymentFeatureAvailability{Sandbox: true, SandboxRemote: true})
|
||||
require.False(t, off.Capabilities["settings.sandbox.user_allocation"].Supported)
|
||||
require.Equal(t, "deployment_gate_off", off.Capabilities["settings.sandbox.user_allocation"].Reason)
|
||||
|
||||
on := BuildDeploymentCapabilities("standard", DeploymentFeatureAvailability{
|
||||
Sandbox: true, SandboxRemote: true, SandboxUserAllocation: true,
|
||||
})
|
||||
require.True(t, on.Capabilities["settings.sandbox.user_allocation"].Supported)
|
||||
}
|
||||
Reference in new issue
Block a user