mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
This reverts commit 9cb2bb156b.
This commit is contained in:
1 parent
9cb2bb156b
commit
24d34f28a3
19 files changed
+475
-2341
No files matched your search
@@ -1,95 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { FetchError } from '@opencode-manager/shared'
|
||||
import { settingsApi } from './settings'
|
||||
|
||||
describe('settingsApi', () => {
|
||||
const fetchMock = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.mockReset()
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('installSkillFromGithub', () => {
|
||||
it('posts JSON to skills install endpoint', async () => {
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(JSON.stringify({ skill: { name: 'teach' }, overwritten: false, sourceType: 'github', filesInstalled: ['SKILL.md'] }), { status: 200 }),
|
||||
)
|
||||
|
||||
const result = await settingsApi.installSkillFromGithub({
|
||||
sourceType: 'github',
|
||||
url: 'https://github.com/user/repo/tree/main/teach',
|
||||
scope: 'global',
|
||||
})
|
||||
|
||||
expect(result.skill.name).toBe('teach')
|
||||
|
||||
const callUrl = fetchMock.mock.calls[0][0]
|
||||
expect(callUrl).toEqual(expect.stringContaining('/api/settings/skills/install'))
|
||||
|
||||
const callOptions = fetchMock.mock.calls[0][1]
|
||||
expect(callOptions.method).toBe('POST')
|
||||
expect(callOptions.headers['Content-Type']).toBe('application/json')
|
||||
|
||||
const body = JSON.parse(callOptions.body)
|
||||
expect(body.sourceType).toBe('github')
|
||||
})
|
||||
|
||||
it('surfaces 409 conflict as FetchError', async () => {
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(JSON.stringify({ error: 'Skill "teach" already exists in global scope' }), { status: 409 }),
|
||||
)
|
||||
|
||||
await expect(
|
||||
settingsApi.installSkillFromGithub({
|
||||
sourceType: 'github',
|
||||
url: 'https://github.com/user/repo/tree/main/teach',
|
||||
scope: 'global',
|
||||
}),
|
||||
).rejects.toThrow(FetchError)
|
||||
|
||||
await expect(
|
||||
settingsApi.installSkillFromGithub({
|
||||
sourceType: 'github',
|
||||
url: 'https://github.com/user/repo/tree/main/teach',
|
||||
scope: 'global',
|
||||
}),
|
||||
).rejects.toMatchObject({ statusCode: 409 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('installSkillFromUpload', () => {
|
||||
it('posts FormData manifest and files', async () => {
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(JSON.stringify({ skill: { name: 'teach' }, overwritten: false, sourceType: 'upload', filesInstalled: ['teach/SKILL.md'] }), { status: 200 }),
|
||||
)
|
||||
|
||||
const file = new File(['# Teach Skill'], 'SKILL.md', { type: 'text/markdown' })
|
||||
Object.defineProperty(file, 'webkitRelativePath', { value: 'teach/SKILL.md' })
|
||||
|
||||
const result = await settingsApi.installSkillFromUpload({ files: [file], scope: 'global' })
|
||||
|
||||
expect(result.sourceType).toBe('upload')
|
||||
|
||||
const callUrl = fetchMock.mock.calls[0][0]
|
||||
expect(callUrl).toEqual(expect.stringContaining('/api/settings/skills/install'))
|
||||
|
||||
const callOptions = fetchMock.mock.calls[0][1]
|
||||
expect(callOptions.method).toBe('POST')
|
||||
expect(callOptions.headers?.hasOwnProperty).toBeFalsy()
|
||||
|
||||
const formData = callOptions.body as FormData
|
||||
expect(formData.get('sourceType')).toBe('upload')
|
||||
expect(formData.get('file0')).toBe(file)
|
||||
|
||||
const manifest = JSON.parse(formData.get('fileManifest') as string)
|
||||
expect(manifest).toHaveLength(1)
|
||||
expect(manifest[0].fieldName).toBe('file0')
|
||||
expect(manifest[0].relativePath).toBe('teach/SKILL.md')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -11,8 +11,6 @@ import type {
|
||||
CreateSkillRequest,
|
||||
UpdateSkillRequest,
|
||||
SkillScope,
|
||||
InstallSkillFromGithubRequest,
|
||||
InstallSkillResponse,
|
||||
} from './types/settings'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { fetchWrapper, FetchError } from './fetchWrapper'
|
||||
@@ -270,43 +268,6 @@ export const settingsApi = {
|
||||
method: 'DELETE',
|
||||
})
|
||||
},
|
||||
|
||||
installSkillFromGithub: async (data: InstallSkillFromGithubRequest): Promise<InstallSkillResponse> => {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/skills/install`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
},
|
||||
|
||||
installSkillFromUpload: async (data: {
|
||||
files: File[]
|
||||
scope: SkillScope
|
||||
repoId?: number
|
||||
overwrite?: boolean
|
||||
}): Promise<InstallSkillResponse> => {
|
||||
const formData = new FormData()
|
||||
formData.append('sourceType', 'upload')
|
||||
formData.append('scope', data.scope)
|
||||
if (data.repoId !== undefined) formData.append('repoId', String(data.repoId))
|
||||
if (data.overwrite !== undefined) formData.append('overwrite', String(data.overwrite))
|
||||
|
||||
const fileManifest: Array<{ fieldName: string; relativePath: string }> = []
|
||||
|
||||
data.files.forEach((file, index) => {
|
||||
const fieldName = `file${index}`
|
||||
const relativePath = file.webkitRelativePath || file.name
|
||||
fileManifest.push({ fieldName, relativePath })
|
||||
formData.append(fieldName, file)
|
||||
})
|
||||
|
||||
formData.append('fileManifest', JSON.stringify(fileManifest))
|
||||
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/skills/install`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
export interface VersionInfo {
|
||||
|
||||
@@ -15,14 +15,10 @@ import {
|
||||
type CreateSkillRequest,
|
||||
type UpdateSkillRequest,
|
||||
type SkillScope,
|
||||
type InstallSkillFromGithubRequest,
|
||||
type InstallSkillUploadRequest,
|
||||
type InstallSkillUploadManifestEntry,
|
||||
type InstallSkillResponse,
|
||||
} from '@opencode-manager/shared'
|
||||
import type { NotificationPreferences } from '@opencode-manager/shared/types'
|
||||
|
||||
export type { TTSConfig, STTConfig, OpenCodeConfigContent, ModelConfig, ProviderConfig, NotificationPreferences, SkillFileInfo, CreateSkillRequest, UpdateSkillRequest, SkillScope, InstallSkillFromGithubRequest, InstallSkillUploadRequest, InstallSkillUploadManifestEntry, InstallSkillResponse }
|
||||
export type { TTSConfig, STTConfig, OpenCodeConfigContent, ModelConfig, ProviderConfig, NotificationPreferences, SkillFileInfo, CreateSkillRequest, UpdateSkillRequest, SkillScope }
|
||||
export { DEFAULT_TTS_CONFIG, DEFAULT_STT_CONFIG, DEFAULT_KEYBOARD_SHORTCUTS, DEFAULT_USER_PREFERENCES, DEFAULT_LEADER_KEY, BLOCKED_SERVER_ENV_KEYS, DEFAULT_SERVER_ENV_VARS }
|
||||
|
||||
export interface CustomCommand {
|
||||
|
||||
Reference in new issue
Block a user