mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat: add workspace plugin for OpenCode TUI integration
- Add @opencode-manager/workspace-plugin package - Add API tokens management with scoped access control - Add workspace-plugin routes for project discovery - Add bearer token authentication for external access - Add proxy WebSocket support for remote workspaces - Add frontend UI for API token management - Update documentation with workspace plugin guide
This commit is contained in:
1 parent
0836e324a3
commit
d5342ecd91
118 files changed
+7831
-1715
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { PluginOptionsSchema } from '../src/types'
|
||||
import { resolveConfig } from '../src/index'
|
||||
|
||||
describe('PluginOptionsSchema', () => {
|
||||
it('accepts url from options', () => {
|
||||
const parsed = PluginOptionsSchema.parse({ url: 'http://test.com' })
|
||||
expect(parsed.url).toBe('http://test.com')
|
||||
})
|
||||
|
||||
it('accepts token from options', () => {
|
||||
const parsed = PluginOptionsSchema.parse({ token: 'test-token' })
|
||||
expect(parsed.token).toBe('test-token')
|
||||
})
|
||||
|
||||
it('requires token to be non-empty', () => {
|
||||
expect(() => PluginOptionsSchema.parse({ token: '' })).toThrow()
|
||||
})
|
||||
|
||||
it('rejects malformed url', () => {
|
||||
expect(() => PluginOptionsSchema.parse({ url: 'not-a-url' })).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveConfig', () => {
|
||||
const ORIGINAL_URL = process.env.OPENCODE_MANAGER_URL
|
||||
const ORIGINAL_TOKEN = process.env.OPENCODE_MANAGER_TOKEN
|
||||
|
||||
beforeEach(() => {
|
||||
delete process.env.OPENCODE_MANAGER_URL
|
||||
delete process.env.OPENCODE_MANAGER_TOKEN
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
if (ORIGINAL_URL === undefined) delete process.env.OPENCODE_MANAGER_URL
|
||||
else process.env.OPENCODE_MANAGER_URL = ORIGINAL_URL
|
||||
if (ORIGINAL_TOKEN === undefined) delete process.env.OPENCODE_MANAGER_TOKEN
|
||||
else process.env.OPENCODE_MANAGER_TOKEN = ORIGINAL_TOKEN
|
||||
})
|
||||
|
||||
it('uses options when provided', () => {
|
||||
const cfg = resolveConfig({ url: 'http://options.com', token: 'options-token' })
|
||||
expect(cfg).toEqual({ url: 'http://options.com', token: 'options-token' })
|
||||
})
|
||||
|
||||
it('falls back to env vars when options omit fields', () => {
|
||||
process.env.OPENCODE_MANAGER_URL = 'http://env.com'
|
||||
process.env.OPENCODE_MANAGER_TOKEN = 'env-token'
|
||||
|
||||
const cfg = resolveConfig({})
|
||||
expect(cfg).toEqual({ url: 'http://env.com', token: 'env-token' })
|
||||
})
|
||||
|
||||
it('prefers options over env vars when both present', () => {
|
||||
process.env.OPENCODE_MANAGER_URL = 'http://env.com'
|
||||
process.env.OPENCODE_MANAGER_TOKEN = 'env-token'
|
||||
|
||||
const cfg = resolveConfig({ url: 'http://options.com', token: 'options-token' })
|
||||
expect(cfg).toEqual({ url: 'http://options.com', token: 'options-token' })
|
||||
})
|
||||
|
||||
it('throws when url missing from both options and env', () => {
|
||||
process.env.OPENCODE_MANAGER_TOKEN = 'env-token'
|
||||
expect(() => resolveConfig({})).toThrow(/missing `url`/)
|
||||
})
|
||||
|
||||
it('throws when token missing from both options and env', () => {
|
||||
process.env.OPENCODE_MANAGER_URL = 'http://env.com'
|
||||
expect(() => resolveConfig({})).toThrow(/missing `token`/)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user