This lands the clue collection line on top of origin/dev (v0.32.1, DSH 0.2.2-rc.2). The 14 commits that carried it are squashed into this one because every one of them overlapped upstream's own changes (version, 19 dictionaries, CHANGELOG), and each intermediate commit would have failed to compile against rc.2's menu API. The pre-integration head is kept at backup/clues-uiux-refresh-pre-rebase. What the feature is: - a Clues tab that reads local files, Feishu tasks/docs and GitHub issues/pulls through one source registry, with a scope row, shared search, filters, paging and stable [[dsh-clue:...]] references; - one window host for detail, pack management, source configuration, new pack and sharing (preview and edit are separate paths: a read is never saved over); - .cluepack export/import with per-row resolvability previews; - a source runtime that owns dependency installs and connection authorization (gh, lark-cli device code) and only probes on an explicit read; - the public betterSidebarClues service and the windows capability (features gains clues / windowHost). Merged with upstream rather than over it: - the settings section keeps upstream's start-page takeover group and this branch's clue sources group; navigation is now six groups; - the dictionaries keep both sides' new keys (1211 each, verified equal across all 19), the external-plugin guide and CHANGELOG keep both histories, and service features list both capability sets. Adapted to 0.2.2-rc.2: - menu call sites use anchorPoint instead of getAnchorRect; - the shared SelectMenu mounts the host menu only while open, because rc.2's Menu reads the DOM during render and broke server-rendered settings surfaces; - the submenu flip workaround stays deleted (the host positions submenus now), pinned by an updated layout-css assertion. Version 0.33.0 (three synced spots) with a new 未发布 / Unreleased changelog section; package.json regains the ./clues export, lib/clues.js and the uqr dependency that upstream never had. Gates: typecheck, lint, 5410 unit tests, build, check:consumer-types and the full mount lane (35 passed) against dsh 0.2.2-rc.2 in Chromium.
217 lines
8.8 KiB
TypeScript
217 lines
8.8 KiB
TypeScript
// @vitest-environment jsdom
|
|
/**
|
|
* The git fold expansion path: DiffFiles forwards a resolveFold loader to
|
|
* DiffRows, whose first click on a rows-less git gap fold fetches the hidden
|
|
* rows (loading/failed markers in between) and later clicks toggle; folds
|
|
* that carry rows (the session-op path) expand directly, and gaps without a
|
|
* loader stay inert markers — the pre-fix behavior for op diffs.
|
|
*/
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { createElement } from 'react'
|
|
import { createRoot, type Root } from 'react-dom/client'
|
|
import { act } from 'react-dom/test-utils'
|
|
import { DiffFiles } from '../src/client/diff/DiffFiles.tsx'
|
|
import { DiffRows } from '../src/client/diff/DiffRows.tsx'
|
|
import { buildDiffSegments, diffLines, type DiffFile, type FoldSegment } from '../src/client/diff/rows.ts'
|
|
|
|
import { setupReactAct } from './test-utils.ts'
|
|
setupReactAct()
|
|
|
|
// A git-shaped two-hunk patch: the gap between the hunks (old/new lines
|
|
// 2..11) is a fold WITHOUT rows — expandable only through a resolveFold.
|
|
const gapDiff = [
|
|
'diff --git a/src/a.ts b/src/a.ts',
|
|
'--- a/src/a.ts',
|
|
'+++ b/src/a.ts',
|
|
'@@ -1 +1 @@',
|
|
'-old',
|
|
'+new',
|
|
'@@ -12 +12 @@',
|
|
'-tail',
|
|
'+tail2',
|
|
].join('\n')
|
|
|
|
// The hidden context rows a loader slices out of both sides' contents.
|
|
const hiddenRows = Array.from({ length: 10 }, (_, i) => ({
|
|
kind: 'context' as const,
|
|
oldLine: i + 2,
|
|
newLine: i + 2,
|
|
text: `ctx-${String(i + 2)}`,
|
|
}))
|
|
|
|
afterEach(() => { document.body.innerHTML = '' })
|
|
|
|
describe('DiffFiles on-demand fold expansion', () => {
|
|
it('renders syntax tokens across inline changes without duplicate React keys', () => {
|
|
const error = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
const container = document.createElement('div')
|
|
const root = createRoot(container)
|
|
try {
|
|
const segments = buildDiffSegments(diffLines('const value = "old" + 1', 'const value = "new" + 2'))
|
|
act(() => { root.render(createElement(DiffRows, { segments, lang: 'ts' })) })
|
|
expect(container.textContent).toContain('"old"')
|
|
expect(container.textContent).toContain('"new"')
|
|
expect(error.mock.calls.flat().join(' ')).not.toContain('same key')
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
error.mockRestore()
|
|
}
|
|
})
|
|
|
|
it('expands a git gap fold through resolveFold, then collapses back', async () => {
|
|
const resolveFold = vi.fn((_file: DiffFile, _segment: FoldSegment) => Promise.resolve(hiddenRows))
|
|
const container = document.createElement('div')
|
|
document.body.append(container)
|
|
const root: Root = createRoot(container)
|
|
try {
|
|
act(() => { root.render(createElement(DiffFiles, { diff: gapDiff, resolveFold })) })
|
|
const fold = container.querySelector<HTMLElement>('[data-expandable="true"]')
|
|
expect(fold).not.toBeNull()
|
|
expect(container.textContent).not.toContain('ctx-5')
|
|
|
|
await act(async () => { fold!.click() })
|
|
expect(resolveFold).toHaveBeenCalledOnce()
|
|
expect(container.textContent).toContain('ctx-5')
|
|
// The loader received the gap fold itself (line ranges on board).
|
|
const segment = resolveFold.mock.calls[0]![1]
|
|
expect(segment.kind).toBe('fold')
|
|
expect(segment.oldStart).toBe(2)
|
|
|
|
// Collapse: the marker is back; the fetch never repeats.
|
|
const expanded = container.querySelector<HTMLElement>('[data-expandable="true"]')
|
|
await act(async () => { expanded!.click() })
|
|
expect(container.textContent).not.toContain('ctx-5')
|
|
expect(resolveFold).toHaveBeenCalledOnce()
|
|
|
|
// Re-expanding resolves from the per-fold cache (no second fetch).
|
|
const collapsed = container.querySelector<HTMLElement>('[data-expandable="true"]')
|
|
await act(async () => { collapsed!.click() })
|
|
expect(container.textContent).toContain('ctx-5')
|
|
expect(resolveFold).toHaveBeenCalledOnce()
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
container.remove()
|
|
}
|
|
})
|
|
|
|
it('degrades to the unavailable marker when the loader rejects', async () => {
|
|
const resolveFold = vi.fn(() => Promise.reject(new Error('boom')))
|
|
const container = document.createElement('div')
|
|
document.body.append(container)
|
|
const root: Root = createRoot(container)
|
|
try {
|
|
act(() => { root.render(createElement(DiffFiles, { diff: gapDiff, resolveFold })) })
|
|
const fold = container.querySelector<HTMLElement>('[data-expandable="true"]')
|
|
await act(async () => { fold!.click() })
|
|
// The degraded fold promises no interaction.
|
|
expect(container.querySelector('[data-expandable]')).toBeNull()
|
|
expect(container.textContent).not.toContain('ctx-5')
|
|
// jsdom's navigator.language is en-US → the en copy.
|
|
expect(container.textContent).toContain('Context unavailable')
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
container.remove()
|
|
}
|
|
})
|
|
|
|
it('keeps git gap folds inert without a resolver (session surfaces unchanged)', () => {
|
|
const container = document.createElement('div')
|
|
document.body.append(container)
|
|
const root: Root = createRoot(container)
|
|
try {
|
|
act(() => { root.render(createElement(DiffFiles, { diff: gapDiff })) })
|
|
expect(container.querySelector('[data-expandable]')).toBeNull()
|
|
// The quiet marker still shows the hidden line count.
|
|
expect(container.textContent).toContain('10 lines')
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
container.remove()
|
|
}
|
|
})
|
|
|
|
it('expands session folds (rows carried) directly, without any loader', async () => {
|
|
// buildDiffSegments output — the session-op path: folds carry their rows,
|
|
// so they toggle on click exactly as before the git expansion existed.
|
|
const rows = diffLines(
|
|
'a\nb\nc\nd\ne\nX\nf\ng\nh\ni\nj\nk\nl\n',
|
|
'a\nb\nc\nd\ne\nY\nf\ng\nh\ni\nj\nk\nl\n',
|
|
)
|
|
const segments = buildDiffSegments(rows)
|
|
const container = document.createElement('div')
|
|
document.body.append(container)
|
|
const root: Root = createRoot(container)
|
|
try {
|
|
act(() => { root.render(createElement(DiffRows, { segments })) })
|
|
const fold = container.querySelector<HTMLElement>('[data-expandable="true"]')
|
|
expect(fold).not.toBeNull()
|
|
// 'j' is hidden in the tail fold (the marker copy carries no 'j').
|
|
expect(container.textContent).not.toContain('j')
|
|
await act(async () => { fold!.click() })
|
|
expect(container.textContent).toContain('j')
|
|
const expanded = container.querySelector<HTMLElement>('[data-expandable="true"]')
|
|
await act(async () => { expanded!.click() })
|
|
expect(container.textContent).not.toContain('j')
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
container.remove()
|
|
}
|
|
})
|
|
})
|
|
|
|
/**
|
|
* The renderer's budget for pathologically long lines: >20K chars renders a
|
|
* bounded plain preview (2K folded / 20K expanded) instead of the full text.
|
|
* Normal long lines keep the old full-text rendering.
|
|
*/
|
|
describe('DiffRows long-line budget', () => {
|
|
const mount = (text: string): { container: HTMLElement; root: Root } => {
|
|
// A punctuation-heavy minified line: with lang 'js' it also exercises
|
|
// diffBlockEntries' cross-line scan on the over-budget row.
|
|
const segments = [{
|
|
kind: 'hunk' as const,
|
|
rows: [{ kind: 'add' as const, newLine: 1, text }],
|
|
}]
|
|
const container = document.createElement('div')
|
|
document.body.append(container)
|
|
const root: Root = createRoot(container)
|
|
act(() => { root.render(createElement(DiffRows, { segments, lang: 'js' })) })
|
|
return { container, root }
|
|
}
|
|
|
|
it('bounds an over-budget row while folded, then bounds it again when expanded', () => {
|
|
const long = '{' + '"k":1,'.repeat(12_000) + '}'
|
|
const { container, root } = mount(long)
|
|
try {
|
|
const row = container.querySelector<HTMLElement>('[data-folded="true"]')
|
|
expect(row).not.toBeNull()
|
|
// Folded: 2K preview + '…' (plus the line number and sign).
|
|
expect(row!.textContent!.length).toBeGreaterThan(2_000)
|
|
expect(row!.textContent!.length).toBeLessThan(3_000)
|
|
expect(row!.textContent).not.toContain(long)
|
|
|
|
act(() => { row!.click() })
|
|
expect(container.querySelector('[data-folded="true"]')).toBeNull()
|
|
// Expanded: 20K body + '…' (plus the line number and sign).
|
|
expect(container.textContent!.length).toBeGreaterThan(20_000)
|
|
expect(container.textContent!.length).toBeLessThan(21_000)
|
|
expect(container.textContent).not.toContain(long)
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
container.remove()
|
|
}
|
|
})
|
|
|
|
it('keeps a normal long row (500 chars) rendering in full', () => {
|
|
const text = 'y'.repeat(500)
|
|
const { container, root } = mount(text)
|
|
try {
|
|
expect(container.querySelector('[data-folded="true"]')).not.toBeNull()
|
|
expect(container.textContent).toContain(text)
|
|
expect(container.textContent).not.toContain('…')
|
|
} finally {
|
|
act(() => { root.unmount() })
|
|
container.remove()
|
|
}
|
|
})
|
|
})
|