From 3edaa5aee8199c3a4d5b75ec6ba1806cbef4c279 Mon Sep 17 00:00:00 2001 From: vlln Date: Thu, 15 Oct 2026 19:56:40 -0700 Subject: [PATCH] =?UTF-8?q?test(e2e):=20=E5=9B=BE=E8=B0=B1=E5=9C=A8?= =?UTF-8?q?=E7=9C=9F=E5=AE=9E=E5=AE=BF=E4=B8=BB=E4=B8=8A=E7=9A=84=E6=8C=82?= =?UTF-8?q?=E8=BD=BD=E5=86=92=E7=83=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在真实 `dsh web` 上建一个带合并的真实仓库,走完整链路:`git.graph` 路由 → 打开 Git 页并切到 Git Graph → 渲染出合并历史 → 点合并提交(详情卡片里是 完整 hash 与两个父提交短哈希,且没有已删除的「与第一个父提交比较」提示) → 分支下拉框筛选后历史收窄。同时断言全程无 pageerror,且仓库的 HEAD / refs / status 在读图前后逐字不变——这一条是「只读」最硬的证据。 选择器都锚定到具体容器:短 hash 在(隐藏的)Git 视角里也有,纯文本匹配会命中 隐藏元素;分支名 `main` 在下拉框的 option 里也有一份。 --- tests/e2e/git-graph.e2e.ts | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/e2e/git-graph.e2e.ts diff --git a/tests/e2e/git-graph.e2e.ts b/tests/e2e/git-graph.e2e.ts new file mode 100644 index 00000000..e7f765c8 --- /dev/null +++ b/tests/e2e/git-graph.e2e.ts @@ -0,0 +1,75 @@ +import { execFileSync } from 'node:child_process' +import { mkdtempSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { test, expect } from '@playwright/test' +import { createHostApi, gotoPage, hostRpc, sendFirstMessage, sidebarApi } from './host' + +// A dedicated fixture: never initialize or write the caller's working repository. +test('read-only Git Graph renders merge history and filters without checkout', async ({ page }, testInfo) => { + const root = mkdtempSync(join(tmpdir(), 'sidebar-graph-e2e-')) + const git = (...args: string[]) => execFileSync('git', ['-C', root, ...args], { encoding: 'utf8' }).trim() + git('init', '-b', 'main') + git('config', 'user.name', 'Graph fixture') + git('config', 'user.email', 'graph@example.invalid') + writeFileSync(join(root, 'base.txt'), 'base\n') + git('add', '.') + git('commit', '-m', 'Graph base') + git('checkout', '-b', 'feature') + writeFileSync(join(root, 'feature.txt'), 'feature\n') + git('add', '.') + git('commit', '-m', 'Graph feature') + git('checkout', 'main') + writeFileSync(join(root, 'main.txt'), 'main\n') + git('add', '.') + git('commit', '-m', 'Graph main') + git('merge', '--no-ff', 'feature', '-m', 'Graph merge') + const before = { head: git('rev-parse', 'HEAD'), refs: git('show-ref'), status: git('status', '--porcelain') } + const api = await createHostApi() + const errors: string[] = [] + page.on('pageerror', error => errors.push(String(error))) + try { + const workspace = await hostRpc<{ workspace: { workspaceId: string } }>(api, 'workspace.create', { path: root }) + const session = await hostRpc<{ sessionId: string }>(api, 'session.create', { workspaceId: workspace.value.workspace.workspaceId }) + const response = await api.post(sidebarApi('git.graph'), { data: { sessionId: session.value.sessionId, cwd: root } }) + expect(response.ok()).toBe(true) + await gotoPage(page) + await expect(page.locator('[data-dsh-better-sidebar]')).toBeAttached({ timeout: 90_000 }) + for (const label of [/^Continue$/, /^Configure later$/]) { + const button = page.getByRole('button', { name: label }).first() + try { await button.click({ timeout: 8_000 }) } catch { /* onboarding may already be dismissed */ } + } + await sendFirstMessage(page) + await page.locator('[data-sidebar-right-expand]').first().click() + await page.locator('[data-sidebar-right-guide-entry="git"]').click() + await page.getByText('Git Graph', { exact: true }).click() + const graph = page.locator('[data-git-graph]:visible') + await expect(graph.getByText('Graph merge', { exact: true }).first()).toBeVisible({ timeout: 30_000 }) + await expect(graph.getByText('Graph feature', { exact: true }).first()).toBeVisible() + await graph.getByText('Graph merge', { exact: true }).first().click() + // The selection opens the DETAILS card in the shared bottom pane: the full + // hash chip, both merge parents (7-char chips), and no first-parent note. + // Scope to the card — short hashes also appear in the (hidden) Git lens. + const panel = page.locator('[data-sidebar-right-panel]:visible') + const card = panel.locator('section[aria-label]') + await expect(card.getByText(before.head, { exact: true })).toBeVisible() + const parents = git('rev-parse', 'HEAD^1', 'HEAD^2').split('\n') + await expect(card.getByText(parents[0]!.slice(0, 7), { exact: true }).first()).toBeVisible() + await expect(card.getByText(parents[1]!.slice(0, 7), { exact: true }).first()).toBeVisible() + await expect(panel.getByText(/first parent/i)).toHaveCount(0) + // The current branch's pill (HEAD folds into it) sits on the merge row. + // Scoped to the row: the bare name also lives in the branch select. + const mergeRow = graph.locator('[data-graph-commit]', { hasText: 'Graph merge' }).first() + await expect(mergeRow.getByText('main', { exact: true })).toBeVisible() + await page.screenshot({ path: testInfo.outputPath('git-graph.png'), fullPage: true }) + const branchFilter = page.locator('[data-git-graph] select').filter({ has: page.locator('option[value="refs/heads/feature"]') }) + await branchFilter.selectOption('refs/heads/feature') + await expect(graph.getByText('Graph merge', { exact: true })).toHaveCount(0) + await expect(graph.getByText('Graph feature', { exact: true }).first()).toBeVisible() + expect(errors).toEqual([]) + expect({ head: git('rev-parse', 'HEAD'), refs: git('show-ref'), status: git('status', '--porcelain') }).toEqual(before) + } finally { + await api.dispose() + // Fixture retained with test artifacts for inspecting failures; no shared-path cleanup. + } +})