feat: switch workspace plugin to remote adaptor with manager proxy

Switch the @opencode-manager/workspace-plugin adaptor from type local to
type remote so opencode TUIs running on machines without filesystem access
can use the manager's managed opencode server as their workspace backend.

Phase 1 - Plugin adaptor:
- Update target() to return type remote with manager URL and bearer auth
- Export makeAdaptor for testing
- Add tests for remote URL construction, slug encoding, and trailing slash

Phase 2 - HTTP proxy route:
- Add ALL /opencode/:slug/* catch-all proxy in workspace-plugin routes
- Reuses existing proxyRequest helper with slug-to-directory translation
- Rewrites inbound URL to /api/opencode/* shape for shared proxy logic
- Includes bearer token scope validation and project service

Phase 3 - WebSocket proxy:
- Extract verifyPluginBearerAuth as named function for reuse
- Attach second WebSocket proxy mount for /api/workspace-plugin/opencode prefix
- Both /api/opencode and /api/workspace-plugin/opencode prefixes supported

Phase 4 - Tests:
- Add 8 backend route tests covering auth, proxy forwarding, and POST body
- Add 3 plugin adaptor tests for remote target construction
This commit is contained in:
Chris Scott committed 2026-04-20 23:05:44 -04:00
1 parent ffab02f386
commit d07eb7f523
5 files changed
+318 -15

No files matched your search

+39 -1
View File
@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { PluginOptionsSchema } from '../src/types'
import { resolveConfig } from '../src/index'
import type { WorkspaceInfo } from '@opencode-ai/plugin'
describe('PluginOptionsSchema', () => {
it('accepts url from options', () => {
@@ -69,3 +70,40 @@ describe('resolveConfig', () => {
expect(() => resolveConfig({})).toThrow(/missing `token`/)
})
})
describe('adaptor.target', () => {
const sampleInfo: WorkspaceInfo = {
name: 'Test Workspace',
directory: '/test/dir',
extra: {},
}
it('returns { type: "remote", url, headers } with bearer auth when target is invoked', 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 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' })
})
it('url-encodes special slug characters', 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 result = adaptor.target(sampleInfo)
expect(result.url).toBe('http://manager.test:5003/api/workspace-plugin/opencode/42')
})
})