mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 15:14:10 +00:00
feat: configure embedding servers and transcript agents
This commit is contained in:
@@ -6,6 +6,8 @@ import { authMiddleware } from './middleware/auth'
|
||||
import { teamService } from '@shumai/core/src/team/team'
|
||||
import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
|
||||
import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
|
||||
import { embeddingServerService } from '@shumai/core/src/search/embedding-server'
|
||||
import { HTTPException } from 'hono/http-exception'
|
||||
|
||||
vi.mock('@shumai/core/src/authz/authz', () => ({
|
||||
authzService: {
|
||||
@@ -112,6 +114,73 @@ describe('team api', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('lets team members view the effective embedding server settings', async () => {
|
||||
vi.spyOn(embeddingServerService, 'getSettings').mockResolvedValue({
|
||||
url: 'http://embedding:9379/v1',
|
||||
isEnvConfigured: true,
|
||||
})
|
||||
const response = await app.request('/teams/t1/embedding-server-settings')
|
||||
expect(await response.json()).toEqual({
|
||||
url: 'http://embedding:9379/v1',
|
||||
isEnvConfigured: true,
|
||||
})
|
||||
expect(authzService.hasPermission).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ id: 't1', permission: Permission.Read }),
|
||||
)
|
||||
})
|
||||
|
||||
it('lets admins save and test embedding server settings', async () => {
|
||||
vi.mocked(authzService.hasPermission).mockClear()
|
||||
const url = 'http://embedding:9379/v1'
|
||||
const settings = { url, isEnvConfigured: false }
|
||||
const save = vi.spyOn(embeddingServerService, 'updateSettings').mockResolvedValue(settings)
|
||||
const test = vi.spyOn(embeddingServerService, 'testConnection').mockResolvedValue({ ok: true })
|
||||
const body = JSON.stringify({ url })
|
||||
const headers = { 'Content-Type': 'application/json' }
|
||||
const saved = await app.request('/teams/t1/embedding-server-settings', {
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body,
|
||||
})
|
||||
expect(await saved.json()).toEqual(settings)
|
||||
const tested = await app.request('/teams/t1/embedding-server-settings/test', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
})
|
||||
expect(await tested.json()).toEqual({ ok: true })
|
||||
expect(save).toHaveBeenCalledWith('t1', url)
|
||||
expect(test).toHaveBeenCalledWith('t1', url)
|
||||
expect(authzService.hasPermission).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
expect.objectContaining({ permission: Permission.Admin }),
|
||||
)
|
||||
expect(authzService.hasPermission).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({ permission: Permission.Admin }),
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects embedding settings writes and connection tests without admin permission', async () => {
|
||||
const save = vi.spyOn(embeddingServerService, 'updateSettings')
|
||||
const test = vi.spyOn(embeddingServerService, 'testConnection')
|
||||
vi.mocked(authzService.hasPermission).mockRejectedValue(new HTTPException(403))
|
||||
for (const [method, suffix] of [
|
||||
['PUT', ''],
|
||||
['POST', '/test'],
|
||||
]) {
|
||||
const denied = await app.request(`/teams/t1/embedding-server-settings${suffix}`, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: 'http://embedding:9379/v1' }),
|
||||
})
|
||||
expect(denied.status).toBe(403)
|
||||
}
|
||||
expect(save).not.toHaveBeenCalled()
|
||||
expect(test).not.toHaveBeenCalled()
|
||||
vi.mocked(authzService.hasPermission).mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
it('POST /teams returns 404 without creating a team or writing an audit entry', async () => {
|
||||
const createTeam = vi.spyOn(teamService, 'createTeam').mockResolvedValue({
|
||||
id: 't1',
|
||||
|
||||
Reference in New Issue
Block a user