Files
goodbuddy/src/shared/runtime-extension-contracts.test.ts
T
mesalogo ff61b5f81d feat: add DSH plugin marketplace and shared MCP
GoodBuddy could share Skills across runtimes, but custom MCP remained limited and DeepSeek Harness could not manage third-party extensions. The app now provides a default-off DSH npm marketplace with managed installation, configuration, failure isolation, and packaged npm support, while assigned custom MCP is available to managed OpenCode, Continue Agent, and DeepSeek Harness in Execute.

Third-party DSH install scripts, initialization, and tools run with the current user's permissions. Ask remains read-only at dispatch, and turning off the marketplace hides management without disabling installed plugins.

Release note: 新增默认关闭的 DSH 插件市场,并让自定义 MCP 可分配给 OpenCode、Continue 和 DeepSeek Harness;安装第三方插件前会明确提示当前用户权限边界。
2026-08-16 11:47:11 +08:00

148 lines
3.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
runtimeExtensionActionSchema,
runtimeExtensionCatalogEntrySchema,
runtimeExtensionMarketplaceSnapshotSchema
} from './runtime-extension-contracts'
const catalogEntry = {
id: 'web-research',
package: {
name: '@goodbuddy/dsh-web-research',
version: '1.2.3'
},
displayName: 'Web research',
description: 'Researches public web pages.',
repository: 'https://example.com/goodbuddy/web-research',
license: 'MIT'
}
describe('runtime extension contracts', () => {
it('accepts the minimal catalog metadata', () => {
expect(runtimeExtensionCatalogEntrySchema.parse(catalogEntry)).toEqual(
catalogEntry
)
})
it('requires exact semantic versions', () => {
expect(
runtimeExtensionActionSchema.safeParse({
type: 'install',
extensionId: catalogEntry.id,
package: { ...catalogEntry.package, version: '^1.2.3' }
}).success
).toBe(false)
})
it('rejects removed policy fields and rollback actions', () => {
expect(
runtimeExtensionCatalogEntrySchema.safeParse({
...catalogEntry,
permissions: []
}).success
).toBe(false)
expect(
runtimeExtensionActionSchema.safeParse({
type: 'rollback',
extensionId: catalogEntry.id
}).success
).toBe(false)
})
it('models snapshots with JSON-like configuration', () => {
const snapshot = {
marketplaceEnabled: true,
catalog: [catalogEntry],
installed: [
{
id: catalogEntry.id,
package: catalogEntry.package,
installedAt: '2026-08-16T00:00:00.000Z',
enabled: true,
integrity: `sha512-${Buffer.from('digest').toString(
'base64'
)}`,
configuration: {
resultLimit: 10,
filters: { domains: ['example.com'], exact: true },
optional: null
}
}
]
}
expect(
runtimeExtensionMarketplaceSnapshotSchema.parse(snapshot)
).toEqual(snapshot)
expect(
runtimeExtensionMarketplaceSnapshotSchema.safeParse({
...snapshot,
installed: [
{
...snapshot.installed[0],
entrypoint:
'C:\\Users\\tester\\runtime-extensions\\extensions\\web-research\\dist\\index.js'
}
]
}).success
).toBe(false)
expect(
runtimeExtensionMarketplaceSnapshotSchema.safeParse({
...snapshot,
warnings: []
}).success
).toBe(false)
})
it('supports only the explicit marketplace switch action', () => {
expect(
runtimeExtensionActionSchema.parse({
type: 'set-marketplace-enabled',
enabled: true
})
).toEqual({
type: 'set-marketplace-enabled',
enabled: true
})
expect(
runtimeExtensionActionSchema.safeParse({
type: 'set-marketplace-enabled',
enabled: true,
extensionId: 'unexpected'
}).success
).toBe(false)
})
it('bounds configuration size, depth, and collection width', () => {
let deeplyNested: Record<string, unknown> = {}
for (let depth = 0; depth < 18; depth += 1) {
deeplyNested = { nested: deeplyNested }
}
const action = {
type: 'configure',
extensionId: catalogEntry.id
}
expect(
runtimeExtensionActionSchema.safeParse({
...action,
configuration: { value: 'x'.repeat(65 * 1_024) }
}).success
).toBe(false)
expect(
runtimeExtensionActionSchema.safeParse({
...action,
configuration: deeplyNested
}).success
).toBe(false)
expect(
runtimeExtensionActionSchema.safeParse({
...action,
configuration: {
values: Array.from({ length: 257 }, () => true)
}
}).success
).toBe(false)
})
})