fix: skip repeated OpenCode binary validation

OpenCode startup on Linux ARM could run a --version probe before launching the configured Runtime and recheck registered remote binary metadata. Execution now trusts the selected path and registered manifest identity after setup-time verification, so switching and cold launch avoid duplicate binary work.

Release note: 优化 Linux ARM 上切换 OpenCode 的启动速度;已安装或已登记的 Runtime 在执行时不再重复启动或检查二进制。
This commit is contained in:
mesalogo
2026-09-02 22:41:50 +08:00
parent cdecb584d5
commit dc36e7a967
6 changed files with 119 additions and 13 deletions
+24 -1
View File
@@ -1,6 +1,6 @@
import { EventEmitter } from 'node:events'
import { realpath } from 'node:fs/promises'
import { basename, dirname } from 'node:path'
import { basename, dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { afterEach, describe, expect, it, vi } from 'vitest'
import {
@@ -93,6 +93,29 @@ describe('runtime discovery', () => {
expect(detection.version).toMatch(/^\d+\.\d+\.\d+/u)
})
it('trusts a configured execution path without reading or launching it', async () => {
process.env.PATH = ''
process.env.Path = ''
const candidate = resolve(
dirname(fileURLToPath(import.meta.url)),
'runtime-that-does-not-exist'
)
const detection = await detectRuntimeBinary({
binaryPath: candidate,
validation: 'path-only',
binaryNames: ['binary-that-does-not-exist'],
label: 'Managed Runtime'
})
expect(detection).toEqual({
available: true,
path: candidate,
source: 'configured',
detail: 'Managed Runtime 已就绪'
})
})
it('rejects relative configured paths without resolving them from cwd', async () => {
process.env.PATH = ''
process.env.Path = ''