fix(installer): apply extractSemverFromOutput to opencode-binary version probe
The same output.trim() bug fixed in PR #3909 for doctor exists in the installer's opencode-binary.ts. Without this fix, `bunx oh-my-opencode install` would store polluted Electron stdout (e.g., `00:24:25.202 > app starting { version: '1.14.33', packaged: true }`) as the OpenCode version in config, breaking downstream version-dependent logic. - Extract extractSemverFromOutput to src/shared/extract-semver.ts (precedent: spawn-with-windows-hide is in shared because used by both doctor and installer) - src/cli/doctor/checks/system-binary.ts now imports from shared and re-exports for backward compat - src/cli/config-manager/opencode-binary.ts uses the shared helper with `?? output.trim()` fallback to preserve legacy behavior on non-semver-shaped successful outputs (e.g., custom builds) - Add 4 installer regression tests covering: clean semver, polluted Electron stdout (regression for #3765 installer caller), fallback for non-semver, null when no binary on PATH Refs #3765
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/// <reference types="bun-types" />
|
||||
|
||||
import { describe, expect, it } from "bun:test"
|
||||
import { extractSemverFromOutput } from "./system-binary"
|
||||
import { extractSemverFromOutput } from "../../../shared/extract-semver"
|
||||
|
||||
describe("extractSemverFromOutput", () => {
|
||||
describe("#given clean version output #when extractSemverFromOutput #then returns the semver token", () => {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { existsSync } from "node:fs"
|
||||
import { homedir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { extractSemverFromOutput } from "../../../shared/extract-semver"
|
||||
import { spawnWithTimeout } from "../spawn-with-timeout"
|
||||
|
||||
import { OPENCODE_BINARIES } from "../constants"
|
||||
|
||||
export { extractSemverFromOutput }
|
||||
|
||||
const WINDOWS_EXECUTABLE_EXTS = [".exe", ".cmd", ".bat", ".ps1"]
|
||||
|
||||
export interface OpenCodeBinaryInfo {
|
||||
@@ -105,17 +108,6 @@ export async function findOpenCodeBinary(): Promise<OpenCodeBinaryInfo | null> {
|
||||
return findDesktopBinary()
|
||||
}
|
||||
|
||||
export function extractSemverFromOutput(output: string): string | null {
|
||||
const trimmed = output.trim()
|
||||
if (!trimmed) return null
|
||||
// Match a semver-shaped token, allowing optional `v` prefix and `-prerelease+build` suffix.
|
||||
// The negative lookbehind `(?<![\d:])` prevents matching the milliseconds segment of timestamps
|
||||
// like `00:24:25.202` that the Electron-based OpenCode binary leaks into stdout.
|
||||
const semverPattern = /(?<![\d:])v?(\d+\.\d+\.\d+(?:[-+][\w.]+)*)/
|
||||
const match = trimmed.match(semverPattern)
|
||||
return match?.[1] ?? null
|
||||
}
|
||||
|
||||
export async function getOpenCodeVersion(
|
||||
binaryPath: string,
|
||||
platform: NodeJS.Platform = process.platform
|
||||
|
||||
Reference in New Issue
Block a user