Files
goodbuddy/src/shared/local-tool-environment-contracts.test.ts
T
mesalogo be39665ca9 feat: add managed local tool environments
GoodBuddy can now provide managed Node.js and on-demand Python to local Skills and stdio MCP servers, or validate an explicitly selected custom interpreter. The Capabilities and tools settings page exposes source selection, diagnostics, installation progress, cancellation, and removal while new processes receive immutable PATH snapshots.

Application settings migrate to v10. Local terminal and remote Host environments remain unchanged. Windows x64 native-source Node and Python paths are validated; OSS mirror publication, redistributed license resources, and the remaining native platform probes are recorded as release blockers.

Release note: 新增工具执行环境,可为本机 Skills 和 stdio MCP 使用 GoodBuddy 托管的 Node.js、按需安装的 Python,或经过验证的自定义解释器。
2026-09-02 10:36:56 +08:00

110 lines
3.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
artifactDownloadSourceSchema,
defaultLocalToolEnvironmentSettings,
localToolCandidateSchema,
localToolEnvironmentSettingsSchema,
localToolPythonOperationSchema,
localToolRuntimeSelectionSchema
} from './local-tool-environment-contracts'
describe('local tool environment contracts', () => {
it('accepts managed defaults and both download sources', () => {
expect(
localToolEnvironmentSettingsSchema.parse(
defaultLocalToolEnvironmentSettings
)
).toEqual(defaultLocalToolEnvironmentSettings)
expect(artifactDownloadSourceSchema.parse('oss')).toBe('oss')
})
it('accepts cross-platform absolute custom executable paths', () => {
for (const executablePath of [
'/usr/local/bin/node',
'C:\\Program Files\\nodejs\\node.exe',
'\\\\server\\tools\\python.exe'
]) {
expect(
localToolRuntimeSelectionSchema.parse({
source: 'custom',
executablePath
})
).toEqual({ source: 'custom', executablePath })
}
})
it('strictly rejects relative, unbounded, and mismatched selections', () => {
for (const input of [
{ source: 'custom', executablePath: 'bin/node' },
{ source: 'custom', executablePath: '/bin/node ' },
{ source: 'custom', executablePath: `/${'x'.repeat(4_096)}` },
{ source: 'custom' },
{ source: 'managed', executablePath: '/bin/node' },
{ source: 'automatic' }
]) {
expect(localToolRuntimeSelectionSchema.safeParse(input).success).toBe(
false
)
}
})
it('strictly rejects incomplete and unknown settings', () => {
expect(
localToolEnvironmentSettingsSchema.safeParse({
...defaultLocalToolEnvironmentSettings,
extra: true
}).success
).toBe(false)
expect(
localToolEnvironmentSettingsSchema.safeParse({
node: { source: 'managed' },
python: { source: 'managed' }
}).success
).toBe(false)
expect(artifactDownloadSourceSchema.safeParse('mirror').success).toBe(false)
})
it('requires validated candidate version and architecture metadata', () => {
expect(
localToolCandidateSchema.parse({
kind: 'node',
executablePath: 'C:\\Tools\\node.exe',
version: '22.14.0',
architecture: 'x64'
})
).toEqual({
kind: 'node',
executablePath: 'C:\\Tools\\node.exe',
version: '22.14.0',
architecture: 'x64'
})
expect(
localToolCandidateSchema.safeParse({
kind: 'python',
executablePath: '/usr/bin/python3'
}).success
).toBe(false)
})
it('freezes the download source into Python operation snapshots', () => {
expect(
localToolPythonOperationSchema.parse({
source: 'oss',
phase: 'downloading',
receivedBytes: 10,
totalBytes: 100
})
).toEqual({
source: 'oss',
phase: 'downloading',
receivedBytes: 10,
totalBytes: 100
})
expect(
localToolPythonOperationSchema.safeParse({
phase: 'validating'
}).success
).toBe(false)
})
})