merge fix/git-scm-layout: restore selected Git row layout

This commit is contained in:
Menghuan1918 committed 2026-10-16 21:46:54 +08:00
commit 612cea242f
5 files changed
+255 -4

No files matched your search

+1
View File
@@ -1149,6 +1149,7 @@ interface SettingsDescriptor {
- **拖拽区退出**:交互 chrome(`.toggleCluster` / `.toggleButton` / `.tabBar`)统一 `-webkit-app-region: no-drag`(无边框壳拖拽带吞点击,#103/#111)。
- **拖拽区退出(视口层)**:宿主把每个**直挂 body 的子元素**都设成 `no-drag`(`html[data-platform=darwin] body > :not(#root)`,选择器含 id,只能靠 `!important` 压过),而 app-region **无视 `pointer-events`**——插件宿主就是这样一个 body 子元素,在 Electron 里该值还会传到它内部的**铺满视口的面板层**(#772 的 CDP 实测;挂载 lane 用的浏览器引擎不传播该属性,所以面板层自己也声明了同一条规则),于是它把下面每条 `[data-window-drag]` 拖拽带一起抵消(窗口拖一次就失效,同时丢掉 macOS 双击标题栏缩放,issue #772)。契约:装饰性的视口层用**中性值** `-webkit-app-region: initial !important` 退出计算(`initial` 的计算值 `none` 不扣减拖拽区;注意**字面量 `none` 不是中性值**——它计算成 `no-drag`,是扣减值),层内的面板/控件再声明 `no-drag` 保住点击;当前覆盖 `[data-dsh-better-sidebar]`、`[data-dsh-panel-host]`(`> *` 保持 `no-drag`)与 `.mermaidModal`(放大视图是第二个**持久**铺满视口的 body 直挂层)。**交互弹层不要加 `initial`**(`.selectionPopup` 是 `<button>`,`FloatingWindow` / `AnchoredPopover` 自带指针拖拽、不是遮罩层):宿主 `:is(button, a, input, …)` 已给它们 `no-drag`,反过来声明 `initial !important` 会让按下变成拖窗(重演 #103/#111)。放大视图是**遮罩层例外**——它是模态,只有其中的控件必须保持 `no-drag`;代价是它覆盖在顶部拖拽带上时,点背景会变成拖窗而不是关闭(为「放大图时窗口仍可拖」付的账)。**未纳入**:`FileTree` 的 `.uploadDropChatHint` 同样是 body 直挂的装饰层,但它只在 OS 文件拖拽悬停期间存在且 `pointer-events: none`,收益极小、暂不处理(`FloatingWindow` / `AnchoredPopover` 是交互层,按上面的判据本就该保持 `no-drag`)。形状由 `tests/panel-host-css.spec.ts` 在 Linux 的 `pnpm test` 里守护(无 macOS runner;`tests/theme.spec.ts` 只守颜色,故本轮不涉及),真实级联由挂载 lane 的探针按宿主规则断言计算值(面板宿主探针复现宿主两条 darwin 规则,放大视图探针直接用页面里宿主自己的规则)。
- **z-index**:面板宿主层 25、按钮簇 45——低于 DSH ui-cordis 插件面板(30)与浮层栈(100/1000+),浮层天然盖住侧边栏。
- **更改行选中态**:Git 文件行和本轮操作行保持原有布局;选中只绘制 `--dsw-alias-interactive-bg-active` 背景,以及行内 inset 4px、宽 2px 的 `--dsw-alias-state-business-primary` 标记。选中规则与缩进参考线的绝对定位规则必须分开;`tests/theme.spec.ts` 解析实际 CSS 规则守护,挂载测试验证点击后文件行仍在原分组内。
### 12.2 注意事项
@@ -63,8 +63,10 @@
- CI:每一批推送都等 `ci` / `ci-windows` / `plugin-mount` 三绿;`plugin-mount` 跑真实挂载
(含本批新增的 `tests/e2e/git-graph.e2e.ts`:真机建带合并的仓库、渲染历史、点开提交详情、
按分支筛选,并断言读图前后 HEAD / refs / status 逐字不变)。
- **本地 `pnpm test:mount` 跑不了**:脚本要写真实 `~/.dsh/profiles/web` 的锁文件,被文件沙箱拒绝;
该 lane 由 CI 的 `plugin-mount` job 覆盖。
- **本地挂载入口**:桌面 `dsh` shim 会覆盖 `DSH_HOME`,导致 scratch 测试误用真实 profile;
测试改用不覆盖 `DSH_HOME` 的 CLI wrapper 后可以在独立 scratch profile 运行。
本机完整 lane 的终端测试仍受 PTY 沙箱限制(`posix_openpt: Operation not permitted`),
不削弱该断言,完整通过结果以 CI 的 `plugin-mount` 为准。
## 过程中发现并修掉的三处 CI 红
@@ -76,3 +78,16 @@
`wait` 参数契约。
3. **`tests/e2e-aggregate-auth.spec.ts` 的过宽正则**(Windows 上偶发红):`/-[^-\s]*L/` 在整行里
匹配到了 mkdtemp 后缀(`dsh-aggregate-auth-6mLM51`)。改为只查 **flag token**。
## 选中行错位回归
- **触发条件**:在 Git 更改组中点击文件打开差异。只检查未选中的初始截图不能发现此问题。
- **根因**:整合 #969 时删除 `.logRow` 规则,连同它与 `.row` / `.opRow` 共用的声明块一起删掉,
留下逗号结尾的选择器。CSS 将这些选择器与后面的 `.guide` 合并,选中文件行因此收到
`position: absolute; top: 0; bottom: 0; width: 0; border-left: ...`,脱离分组并绘制异常长边框。
此问题来自维护者整合提交 `88ded478`,不是贡献者原 PR 的行为。
- **证据**:真实挂载复现中,未暂存行点击前高 28px、位于 y=351..379;点击后高 862px、
位于 y=38..900,超出分组 y=239..353。恢复声明后,同一点击前后行高和坐标保持一致。
- **修复**:只恢复两类现役行的选中背景与 `::before` 标记声明,不改变图谱尺寸、滚动结构或数据逻辑。
- **回归门禁**:`tests/theme.spec.ts` 解析真实 CSS 规则,覆盖 `.row` 与 `.opRow`,最小复现先红后绿;
真实挂载测试覆盖冲突、暂存、未暂存、未跟踪文件及选中后的分组边界。临时几何探针不随代码提交。
+13 -2
View File
@@ -166,10 +166,21 @@
(the tasks page's own recipe), so the row stays shadowless and no metric
shifts between rows. */
.row[data-selected='true'],
.opRow[data-selected='true'],
.opRow[data-selected='true'] {
background: var(--dsw-alias-interactive-bg-active);
}
.row[data-selected='true']::before,
.opRow[data-selected='true']::before,
.opRow[data-selected='true']::before {
content: '';
position: absolute;
left: 0;
top: 4px;
bottom: 4px;
width: 2px;
border-radius: 1px;
background: var(--dsw-alias-state-business-primary);
}
/* The tree's indent guides: the same 1px `border-l1` edge the old nested
`.treeChildren` wrapper drew (`margin-left: 11px` boundaries become the
+195
View File
@@ -0,0 +1,195 @@
import { execFileSync } from 'node:child_process'
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { test, expect, type Page } from '@playwright/test'
import { createHostApi, gotoPage, hostRpc, sendFirstMessage } from './host'
/**
* A SELECTED change row must stay an in-flow 28px band inside its own
* `[data-group]` (the "staging area misaligned" report).
*
* The regression: a dangling selector list in `changes.module.css` (the
* selected-row / `::before` selectors left without a declaration block, a
* comment sitting between the trailing comma and `.guide`) joined the three
* selected selectors onto the indent-guide rule. Every `[data-selected]` row
* therefore inherited `position: absolute; top: 0; bottom: 0; width: 0;
* border-left: 1px solid var(--dsw-alias-border-l1)` — it left its group,
* stretched over the panel (28px → the panel's full height), collapsed to zero
* width and painted the guide's pale hairline.
*
* jsdom cannot observe any of that (no layout engine — `tests/changes-tab.spec.tsx`
* pins the sheet's dock/scroll rules as text instead), so this lane asserts the
* RENDERED geometry of the selected row: computed `position`, width, the 28px
* band height, its box inside its `[data-group]` and inside the changes
* section, no borrowed `border-left`, and no overlap with the docked footer or
* the preview pane. Waits are locator/poll based — no fixed sleeps.
*/
/** The fixture's porcelain states: a conflicted path, a path staged AND then
* edited (one row in each band), and an untracked file. */
function buildFixture(): { root: string; status: string[] } {
const root = mkdtempSync(join(tmpdir(), 'sidebar-git-layout-'))
const git = (...args: string[]): string => execFileSync('git', ['-C', root, ...args], { encoding: 'utf8' }).trim()
git('init', '-b', 'main')
git('config', 'user.name', 'Layout fixture')
git('config', 'user.email', 'layout@example.invalid')
mkdirSync(join(root, 'src/app'), { recursive: true })
mkdirSync(join(root, 'docs'), { recursive: true })
writeFileSync(join(root, 'src/app/main.ts'), 'export const main = 1\n')
writeFileSync(join(root, 'src/app/util.ts'), 'export const util = 1\n')
writeFileSync(join(root, 'docs/readme.md'), '# readme\n')
git('add', '.')
git('commit', '-m', 'base')
// The conflict that produces the Merge band.
git('checkout', '-b', 'side')
writeFileSync(join(root, 'src/app/main.ts'), 'export const main = 99\n')
git('add', '.')
git('commit', '-m', 'side change')
git('checkout', 'main')
writeFileSync(join(root, 'src/app/main.ts'), 'export const main = 100\n')
git('add', '.')
git('commit', '-m', 'main change')
try { git('merge', '--no-ff', 'side', '-m', 'merge') } catch { /* the conflict is the point */ }
// util.ts is STAGED and then edited again: 'MM' ⇒ one row in the Staged band
// and one in the Changes band, which is what makes the band distinction
// observable at all.
writeFileSync(join(root, 'src/app/util.ts'), 'export const util = 2\nexport const more = 3\n')
git('add', 'src/app/util.ts')
writeFileSync(join(root, 'src/app/util.ts'), 'export const util = 5\n')
writeFileSync(join(root, 'docs/notes.md'), 'notes\n')
return { root, status: git('status', '--porcelain').split('\n') }
}
/** The one selection the probe expects, or null before anything is clicked. */
interface SelectedRow { group: string; path: string }
/**
* Geometry verdict for EVERY change row, plus the selected row's own computed
* style. Returns human reasons (empty = pass), so a failing `expect.poll` names
* the row and the measurement instead of a bare timeout.
*/
function rowGeometryProblems(page: Page, expected: SelectedRow | null): Promise<string[]> {
return page.evaluate((target) => {
const problems: string[] = []
const view = document.defaultView
if (view === null) return ['no browsing context']
const changes = document.querySelector('[data-scm-section="changes"]')
if (changes === null) return ['no [data-scm-section="changes"]']
const changesBox = changes.getBoundingClientRect()
const footer = document.querySelector('[data-git-footer]')?.getBoundingClientRect() ?? null
const pane = document.querySelector('[class*="diffPane"]')?.getBoundingClientRect() ?? null
const rows = [...document.querySelectorAll<HTMLElement>('[data-scm-section="changes"] [data-row]')]
if (rows.length === 0) problems.push('no change rows rendered')
for (const row of rows) {
const group = row.closest('[data-group]')
const name = row.getAttribute('data-row') ?? '?'
const band = group?.getAttribute('data-group') ?? null
const label = `${band ?? 'no-group'}/${name}`
if (group === null) { problems.push(`${label}: not inside a [data-group]`); continue }
const box = row.getBoundingClientRect()
const style = view.getComputedStyle(row)
// The regression's signature: the row borrowed the `.guide` box rule.
if (style.position !== 'relative') problems.push(`${label}: computed position is ${style.position}, expected relative`)
if (style.width === '0px' || Math.round(box.width) < 100) problems.push(`${label}: width ${style.width} (${String(Math.round(box.width))}px)`)
if (style.borderLeftWidth !== '0px') problems.push(`${label}: borrowed border-left ${style.borderLeftWidth} ${style.borderLeftStyle} ${style.borderLeftColor}`)
if (Math.abs(box.height - 28) > 1) problems.push(`${label}: height ${String(Math.round(box.height))}, expected the 28px band`)
const groupBox = group.getBoundingClientRect()
if (box.top < groupBox.top - 1 || box.bottom > groupBox.bottom + 1) {
problems.push(`${label}: box ${String(Math.round(box.top))}..${String(Math.round(box.bottom))} escapes its group ${String(Math.round(groupBox.top))}..${String(Math.round(groupBox.bottom))}`)
}
if (box.top < changesBox.top - 1 || box.bottom > changesBox.bottom + 1) problems.push(`${label}: box escapes the changes section`)
if (footer !== null && box.bottom > footer.top + 1) problems.push(`${label}: box overlaps the docked footer`)
if (pane !== null && box.bottom > pane.top + 1) problems.push(`${label}: box overlaps the preview pane`)
}
const selected = [...document.querySelectorAll<HTMLElement>('[data-scm-section="changes"] [data-row][data-selected="true"]')]
if (target === null) {
if (selected.length > 0) problems.push(`${String(selected.length)} row(s) selected before any click`)
} else {
if (selected.length !== 1) problems.push(`${String(selected.length)} selected rows, expected exactly 1`)
const wanted = selected.filter(row => row.getAttribute('data-row') === target.path
&& row.closest('[data-group]')?.getAttribute('data-group') === target.group)
if (wanted.length !== 1) problems.push(`${target.group}/${target.path}: ${String(wanted.length)} selected rows, expected exactly 1`)
}
if (footer !== null && pane !== null && footer.bottom > pane.top + 2) problems.push('the docked footer overlaps the preview pane')
return problems
}, expected)
}
/** Open the Git guide entry and wait for the SCM body (never the control twice:
* the expand control is gone once the sidebar is open). */
async function openGitPage(page: Page): Promise<void> {
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 expect(page.locator('[data-scm-section="changes"]')).toBeVisible({ timeout: 30_000 })
}
/** Select one band's file row and return the reasons the rendered result is wrong. */
async function selectRow(page: Page, target: SelectedRow): Promise<{ widthBefore: number; widthAfter: number }> {
const row = page.locator(`[data-group="${target.group}"] [data-row="${target.path}"]`)
await expect(row).toHaveCount(1)
const before = await row.boundingBox()
expect(before, `${target.group}/${target.path} has no box before selection`).not.toBeNull()
await row.locator(`[data-path="${target.path}"]`).click()
await expect(row).toHaveAttribute('data-selected', 'true')
const pane = page.locator('[class*="diffPane"]')
await expect(pane).toBeVisible({ timeout: 30_000 })
await expect(pane.getByRole('button', { name: 'Refresh', exact: true })).toBeEnabled()
await expect.poll(() => rowGeometryProblems(page, target), { timeout: 10_000 }).toEqual([])
const after = await row.boundingBox()
expect(after, `${target.group}/${target.path} has no box after selection`).not.toBeNull()
return { widthBefore: before?.width ?? 0, widthAfter: after?.width ?? 0 }
}
test('a selected change row stays an in-flow band inside its group', async ({ page }, testInfo) => {
const { root, status } = buildFixture()
// The fixture is only a valid probe if every band really has its row.
expect(status).toContain('UU src/app/main.ts')
expect(status).toContain('MM src/app/util.ts')
expect(status).toContain('?? docs/notes.md')
const api = await createHostApi()
const pageErrors: string[] = []
page.on('pageerror', error => { pageErrors.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 })
expect(session.value.sessionId).toBeTruthy()
await gotoPage(page)
await openGitPage(page)
// Nothing selected yet: every row is already an in-flow band in its group.
await expect(page.locator('[data-group="merge"] [data-row="src/app/main.ts"]')).toBeVisible()
await expect(page.locator('[data-group="staged"] [data-row="src/app/util.ts"]')).toBeVisible()
await expect(page.locator('[data-graph-commit]')).toHaveCount(3)
await expect.poll(() => rowGeometryProblems(page, null), { timeout: 10_000 }).toEqual([])
// Both bands carry the SAME path: each selection must keep its own row put.
for (const target of [
{ group: 'unstaged', path: 'src/app/util.ts', shot: 'selected-unstaged.png' },
{ group: 'staged', path: 'src/app/util.ts', shot: 'selected-staged.png' },
{ group: 'merge', path: 'src/app/main.ts', shot: 'selected-conflict.png' },
]) {
const widths = await selectRow(page, target)
expect(Math.abs(widths.widthAfter - widths.widthBefore), `${target.group}/${target.path} jumped width on selection`).toBeLessThanOrEqual(1)
await page.screenshot({ path: testInfo.outputPath(target.shot) })
}
// A narrower desktop shell (still above the 768px mobile gate) must hold the
// same invariants: the band is panel-width, not viewport-width.
await page.setViewportSize({ width: 1024, height: 800 })
await expect(page.locator('[data-scm-section="changes"]')).toBeVisible()
await selectRow(page, { group: 'unstaged', path: 'src/app/util.ts' })
await page.screenshot({ path: testInfo.outputPath('selected-narrow.png') })
expect(pageErrors).toEqual([])
} finally {
await api.dispose()
}
})
+29
View File
@@ -161,6 +161,35 @@ describe('skin contract: the plugin owns no color of its own', () => {
}
})
it('selected change rows keep their layout and separate their accent from indent guides', () => {
const sheet = document.createElement('style')
sheet.textContent = readFileSync(resolve(ROOT, 'src/client/changes/changes.module.css'), 'utf8')
document.head.append(sheet)
try {
const rules = Array.from(sheet.sheet!.cssRules).filter((rule): rule is CSSStyleRule => 'selectorText' in rule)
for (const name of ['row', 'opRow']) {
const selector = `.${name}[data-selected='true']`
const selected = rules.filter(rule => rule.selectorText.split(',').some(part => part.trim() === selector))
expect(selected).toHaveLength(1)
const style = selected[0]!.style
expect(style.getPropertyValue('position')).toBe('')
expect(style.getPropertyValue('width')).toBe('')
expect(style.getPropertyValue('border-left')).toBe('')
expect(style.getPropertyValue('background')).toBe('var(--dsw-alias-interactive-bg-active)')
const marker = rules.find(rule => rule.selectorText.split(',').some(part => part.trim() === `${selector}::before`))!
expect(marker.style.getPropertyValue('width')).toBe('2px')
expect(marker.style.getPropertyValue('top')).toBe('4px')
expect(marker.style.getPropertyValue('bottom')).toBe('4px')
expect(marker.style.getPropertyValue('background')).toBe('var(--dsw-alias-state-business-primary)')
}
const guide = rules.find(rule => rule.selectorText === '.guide')!
expect(guide.style.getPropertyValue('position')).toBe('absolute')
expect(guide.style.getPropertyValue('border-left')).toBe('1px solid var(--dsw-alias-border-l1)')
} finally {
sheet.remove()
}
})
it('the running bar sweeps the FULL width (a band either side, not a partial blob)', () => {
// Reader report: the first cut moved a 45%-wide band with
// `background-position`, so the bar was only ever partially lit. The