fix(plugin-manager): offer another way when a GitHub failure already asked the mirror
This commit is contained in:
1 parent
55fadaa601
commit
ef516f98cf
12 files changed
+164
-14
No files matched your search
@@ -0,0 +1,22 @@
|
||||
- dialog "添加插件":
|
||||
- heading "添加插件" [level=2]
|
||||
- button "关闭"
|
||||
- textbox "插件包名":
|
||||
- /placeholder: 例如 @deepseek-ai/dsh-experimental-auto-review
|
||||
- button "收起引导" [expanded]
|
||||
- button "安装源 中国大陆镜像源"
|
||||
- list:
|
||||
- listitem:
|
||||
- text: 包名 插件包名即 npm 包名(如 dsh-xxx 或 @作者/插件名),社区插件的 README 安装命令中 dsh plugin add 或 pnpm add 之后的部分。 示例:
|
||||
- code: "@deepseek-ai/dsh-experimental-auto-review"
|
||||
- button "填入示例 @deepseek-ai/dsh-experimental-auto-review": 填入示例
|
||||
- listitem:
|
||||
- text: GitHub 仓库地址 插件在 GitHub 上的开源仓库地址,也支持其他 Git 仓库。 示例:
|
||||
- code: https://github.com/author/dsh-plugin
|
||||
- button "填入示例 https://github.com/author/dsh-plugin": 填入示例
|
||||
- listitem:
|
||||
- text: 本地插件目录 本机上插件目录的绝对路径,适用于自行开发或已下载的插件。 示例:
|
||||
- code: /Users/name/my-plugin
|
||||
- button "填入示例 /Users/name/my-plugin": 填入示例
|
||||
- note: 请确认插件来源可信。插件在本机以你的权限运行,来源不明的插件可能损坏 DeepSeek Harness,或读取和泄露你的数据。
|
||||
- button "安装" [disabled]
|
||||
@@ -0,0 +1,6 @@
|
||||
- dialog "无法访问 GitHub":
|
||||
- heading "无法访问 GitHub" [level=2]
|
||||
- button "关闭"
|
||||
- paragraph: 请尝试其他安装来源。
|
||||
- button "取消"
|
||||
- button "试试其他方式"
|
||||
@@ -0,0 +1,6 @@
|
||||
- dialog "连接 GitHub 超时":
|
||||
- heading "连接 GitHub 超时" [level=2]
|
||||
- button "关闭"
|
||||
- paragraph: 请尝试其他安装来源。
|
||||
- button "取消"
|
||||
- button "试试其他方式"
|
||||
@@ -1,5 +1,6 @@
|
||||
// Real Git reaches a controlled proxy failure or stall; the browser
|
||||
// offers a mirror for a replacement spec without retrying the failed address.
|
||||
// offers a mirror for a replacement spec, or another way once the install
|
||||
// already asks the mirror, without retrying the failed address.
|
||||
import { once } from 'node:events'
|
||||
import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises'
|
||||
import { createServer, type Socket } from 'node:net'
|
||||
@@ -11,7 +12,7 @@ import { expect, it, onTestFinished } from 'vitest'
|
||||
import { launchWebScaffold, captureStableAria, compareOrRefreshGolden, webSnapshotMode, watchConsole } from './scaffold.ts'
|
||||
import { ZH_BROWSER_LOCALE } from './support.ts'
|
||||
|
||||
it.each(['network', 'timeout'] as const)('offers a mirror after a GitHub %s and waits for replacement input', async (failure) => {
|
||||
it.each(['network', 'timeout'] as const)('offers a mirror after a GitHub %s, then another way on the mirror, and waits for replacement input', async (failure) => {
|
||||
const scratch = await mkdtemp(join(tmpdir(), 'dsh-install-github-'))
|
||||
onTestFinished(() => rm(scratch, { recursive: true, force: true }))
|
||||
const sockets = new Set<Socket>()
|
||||
@@ -97,6 +98,23 @@ it.each(['network', 'timeout'] as const)('offers a mirror after a GitHub %s and
|
||||
await input.fill(spec)
|
||||
await dialog.getByRole('button', { name: '安装', exact: true }).click()
|
||||
dialog = page.getByRole('dialog', { name: title, exact: true })
|
||||
await dialog.waitFor()
|
||||
await compareOrRefreshGolden(
|
||||
fileURLToPath(new URL(`./expected/plugin-install-github/${failure === 'timeout' ? 'timeout' : 'failed'}-on-mirror.expected.md`, import.meta.url)),
|
||||
await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd), webSnapshotMode(),
|
||||
)
|
||||
await dialog.getByRole('button', { name: '试试其他方式', exact: true }).click()
|
||||
dialog = page.getByRole('dialog', { name: '添加插件', exact: true })
|
||||
await dialog.getByRole('button', { name: '收起引导', exact: true }).waitFor()
|
||||
expect(await input.inputValue()).toBe('')
|
||||
expect(await input.evaluate(element => element === document.activeElement)).toBe(true)
|
||||
await compareOrRefreshGolden(
|
||||
fileURLToPath(new URL('./expected/plugin-install-github/another-way.expected.md', import.meta.url)),
|
||||
await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd), webSnapshotMode(),
|
||||
)
|
||||
await input.fill(spec)
|
||||
await dialog.getByRole('button', { name: '安装', exact: true }).click()
|
||||
dialog = page.getByRole('dialog', { name: title, exact: true })
|
||||
await dialog.getByRole('button', { name: '取消', exact: true }).click()
|
||||
await dialog.waitFor({ state: 'detached' })
|
||||
expect(await readFile(join(profile, '.attempts'), 'utf8')).toBe('')
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
en: ca2748d14de42df7
|
||||
zh: 51225f56acb1bada
|
||||
/deepseek-ai-dsh-client-ui-plugin-manager/use-this-package/installing-a-bundle:
|
||||
en: ac2358f44fb6d9a8
|
||||
zh: 28838f205f968c1d
|
||||
en: 130b84453fcb0f8c
|
||||
zh: f03976813657b35b
|
||||
/deepseek-ai-dsh-client-ui-plugin-manager/use-this-package/switching-a-bundle:
|
||||
en: abc90531efa889d5
|
||||
zh: 0562570f85e69c35
|
||||
|
||||
@@ -39,7 +39,7 @@ The Host sends GET requests to `https://registry.npmjs.org/-/ping` and `https://
|
||||
|
||||
During preparation and download, **Cancel install** asks the Host to stop the run and waits for confirmation. Loading the bundle cannot be cancelled. Closing with ×, Escape, or the backdrop hides the dialog immediately and requests cancellation when possible. **View installation** reopens the same task with its output; another installation cannot start while its outcome is pending or unconfirmed. Confirmed cancellation returns to the spec and shows a toast; the manifest and lockfile are restored, while downloaded files can remain. A lost installation response triggers a request to recover the result; **Check installation status** and reconnect retry that request. If the Host has no active request, **Installation result unavailable** allows returning to editing after checking the plugin list. A cancellation sent before acceptance waits and retries automatically; a failed cancellation can be retried manually. Hidden tasks report their outcome through toasts without reopening the dialog.
|
||||
|
||||
When the Host attributes a network failure or timeout to a GitHub address and offers npmmirror, the dialog says **Cannot access GitHub**, or **GitHub connection timed out** for a timeout, and offers **Use mainland China mirror** or **Cancel**. Choosing the mirror returns to an empty package-name field and remembers the selected registry without starting another installation. Other failures retain their existing diagnostics and actions. The mirror supplies registry packages and dependencies, not the GitHub repository itself.
|
||||
When the Host attributes a network failure or timeout to a GitHub address and offers npmmirror, the dialog says **Cannot access GitHub**, or **GitHub connection timed out** for a timeout, and offers **Use mainland China mirror** or **Cancel**. Choosing the mirror returns to an empty package-name field and remembers the selected registry without starting another installation. When the install already asks npmmirror, whether picked, typed, or named by pnpm's own configuration, the button reads **Try another way** instead and returns to the same empty field with **Install guide and examples** unfolded and the registry unchanged. Other failures retain their existing diagnostics and actions. The mirror supplies registry packages and dependencies, not the GitHub repository itself.
|
||||
|
||||
### Switching a bundle
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ Host 通过普通 fetch 代理向 `https://registry.npmjs.org/-/ping` 和 `https
|
||||
|
||||
准备和下载期间,**取消安装**会请求 Host 停止运行并等待确认。加载组合包的阶段不可取消。点击 ×、按 Escape 或点击遮罩会立即隐藏对话框,并在可以取消时请求取消。**查看安装任务**会重新打开同一任务并保留输出;结果待定或尚未确认时不能发起另一项安装。确认取消后回到 spec 输入界面并显示 toast;manifest 与 lockfile 已恢复,已下载文件可能保留。安装响应丢失后会请求恢复结果;**核对安装状态**和重连会重试该请求。Host 已无活动请求时,**未能获取安装结果**允许检查插件列表后返回编辑。早于接收确认的取消请求会等待并自动重试;取消失败可手动重试。隐藏的任务通过 toast 通知结果,不会重新弹出对话框。
|
||||
|
||||
Host 将网络失败或超时归因于 GitHub 地址,且提供 npmmirror 时,对话框显示**无法访问 GitHub**,超时时显示**连接 GitHub 超时**,提供**改用国内镜像**和**取消**。选择镜像后回到空的包名输入框,记住所选安装源,不自动开始下一次安装。其他失败保留原有诊断和操作。镜像提供注册表中的包及依赖,不代替 GitHub 仓库下载。
|
||||
Host 将网络失败或超时归因于 GitHub 地址,且提供 npmmirror 时,对话框显示**无法访问 GitHub**,超时时显示**连接 GitHub 超时**,提供**改用国内镜像**和**取消**。选择镜像后回到空的包名输入框,记住所选安装源,不自动开始下一次安装。安装已在使用 npmmirror 时(无论是选中、手动输入,还是 pnpm 自身配置指向它),按钮改为**试试其他方式**,同样回到空的包名输入框并展开**插件安装引导和示例**,安装源保持不变。其他失败保留原有诊断和操作。镜像提供注册表中的包及依赖,不代替 GitHub 仓库下载。
|
||||
|
||||
### 切换一个组合包
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import type { InjectFace, PropsLocale, PropsRenderSlots, PropsRuntime } from '@d
|
||||
import { rowConfigKey, type OfficialItem } from './config-ledger.ts'
|
||||
import type { PluginManagerLocaleKey } from './locales.ts'
|
||||
import {
|
||||
githubRecoveryRegistry, isInstallPending, offeredRegistries, rowKey,
|
||||
asksMirror, githubRecoveryRegistry, isInstallPending, offeredRegistries, rowKey,
|
||||
type InstallInputError, type InstallState, type InstallSubject, type PackageRow, type PackageView,
|
||||
type PluginManagerFace, type RegistryChoice,
|
||||
} from './manager-store.ts'
|
||||
@@ -785,6 +785,7 @@ function InstallDialog({
|
||||
return () => { document.removeEventListener('keydown', onKeyDown, true) }
|
||||
}, [registryShown, onToggleRegistry])
|
||||
if (githubRecoveryRegistry(install) !== undefined) {
|
||||
const anotherWay = asksMirror(install)
|
||||
return (
|
||||
<Modal
|
||||
open={install.open}
|
||||
@@ -795,7 +796,17 @@ function InstallDialog({
|
||||
footer={(
|
||||
<>
|
||||
<Button variant="outline" onClick={onClose}>{t('cancel')}</Button>
|
||||
<Button variant="primary" autoFocus onClick={onUseGithubMirror}>{t('installUseGithubMirror')}</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
autoFocus
|
||||
onClick={() => {
|
||||
// The mirror is already asked, so the form opens with the guide to the other kinds of spec.
|
||||
if (anotherWay) setGuideOpen(true)
|
||||
onUseGithubMirror()
|
||||
}}
|
||||
>
|
||||
{t(anotherWay ? 'installTryAnotherWay' : 'installUseGithubMirror')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -92,6 +92,7 @@ export const zh = {
|
||||
installGithubTimeoutTitle: '连接 GitHub 超时',
|
||||
installGithubFailedDescription: '请尝试其他安装来源。',
|
||||
installUseGithubMirror: '改用国内镜像',
|
||||
installTryAnotherWay: '试试其他方式',
|
||||
installPackageLabel: '插件包名',
|
||||
installEdit: '编辑',
|
||||
installEditAria: '返回编辑',
|
||||
@@ -284,6 +285,7 @@ export const en = {
|
||||
installGithubTimeoutTitle: 'GitHub connection timed out',
|
||||
installGithubFailedDescription: 'Try another installation source.',
|
||||
installUseGithubMirror: 'Use mainland China mirror',
|
||||
installTryAnotherWay: 'Try another way',
|
||||
installPackageLabel: 'Plugin package name',
|
||||
installEdit: 'Edit',
|
||||
installEditAria: 'Back to editing',
|
||||
|
||||
@@ -237,15 +237,26 @@ export function isInstallPending(phase: InstallState['phase']): boolean {
|
||||
/**
|
||||
* Offer the configured mainland mirror after a confirmed GitHub connection failure.
|
||||
* @param install - the installation and the Host's failure attribution.
|
||||
* @returns the offered mirror URL, or undefined when this recovery does not apply.
|
||||
* @returns the offered entry that asks npmmirror, null when pnpm's own configuration names it, or undefined when
|
||||
* this recovery does not apply.
|
||||
*/
|
||||
export function githubRecoveryRegistry(install: InstallState): string | undefined {
|
||||
export function githubRecoveryRegistry(install: InstallState): Registry | undefined {
|
||||
if (install.phase !== 'failed' || install.failure?.failedAt !== 'spec-host'
|
||||
|| (install.failure.kind !== 'network' && install.failure.kind !== 'timeout')) return undefined
|
||||
const host = install.subject?.host?.toLowerCase().split(':')[0]
|
||||
if (host !== 'github.com' && !host?.endsWith('.github.com')) return undefined
|
||||
return offeredRegistries(install.registries).find((registry): registry is string =>
|
||||
registry !== null && new URL(registry).hostname === 'registry.npmmirror.com')
|
||||
const resolved = install.registries?.resolved ?? null
|
||||
return offeredRegistries(install.registries).find(registry => registryKey(registry, resolved) === NPMMIRROR_REGISTRY)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the install already asks npmmirror first, so switching to the offered mirror would not change the registry.
|
||||
* @param install - the installation and its registry choice.
|
||||
* @returns true when the chosen registry, offered or typed, compares as npmmirror.
|
||||
*/
|
||||
export function asksMirror(install: InstallState): boolean {
|
||||
const choice = install.registry
|
||||
return registryKey(choice.kind === 'custom' ? choice.url.trim() : choice.registry, install.registries?.resolved ?? null) === NPMMIRROR_REGISTRY
|
||||
}
|
||||
|
||||
/** A destructive action waiting for the user's confirmation: a package's uninstall. */
|
||||
@@ -298,7 +309,7 @@ export interface PluginManagerFace {
|
||||
chooseRegistry: (choice: RegistryChoice) => void
|
||||
/** From the failed screen: back to the spec with the registry options unfolded. */
|
||||
changeRegistry: () => void
|
||||
/** Return from a GitHub connection failure to an empty spec with the offered mainland mirror selected. */
|
||||
/** Return from a GitHub connection failure to an empty spec asking the offered mainland mirror, keeping a choice that asks it. */
|
||||
useGithubMirror: () => void
|
||||
/** Allow the install scripts the failed run left pending, saved for this profile, and run the same spec again. */
|
||||
approveBuildsAndRetry: () => void
|
||||
@@ -575,9 +586,15 @@ export class PluginManagerController {
|
||||
const install = this.getSnapshot().install
|
||||
const mirror = githubRecoveryRegistry(install)
|
||||
if (mirror === undefined) return
|
||||
const recovered = { ...specAgain(install), spec: '', mirrorRecovery: true }
|
||||
// A typed address or pnpm's own entry that already asks the mirror stays chosen instead of becoming the offered one.
|
||||
if (asksMirror(install)) {
|
||||
this.patch({ install: recovered })
|
||||
return
|
||||
}
|
||||
const registry: RegistryChoice = { kind: 'offered', registry: mirror }
|
||||
this.registryMemory.set(registry)
|
||||
this.patch({ install: { ...specAgain(install), spec: '', mirrorRecovery: true, registry } })
|
||||
this.patch({ install: { ...recovered, registry } })
|
||||
},
|
||||
approveBuildsAndRetry: () => { void this.approveBuildsAndRetry() },
|
||||
cancelInstall: () => { void this.cancelInstall() },
|
||||
|
||||
@@ -1109,6 +1109,46 @@ describe('PluginManagerPage', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('offers another way instead of a mirror the failed GitHub install already asked', () => {
|
||||
const subject = { spec: 'github:a/b', status: 'accepted', kind: 'git', bundle: null, registry: null, host: 'github.com' } as const
|
||||
const failed: InstallState = {
|
||||
...IDLE_INSTALL, open: true, spec: subject.spec, registries: REGISTRIES, registry: { kind: 'offered', registry: MIRROR },
|
||||
phase: 'failed', subject, failure: { reason: 'GitHub connection timed out', kind: 'timeout', failedAt: 'spec-host' },
|
||||
}
|
||||
const { actions, set, setLanguage } = renderTab({ install: failed })
|
||||
// The mirror picked from the options, also while pnpm's own configuration is unread, typed as an address, or named
|
||||
// by pnpm's own configuration.
|
||||
for (const patch of [
|
||||
{},
|
||||
{ registries: { ...REGISTRIES, resolved: null } },
|
||||
{ registry: { kind: 'custom', url: ' https://registry.npmmirror.com ' } },
|
||||
{ registries: { ...REGISTRIES, resolved: MIRROR }, registry: { kind: 'offered', registry: null } },
|
||||
] as const) {
|
||||
set({ install: { ...failed, ...patch } })
|
||||
const dialog = within(screen.getByRole('dialog', { name: en.installGithubTimeoutTitle }))
|
||||
expect(dialog.getByText(en.installGithubFailedDescription)).toBeTruthy()
|
||||
expect(dialog.getAllByRole('button')).toEqual([
|
||||
dialog.getByRole('button', { name: en.close }),
|
||||
dialog.getByRole('button', { name: en.cancel }),
|
||||
dialog.getByRole('button', { name: en.installTryAnotherWay }),
|
||||
])
|
||||
}
|
||||
fireEvent.click(screen.getByRole('button', { name: en.installTryAnotherWay }))
|
||||
expect(actions.useGithubMirror).toHaveBeenCalledOnce()
|
||||
expect(actions.runInstall).not.toHaveBeenCalled()
|
||||
// The form it returns to opens the guide to the other kinds of spec.
|
||||
set({ install: { ...IDLE_INSTALL, open: true, mirrorRecovery: true, registries: REGISTRIES, registry: failed.registry } })
|
||||
expect(screen.getByRole('button', { name: en.installGuideHide }).getAttribute('aria-expanded')).toBe('true')
|
||||
expect(screen.getByText(en.installGuidePathExample)).toBeTruthy()
|
||||
// A typed address other than the mirror can still switch to it.
|
||||
set({ install: { ...failed, registry: { kind: 'custom', url: 'npm.corp' } } })
|
||||
expect(screen.getByRole('button', { name: en.installUseGithubMirror })).toBeTruthy()
|
||||
setLanguage(zh)
|
||||
set({ install: failed })
|
||||
expect(screen.getByRole('button', { name: '试试其他方式' })).toBeTruthy()
|
||||
expect(screen.queryByRole('button', { name: '改用国内镜像' })).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps the ordinary failure view for registry errors, other hosts, and unavailable mirrors', () => {
|
||||
const failed: InstallState = {
|
||||
...IDLE_INSTALL, open: true, registries: REGISTRIES, phase: 'failed',
|
||||
|
||||
@@ -1255,6 +1255,34 @@ describe('PluginManagerController', () => {
|
||||
await vi.waitFor(() => { expect(state().install.registries).toEqual(REGISTRIES) })
|
||||
expect(state().install.registry).toEqual({ kind: 'offered', registry: MIRROR })
|
||||
})
|
||||
|
||||
it.each([
|
||||
['typed as an address', { kind: 'custom', url: 'https://registry.npmmirror.com' }, REGISTRIES],
|
||||
['named by pnpm\'s own configuration', { kind: 'offered', registry: null }, { ...REGISTRIES, resolved: MIRROR }],
|
||||
] as const)('leaves only the GitHub address behind when the install already asked the mirror %s', async (_how, choice, registries) => {
|
||||
const { face, state, plugins } = bench({
|
||||
registries: vi.fn(() => Promise.resolve(ok(registries))),
|
||||
inspect: vi.fn(() => Promise.resolve(ok({ status: 'accepted', kind: 'git', bundle: null, registry: MIRROR, host: 'github.com' }))),
|
||||
installBundle: vi.fn(() => Promise.resolve(ok({
|
||||
...failed(undefined, { exitCode: 1, output: 'Could not resolve host: github.com', truncated: false, logPath: '/l', kind: 'timeout' }),
|
||||
failedAt: 'spec-host',
|
||||
}))),
|
||||
})
|
||||
face.openInstall()
|
||||
await vi.waitFor(() => { expect(state().install.registries).toEqual(registries) })
|
||||
face.chooseRegistry(choice)
|
||||
face.editInstallSpec('https://github.com/example/dsh-plugin.git')
|
||||
face.runInstall()
|
||||
await vi.waitFor(() => { expect(state().install.phase).toBe('failed') })
|
||||
face.useGithubMirror()
|
||||
expect(state().install).toMatchObject({ phase: 'idle', spec: '', mirrorRecovery: true, registry: choice, failure: null })
|
||||
// The choice stays as made, so the next dialog starts from it too.
|
||||
face.closeInstall()
|
||||
face.openInstall()
|
||||
await vi.waitFor(() => { expect(state().install.registries).toEqual(registries) })
|
||||
expect(state().install.registry).toEqual(choice)
|
||||
expect(plugins.installBundle).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Host registry response recommendation', () => {
|
||||
|
||||
Reference in new issue
Block a user