Files
WeKnora/internal/handler/deployment_capabilities_test.go
T
ttommybotandwizardchen 1d68b4dcd7 fix: filter menus by deployment capabilities (#2674)
* fix: filter menus by deployment capabilities

* fix: address deployment capabilities review feedback

Restore Lite organizations hiding when the capabilities probe fails,
align embed capability detection with route registration, move the
handler into SystemHandler for Swagger/docs/client sync, and add
cross-layer capability key contract tests.

* style: gofmt deployment capabilities files

Fix App CI formatting check so the vet/test step can run.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-08-13 20:18:48 +08:00

74 lines
1.8 KiB
Go

package handler
import (
"os"
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"
"testing"
)
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 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
}