Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(plugin): 不兼容安装改走授权气泡,github 来源不再被判为无效 spec (#934)

Mao Mre364c2e5de6d
diff --git a/src-tauri/src/service/plugin/install/inspect.rs b/src-tauri/src/service/plugin/install/inspect.rs
index 6c9c3039..3318d587 100644
--- a/src-tauri/src/service/plugin/install/inspect.rs
+++ b/src-tauri/src/service/plugin/install/inspect.rs
@@ -44,8 +44,8 @@ pub async fn inspect_specs(
Ok(results)
}
-/// 单条 spec:本地目录离线读清单,静态解析不出包名(git / URL / 非法写法)时不做
-/// 网络请求。
+/// 单条 spec:本地目录离线读清单;静态解析不出 registry 包名的来源(`github:`
+/// 简写、git / tarball URL)不做网络请求。
async fn inspect_one(
client: &reqwest::Client,
spec: &str,
@@ -56,8 +56,11 @@ async fn inspect_one(
if spec::local_path_spec(raw).is_some() {
return inspect_local(raw, base, runtime);
}
+ // 解析不出包名不等于 spec 写错了:`github:owner/repo` 与 git / tarball URL 都是
+ // pnpm 与 dsh 接受的合法来源,只是只读检查无从查询其版本与依赖。留空交给安装
+ // 链路自己解析(Fail-Open)——报 invalid-spec 会把合法来源说成写法错误。
let Some(name) = spec::package_name_of_spec(raw, base) else {
- return problem_result(raw, None, "invalid-spec");
+ return uninspected(raw, None);
};
let requested = requested_version(raw, &name);
@@ -164,13 +167,22 @@ fn requested_version(raw: &str, name: &str) -> Option<String> {
/// 出错条目:保留已解析到的包名便于前端展示,兼容性留空(Fail-Open)。
fn problem_result(spec: &str, name: Option<String>, problem: &str) -> PluginInspect {
+ PluginInspect {
+ problem: Some(problem.to_string()),
+ ..uninspected(spec, name)
+ }
+}
+
+/// 无从静态检查的条目:来源本身合法,但没有 registry 清单可读,因此既不给版本、
+/// 也不给任何判定——安装链路会自己解析它。
+fn uninspected(spec: &str, name: Option<String>) -> PluginInspect {
PluginInspect {
spec: spec.to_string(),
name,
version: None,
compatible: None,
peers: None,
- problem: Some(problem.to_string()),
+ problem: None,
}
}
@@ -253,7 +265,7 @@ mod tests {
#[test]
fn local_spec_reports_local_missing_for_absent_dir_or_manifest() {
// 三种「本地路径但拿不到清单」的形态都必须落到 local-missing,而不是
- // invalid-spec / not-found —— 后两者会让用户以为要改写法或去 registry 找包。
+ // not-found / 干脆不判定 —— 前者会让用户以为要去 registry 找包。
let (base, dir) = fixture("absent", None);
let missing_dir = inspect_local("./never-existed", &base, Some("0.2.0"));
@@ -284,4 +296,24 @@ mod tests {
let _ = std::fs::remove_dir_all(&base);
}
+
+ #[tokio::test]
+ async fn non_registry_specs_are_left_uninspected() {
+ // 回归:`github:owner/repo` 与 git / tarball URL 是 pnpm 与 dsh 都接受的合法
+ // 来源,只是查不到 registry 清单——报 invalid-spec 会让用户以为 spec 写错了。
+ let client = reqwest::Client::new();
+ let base = std::path::Path::new(".");
+ for spec in [
+ "github:MengYuil/dsh-ponytail",
+ "https://github.com/MengYuil/dsh-ponytail",
+ "git+https://github.com/MengYuil/dsh-ponytail.git#main",
+ "https://example.com/plugin.tgz",
+ ] {
+ let result = inspect_one(&client, spec, base, Some("0.2.0")).await;
+ assert_eq!(result.spec, spec);
+ assert_eq!(result.problem, None, "{spec}");
+ assert_eq!(result.compatible, None, "{spec}");
+ assert_eq!(result.name, None, "{spec}");
+ }
+ }
}
diff --git a/src-tauri/src/service/plugin/install/spec.rs b/src-tauri/src/service/plugin/install/spec.rs
index fb5ac361..7a6f6a35 100644
--- a/src-tauri/src/service/plugin/install/spec.rs
+++ b/src-tauri/src/service/plugin/install/spec.rs
@@ -13,8 +13,8 @@ use super::PreinstallPluginInfo;
/// 根路径与 `./` / `../` 显式相对路径都算;返回尚未绝对化的原始路径。
///
/// 判定必须先于 [`package_name_of_spec`] 里「含 `:` 即放弃」的形态检查:Windows
-/// 盘符自带冒号,裸路径否则会被当成 git / URL 形态丢掉包名,安装前的只读检查也会
-/// 误报 `invalid-spec`。
+/// 盘符自带冒号,裸路径否则会被当成 git / URL 来源丢掉包名,安装前的只读检查也就
+/// 读不到本地清单、给不出名字与版本。
pub(super) fn local_path_spec(spec: &str) -> Option<PathBuf> {
let trimmed = unquote(spec.trim());
if trimmed.is_empty() {
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index ca909731..a51e980c 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -360,9 +360,7 @@
"plugins.result_enable_failed": "Failed to enable {{name}}",
"plugins.install": "Install",
"plugins.install_placeholder": "Enter a plugin package or spec (comma-separated for multiple)",
- "plugins.search_incompatible": "These plugins are incompatible with the current core: {{names}}",
"plugins.search_incompatible_badge": "Incompatible",
- "plugins.search_invalid_spec": "Invalid spec",
"plugins.search_not_found": "Not found in registry",
"plugins.search_network": "Registry lookup failed",
"plugins.search_unsupported": "Source not supported yet",
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index 9a993e84..be645189 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -360,9 +360,7 @@
"plugins.result_enable_failed": "启用插件 {{name}} 失败",
"plugins.install": "安装",
"plugins.install_placeholder": "输入插件包名或 spec(可逗号分隔多个)",
- "plugins.search_incompatible": "以下插件与当前核心不兼容:{{names}}",
"plugins.search_incompatible_badge": "不兼容",
- "plugins.search_invalid_spec": "无效的 spec",
"plugins.search_not_found": "未在仓库中找到",
"plugins.search_network": "联网查询失败",
"plugins.search_unsupported": "暂不支持该来源",
diff --git a/src/store/modules/plugins/store.ts b/src/store/modules/plugins/store.ts
index 4b2cfb13..17fe5e22 100644
--- a/src/store/modules/plugins/store.ts
+++ b/src/store/modules/plugins/store.ts
@@ -621,6 +621,9 @@ export const plugins = defineStore({
failed > 0 ? i18next.t('plugins.queue_summary_failed', { count: failed }) : '',
noop > 0 ? i18next.t('plugins.queue_summary_skipped', { count: noop }) : '',
].filter(part => part !== '')
+ // 每一项都是用户自己的选择时没有任何收支可报,别弹一条空汇总气泡追问他。
+ if (parts.length === 0)
+ return
restartKey = toast(i18next.t('plugins.queue_summary'), {
description: parts.join(' · '),
variant: failed > 0 ? 'danger' : restart ? 'accent' : 'default',
diff --git a/src/store/modules/plugins/types.ts b/src/store/modules/plugins/types.ts
index 5a228f43..1455b2e3 100644
--- a/src/store/modules/plugins/types.ts
+++ b/src/store/modules/plugins/types.ts
@@ -73,7 +73,7 @@ export interface PluginManagerLog {
processId?: string
}
-export type PluginSearchProblem = 'invalid-spec' | 'not-found' | 'local-missing' | 'network' | 'unsupported' | 'unknown'
+export type PluginSearchProblem = 'not-found' | 'local-missing' | 'network' | 'unsupported' | 'unknown'
export interface PluginSearchResult {
spec: string
diff --git a/src/ui/config/plugin.test.tsx b/src/ui/config/plugin.test.tsx
index 85f5a500..11a038f8 100644
--- a/src/ui/config/plugin.test.tsx
+++ b/src/ui/config/plugin.test.tsx
@@ -363,6 +363,53 @@ describe('local plugin folder picking', () => {
})
})
+describe('incompatible plugin install', () => {
+ /** 不兼容的 spec 必须照样入队:授权气泡由管理器弹,面板不能提前拦截成一条错误提示。 */
+ it('still hands an incompatible spec to the manager instead of failing it at the panel', async () => {
+ manager.search.mockResolvedValue([
+ { spec: 'dsh-a', name: 'dsh-a', version: '1.0.0', compatible: false },
+ ])
+ render(<ConfigPlugin />)
+ const input = screen.getByPlaceholderText('plugins.install_placeholder')
+ await act(async () => fireEvent.change(input, { target: { value: 'dsh-a' } }))
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.install' })))
+
+ await waitFor(() => expect(manager.install).toHaveBeenCalledExactlyOnceWith(['dsh-a']))
+ // 面板既不拦也不报错:授权与否留给管理器那条气泡。
+ expect(mocks.toast).not.toHaveBeenCalled()
+ })
+
+ it('shows the resolved version of an incompatible spec without blocking the install', async () => {
+ manager.search.mockResolvedValue([
+ { spec: 'dsh-a', name: 'dsh-a', version: '1.0.0', compatible: false },
+ ])
+ render(<ConfigPlugin />)
+ const input = screen.getByPlaceholderText('plugins.install_placeholder')
+ await act(async () => fireEvent.change(input, { target: { value: 'dsh-a' } }))
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.install' })))
+
+ expect(await screen.findByText('plugins.search_incompatible_badge')).toBeTruthy()
+ expect(manager.install).toHaveBeenCalledWith(['dsh-a'])
+ })
+})
+
+describe('non-registry spec search results', () => {
+ /** 宿主对 `github:` 简写与 git URL 不做 registry 解析,面板只转述它给出的结论,不得自己判定 spec 非法。 */
+ it('renders a github spec without a problem label and still installs it', async () => {
+ manager.search.mockResolvedValue([
+ { spec: 'github:MengYuil/dsh-ponytail', compatible: null },
+ ])
+ const { container } = render(<ConfigPlugin />)
+ const input = screen.getByPlaceholderText('plugins.install_placeholder')
+ await act(async () => fireEvent.change(input, { target: { value: 'github:MengYuil/dsh-ponytail' } }))
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'plugins.install' })))
+
+ await waitFor(() => expect(manager.install).toHaveBeenCalledExactlyOnceWith(['github:MengYuil/dsh-ponytail']))
+ expect(container.querySelector('.text-danger')).toBeNull()
+ expect(screen.getByText('github:MengYuil/dsh-ponytail')).toBeTruthy()
+ })
+})
+
describe('local plugin hot reload switch', () => {
it('hides the whole hot reload block unless advanced options are enabled', () => {
hmrStatus.data = { enabled: true, watching: false, patchPath: null, roots: [] }
diff --git a/src/ui/config/plugin.tsx b/src/ui/config/plugin.tsx
index 7c2b4a8f..e4737831 100644
--- a/src/ui/config/plugin.tsx
+++ b/src/ui/config/plugin.tsx
@@ -44,7 +44,6 @@ const QUEUED_ACTIONS: Record<PluginProcess['type'], string> = {
/** 兼容性检查的问题码 → i18n key:管理器把宿主返回的 problem 原样透传给调用方 */
const searchProblemKeys: Record<PluginSearchProblem, string> = {
- 'invalid-spec': 'plugins.search_invalid_spec',
'local-missing': 'plugins.search_local_missing',
'not-found': 'plugins.search_not_found',
'network': 'plugins.search_network',
@@ -295,8 +294,8 @@ export function ConfigPlugin() {
}
/**
- * 新增安装入口:先 `manager.search` 预检兼容性(只读,不改 Profile),
- * 命中明确不兼容的 spec 时中止并提示,其余交给 `manager.install` 走统一队列。
+ * 新增安装入口:`manager.search` 只把解析到的版本与兼容性标记显示出来(只读,不改 Profile),
+ * 安装本身一律交给 `manager.install`;不兼容由宿主拒绝后在管理器里弹授权气泡,面板不提前拦。
*/
async function onInstall() {
const refs = splitRefs(installRef, pickedSpec)
@@ -306,12 +305,6 @@ export function ConfigPlugin() {
try {
const results = await manager.search(refs)
setSearchResults(results)
- const incompatibles = results.filter(item => item.compatible === false)
- if (incompatibles.length > 0) {
- const names = incompatibles.map(item => item.name ?? item.spec).join(', ')
- toast(t('plugins.search_incompatible', { names }), { variant: 'danger' })
- return
- }
setInstallRef('')
setPickedSpec(null)
await manager.install(refs)
@@ -717,7 +710,7 @@ export function ConfigPlugin() {
<Panel.Loadable loading={manager.loading} error={manager.error}>
<div className="flex flex-col gap-4">
- {/* 安装入口:接受 npm spec(可逗号/空白分隔多个),先经管理器只读预检再入队 */}
+ {/* 安装入口:接受 npm spec(可逗号/空白分隔多个),搜索结果只作展示,安装统一入队 */}
<div className="flex flex-col gap-2">
<div className="flex items-center gap-2">
<Input
diff --git a/test/plugin-manager-summary.test.ts b/test/plugin-manager-summary.test.ts
index 77206f30..20bf852f 100644
--- a/test/plugin-manager-summary.test.ts
+++ b/test/plugin-manager-summary.test.ts
@@ -7,6 +7,7 @@ interface ToastCallOptions {
variant?: string
isLoading?: boolean
description?: string
+ onClose?: (reason: string) => void
actionProps?: { children?: string, onPress?: () => void }
}
@@ -108,3 +109,65 @@ describe('plugins manager queue summary', () => {
expect(toasts[0][1]?.actionProps).toBeUndefined()
})
})
+
+describe('plugins manager summary after a dismissed authorization', () => {
+ const BLOCKED = [
+ { name: 'b', version: '0.22.1', runtime_version: '0.2.0-rc.1' },
+ { name: 'c', version: '0.22.1', runtime_version: '0.2.0-rc.1' },
+ ]
+
+ function approvalToasts() {
+ return toast.mock.calls.filter(call => call[1]?.onClose !== undefined)
+ }
+
+ function summaryToasts() {
+ return toast.mock.calls.filter(call => call[0] === 'Plugin operations finished')
+ }
+
+ it('stays silent when a multi-spec group ends with every process dismissed by the user', async () => {
+ invoke.mockImplementation(async (command: string) => {
+ if (command === 'install_plugin_specs')
+ throw new Error(`PLUGIN_VERSION_INCOMPATIBLE: ${JSON.stringify(BLOCKED)}`)
+ return undefined
+ })
+
+ const done = plugins.enqueue('install', ['b', 'c'], { toast: true, restartOnSettle: false })
+ await vi.waitFor(() => expect(approvalToasts()).toHaveLength(2))
+
+ for (const call of approvalToasts())
+ call[1]?.onClose?.('dismissed')
+
+ const results = await done
+ expect(results.map(result => [result.ok, result.reason])).toEqual([
+ [false, 'rejected'],
+ [false, 'rejected'],
+ ])
+ // 用户自己拒绝了两项:既不报失败,也不该弹一条没有任何收支的空汇总气泡。
+ expect(summaryToasts()).toHaveLength(0)
+ })
+
+ it('still summarises a group where a dismissal sits next to a real success', async () => {
+ let installCalls = 0
+ invoke.mockImplementation(async (command: string) => {
+ if (command !== 'install_plugin_specs')
+ return undefined
+ installCalls += 1
+ if (installCalls === 1)
+ throw new Error(`PLUGIN_VERSION_INCOMPATIBLE: ${JSON.stringify([BLOCKED[0]])}`)
+ return undefined
+ })
+
+ const done = plugins.enqueue('install', ['a', 'b'], { toast: true, restartOnSettle: false })
+ await vi.waitFor(() => expect(approvalToasts()).toHaveLength(1))
+
+ approvalToasts()[0][1]?.onClose?.('dismissed')
+
+ const results = await done
+ expect(Object.fromEntries(results.map(result => [result.process.name, [result.ok, result.reason]]))).toEqual({
+ a: [true, undefined],
+ b: [false, 'rejected'],
+ })
+ expect(summaryToasts()).toHaveLength(1)
+ expect(summaryToasts()[0][1]?.description).toBe('1 succeeded')
+ })
+})