chore: 同步 v5.0 基础设施完善到 v5.1
CI / 前端检查 (格式 + 类型 + Lint + 测试 + 覆盖率) (push) Has been cancelled
CI / Rust 检查 (格式 + Check + Clippy + Test) (push) Has been cancelled

从 v5.0 cherry-pick 的开源项目基础设施改进:

新增配置文件:
- .editorconfig, .gitattributes, .prettierrc, .markdownlint.json
- commitlint.config.js

新增 GitHub 社区文件:
- .github/dependabot.yml — 依赖自动更新
- .github/CODEOWNERS — 自动 PR 审查分配
- .github/FUNDING.yml — 开源赞助入口

新增文档:
- ROADMAP.md — 路线图
- SUPPORT.md — 帮助指南
- docs/screenshots/ — 应用截图

新增 Git Hooks:
- .husky/pre-commit — lint-staged 自动格式化+修复
- .husky/commit-msg — commitlint 校验

CI 强化:
- 新增 Prettier 格式检查
- 新增 Vitest 覆盖率 + Codecov 上报
- 保留 v5.1 已有的 rust-cache + jsdom 全局环境

修复:
- index.html 标题 v4.0 → v5.1
- PathEditDialog set-state-in-effect 改用 useRef prevOpen 守卫
- merge-preview.test.tsx no-explicit-any 修复
- 所有 TS/TSX 文件 Prettier 格式化统一

