chore(opencode): move the pinned OpenCode version to 2.1.2

The supported floor is derived from the pin, so this raises the accepted
range to >=2.1.2 <3.0.0 for the bundled image, managed installs, and the
version check that gates startup.

- Dockerfile ARG OPENCODE_VERSION and the shared pin move together
- CI e2e installs 2.1.2 instead of 2.0.24
- contract, installer, manager, registry and settings fixtures follow the new
  floor, keeping their below-floor and wrong-major rejection cases
This commit is contained in:
Chris Scott committed 2026-10-23 14:41:48 -04:00
1 parent 36a5693b5c
commit 19b52ecd58
9 files changed
+191 -189

No files matched your search

+1 -1
View File
@@ -125,7 +125,7 @@ jobs:
- name: Install OpenCode CLI
run: |
source scripts/lib/opencode-release.sh
download_opencode_to 2.0.24 "$RUNNER_TEMP/opencode/bin/opencode"
download_opencode_to 2.1.2 "$RUNNER_TEMP/opencode/bin/opencode"
echo "$RUNNER_TEMP/opencode/bin" >> "$GITHUB_PATH"
- name: Verify OpenCode CLI
+1 -1
View File
@@ -63,7 +63,7 @@ FROM base AS runner
# an arm64 host builds the amd64 platform; 0.12.7 is the newest verified-good
# release, so re-verify a bump there before moving it.
ARG UV_VERSION=0.12.7
ARG OPENCODE_VERSION=2.0.15
ARG OPENCODE_VERSION=2.1.2
ARG MICROSANDBOX_VERSION=0.7.2
ARG PLAYWRIGHT_VERSION=1.63.0
# Bump TOOLS_CACHEBUST (e.g. via --build-arg) to force a fresh uv/opencode
@@ -449,7 +449,7 @@ describe('OpenCodeServerRegistry', () => {
describe('test', () => {
it('reports a supported version', async () => {
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.0.15' }))
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.1.2' }))
const result = await registry.test({
baseUrl: 'https://studio.example.com/',
@@ -457,7 +457,7 @@ describe('OpenCodeServerRegistry', () => {
password: 'super-secret',
})
expect(result).toEqual({ ok: true, version: '2.0.15', versionSupported: true, error: null })
expect(result).toEqual({ ok: true, version: '2.1.2', versionSupported: true, error: null })
expect(fetchFn.mock.calls[0]?.[0]).toBe('https://studio.example.com/api/info')
const headers = new Headers(fetchFn.mock.calls[0]?.[1]?.headers)
expect(headers.get('authorization')).toBe(`Basic ${btoa('alice:super-secret')}`)
@@ -478,7 +478,7 @@ describe('OpenCodeServerRegistry', () => {
username: 'alice',
password: 'super-secret',
})
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.0.15' }))
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.1.2' }))
const result = await registry.test({ serverId: server.id })
@@ -493,7 +493,7 @@ describe('OpenCodeServerRegistry', () => {
baseUrl: 'https://studio.example.com',
password: 'super-secret',
})
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.0.15' }))
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.1.2' }))
const result = await registry.test({
baseUrl: 'https://studio.example.com/opencode',
@@ -513,7 +513,7 @@ describe('OpenCodeServerRegistry', () => {
baseUrl: 'https://studio.example.com',
password: 'super-secret',
})
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.0.15' }))
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.1.2' }))
const result = await registry.test({
baseUrl: 'https://relocated.example.com',
@@ -533,7 +533,7 @@ describe('OpenCodeServerRegistry', () => {
baseUrl: 'https://studio.example.com',
password: 'super-secret',
})
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.0.15' }))
fetchFn.mockResolvedValueOnce(jsonResponse({ version: '2.1.2' }))
await registry.test({
baseUrl: 'https://studio.example.com',
+1 -1
View File
@@ -16,7 +16,7 @@ vi.mock('child_process', () => ({
spawn: childProcessMock.spawn,
}))
const SUPPORTED_VERSION = '2.0.15'
const SUPPORTED_VERSION = '2.1.2'
const OPENCODE_BIN_FIXTURE = '/fixture/opencode-2'
const PATH_CANDIDATE = 'opencode'
const ABSOLUTE_CANDIDATES = ['/usr/local/bin/opencode', '/opt/opencode/bin/opencode']
+89 -89
View File
@@ -377,7 +377,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
mockInstallOpenCodeVersion.mockResolvedValue('/home/node/.opencode/bin/opencode')
clearOpenCodeVersionCache()
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({
versions: { '2.0.15': {} },
versions: { '2.1.2': {} },
time: {},
}), { status: 200 })))
forceProcessAttestation(true)
@@ -756,8 +756,8 @@ describe('Settings Routes - OpenCode Upgrade', () => {
describe('POST /opencode-upgrade', () => {
describe('successful upgrade scenarios', () => {
it('should install the latest version and respond with success', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const req = new Request('http://localhost/opencode-upgrade', {
@@ -769,14 +769,14 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(res.status).toBe(200)
expect(json.success).toBe(true)
expect(json.upgraded).toBe(true)
expect(json.oldVersion).toBe('2.0.14')
expect(json.newVersion).toBe('2.0.15')
expect(json.message).toBe('OpenCode upgraded from v2.0.14 to v2.0.15 and restarted')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.0.15')
expect(json.oldVersion).toBe('2.1.1')
expect(json.newVersion).toBe('2.1.2')
expect(json.message).toBe('OpenCode upgraded from v2.1.1 to v2.1.2 and restarted')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.1.2')
})
it('should not install when the latest version is not newer', async () => {
mockGetVersion.mockReturnValueOnce('2.0.15')
mockGetVersion.mockReturnValueOnce('2.1.2')
const req = new Request('http://localhost/opencode-upgrade', {
method: 'POST'
@@ -794,7 +794,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
it('should replace an unsupported newer major with the latest supported release', async () => {
mockGetVersion.mockReturnValueOnce('3.0.0')
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const res = await settingsApp.fetch(new Request('http://localhost/opencode-upgrade', { method: 'POST' }))
@@ -802,12 +802,12 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(res.status).toBe(200)
expect(json.upgraded).toBe(true)
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.0.15')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.1.2')
})
it('should restart directly after a successful upgrade', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const req = new Request('http://localhost/opencode-upgrade', {
@@ -820,22 +820,22 @@ describe('Settings Routes - OpenCode Upgrade', () => {
it('allows upgrading while sandbox enforcement is active', async () => {
mockIsSandboxEnforced.mockReturnValue(true)
mockGetVersion.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const res = await settingsApp.fetch(new Request('http://localhost/opencode-upgrade', { method: 'POST' }))
expect(res.status).toBe(200)
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.0.15')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.1.2')
expect(mockRestart).toHaveBeenCalled()
})
})
describe('failure and recovery scenarios', () => {
it('should attempt server recovery when the install fails after the binary swap started', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
.mockReturnValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
.mockReturnValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new OpenCodeInstallError('download failed', true))
const req = new Request('http://localhost/opencode-upgrade', {
@@ -850,14 +850,14 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(json).toMatchObject({
upgraded: false,
recovered: true,
oldVersion: '2.0.14',
newVersion: '2.0.14'
oldVersion: '2.1.1',
newVersion: '2.1.1'
})
expect(json.error).toContain('recovered')
})
it('should not restart the server when the install fails before the binary swap', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new OpenCodeInstallError('download failed', false))
const req = new Request('http://localhost/opencode-upgrade', {
@@ -871,14 +871,14 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(json).toMatchObject({
upgraded: false,
recovered: false,
oldVersion: '2.0.14',
newVersion: '2.0.14'
oldVersion: '2.1.1',
newVersion: '2.1.1'
})
})
it('should return 500 when recovery fails', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
.mockReturnValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
.mockReturnValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new OpenCodeInstallError('download failed', true))
mockRestart.mockRejectedValueOnce(new Error('Restart failed'))
@@ -896,7 +896,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
describe('version handling', () => {
it('should install and restart when getVersion returns null', async () => {
mockGetVersion.mockReturnValueOnce(null)
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const req = new Request('http://localhost/opencode-upgrade', {
@@ -909,8 +909,8 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(json.success).toBe(true)
expect(json.upgraded).toBe(true)
expect(json.oldVersion).toBe(null)
expect(json.newVersion).toBe('2.0.15')
expect(json.message).toBe('OpenCode v2.0.15 installed and restarted')
expect(json.newVersion).toBe('2.1.2')
expect(json.message).toBe('OpenCode v2.1.2 installed and restarted')
expect(mockFetchVersion).toHaveBeenCalled()
expect(mockClearStartupError).toHaveBeenCalled()
expect(mockRestart).toHaveBeenCalledTimes(1)
@@ -932,13 +932,13 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(json.upgraded).toBe(false)
expect(json.recovered).toBe(true)
expect(json.error).toBe('Upgrade failed but server recovered')
expect(json.details).toContain('did not result in version 2.0.15')
expect(json.details).toContain('did not result in version 2.1.2')
expect(mockRestart).toHaveBeenCalledTimes(1)
})
it('should not report success when an override still resolves to the older version', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const res = await settingsApp.fetch(new Request('http://localhost/opencode-upgrade', { method: 'POST' }))
@@ -949,7 +949,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(json.upgraded).toBe(false)
expect(json.recovered).toBe(true)
expect(json.error).toBe('Upgrade failed but server recovered')
expect(json.details).toContain('did not result in version 2.0.15')
expect(json.details).toContain('did not result in version 2.1.2')
expect(mockRestart).toHaveBeenCalledTimes(1)
})
})
@@ -958,13 +958,13 @@ describe('Settings Routes - OpenCode Upgrade', () => {
describe('POST /opencode-install-version', () => {
describe('successful installation', () => {
it('should install specific version successfully', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const req = new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
headers: { 'Content-Type': 'application/json' }
})
const res = await settingsApp.fetch(req)
@@ -972,70 +972,70 @@ describe('Settings Routes - OpenCode Upgrade', () => {
expect(res.status).toBe(200)
expect(json.success).toBe(true)
expect(json.newVersion).toBe('2.0.15')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.0.15')
expect(json.newVersion).toBe('2.1.2')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.1.2')
})
it('does not report success when the requested version was not installed', async () => {
mockGetVersion.mockReturnValue('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.14')
mockGetVersion.mockReturnValue('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const res = await settingsApp.fetch(new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
headers: { 'Content-Type': 'application/json' }
}))
const json = await res.json() as Record<string, unknown>
expect(res.status).toBe(400)
expect(json.success).toBe(false)
expect(json.details).toContain('did not result in version 2.0.15')
expect(json.newVersion).toBe('2.0.14')
expect(json.details).toContain('did not result in version 2.1.2')
expect(json.newVersion).toBe('2.1.1')
})
it('allows installing any version while sandbox enforcement is active', async () => {
mockIsSandboxEnforced.mockReturnValue(true)
mockGetVersion.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const res = await settingsApp.fetch(new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
headers: { 'Content-Type': 'application/json' }
}))
expect(res.status).toBe(200)
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.0.15')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.1.2')
})
it('should install the bare version when the request carries a v prefix', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.15')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const req = new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version: 'v2.0.15' }),
body: JSON.stringify({ version: 'v2.1.2' }),
headers: { 'Content-Type': 'application/json' }
})
await settingsApp.fetch(req)
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.0.15')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.1.2')
})
})
describe('failure and recovery', () => {
it('should recover the server when the version install fails after the binary swap started', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
.mockReturnValueOnce('2.0.14')
mockFetchVersion.mockResolvedValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockResolvedValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new OpenCodeInstallError('download failed', true))
const req = new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
headers: { 'Content-Type': 'application/json' }
})
const res = await settingsApp.fetch(req)
@@ -1047,12 +1047,12 @@ describe('Settings Routes - OpenCode Upgrade', () => {
})
it('should not restart the server when the version install fails before the binary swap', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new OpenCodeInstallError('download failed', false))
const req = new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
headers: { 'Content-Type': 'application/json' }
})
const res = await settingsApp.fetch(req)
@@ -1119,11 +1119,11 @@ describe('Settings Routes - OpenCode Upgrade', () => {
const json = await res.json() as Record<string, unknown>
expect(res.status).toBe(400)
expect(json.error).toBe('OpenCode 1.18.32 is not supported; OpenCode Manager requires OpenCode >=2.0.15 <3.0.0')
expect(json.error).toBe('OpenCode 1.18.32 is not supported; OpenCode Manager requires OpenCode >=2.1.2 <3.0.0')
expect(mockInstallOpenCodeVersion).not.toHaveBeenCalled()
})
it.each(['2.0.14', '3.0.0'])('should reject %s outside the supported range before installing anything', async (version) => {
it.each(['2.1.1', '3.0.0'])('should reject %s outside the supported range before installing anything', async (version) => {
const res = await settingsApp.fetch(new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version }),
@@ -1132,14 +1132,14 @@ describe('Settings Routes - OpenCode Upgrade', () => {
const json = await res.json() as Record<string, unknown>
expect(res.status).toBe(400)
expect(json.error).toBe(`OpenCode ${version} is not supported; OpenCode Manager requires OpenCode >=2.0.15 <3.0.0`)
expect(json.error).toBe(`OpenCode ${version} is not supported; OpenCode Manager requires OpenCode >=2.1.2 <3.0.0`)
expect(mockInstallOpenCodeVersion).not.toHaveBeenCalled()
})
it('should reject a prerelease version before installing anything', async () => {
const res = await settingsApp.fetch(new Request('http://localhost/opencode-install-version', {
method: 'POST',
body: JSON.stringify({ version: '2.1.0-beta.1' }),
body: JSON.stringify({ version: '2.1.2-beta.1' }),
headers: { 'Content-Type': 'application/json' }
}))
@@ -1176,7 +1176,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
const res = await settingsApp.fetch(new Request('http://localhost/opencode-install-version', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
}))
const json = await res.json() as Record<string, unknown>
@@ -1189,7 +1189,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
describe('error scenarios - server stability', () => {
it('should not restart the server when the install fails before the binary swap', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new OpenCodeInstallError('Unexpected error', false))
mockRestart.mockResolvedValue(undefined)
@@ -1205,7 +1205,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
})
it('should not crash when getVersion throws error during failure recovery', async () => {
mockGetVersion.mockImplementationOnce(() => '2.0.14')
mockGetVersion.mockImplementationOnce(() => '2.1.1')
.mockImplementationOnce(() => {
throw new Error('GetVersion failed')
})
@@ -1222,8 +1222,8 @@ describe('Settings Routes - OpenCode Upgrade', () => {
})
it('should handle fetchVersion throwing error during normal upgrade', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
.mockReturnValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
.mockReturnValueOnce('2.1.1')
mockFetchVersion.mockRejectedValueOnce(new Error('Fetch version failed'))
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
@@ -1239,8 +1239,8 @@ describe('Settings Routes - OpenCode Upgrade', () => {
})
it('should not leave server in broken state when the install fails', async () => {
mockGetVersion.mockReturnValueOnce('2.0.14')
.mockReturnValueOnce('2.0.14')
mockGetVersion.mockReturnValueOnce('2.1.1')
.mockReturnValueOnce('2.1.1')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new OpenCodeInstallError('install failed', true))
mockRestart.mockResolvedValue(undefined)
@@ -1892,8 +1892,8 @@ describe('Settings Routes - versions, directory files, skills, MCP and maintenan
fetchMock = vi.fn()
vi.stubGlobal('fetch', fetchMock)
clearOpenCodeVersionCache()
mockGetVersion.mockReturnValue('2.0.15')
mockFetchVersion.mockResolvedValue('2.0.15')
mockGetVersion.mockReturnValue('2.1.2')
mockFetchVersion.mockResolvedValue('2.1.2')
mockInstallOpenCodeVersion.mockReset()
mockInstallOpenCodeVersion.mockResolvedValue('/home/node/.opencode/bin/opencode')
mockClearStartupError.mockReturnValue(undefined)
@@ -1915,15 +1915,15 @@ describe('Settings Routes - versions, directory files, skills, MCP and maintenan
fetchMock.mockResolvedValue(new Response(JSON.stringify({
versions: {
'1.18.32': {},
'2.0.14': {},
'2.0.15': {},
'2.0.16': {},
'2.1.0-beta.1': {},
'2.1.1': {},
'2.1.2': {},
'2.1.3': {},
'2.1.2-beta.1': {},
'3.0.0': {},
},
time: {
'2.0.15': '2026-01-02T00:00:00Z',
'2.0.16': '2026-01-03T00:00:00Z',
'2.1.2': '2026-01-02T00:00:00Z',
'2.1.3': '2026-01-03T00:00:00Z',
},
}), { status: 200 }))
@@ -1931,16 +1931,16 @@ describe('Settings Routes - versions, directory files, skills, MCP and maintenan
const json = await res.json() as { versions: Array<{ version: string; tag: string; name: string; publishedAt: string | null }>; currentVersion: string }
expect(res.status).toBe(200)
expect(json.currentVersion).toBe('2.0.15')
expect(json.currentVersion).toBe('2.1.2')
expect(json.versions).toEqual([
{ version: '2.0.16', tag: 'v2.0.16', name: 'v2.0.16', publishedAt: '2026-01-03T00:00:00Z' },
{ version: '2.0.15', tag: 'v2.0.15', name: 'v2.0.15', publishedAt: '2026-01-02T00:00:00Z' },
{ version: '2.1.3', tag: 'v2.1.3', name: 'v2.1.3', publishedAt: '2026-01-03T00:00:00Z' },
{ version: '2.1.2', tag: 'v2.1.2', name: 'v2.1.2', publishedAt: '2026-01-02T00:00:00Z' },
])
expect(fetchMock).toHaveBeenCalledWith('https://registry.npmjs.org/@opencode/cli')
})
it('serves repeated requests from the installer cache', async () => {
fetchMock.mockImplementation(async () => new Response(JSON.stringify({ versions: { '2.0.15': {} }, time: {} }), { status: 200 }))
fetchMock.mockImplementation(async () => new Response(JSON.stringify({ versions: { '2.1.2': {} }, time: {} }), { status: 200 }))
await app.request(new Request('http://localhost/opencode-versions'))
const res = await app.request(new Request('http://localhost/opencode-versions'))
@@ -1977,42 +1977,42 @@ describe('Settings Routes - versions, directory files, skills, MCP and maintenan
describe('POST /opencode-install-version', () => {
it('installs the requested version and restarts the server', async () => {
mockGetVersion.mockReturnValue('2.0.14')
mockFetchVersion.mockResolvedValue('2.0.15')
mockGetVersion.mockReturnValue('2.1.1')
mockFetchVersion.mockResolvedValue('2.1.2')
mockInstallOpenCodeVersion.mockResolvedValueOnce('/home/node/.opencode/bin/opencode')
const res = await app.request(new Request('http://localhost/opencode-install-version', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
}))
const json = await res.json() as { success: boolean; message: string; oldVersion: string; newVersion: string }
expect(res.status).toBe(200)
expect(json.success).toBe(true)
expect(json.oldVersion).toBe('2.0.14')
expect(json.newVersion).toBe('2.0.15')
expect(json.message).toContain('changed from v2.0.14 to v2.0.15')
expect(json.oldVersion).toBe('2.1.1')
expect(json.newVersion).toBe('2.1.2')
expect(json.message).toContain('changed from v2.1.1 to v2.1.2')
expect(supervisor.restart).toHaveBeenCalledTimes(1)
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.0.15')
expect(mockInstallOpenCodeVersion).toHaveBeenCalledWith('2.1.2')
})
it('returns 500 without restarting when the version install fails before the binary swap', async () => {
mockGetVersion.mockReturnValue('2.0.14')
mockFetchVersion.mockResolvedValue('2.0.15')
mockGetVersion.mockReturnValue('2.1.1')
mockFetchVersion.mockResolvedValue('2.1.2')
mockInstallOpenCodeVersion.mockRejectedValueOnce(new Error('download failed'))
supervisor.restart.mockResolvedValue({ healthy: false })
const res = await app.request(new Request('http://localhost/opencode-install-version', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ version: '2.0.15' }),
body: JSON.stringify({ version: '2.1.2' }),
}))
const json = await res.json() as { recovered: boolean; newVersion: string }
expect(res.status).toBe(500)
expect(json.recovered).toBe(false)
expect(json.newVersion).toBe('2.0.14')
expect(json.newVersion).toBe('2.1.1')
expect(supervisor.restart).not.toHaveBeenCalled()
})
})
@@ -131,46 +131,46 @@ describe('resolveOpenCodeInstallTarget', () => {
describe('installOpenCodeVersion', () => {
it('downloads, verifies and installs the requested version', async () => {
const homeDirectory = join(workDirectory, 'home')
const archivePath = createArchive(workDirectory, '2.0.15')
const archivePath = createArchive(workDirectory, '2.1.2')
const { calls, fetchFn } = createFetch(archivePath)
const installedPath = await installOpenCodeVersion('2.0.15', { fetch: fetchFn, homeDirectory, target: linuxTarget })
const installedPath = await installOpenCodeVersion('2.1.2', { fetch: fetchFn, homeDirectory, target: linuxTarget })
expect(installedPath).toBe(resolveOpenCodeBinaryPath(homeDirectory))
expect(calls).toEqual(['https://opencode.ai/files/bin/2.0.15/opencode-linux-x64.tar.gz'])
expect(calls).toEqual(['https://opencode.ai/files/bin/2.1.2/opencode-linux-x64.tar.gz'])
expect(statSync(installedPath).mode & 0o777).toBe(0o755)
expect(readFileSync(installedPath, 'utf-8')).toContain('2.0.15')
expect(readFileSync(installedPath, 'utf-8')).toContain('2.1.2')
})
it('requests the musl asset for a musl linux target', async () => {
const homeDirectory = join(workDirectory, 'home')
const archivePath = createArchive(workDirectory, '2.0.15')
const archivePath = createArchive(workDirectory, '2.1.2')
const { calls, fetchFn } = createFetch(archivePath)
await installOpenCodeVersion('2.0.15', {
await installOpenCodeVersion('2.1.2', {
fetch: fetchFn,
homeDirectory,
target: { platform: 'linux', arch: 'arm64', musl: true },
})
expect(calls).toEqual(['https://opencode.ai/files/bin/2.0.15/opencode-linux-arm64-musl.tar.gz'])
expect(calls).toEqual(['https://opencode.ai/files/bin/2.1.2/opencode-linux-arm64-musl.tar.gz'])
})
it('extracts the darwin zip asset and installs it', async () => {
const homeDirectory = join(workDirectory, 'home')
const archivePath = createDarwinArchive(workDirectory, '2.0.15')
const archivePath = createDarwinArchive(workDirectory, '2.1.2')
const { calls, fetchFn } = createFetch(archivePath)
const installedPath = await installOpenCodeVersion('2.0.15', {
const installedPath = await installOpenCodeVersion('2.1.2', {
fetch: fetchFn,
homeDirectory,
target: { platform: 'darwin', arch: 'arm64', musl: false },
})
expect(calls).toEqual(['https://opencode.ai/files/bin/2.0.15/opencode-darwin-arm64.zip'])
expect(calls).toEqual(['https://opencode.ai/files/bin/2.1.2/opencode-darwin-arm64.zip'])
expect(installedPath).toBe(resolveOpenCodeBinaryPath(homeDirectory))
expect(statSync(installedPath).mode & 0o777).toBe(0o755)
expect(readFileSync(installedPath, 'utf-8')).toContain('2.0.15')
expect(readFileSync(installedPath, 'utf-8')).toContain('2.1.2')
})
it('rejects an OpenCode 1.x version before downloading anything', async () => {
@@ -178,18 +178,18 @@ describe('installOpenCodeVersion', () => {
const { calls, fetchFn } = createFetch(null)
await expect(installOpenCodeVersion('1.18.32', { fetch: fetchFn, homeDirectory, target: linuxTarget }))
.rejects.toThrow('OpenCode 1.18.32 is not supported; OpenCode Manager requires OpenCode >=2.0.15 <3.0.0')
.rejects.toThrow('OpenCode 1.18.32 is not supported; OpenCode Manager requires OpenCode >=2.1.2 <3.0.0')
expect(calls).toEqual([])
})
it.each(['2.0.14', '3.0.0', '2.1.0-beta.1', '2.0.15; rm -rf /'])(
it.each(['2.1.1', '3.0.0', '2.1.2-beta.1', '2.1.2; rm -rf /'])(
'rejects %s outside the supported stable range before downloading anything',
async (version) => {
const homeDirectory = join(workDirectory, 'home')
const { calls, fetchFn } = createFetch(null)
await expect(installOpenCodeVersion(version, { fetch: fetchFn, homeDirectory, target: linuxTarget }))
.rejects.toThrow(/requires OpenCode >=2\.0\.15 <3\.0\.0/)
.rejects.toThrow(/requires OpenCode >=2\.1\.2 <3\.0\.0/)
expect(calls).toEqual([])
},
)
@@ -198,41 +198,41 @@ describe('installOpenCodeVersion', () => {
const homeDirectory = join(workDirectory, 'home')
const { fetchFn } = createFetch(null, 404)
await expect(installOpenCodeVersion('2.0.15', { fetch: fetchFn, homeDirectory, target: linuxTarget }))
await expect(installOpenCodeVersion('2.1.2', { fetch: fetchFn, homeDirectory, target: linuxTarget }))
.rejects.toThrow(/404/)
expect(() => statSync(resolveOpenCodeBinaryPath(homeDirectory))).toThrow()
})
it('fails and leaves no binary behind when the archive reports a different version', async () => {
const homeDirectory = join(workDirectory, 'home')
const archivePath = createArchive(workDirectory, '2.0.16')
const archivePath = createArchive(workDirectory, '2.1.3')
const { fetchFn } = createFetch(archivePath)
await expect(installOpenCodeVersion('2.0.15', { fetch: fetchFn, homeDirectory, target: linuxTarget }))
.rejects.toThrow(/2\.0\.15/)
await expect(installOpenCodeVersion('2.1.2', { fetch: fetchFn, homeDirectory, target: linuxTarget }))
.rejects.toThrow(/2\.1\.2/)
expect(() => statSync(resolveOpenCodeBinaryPath(homeDirectory))).toThrow()
})
it('replaces an existing installed binary with the requested version', async () => {
const homeDirectory = join(workDirectory, 'home')
mkdirSync(join(homeDirectory, '.opencode', 'bin'), { recursive: true })
writeFileSync(resolveOpenCodeBinaryPath(homeDirectory), '#!/bin/sh\necho "opencode v2.0.14"\n')
writeFileSync(resolveOpenCodeBinaryPath(homeDirectory), '#!/bin/sh\necho "opencode v2.1.1"\n')
const archivePath = createArchive(workDirectory, '2.0.15')
const archivePath = createArchive(workDirectory, '2.1.2')
const { fetchFn } = createFetch(archivePath)
await installOpenCodeVersion('2.0.15', { fetch: fetchFn, homeDirectory, target: linuxTarget })
await installOpenCodeVersion('2.1.2', { fetch: fetchFn, homeDirectory, target: linuxTarget })
expect(readFileSync(resolveOpenCodeBinaryPath(homeDirectory), 'utf-8')).toContain('2.0.15')
expect(readFileSync(resolveOpenCodeBinaryPath(homeDirectory), 'utf-8')).toContain('2.1.2')
})
it('cleans up its staging directory after a successful install', async () => {
const homeDirectory = join(workDirectory, 'home')
const archivePath = createArchive(workDirectory, '2.0.15')
const archivePath = createArchive(workDirectory, '2.1.2')
const { fetchFn } = createFetch(archivePath)
const before = countStagingDirectories()
await installOpenCodeVersion('2.0.15', { fetch: fetchFn, homeDirectory, target: linuxTarget })
await installOpenCodeVersion('2.1.2', { fetch: fetchFn, homeDirectory, target: linuxTarget })
expect(countStagingDirectories()).toBe(before)
})
@@ -242,17 +242,17 @@ describe('listOpenCodeVersions', () => {
const registryPayload = {
versions: {
'1.18.32': {},
'2.0.0': {},
'2.0.14': {},
'2.0.15': {},
'2.0.16': {},
'2.1.0-beta.1': {},
'2.1.1': {},
'2.1.2': {},
'2.1.3': {},
'2.1.2-beta.1': {},
'3.0.0': {},
'not-a-version': {},
},
time: {
'2.0.15': '2026-02-01T00:00:00.000Z',
'2.0.16': '2026-03-01T00:00:00.000Z',
'2.1.2': '2026-02-01T00:00:00.000Z',
'2.1.3': '2026-03-01T00:00:00.000Z',
},
}
@@ -262,20 +262,20 @@ describe('listOpenCodeVersions', () => {
const versions = await listOpenCodeVersions({ fetch: fetchFn })
expect(versions).toEqual([
{ version: '2.0.16', publishedAt: '2026-03-01T00:00:00.000Z' },
{ version: '2.0.15', publishedAt: '2026-02-01T00:00:00.000Z' },
{ version: '2.1.3', publishedAt: '2026-03-01T00:00:00.000Z' },
{ version: '2.1.2', publishedAt: '2026-02-01T00:00:00.000Z' },
])
expect(calls).toEqual(['https://registry.npmjs.org/@opencode/cli'])
})
it('reports a null publishedAt when the registry has no timestamp for a version', async () => {
const { fetchFn } = createRegistryFetch({
versions: { '2.0.20': {} },
versions: { '2.1.5': {} },
time: {},
})
await expect(listOpenCodeVersions({ fetch: fetchFn })).resolves.toEqual([
{ version: '2.0.20', publishedAt: null },
{ version: '2.1.5', publishedAt: null },
])
})
@@ -293,14 +293,14 @@ describe('listOpenCodeVersions', () => {
it('refreshes the list once the five minute cache expires', async () => {
const stale = createRegistryFetch(registryPayload)
const fresh = createRegistryFetch({ versions: { '2.0.17': {} }, time: {} })
const fresh = createRegistryFetch({ versions: { '2.1.7': {} }, time: {} })
let now = 1_000_000
await listOpenCodeVersions({ fetch: stale.fetchFn, now: () => now })
now += 5 * 60 * 1000
const refreshed = await listOpenCodeVersions({ fetch: fresh.fetchFn, now: () => now })
expect(refreshed).toEqual([{ version: '2.0.17', publishedAt: null }])
expect(refreshed).toEqual([{ version: '2.1.7', publishedAt: null }])
expect(stale.calls).toHaveLength(1)
expect(fresh.calls).toHaveLength(1)
})
@@ -331,7 +331,7 @@ describe('OpenCodeInstallError swap signalling', () => {
const homeDirectory = join(workDirectory, 'home')
const { fetchFn } = createFetch(null, 404)
const promise = installOpenCodeVersion('2.0.15', { fetch: fetchFn, homeDirectory, target: linuxTarget })
const promise = installOpenCodeVersion('2.1.2', { fetch: fetchFn, homeDirectory, target: linuxTarget })
await expect(promise).rejects.toBeInstanceOf(OpenCodeInstallError)
await expect(promise).rejects.toMatchObject({ swapStarted: false })
@@ -341,10 +341,10 @@ describe('OpenCodeInstallError swap signalling', () => {
it('marks a failure while replacing the binary as having started the binary swap', async () => {
const homeDirectory = join(workDirectory, 'home')
mkdirSync(resolveOpenCodeBinaryPath(homeDirectory), { recursive: true })
const archivePath = createArchive(workDirectory, '2.0.15')
const archivePath = createArchive(workDirectory, '2.1.2')
const { fetchFn } = createFetch(archivePath)
const promise = installOpenCodeVersion('2.0.15', { fetch: fetchFn, homeDirectory, target: linuxTarget })
const promise = installOpenCodeVersion('2.1.2', { fetch: fetchFn, homeDirectory, target: linuxTarget })
await expect(promise).rejects.toBeInstanceOf(OpenCodeInstallError)
await expect(promise).rejects.toMatchObject({ swapStarted: true })
@@ -3,7 +3,7 @@ import { describe, it, expect, vi, beforeEach, afterEach, beforeAll } from 'vite
const createOpenCodeClientMock = vi.hoisted(() => vi.fn(() => ({
api: {
server: {
info: vi.fn().mockResolvedValue({ version: '2.0.15', pid: 1234, urls: ['http://127.0.0.1:5551'], paths: { tmp: '/tmp' } }),
info: vi.fn().mockResolvedValue({ version: '2.1.2', pid: 1234, urls: ['http://127.0.0.1:5551'], paths: { tmp: '/tmp' } }),
},
},
forwardRaw: vi.fn(),
@@ -335,7 +335,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
setOpenCodeEnv({ host: '0.0.0.0', password: 'envpassword123' })
@@ -363,7 +363,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
setOpenCodeEnv({ host: '0.0.0.0', password: '' })
@@ -401,7 +401,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -520,7 +520,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const savedEnv = snapshotMicrosandboxEnv()
@@ -763,7 +763,7 @@ describe('OpenCodeServerManager - server auth', () => {
let capturedSignal: AbortSignal | undefined
const info = vi.fn(async (options: { signal?: AbortSignal }) => {
capturedSignal = options.signal
return { version: '2.0.15', pid: 1234, urls: ['http://127.0.0.1:5551'], paths: { tmp: '/tmp' } }
return { version: '2.1.2', pid: 1234, urls: ['http://127.0.0.1:5551'], paths: { tmp: '/tmp' } }
})
createOpenCodeClientMock.mockImplementationOnce(() => ({
api: { server: { info } },
@@ -793,7 +793,7 @@ describe('OpenCodeServerManager - server auth', () => {
capturedSignal = options.signal
queueMicrotask(() => emitExit(1, null))
return new Promise((resolve) => {
setTimeout(() => resolve({ version: '2.0.15', pid: 1234, urls: [], paths: { tmp: '/tmp' } }), 0)
setTimeout(() => resolve({ version: '2.1.2', pid: 1234, urls: [], paths: { tmp: '/tmp' } }), 0)
})
})
createOpenCodeClientMock.mockImplementationOnce(() => ({
@@ -842,7 +842,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -930,7 +930,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -1016,7 +1016,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
manager.setDatabase(createPasswordDb(null))
@@ -1129,7 +1129,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -1179,7 +1179,7 @@ describe('OpenCodeServerManager - server auth', () => {
if (cmd.includes('lsof')) {
return spawnMock.mock.calls.length > 0 ? '1234\n' : '9999\n'
}
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -1926,7 +1926,7 @@ describe('OpenCodeServerManager - server auth', () => {
if (cmd.includes('lsof')) {
return spawnMock.mock.calls.length > 0 ? '1234\n' : '9999\n'
}
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
readFileSyncMock.mockReturnValue(procStatStringWithGroup(9999, '42'))
@@ -1983,7 +1983,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
readdirSyncMock.mockReturnValue(['10001'])
@@ -2062,7 +2062,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
readdirSyncMock.mockReturnValue(['10001'])
@@ -2125,7 +2125,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
readFileSyncMock.mockImplementation((filePath: string) => {
@@ -2181,7 +2181,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return '9999\n'
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
readFileSyncMock.mockReturnValue(procStatStringWithGroup(9999, '42'))
@@ -2223,7 +2223,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return '9998\n'
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
killSpy.mockImplementation(((pid: number, signal?: number | string) => {
@@ -2260,7 +2260,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return '9997\n'
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
killSpy.mockImplementation(((pid: number, signal?: number | string) => {
@@ -2292,7 +2292,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '8888\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
killSpy.mockImplementation(((pid: number, signal?: number | string) => {
@@ -2965,7 +2965,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
installManagedPluginsMock.mockRejectedValueOnce(new Error('readonly filesystem'))
@@ -2997,7 +2997,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -3028,7 +3028,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -3056,7 +3056,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
restoreQuarantinedOpenCodePluginsMock.mockRejectedValueOnce(new Error('readonly filesystem'))
@@ -3087,7 +3087,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
installManagedPluginsMock.mockRejectedValueOnce(new Error('readonly filesystem'))
@@ -3119,7 +3119,7 @@ describe('OpenCodeServerManager - server auth', () => {
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
if (cmd.includes('opencode --version')) return '2.0.15\n'
if (cmd.includes('opencode --version')) return '2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -3155,7 +3155,7 @@ describe('OpenCodeServerManager - server auth', () => {
await expect(manager.start()).rejects.toThrow('OpenCode 1.18.32 is not supported')
expect(spawnMock).not.toHaveBeenCalled()
expect(manager.getLastStartupError()).toContain('requires OpenCode >=2.0.15 <3.0.0')
expect(manager.getLastStartupError()).toContain('requires OpenCode >=2.1.2 <3.0.0')
expect(manager.isLastStartupErrorNonRecoverable()).toBe(true)
})
@@ -3164,7 +3164,7 @@ describe('OpenCodeServerManager - server auth', () => {
isEnabled: () => false,
}))
execSyncMock.mockImplementation((cmd: string) => {
if (cmd.includes('opencode --version')) return 'opencode v2.0.15\n'
if (cmd.includes('opencode --version')) return 'opencode v2.1.2\n'
throw new Error('not found')
})
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
@@ -3174,7 +3174,7 @@ describe('OpenCodeServerManager - server auth', () => {
await manager.start()
expect(spawnMock).toHaveBeenCalled()
expect(manager.getVersion()).toBe('2.0.15')
expect(manager.getVersion()).toBe('2.1.2')
expect(manager.isVersionSupported()).toBe(true)
})
@@ -3195,7 +3195,7 @@ describe('OpenCodeServerManager - server auth', () => {
marked = true
manager.markRestartPending()
}
return { version: '2.0.15', pid: 1234, urls: [], paths: { tmp: '/tmp' } }
return { version: '2.1.2', pid: 1234, urls: [], paths: { tmp: '/tmp' } }
}),
},
},
@@ -3399,7 +3399,7 @@ describe('ConfigReloadError', () => {
})
describe('OpenCodeServerManager - checkHealth', () => {
const serverInfo = { version: '2.0.15', pid: 1234, urls: ['http://127.0.0.1:5551'], paths: { tmp: '/tmp' } }
const serverInfo = { version: '2.1.2', pid: 1234, urls: ['http://127.0.0.1:5551'], paths: { tmp: '/tmp' } }
it('probes GET /api/info through the API client and returns true for a ServerInfo response', async () => {
const { opencodeServerManager } = await import('../../src/services/opencode-single-server')
+22 -20
View File
@@ -46,56 +46,58 @@ function createFetchSpy() {
describe('OpenCode v2 contract', () => {
describe('version policy', () => {
it('pins the client version, derives the floor from it and fixes the V2 server username', () => {
expect(OPENCODE_PINNED_VERSION).toBe('2.0.15')
expect(OPENCODE_SUPPORTED_VERSION_RANGE).toBe('>=2.0.15 <3.0.0')
expect(OPENCODE_PINNED_VERSION).toBe('2.1.2')
expect(OPENCODE_SUPPORTED_VERSION_RANGE).toBe('>=2.1.2 <3.0.0')
expect(OPENCODE_SERVER_USERNAME).toBe('opencode')
})
it('accepts releases of the pinned major at or above the pin and rejects everything else', () => {
expect(isSupportedOpenCodeVersion('1.18.32')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.0')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.14')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.15')).toBe(true)
expect(isSupportedOpenCodeVersion('2.0.16')).toBe(true)
expect(isSupportedOpenCodeVersion('2.1.0')).toBe(true)
expect(isSupportedOpenCodeVersion('v2.0.15')).toBe(true)
expect(isSupportedOpenCodeVersion(' v2.0.15 ')).toBe(true)
expect(isSupportedOpenCodeVersion('2.0.15')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.0')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.1')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.2')).toBe(true)
expect(isSupportedOpenCodeVersion('2.1.3')).toBe(true)
expect(isSupportedOpenCodeVersion('2.2.0')).toBe(true)
expect(isSupportedOpenCodeVersion('v2.1.2')).toBe(true)
expect(isSupportedOpenCodeVersion(' v2.1.2 ')).toBe(true)
expect(isSupportedOpenCodeVersion('3.0.0')).toBe(false)
expect(isSupportedOpenCodeVersion('3.1.0')).toBe(false)
expect(isSupportedOpenCodeVersion('not-a-version')).toBe(false)
})
it('rejects prereleases of the pinned version', () => {
expect(isSupportedOpenCodeVersion('2.0.15-alpha.1')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.15-alpha')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.15-rc.1+build.5')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.15-0')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.2-alpha.1')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.2-alpha')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.2-rc.1+build.5')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.2-0')).toBe(false)
})
it('accepts prereleases of higher numeric cores within the pinned major', () => {
expect(isSupportedOpenCodeVersion('2.1.0-beta.1')).toBe(true)
expect(isSupportedOpenCodeVersion('2.0.16-rc.2')).toBe(true)
expect(isSupportedOpenCodeVersion('2.2.0-beta.1')).toBe(true)
expect(isSupportedOpenCodeVersion('2.1.3-rc.2')).toBe(true)
expect(isSupportedOpenCodeVersion('3.0.0-beta.1')).toBe(false)
})
it('ignores build metadata for precedence', () => {
expect(isSupportedOpenCodeVersion('2.0.15+build')).toBe(true)
expect(isSupportedOpenCodeVersion('2.0.15+2.0.0')).toBe(true)
expect(isSupportedOpenCodeVersion('2.1.2+build')).toBe(true)
expect(isSupportedOpenCodeVersion('2.1.2+2.0.0')).toBe(true)
})
it('rejects malformed and incomplete versions', () => {
expect(isSupportedOpenCodeVersion('2garbage')).toBe(false)
expect(isSupportedOpenCodeVersion('2')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.15.1')).toBe(false)
expect(isSupportedOpenCodeVersion('02.0.15')).toBe(false)
expect(isSupportedOpenCodeVersion('2.0.15-alpha..1')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.2.1')).toBe(false)
expect(isSupportedOpenCodeVersion('02.1.2')).toBe(false)
expect(isSupportedOpenCodeVersion('2.1.2-alpha..1')).toBe(false)
expect(isSupportedOpenCodeVersion('')).toBe(false)
})
it('describes the supported range for unsupported versions', () => {
expect(describeUnsupportedOpenCodeVersion('3.0.0')).toBe(
'OpenCode 3.0.0 is not supported; OpenCode Manager requires OpenCode >=2.0.15 <3.0.0',
'OpenCode 3.0.0 is not supported; OpenCode Manager requires OpenCode >=2.1.2 <3.0.0',
)
})
})
+1 -1
View File
@@ -1,6 +1,6 @@
import { compareParsedSemver, compareSemver, normalizeSemver, parseSemver, type Semver } from '../utils/semver'
export const OPENCODE_PINNED_VERSION = '2.0.15'
export const OPENCODE_PINNED_VERSION = '2.1.2'
const OPENCODE_RELEASE_BASE_URL = 'https://opencode.ai/files/bin'