mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(workspace): switch to local workspace targeting with TUI prewarming
This commit is contained in:
1 parent
7870e97c38
commit
7a46fa27c5
19 files changed
+530
-479
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { PluginOptionsSchema } from '../src/types'
|
||||
import { resolveConfig } from '../src/index'
|
||||
import type { WorkspaceInfo } from '@opencode-ai/plugin'
|
||||
@@ -14,6 +14,12 @@ describe('PluginOptionsSchema', () => {
|
||||
expect(parsed.token).toBe('test-token')
|
||||
})
|
||||
|
||||
it('ignores unknown fields', () => {
|
||||
const parsed = PluginOptionsSchema.parse({ url: 'http://test.com', token: 'test', unknownField: 'ignored' })
|
||||
expect(parsed.url).toBe('http://test.com')
|
||||
expect(parsed.token).toBe('test')
|
||||
})
|
||||
|
||||
it('requires token to be non-empty', () => {
|
||||
expect(() => PluginOptionsSchema.parse({ token: '' })).toThrow()
|
||||
})
|
||||
@@ -40,8 +46,14 @@ describe('resolveConfig', () => {
|
||||
})
|
||||
|
||||
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' })
|
||||
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', () => {
|
||||
@@ -49,15 +61,24 @@ describe('resolveConfig', () => {
|
||||
process.env.OPENCODE_MANAGER_TOKEN = 'env-token'
|
||||
|
||||
const cfg = resolveConfig({})
|
||||
expect(cfg).toEqual({ url: 'http://env.com', token: 'env-token' })
|
||||
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' })
|
||||
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', () => {
|
||||
@@ -78,32 +99,56 @@ describe('adaptor.target', () => {
|
||||
extra: {},
|
||||
}
|
||||
|
||||
it('returns { type: "remote", url, headers } with bearer auth when target is invoked', async () => {
|
||||
const baseCfg = {
|
||||
url: 'http://manager.test:5003',
|
||||
token: 'tok-abc',
|
||||
}
|
||||
|
||||
it('returns { type: "local", directory: project.directory }', async () => {
|
||||
const { makeAdaptor } = await import('../src/index.js')
|
||||
const cfg = { url: 'http://manager.test:5003', token: 'tok-abc' }
|
||||
const project = { slug: '42', name: 'Test Project', directory: '/workspace/repos/test' }
|
||||
const adaptor = makeAdaptor(cfg, project)
|
||||
const adaptor = makeAdaptor(baseCfg, project)
|
||||
const result = adaptor.target(sampleInfo)
|
||||
expect(result.type).toBe('remote')
|
||||
expect(result.url).toBe('http://manager.test:5003/api/workspace-plugin/opencode/42')
|
||||
expect(result.headers).toEqual({ Authorization: 'Bearer tok-abc' })
|
||||
expect(result.type).toBe('local')
|
||||
expect(result.directory).toBe('/workspace/repos/test')
|
||||
})
|
||||
|
||||
it('url-encodes special slug characters', async () => {
|
||||
it('returns directory from project, not from info', async () => {
|
||||
const { makeAdaptor } = await import('../src/index.js')
|
||||
const cfg = { url: 'http://manager.test:5003', token: 'tok-abc' }
|
||||
const project = { slug: 'a/b c', name: 'Test Project', directory: '/workspace/repos/test' }
|
||||
const adaptor = makeAdaptor(cfg, project)
|
||||
const result = adaptor.target(sampleInfo)
|
||||
expect(result.url).toContain('a%2Fb%20c')
|
||||
})
|
||||
|
||||
it('strips trailing slash from manager url', async () => {
|
||||
const { makeAdaptor } = await import('../src/index.js')
|
||||
const cfg = { url: 'http://manager.test:5003/', token: 'tok-abc' }
|
||||
const project = { slug: '42', name: 'Test Project', directory: '/workspace/repos/test' }
|
||||
const adaptor = makeAdaptor(cfg, project)
|
||||
const adaptor = makeAdaptor(baseCfg, project)
|
||||
const result = adaptor.target(sampleInfo)
|
||||
expect(result.url).toBe('http://manager.test:5003/api/workspace-plugin/opencode/42')
|
||||
expect(result.directory).toBe('/workspace/repos/test')
|
||||
})
|
||||
})
|
||||
|
||||
describe('adaptor.configure', () => {
|
||||
const sampleInfo: WorkspaceInfo = {
|
||||
name: 'Test Workspace',
|
||||
directory: '/test/dir',
|
||||
extra: {},
|
||||
}
|
||||
|
||||
const cfg = {
|
||||
url: 'http://manager.test:5003',
|
||||
token: 'tok-abc',
|
||||
}
|
||||
|
||||
it('returns project directory in configured workspace info', async () => {
|
||||
const { makeAdaptor } = await import('../src/index.js')
|
||||
const project = { slug: '42', name: 'Test Project', directory: '/workspace/repos/test' }
|
||||
const adaptor = makeAdaptor(cfg, project)
|
||||
const result = adaptor.configure(sampleInfo)
|
||||
expect(result.directory).toBe('/workspace/repos/test')
|
||||
})
|
||||
|
||||
it('returns extra with slug in configured workspace info', async () => {
|
||||
const { makeAdaptor } = await import('../src/index.js')
|
||||
const project = { slug: '42', name: 'Test Project', directory: '/workspace/repos/test' }
|
||||
const adaptor = makeAdaptor(cfg, project)
|
||||
const result = adaptor.configure(sampleInfo)
|
||||
expect(result.extra).toEqual({ slug: '42' })
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user