Skip to content

Commit 7fe5040

Browse files
authored
fix plugin package path policy (Project-N-E-K-O#1618)
* fix plugin package path policy * fix plugin package review issues * fix(tests): 增加对 Windows 驱动器或根目录名称的插件引用拒绝测试 fix(request): 优化 formatHttpError 函数以处理无有用细节的 HTTP 响应 fix(source-resolver): 更新路径检查以支持 POSIX 和 Windows 路径 * fix(plugin-package): sync embedded package selections * fix(plugin-list): show fallback import export errors
1 parent f99b5ab commit 7fe5040

18 files changed

Lines changed: 1374 additions & 173 deletions

frontend/plugin-manager/src/api/pluginCli.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ import { API_BASE_URL } from '@/utils/constants'
77
export type PluginCliConflictStrategy = 'rename' | 'fail'
88
export type PluginCliBuildMode = 'selected' | 'single' | 'bundle' | 'all'
99

10+
export interface PluginCliPluginRef {
11+
root_id: 'builtin' | 'user'
12+
directory_name: string
13+
plugin_id?: string
14+
label?: string
15+
}
16+
1017
export interface PluginCliBuildRequest {
1118
mode: PluginCliBuildMode
1219
plugin?: string
1320
plugins?: string[]
21+
plugin_ref?: PluginCliPluginRef
22+
plugin_refs?: PluginCliPluginRef[]
1423
out?: string
1524
target_dir?: string
1625
keep_staging?: boolean
@@ -110,7 +119,8 @@ export interface PluginCliInstallResponse {
110119
}
111120

112121
export interface PluginCliAnalyzeRequest {
113-
plugins: string[]
122+
plugins?: string[]
123+
plugin_refs?: PluginCliPluginRef[]
114124
current_sdk_version?: string
115125
}
116126

@@ -141,6 +151,7 @@ export interface PluginCliAnalyzeResponse {
141151

142152
export interface PluginCliLocalPluginsResponse {
143153
plugins: string[]
154+
plugin_refs?: PluginCliPluginRef[]
144155
count: number
145156
}
146157

frontend/plugin-manager/src/components/plugin/MarketPanel.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ interface InstalledMarketEntry {
413413
plugin_id: string
414414
market_id?: string
415415
installed_version: string
416-
channel: string
416+
channel: 'stable' | 'beta'
417417
package_url: string
418418
}
419419
const installedByPid = ref<Map<string, InstalledMarketEntry>>(new Map())
@@ -663,7 +663,7 @@ interface MarketInstalledItem {
663663
path: string
664664
latest_install_source: {
665665
plugin_market_id?: string
666-
channel: string
666+
channel: 'stable' | 'beta'
667667
version: string
668668
package_sha256: string
669669
payload_hash: string | null

frontend/plugin-manager/src/components/plugin/PackageManagerPanel.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ import PackageResultPanel from '@/components/plugin/PackageResultPanel.vue'
253253
import PluginSelectorPanel from '@/components/plugin/PluginSelectorPanel.vue'
254254
import { usePackageManager } from '@/composables/usePackageManager'
255255
256-
withDefaults(
256+
const props = withDefaults(
257257
defineProps<{
258258
embedded?: boolean
259+
externalSelectedPluginIds?: readonly string[]
259260
}>(),
260261
{
261262
embedded: false,
263+
externalSelectedPluginIds: undefined,
262264
},
263265
)
264266
@@ -319,7 +321,9 @@ const {
319321
handleVerify,
320322
handleInstall,
321323
handleAnalyze,
322-
} = usePackageManager()
324+
} = usePackageManager({
325+
externalSelectedPluginIds: () => props.externalSelectedPluginIds,
326+
})
323327
</script>
324328

325329
<style scoped>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { computed, ref } from 'vue'
2+
import { describe, expect, it, vi } from 'vitest'
3+
4+
import { usePackageManager } from './usePackageManager'
5+
import type { PluginCliPluginRef } from '@/api/pluginCli'
6+
7+
vi.mock('vue-i18n', () => ({
8+
useI18n: () => ({
9+
locale: { value: 'zh-CN' },
10+
t: (key: string, params?: Record<string, unknown>) => `${key}${params ? JSON.stringify(params) : ''}`,
11+
}),
12+
}))
13+
14+
const pluginRef: PluginCliPluginRef = {
15+
root_id: 'builtin',
16+
directory_name: 'demo_plugin',
17+
plugin_id: 'demo_plugin',
18+
label: 'Demo Plugin',
19+
}
20+
21+
vi.mock('@/api/pluginCli', () => ({
22+
getPluginCliPlugins: vi.fn(async () => ({
23+
plugins: [],
24+
plugin_refs: [pluginRef],
25+
})),
26+
getPluginCliPackages: vi.fn(async () => ({
27+
packages: [],
28+
target_dir: '',
29+
})),
30+
analyzePluginBundle: vi.fn(),
31+
inspectPluginPackage: vi.fn(),
32+
buildPluginCli: vi.fn(),
33+
installPluginPackage: vi.fn(),
34+
verifyPluginPackage: vi.fn(),
35+
}))
36+
37+
vi.mock('@/stores/plugin', () => ({
38+
usePluginStore: () => ({
39+
pluginsWithStatus: [
40+
{
41+
id: 'demo_plugin',
42+
name: 'Demo Plugin',
43+
description: '',
44+
version: '0.1.0',
45+
type: 'plugin',
46+
},
47+
],
48+
syncRegistryAndFetch: vi.fn(async () => ({})),
49+
}),
50+
}))
51+
52+
vi.mock('@/utils/request', () => ({
53+
formatHttpError: (error: unknown) => String(error),
54+
}))
55+
56+
vi.mock('element-plus', () => ({
57+
ElMessage: {
58+
error: vi.fn(),
59+
info: vi.fn(),
60+
success: vi.fn(),
61+
warning: vi.fn(),
62+
},
63+
}))
64+
65+
describe('usePackageManager external plugin selection', () => {
66+
it('maps plugin list selections to package build targets', async () => {
67+
const selectedFromPluginList = ref(['demo_plugin'])
68+
const manager = usePackageManager({
69+
externalSelectedPluginIds: computed(() => selectedFromPluginList.value),
70+
})
71+
72+
await manager.refreshPluginSources()
73+
74+
expect(manager.selectedPluginIds.value).toEqual(['builtin:demo_plugin'])
75+
expect(manager.resolvedBuildTargets.value).toEqual(['builtin:demo_plugin'])
76+
})
77+
})

0 commit comments

Comments
 (0)