v5.1 保留特性:
- @tanstack/react-virtual 虚拟滚动
- jsdom 全局测试环境
- Swatinem/rust-cache CI 加速
- 105 测试全部通过
This commit is contained in:
2026-06-19 19:24:03 +08:00
parent 60de924b08
commit 9453006310
52 changed files with 2783 additions and 619 deletions
+79 -32
View File
@@ -14,11 +14,13 @@ vi.mock('@tauri-apps/plugin-dialog', () => ({
}));
vi.mock('@/i18n', () => ({
default: { t: vi.fn((key: string, opts?: Record<string, unknown>) => {
if (key === 'status.deleted') return `已删除 ${opts?.count}`;
if (key === 'status.saveWarningLongPaths') return 'PATH 长度超限';
return key;
}) },
default: {
t: vi.fn((key: string, opts?: Record<string, unknown>) => {
if (key === 'status.deleted') return `已删除 ${opts?.count}`;
if (key === 'status.saveWarningLongPaths') return 'PATH 长度超限';
return key;
}),
},
}));
vi.mock('@/hooks/use-keyboard', () => ({
@@ -83,7 +85,9 @@ describe('useAppActions', () => {
it('handleNew 打开新建弹窗', async () => {
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleNew(); });
act(() => {
result.current.handleNew();
});
expect(dialogs.setNewDialog).toHaveBeenCalledWith(true);
});
@@ -93,9 +97,14 @@ describe('useAppActions', () => {
useAppStore.setState({ selectedIndices: [0] });
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleEdit(); });
act(() => {
result.current.handleEdit();
});
expect(dialogs.setEditDialog).toHaveBeenCalledWith({
open: true, index: 0, value: 'C:\\Windows', target: TargetType.SYSTEM,
open: true,
index: 0,
value: 'C:\\Windows',
target: TargetType.SYSTEM,
});
});
@@ -103,7 +112,9 @@ describe('useAppActions', () => {
useAppStore.setState({ selectedIndices: [] });
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleEdit(); });
act(() => {
result.current.handleEdit();
});
expect(dialogs.setEditDialog).not.toHaveBeenCalled();
});
@@ -113,15 +124,19 @@ describe('useAppActions', () => {
useAppStore.setState({ selectedIndices: [0] });
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleDelete(); });
expect(useAppStore.getState().sysPaths.map(e => e.path)).toEqual(['C:\\Program Files']);
act(() => {
result.current.handleDelete();
});
expect(useAppStore.getState().sysPaths.map((e) => e.path)).toEqual(['C:\\Program Files']);
});
it('handleDelete 无选中项不操作', async () => {
useAppStore.setState({ selectedIndices: [] });
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleDelete(); });
act(() => {
result.current.handleDelete();
});
expect(useAppStore.getState().sysPaths.length).toBe(2);
});
@@ -131,16 +146,26 @@ describe('useAppActions', () => {
useAppStore.setState({ selectedIndices: [1] });
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleMoveUp(); });
expect(useAppStore.getState().sysPaths.map(e => e.path)).toEqual(['C:\\Program Files', 'C:\\Windows']);
act(() => {
result.current.handleMoveUp();
});
expect(useAppStore.getState().sysPaths.map((e) => e.path)).toEqual([
'C:\\Program Files',
'C:\\Windows',
]);
});
it('handleMoveDown 下移选中项', async () => {
useAppStore.setState({ selectedIndices: [0] });
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleMoveDown(); });
expect(useAppStore.getState().sysPaths.map(e => e.path)).toEqual(['C:\\Program Files', 'C:\\Windows']);
act(() => {
result.current.handleMoveDown();
});
expect(useAppStore.getState().sysPaths.map((e) => e.path)).toEqual([
'C:\\Program Files',
'C:\\Windows',
]);
});
// ── handleClean ──
@@ -149,8 +174,10 @@ describe('useAppActions', () => {
resetStore([pe('C:\\Windows'), pe('invalid_path!@#')]);
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleClean(); });
expect(useAppStore.getState().sysPaths.map(e => e.path)).toEqual(['C:\\Windows']);
act(() => {
result.current.handleClean();
});
expect(useAppStore.getState().sysPaths.map((e) => e.path)).toEqual(['C:\\Windows']);
expect(useAppStore.getState().statusMessage).toContain('已删除 1 条');
});
@@ -159,15 +186,19 @@ describe('useAppActions', () => {
it('handleNewConfirm 添加新路径', async () => {
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleNewConfirm('C:\\New'); });
expect(useAppStore.getState().sysPaths.map(e => e.path)).toContain('C:\\New');
act(() => {
result.current.handleNewConfirm('C:\\New');
});
expect(useAppStore.getState().sysPaths.map((e) => e.path)).toContain('C:\\New');
expect(dialogs.setNewDialog).toHaveBeenCalledWith(false);
});
it('handleNewConfirm 空白不添加', async () => {
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleNewConfirm(' '); });
act(() => {
result.current.handleNewConfirm(' ');
});
expect(useAppStore.getState().sysPaths.length).toBe(2);
});
@@ -177,7 +208,9 @@ describe('useAppActions', () => {
dialogs.editDialog = { open: true, index: 0, value: 'C:\\Windows', target: TargetType.SYSTEM };
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleEditConfirm('C:\\Edited'); });
act(() => {
result.current.handleEditConfirm('C:\\Edited');
});
expect(useAppStore.getState().sysPaths[0].path).toBe('C:\\Edited');
});
@@ -189,19 +222,27 @@ describe('useAppActions', () => {
dialogs.importDialog = { open: true, system: sysImport, user: usrImport };
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleImportSelect('both'); });
expect(useAppStore.getState().sysPaths.map(e => e.path)).toEqual(['C:\\ImportSys']);
expect(useAppStore.getState().userPaths.map(e => e.path)).toEqual(['D:\\ImportUsr']);
act(() => {
result.current.handleImportSelect('both');
});
expect(useAppStore.getState().sysPaths.map((e) => e.path)).toEqual(['C:\\ImportSys']);
expect(useAppStore.getState().userPaths.map((e) => e.path)).toEqual(['D:\\ImportUsr']);
expect(dialogs.setImportDialog).toHaveBeenCalledWith({ open: false, system: [], user: [] });
});
it('handleImportSelect system 模式只替换 system', async () => {
dialogs.importDialog = { open: true, system: [pe('C:\\ImportSys')], user: [pe('D:\\ImportUsr')] };
dialogs.importDialog = {
open: true,
system: [pe('C:\\ImportSys')],
user: [pe('D:\\ImportUsr')],
};
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
act(() => { result.current.handleImportSelect('system'); });
expect(useAppStore.getState().sysPaths.map(e => e.path)).toEqual(['C:\\ImportSys']);
expect(useAppStore.getState().userPaths.map(e => e.path)).toEqual(['D:\\User']); // 未变
act(() => {
result.current.handleImportSelect('system');
});
expect(useAppStore.getState().sysPaths.map((e) => e.path)).toEqual(['C:\\ImportSys']);
expect(useAppStore.getState().userPaths.map((e) => e.path)).toEqual(['D:\\User']); // 未变
});
// ── handleSave ──
@@ -211,7 +252,9 @@ describe('useAppActions', () => {
vi.spyOn(useAppStore.getState(), 'savePaths').mockResolvedValue({ kind: 'success' });
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
await act(async () => { await result.current.handleSave(); });
await act(async () => {
await result.current.handleSave();
});
// savePaths is called
expect(useAppStore.getState().savePaths).toHaveBeenCalled();
});
@@ -227,7 +270,9 @@ describe('useAppActions', () => {
});
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
await act(async () => { await result.current.handleSave(); });
await act(async () => {
await result.current.handleSave();
});
expect(callCount).toBe(2);
expect(mockAsk).toHaveBeenCalled();
});
@@ -240,7 +285,9 @@ describe('useAppActions', () => {
});
const { useAppActions } = await import('@/hooks/use-app-actions');
const { result } = renderHook(() => useAppActions('system', dialogs));
await act(async () => { await result.current.handleSave(); });
await act(async () => {
await result.current.handleSave();
});
expect(callCount).toBe(1); // 仅调用一次,不重试
expect(mockAsk).not.toHaveBeenCalled();
});