The Web e2e fixture answered `/mcp` to any `Authorization` header while its header comment promised the issued token, and it folded handler errors into bare 500 responses. It now accepts only tokens it issued, records handler failures for the scenario to assert, and states why its MCP answers are hand-written: `apps/web` carries no MCP SDK dependency. `plugin.spec.ts` covers a configured server that already owns `mcp-client/linear`, the second load-time conflict the README and JSDoc name. The README attributes `systemPrompt` to the base bundle instead of `dsh-web-app`, counts the guidance as three sentences, and cites Linear's documentation for the paid-workspace approval limitation. The jscpd marker names its twins, and the headless snapshot comment states that an empty authorization list means the fixture received no request.
78 lines
4.1 KiB
TypeScript
78 lines
4.1 KiB
TypeScript
// Web e2e scenario: connecting the Linear plugin from its page on the Plugins
|
|
// page. The section reads the MCP manager's real entry, the browser opens the
|
|
// loopback authorization server's page, the Host callback answers with its
|
|
// completion page, the connection reaches the manager, and sign-out returns the
|
|
// section to disconnected. Zero model calls.
|
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import type { Browser, BrowserContext, Page } from 'playwright'
|
|
import { chromium } from 'playwright'
|
|
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
|
|
import { startLinearOAuthFixture, type LinearOAuthFixture } from './linear-oauth-fixture.ts'
|
|
import { launchWebScaffold, watchConsole, type WebScaffold } from './scaffold.ts'
|
|
import { ZH_BROWSER_LOCALE, saveFailureShot } from './support.ts'
|
|
|
|
const LINEAR_DIR = fileURLToPath(new URL('../../../packages/connector/linear', import.meta.url))
|
|
|
|
describe('web e2e: Linear plugin connection', () => {
|
|
let fixture: LinearOAuthFixture
|
|
let overlayDir: string
|
|
let scaffold: WebScaffold
|
|
let browser: Browser
|
|
let context: BrowserContext
|
|
let page: Page
|
|
let tripwire: ReturnType<typeof watchConsole>
|
|
|
|
beforeAll(async () => {
|
|
fixture = await startLinearOAuthFixture()
|
|
overlayDir = await mkdtemp(join(tmpdir(), 'dsh-linear-e2e-'))
|
|
const overlay = join(overlayDir, 'linear.overlay.yml')
|
|
await writeFile(overlay, `- id: linear\n config:\n url: ${fixture.origin}/mcp\n`)
|
|
scaffold = await launchWebScaffold({
|
|
extraOverlayPath: [fileURLToPath(new URL('./pin-browse-picker.overlay.yml', import.meta.url)), overlay],
|
|
profile: { packages: [{ dir: LINEAR_DIR, enabled: true }] },
|
|
})
|
|
browser = await chromium.launch()
|
|
context = await browser.newContext({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
|
|
page = await context.newPage()
|
|
tripwire = watchConsole(page)
|
|
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
|
await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
|
|
}, 120_000)
|
|
|
|
afterAll(async () => {
|
|
await browser?.close()
|
|
await scaffold?.close()
|
|
await fixture?.close()
|
|
if (overlayDir !== undefined) await rm(overlayDir, { recursive: true, force: true })
|
|
})
|
|
|
|
it('connects the account from the plugin page and signs out after confirmation', async () => {
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-linear-connection'))
|
|
await page.getByRole('navigation', { name: '全局面板' }).getByRole('button', { name: '插件', exact: true }).click()
|
|
const panel = page.locator('[data-plugin-panel]')
|
|
await panel.getByRole('button', { name: '查看 Linear 插件', exact: true }).click({ timeout: 20_000 })
|
|
const section = panel.locator('[data-connector-account]')
|
|
await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('disconnected')
|
|
expect(await panel.locator('[data-plugin-detail]').getByText('未连接', { exact: true }).count()).toBe(2)
|
|
|
|
const opened = context.waitForEvent('page')
|
|
await section.getByRole('button', { name: '连接 Linear', exact: true }).click()
|
|
const authorization = await opened
|
|
await expect.poll(async () => await authorization.locator('body').textContent(), { timeout: 20_000 })
|
|
.toContain('已收到授权。可以关闭此页,回到 DSH 查看连接结果。')
|
|
await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('connected')
|
|
await page.getByText('Linear 已连接', { exact: true }).waitFor({ timeout: 10_000 })
|
|
expect(fixture.authorizations()).toBe(1)
|
|
await authorization.close()
|
|
|
|
await section.getByRole('button', { name: '退出登录', exact: true }).click()
|
|
await page.getByRole('dialog', { name: '退出 Linear 登录?' }).getByRole('button', { name: '退出登录', exact: true }).click()
|
|
await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('disconnected')
|
|
expect(tripwire.pageErrors).toEqual([])
|
|
expect(fixture.failures()).toEqual([])
|
|
})
|
|
})
|