The install dialog asks the Host to read a spec before installing it: `plugins/inspect` sorts the spec (registry name, absolute path, git address, tarball), asks the registry through `pnpm view` in the profile directory, or reads a directory's package.json, and refuses what would fail with `plugins/inspect-rejected` and a problem the dialog words under the field. A failed pnpm run carries a `kind` classified from how it ended and what pnpm printed, shown as one line with the output folded behind the details. Enabling happens after the fact from the installed screen, which scrolls the list to the first new bundle. Refusals of the moment and the confirmed cancellation are toasts; the run is stopped through the manager's `cancelInstall` and the dialog offers the spec again once the Host confirms. The non-pack dependency group folds by default under its own name. The host config gains `inspectTimeoutMs`; the CLI passes it explicitly.
75 lines
4.9 KiB
TypeScript
75 lines
4.9 KiB
TypeScript
// A real Host/Remote/browser composition with a controllable package-manager process.
|
|
// No model call is needed: installation state and profile files are the observable result.
|
|
import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { chromium } from 'playwright'
|
|
import { expect, it } from 'vitest'
|
|
import { launchWebScaffold, captureStableAria, compareOrRefreshGolden, webSnapshotMode, watchConsole, type WebScaffold } from './scaffold.ts'
|
|
import { ZH_BROWSER_LOCALE } from './support.ts'
|
|
|
|
it('cancels installation through the UI, restores files, and offers the spec again', async () => {
|
|
const scratch = await mkdtemp(join(tmpdir(), 'dsh-install-cancel-'))
|
|
const overlay = join(scratch, 'cordis.patch.yml')
|
|
await writeFile(overlay, `- id: plugin-manager\n config: ${JSON.stringify({ pnpmCommand: process.execPath, installTimeoutMs: 60_000, installKillGraceMs: 50 })}\n`)
|
|
let scaffold: WebScaffold | undefined
|
|
try {
|
|
scaffold = await launchWebScaffold({ profileRuntime: { packages: [] }, extraOverlayPath: overlay })
|
|
const browser = await chromium.launch()
|
|
try {
|
|
const profile = join(scaffold.harnessHome, 'profiles', 'scaffold')
|
|
const manifestPath = join(profile, 'package.json')
|
|
const manifest = await readFile(manifestPath, 'utf8')
|
|
const lockPath = join(profile, 'pnpm-lock.yaml')
|
|
await writeFile(lockPath, 'original lockfile\n')
|
|
// Node stands in for the pnpm executable: `view` answers the check that precedes the run,
|
|
// and the same installer owns and stops the real `add` child.
|
|
await writeFile(join(profile, 'view'), 'console.log(JSON.stringify({ name: "slow-package", version: "1.0.0" }))\n')
|
|
await writeFile(join(profile, 'add'), `
|
|
import('node:fs').then(fs => {
|
|
fs.writeFileSync('package.json', JSON.stringify({ ...JSON.parse(fs.readFileSync('package.json', 'utf8')), dependencies: { partial: '1.0.0' } }));
|
|
fs.writeFileSync('pnpm-lock.yaml', 'partial lockfile');
|
|
console.log('Waiting for package download');
|
|
setInterval(() => {}, 1000);
|
|
});
|
|
`)
|
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 }, locale: ZH_BROWSER_LOCALE })
|
|
const tripwire = watchConsole(page)
|
|
await page.goto(scaffold.authenticatedUrl)
|
|
await page.waitForSelector('[class*="frame"]')
|
|
if (await page.getByRole('dialog', { name: '设置' }).count() > 0) await page.keyboard.press('Escape')
|
|
await page.getByRole('navigation', { name: '全局面板' }).getByRole('button', { name: '插件', exact: true }).click()
|
|
const panel = page.locator('[data-plugin-panel]')
|
|
await panel.getByRole('button', { name: '添加插件', exact: true }).click()
|
|
// The dialog is named after its current screen, so it is found by role alone.
|
|
const dialog = page.getByRole('dialog')
|
|
await dialog.getByRole('textbox').fill('slow-package')
|
|
await dialog.getByRole('button', { name: '安装', exact: true }).click()
|
|
// The check passed: the running screen names the package and folds pnpm's output behind the details.
|
|
await dialog.getByText('版本 1.0.0', { exact: true }).waitFor()
|
|
await dialog.getByRole('button', { name: '查看安装详情', exact: true }).click()
|
|
await dialog.getByText('Waiting for package download', { exact: true }).waitFor()
|
|
await dialog.getByRole('button', { name: '取消安装', exact: true }).click()
|
|
// The Host's confirmation returns the dialog to the spec and says so in a toast.
|
|
await page.getByText('已取消安装,本次未继续启用插件。下载缓存或已解包文件可能保留,需要时可重新安装。', { exact: true }).waitFor()
|
|
expect(await readFile(manifestPath, 'utf8')).toBe(manifest)
|
|
expect(await readFile(lockPath, 'utf8')).toBe('original lockfile\n')
|
|
expect(await dialog.getByRole('textbox').inputValue()).toBe('slow-package')
|
|
const snapshot = (await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd))
|
|
.split(process.execPath).join('{{node}}')
|
|
.split(scaffold.harnessHome).join('{{harnessHome}}')
|
|
await compareOrRefreshGolden(fileURLToPath(new URL('./expected/plugin-install-cancel/cancelled.expected.md', import.meta.url)), snapshot, webSnapshotMode())
|
|
await writeFile(join(profile, 'add'), 'console.log("Retry completed")\n')
|
|
await dialog.getByRole('button', { name: '安装', exact: true }).click()
|
|
await dialog.getByRole('button', { name: '完成', exact: true }).waitFor()
|
|
await dialog.getByRole('button', { name: '查看安装详情', exact: true }).click()
|
|
await dialog.getByText('Retry completed', { exact: true }).waitFor()
|
|
expect(tripwire.pageErrors).toEqual([])
|
|
} finally { await browser.close() }
|
|
} finally {
|
|
await scaffold?.close()
|
|
await rm(scratch, { recursive: true, force: true })
|
|
}
|
|
})
|