From bf7c6cdbac7eba27ec98dfff6123ad4e14eba291 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:43:35 -0500 Subject: [PATCH] fix(opencode): address review feedback on the 2.2.5 pin Document ocm 0.6.x as requiring OpenCode 2.2.5, matching its @opencode/theme peer, and make the package compatibility test check bounded peer ranges instead of treating them as one version. Linked servers on another 2.x release keep the neutral version notice, while a different major version is shown as unsupported again through a shared version badge. The Docker build now fails when the bundled OpenCode is below the supported minimum, and the entrypoint falls back to the bundled version as the floor when OPENCODE_MIN_VERSION is unset instead of discarding every persisted binary. --- Dockerfile | 2 ++ .../test/scripts/docker-entrypoint.test.ts | 16 ++++++++++++++-- backend/test/shared/opencode-contract.test.ts | 12 +++++++++++- .../settings/OpenCodeServerDialog.tsx | 16 +++++++++++----- .../settings/OpenCodeServersSettings.tsx | 8 ++------ ocm-cli/README.md | 8 ++++---- ocm-cli/test/package-compat.test.ts | 19 ++++++++++++++----- scripts/docker-entrypoint.sh | 2 +- shared/src/opencode/index.ts | 1 + shared/src/opencode/release.ts | 5 +++++ 10 files changed, 65 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab217a4c..d1e5aae1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -80,6 +80,8 @@ RUN echo "Installing uv=${UV_VERSION} opencode=${OPENCODE_VERSION} (cachebust=${ chmod +x /usr/local/bin/uv /usr/local/bin/uvx && \ test "$(uv --version | cut -d' ' -f2)" = "${UV_VERSION}" && \ . /usr/local/lib/ocm/opencode-release.sh && \ + OPENCODE_SUPPORTED_FLOOR="${OPENCODE_MIN_VERSION}" && \ + { is_supported_opencode_version "${OPENCODE_VERSION}" || { echo "OPENCODE_VERSION ${OPENCODE_VERSION} is outside the supported range $(supported_opencode_range)" >&2; exit 1; }; } && \ echo "Downloading opencode ${OPENCODE_VERSION}..." && \ download_opencode_to "${OPENCODE_VERSION}" /opt/opencode/bin/opencode && \ ln -s /opt/opencode/bin/opencode /usr/local/bin/opencode && \ diff --git a/backend/test/scripts/docker-entrypoint.test.ts b/backend/test/scripts/docker-entrypoint.test.ts index cad3ae0f..9c778dd7 100644 --- a/backend/test/scripts/docker-entrypoint.test.ts +++ b/backend/test/scripts/docker-entrypoint.test.ts @@ -460,14 +460,26 @@ exit 1`) expect(curlLog()).toHaveLength(0) }) - it('treats every persisted binary as unsupported when the minimum version is unknown', () => { + it('treats every persisted binary as unsupported when neither the minimum nor the bundled version is known', () => { + mkdirSync(join(stubDir, 'home/.opencode/bin'), { recursive: true }) + writeBinary(join(stubDir, 'home/.opencode/bin'), '2.0.15') + const res = runOpenCodeSection(`${installPrelude()}\nreconcile_persisted_opencode`, { + OPENCODE_MIN_VERSION: '', + OPENCODE_BUNDLED_VERSION: '', + }) + expect(res.status).toBe(0) + expect(existsSync(homeBinPath())).toBe(false) + }) + + it('falls back to the bundled version as the floor when the minimum is unset', () => { mkdirSync(join(stubDir, 'home/.opencode/bin'), { recursive: true }) writeBinary(join(stubDir, 'home/.opencode/bin'), '2.0.15') const res = runOpenCodeSection(`${installPrelude()}\nreconcile_persisted_opencode`, { OPENCODE_MIN_VERSION: '', }) expect(res.status).toBe(0) - expect(existsSync(homeBinPath())).toBe(false) + expect(res.stdout).toContain('Persisted OpenCode 2.0.15 is usable; retaining it') + expect(existsSync(homeBinPath())).toBe(true) }) it('removes a malformed persisted home binary and selects the bundled binary without downloading', () => { diff --git a/backend/test/shared/opencode-contract.test.ts b/backend/test/shared/opencode-contract.test.ts index 0b00dd66..9e6130e0 100644 --- a/backend/test/shared/opencode-contract.test.ts +++ b/backend/test/shared/opencode-contract.test.ts @@ -11,6 +11,7 @@ import { compareOpenCodeVersions, createOpenCodeApi, describeUnsupportedOpenCodeVersion, + isSameOpenCodeMajor, isStableOpenCodeVersion, isSupportedOpenCodeVersion, normalizeOpenCodeVersion, @@ -104,6 +105,15 @@ describe('OpenCode v2 contract', () => { expect(isSupportedOpenCodeVersion('')).toBe(false) }) + it('treats any release of the same major as reachable, regardless of the floor', () => { + expect(isSameOpenCodeMajor('2.0.15')).toBe(true) + expect(isSameOpenCodeMajor('2.2.4')).toBe(true) + expect(isSameOpenCodeMajor('2.9.0')).toBe(true) + expect(isSameOpenCodeMajor('1.18.32')).toBe(false) + expect(isSameOpenCodeMajor('3.0.0')).toBe(false) + expect(isSameOpenCodeMajor('not-a-version')).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.2.5 <3.0.0', @@ -174,7 +184,7 @@ describe('OpenCode v2 contract', () => { const entrypoint = readFileSync(join(REPO_ROOT, 'scripts', 'docker-entrypoint.sh'), 'utf8') const setupDev = readFileSync(join(REPO_ROOT, 'scripts', 'setup-dev.sh'), 'utf8') const releaseHelper = readFileSync(join(REPO_ROOT, 'scripts', 'lib', 'opencode-release.sh'), 'utf8') - expect(entrypoint).toContain('OPENCODE_SUPPORTED_FLOOR="${OPENCODE_MIN_VERSION:-}"') + expect(entrypoint).toContain('OPENCODE_SUPPORTED_FLOOR="${OPENCODE_MIN_VERSION:-${OPENCODE_BUNDLED_VERSION:-}}"') expect(setupDev).toContain("sed -n 's/^ARG OPENCODE_MIN_VERSION=//p' \"$REPO_ROOT/Dockerfile\"") for (const script of [entrypoint, setupDev, releaseHelper]) { expect(script).not.toMatch(/(?Supported + if (result.version && isSameOpenCodeMajor(result.version)) { + return Different version: some features may not work + } + return Unsupported version +} + function TestResultSummary({ result }: { result: OpenCodeServerTestResult }) { if (!result.ok) { return ( @@ -112,11 +122,7 @@ function TestResultSummary({ result }: { result: OpenCodeServerTestResult }) {
Connected — OpenCode {result.version ?? 'unknown version'} - {result.versionSupported ? ( - Supported - ) : ( - Different version: some features may not work - )} +
) } diff --git a/frontend/src/components/settings/OpenCodeServersSettings.tsx b/frontend/src/components/settings/OpenCodeServersSettings.tsx index 3b6e081f..ca95f043 100644 --- a/frontend/src/components/settings/OpenCodeServersSettings.tsx +++ b/frontend/src/components/settings/OpenCodeServersSettings.tsx @@ -12,7 +12,7 @@ import { Switch } from '@/components/ui/switch' import { DeleteDialog } from '@/components/ui/delete-dialog' import { showToast } from '@/lib/toast' import { useOpenCodeServers } from '@/hooks/useOpenCodeServers' -import { OpenCodeServerDialog, type OpenCodeServerFormValues } from './OpenCodeServerDialog' +import { OpenCodeServerDialog, OpenCodeVersionBadge, type OpenCodeServerFormValues } from './OpenCodeServerDialog' function errorMessage(error: unknown, fallback: string): string { return error instanceof Error && error.message ? error.message : fallback @@ -31,11 +31,7 @@ function ServerTestResult({ result }: { result: OpenCodeServerTestResult }) {
OpenCode {result.version ?? 'unknown version'} - {result.versionSupported ? ( - Supported - ) : ( - Different version: some features may not work - )} +
) } diff --git a/ocm-cli/README.md b/ocm-cli/README.md index a9d75128..acb56026 100644 --- a/ocm-cli/README.md +++ b/ocm-cli/README.md @@ -10,7 +10,7 @@ to the local working tree. | ocm | OpenCode Manager | Local OpenCode | |---|---|---| -| 0.6.x | >= 0.19.0 | >= 2.2.3, < 3 | +| 0.6.x | >= 0.19.0 | >= 2.2.5, < 3 | | 0.5.x | >= 0.19.0 | >= 2.2.0, < 3 | | 0.4.x | >= 0.19.0 | >= 2.0.15, < 3 | | 0.3.x | >= 0.19.0 | >= 2.0.15, < 3 | @@ -26,8 +26,8 @@ Use ocm 0.2.x with OpenCode Manager < 0.19.0 and OpenCode 1.x, installed pinned release. From ocm 0.6.0, the TUI plugin is built against `@opencode/plugin` 2.2.5 and -OpenTUI 0.8, so it requires a local OpenCode >= 2.2.3. OpenCode 2.2.0 through -2.2.2 ship OpenTUI 0.7; stay on ocm 0.5.x with those builds. ocm 0.5.0 itself +OpenTUI 0.8 and declares an `@opencode/theme` peer of `>=2.2.5`, so it requires +a local OpenCode >= 2.2.5. Stay on ocm 0.5.x with an older 2.2.x. ocm 0.5.0 itself is built against `@opencode/plugin` 2.2.1 and OpenTUI 0.7 and requires a local OpenCode >= 2.2.0: OpenCode 2.2.0 refuses plugins built for OpenTUI 0.6, and older OpenCode builds may refuse the 0.7 peers. Stay on ocm 0.4.x with a local @@ -324,7 +324,7 @@ global installs); the plugin surface is TUI-only. ## Requirements - macOS or Linux (Windows is unsupported) -- OpenCode >= 2.2.3 (same major, 2.x) available on `PATH` for the TUI plugin +- OpenCode >= 2.2.5 (same major, 2.x) available on `PATH` for the TUI plugin - Node available on `PATH` (runs the `ocm` binary) - OpenCode Manager >= 0.19.0 - `git` and `tar` (with gzip support, i.e. the `-z` flag) available on `PATH` diff --git a/ocm-cli/test/package-compat.test.ts b/ocm-cli/test/package-compat.test.ts index e45c82eb..e02d1771 100644 --- a/ocm-cli/test/package-compat.test.ts +++ b/ocm-cli/test/package-compat.test.ts @@ -45,15 +45,24 @@ function deriveMinorLineRange(version: string): string { } /** - * Asserts that an installed version satisfies a plugin peer declaration, - * accepting both an exact peer pin and an open `>=` floor. + * Asserts that an installed version satisfies a plugin peer declaration: an exact + * pin, or space-separated `>=`, `<=` and `<` bounds such as `>=0.8.0 <0.9.0`. */ function expectVersionSatisfiesPeer(version: string, peer: string): void { - if (peer.startsWith('>=')) { - expect(compareSemver(version, peer.slice(2).trim())).toBeGreaterThanOrEqual(0) + const comparators = peer.trim().split(/\s+/) + if (!comparators.every((comparator) => comparator.startsWith('>=') || comparator.startsWith('<'))) { + expect(version).toBe(peer) return } - expect(version).toBe(peer) + for (const comparator of comparators) { + if (comparator.startsWith('>=')) { + expect(compareSemver(version, comparator.slice(2))).toBeGreaterThanOrEqual(0) + } else if (comparator.startsWith('<=')) { + expect(compareSemver(version, comparator.slice(2))).toBeLessThanOrEqual(0) + } else { + expect(compareSemver(version, comparator.slice(1))).toBeLessThan(0) + } + } } const ocmManifest = readManifest(join(__dirname, '..', 'package.json')) diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index b1ff3934..3d20d77e 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -60,7 +60,7 @@ ensure_auth_secret() { export AUTH_SECRET } -OPENCODE_SUPPORTED_FLOOR="${OPENCODE_MIN_VERSION:-}" +OPENCODE_SUPPORTED_FLOOR="${OPENCODE_MIN_VERSION:-${OPENCODE_BUNDLED_VERSION:-}}" read_opencode_version() { local binary output diff --git a/shared/src/opencode/index.ts b/shared/src/opencode/index.ts index 1893d31e..95b6a7bb 100644 --- a/shared/src/opencode/index.ts +++ b/shared/src/opencode/index.ts @@ -143,6 +143,7 @@ export { compareOpenCodeVersions, describeUnsupportedOpenCodeVersion, isStableOpenCodeVersion, + isSameOpenCodeMajor, isSupportedOpenCodeVersion, normalizeOpenCodeVersion, parseOpenCodeVersion, diff --git a/shared/src/opencode/release.ts b/shared/src/opencode/release.ts index 0be9431d..994668db 100644 --- a/shared/src/opencode/release.ts +++ b/shared/src/opencode/release.ts @@ -67,6 +67,11 @@ export function isSupportedOpenCodeVersion(version: string): boolean { return parsed.major === OPENCODE_MIN.major && compareParsedSemver(parsed, OPENCODE_MIN) >= 0 } +/** Reports whether a server version shares Manager's OpenCode major, so the V2 client can still talk to it. */ +export function isSameOpenCodeMajor(version: string): boolean { + return parseOpenCodeVersion(version)?.major === OPENCODE_MIN.major +} + export function describeUnsupportedOpenCodeVersion(version: string): string { return `OpenCode ${version} is not supported; OpenCode Manager requires OpenCode ${OPENCODE_SUPPORTED_VERSION_RANGE}` }