feat: Reader Skill 支持版本自检与自助更新

微信机器人回复剥离引用编号、列表改用空行分隔,失败通知补失败时刻
 问问微信关键词检索在索引落后时按单会话直读原始记录兜底
 关闭窗口支持记住选择并在设置中修改
 退群监控刷新列表
This commit is contained in:
Wxw-Gu committed 2026-10-14 10:31:01 +08:00
1 parent fd7d5016a8
commit eaa25cd29e
33 files changed
+1401 -154

No files matched your search

@@ -149,9 +149,22 @@ describe('GroupExitMonitorWorkspace', () => {
monitoredRoomIds: ['研发群@chatroom'],
monitoredGroupCount: 1
}
const setGroups = vi.fn().mockResolvedValue(savedState)
const setGroups = vi.fn(async (roomIds: string[]) => {
current = {
...configuredState,
monitoredRoomIds: roomIds,
monitoredGroupCount: roomIds.length
}
return current
})
/**
* 真实服务的 `getState()` 返回的是**内存里的当前状态** —— 保存之后再拉一次,
* 拿到的必然是保存后的值。mock 用可变变量体现这一点:
* 否则"切回事件页时重新拉取"会把它覆盖成保存前的旧值,那是 mock 的失真,不是实现的问题。
*/
let current: GroupExitMonitorState = configuredState
window.api = {
getGroupExitMonitorState: vi.fn().mockResolvedValue(configuredState),
getGroupExitMonitorState: vi.fn(async () => current),
onGroupExitMonitorState: vi.fn(() => () => undefined),
setGroupExitMonitorGroups: setGroups,
checkGroupExitMonitorNow: vi.fn().mockResolvedValue(savedState),
@@ -0,0 +1,110 @@
import { act, render, waitFor } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { ToastProvider } from '../../src/renderer/src/components/ui'
import { MessageInsertSwitches } from '../../src/renderer/src/features/automation/MessageInsertSwitches'
import type { MsgInsertSwitchesSnapshot } from '../../src/shared/msg-insert-switch'
/**
* 自动化页右上角的两个开关 —— 只钉**运行期刷新时机**。
*
* 背景:微信运行期间会新建 `message_N.db`,目标会话集合随之变化,而规则补齐此前
* 只在启动时跑过一次。渲染层如果只在挂载时拉一次,用户看到的就是"计数对不上、
* 而且不会自己变好"。所以要在窗口重新聚焦时问一次(主进程侧再用分片指纹决定要不要补)。
*/
function makeSnapshot(ready: number, total: number): MsgInsertSwitchesSnapshot {
return {
success: true,
helperAvailable: true,
switches: {
recall_notice: {
name: 'recall_notice',
mode: 'rules',
desiredEnabled: true,
effectiveEnabled: ready === total,
readyInstallableRooms: ready,
totalInstallableRooms: total,
notReadyRooms: [],
totalShards: 1,
targetShards: 1
},
group_exit_notice: {
name: 'group_exit_notice',
mode: 'event',
desiredEnabled: true,
effectiveEnabled: true,
readyInstallableRooms: 1,
totalInstallableRooms: 1,
notReadyRooms: [],
totalShards: 0,
targetShards: 0
}
}
} as unknown as MsgInsertSwitchesSnapshot
}
function renderSwitches(): void {
render(
<ToastProvider>
<MessageInsertSwitches />
</ToastProvider>
)
}
describe('微信消息插入开关 · 运行期刷新', () => {
afterEach(() => {
vi.restoreAllMocks()
})
it('挂载只用 GET,不额外触发刷新', async () => {
const get = vi.fn().mockResolvedValue(makeSnapshot(1, 2))
const refresh = vi.fn().mockResolvedValue(makeSnapshot(2, 2))
window.api = {
getMsgInsertSwitches: get,
refreshMsgInsertSwitches: refresh
} as unknown as typeof window.api
renderSwitches()
await waitFor(() => expect(get).toHaveBeenCalled())
expect(refresh).not.toHaveBeenCalled()
})
it('窗口重新聚焦时刷新一次,并画出更新后的计数', async () => {
const get = vi.fn().mockResolvedValue(makeSnapshot(1, 2))
const refresh = vi.fn().mockResolvedValue(makeSnapshot(2, 2))
window.api = {
getMsgInsertSwitches: get,
refreshMsgInsertSwitches: refresh
} as unknown as typeof window.api
renderSwitches()
await waitFor(() => expect(document.body.textContent).toContain('1 / 2 已启用'))
await act(async () => {
window.dispatchEvent(new Event('focus'))
})
await waitFor(() => expect(refresh).toHaveBeenCalledTimes(1))
await waitFor(() => expect(document.body.textContent).toContain('2 / 2 已启用'))
})
it('刷新失败时保持已有状态,不打回禁用态', async () => {
const get = vi.fn().mockResolvedValue(makeSnapshot(1, 2))
const refresh = vi.fn().mockRejectedValue(new Error('boom'))
window.api = {
getMsgInsertSwitches: get,
refreshMsgInsertSwitches: refresh
} as unknown as typeof window.api
renderSwitches()
await waitFor(() => expect(document.body.textContent).toContain('1 / 2 已启用'))
await act(async () => {
window.dispatchEvent(new Event('focus'))
})
await waitFor(() => expect(refresh).toHaveBeenCalled())
expect(document.body.textContent).toContain('1 / 2 已启用')
})
})