WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
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
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (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
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 and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (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
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
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (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
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 and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (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
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
apperrors "github.com/Tencent/WeKnora/internal/errors"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func builtinModelContext(systemAdmin bool) context.Context {
|
||||
ctx := context.WithValue(context.Background(), types.TenantIDContextKey, uint64(7))
|
||||
return context.WithValue(ctx, types.SystemAdminContextKey, systemAdmin)
|
||||
}
|
||||
|
||||
func TestUpdateBuiltinModel_RequiresSystemAdmin(t *testing.T) {
|
||||
stored := &types.Model{
|
||||
ID: "builtin-chat", TenantID: 10000, IsBuiltin: true,
|
||||
ManagedBy: types.BuiltinModelManagedBy,
|
||||
}
|
||||
updated := false
|
||||
svc := NewModelService(&stubModelRepoForDelete{
|
||||
model: stored,
|
||||
update: func(*types.Model) error {
|
||||
updated = true
|
||||
return nil
|
||||
},
|
||||
}, nil, nil, nil, nil, nil)
|
||||
|
||||
err := svc.UpdateModel(builtinModelContext(false), &types.Model{ID: stored.ID})
|
||||
require.Error(t, err)
|
||||
appErr, ok := apperrors.IsAppError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, apperrors.ErrForbidden, appErr.Code)
|
||||
assert.False(t, updated)
|
||||
}
|
||||
|
||||
func TestUpdateBuiltinModel_SystemAdminCreatesRuntimeOverride(t *testing.T) {
|
||||
stored := &types.Model{
|
||||
ID: "builtin-chat", TenantID: 10000, IsBuiltin: true,
|
||||
ManagedBy: types.BuiltinModelManagedBy,
|
||||
}
|
||||
var saved *types.Model
|
||||
svc := NewModelService(&stubModelRepoForDelete{
|
||||
model: stored,
|
||||
update: func(model *types.Model) error {
|
||||
copy := *model
|
||||
saved = ©
|
||||
return nil
|
||||
},
|
||||
}, nil, nil, nil, nil, nil)
|
||||
|
||||
input := &types.Model{ID: stored.ID, Name: "edited"}
|
||||
require.NoError(t, svc.UpdateModel(builtinModelContext(true), input))
|
||||
require.NotNil(t, saved)
|
||||
assert.Equal(t, uint64(10000), saved.TenantID)
|
||||
assert.True(t, saved.IsBuiltin)
|
||||
assert.Empty(t, saved.ManagedBy, "UI edit must stop later YAML reconciliation")
|
||||
}
|
||||
|
||||
func TestUpdateBuiltinModelCredentials_SystemAdminOnly(t *testing.T) {
|
||||
newKey := "sk-new"
|
||||
|
||||
t.Run("tenant admin denied", func(t *testing.T) {
|
||||
stored := &types.Model{ID: "builtin-chat", TenantID: 10000, IsBuiltin: true}
|
||||
svc := NewModelService(&stubModelRepoForDelete{model: stored}, nil, nil, nil, nil, nil)
|
||||
_, err := svc.UpdateModelCredentials(builtinModelContext(false), stored.ID, &newKey, nil)
|
||||
require.Error(t, err)
|
||||
appErr, ok := apperrors.IsAppError(err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, apperrors.ErrForbidden, appErr.Code)
|
||||
})
|
||||
|
||||
t.Run("system admin saves runtime override", func(t *testing.T) {
|
||||
stored := &types.Model{
|
||||
ID: "builtin-chat", TenantID: 10000, IsBuiltin: true,
|
||||
ManagedBy: types.BuiltinModelManagedBy,
|
||||
}
|
||||
var saved *types.Model
|
||||
svc := NewModelService(&stubModelRepoForDelete{
|
||||
model: stored,
|
||||
update: func(model *types.Model) error {
|
||||
copy := *model
|
||||
saved = ©
|
||||
return nil
|
||||
},
|
||||
}, nil, nil, nil, nil, nil)
|
||||
|
||||
updated, err := svc.UpdateModelCredentials(
|
||||
builtinModelContext(true), stored.ID, &newKey, nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newKey, updated.Parameters.APIKey)
|
||||
require.NotNil(t, saved)
|
||||
assert.Empty(t, saved.ManagedBy)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user