Files
WechatExplorer/tests/unit/wcdb4-message-locate.test.ts
Wxw-Gu 518a9662a7 feat: 只读验收模式、文件发送类型与消息定位补全
- 只读验收:TRACEMEMO_READ_ONLY=1 时跳过消息写入、自动发送与退群提示
- 微信发送新增 file 类型,文档、能力探测与 Reader Skill 同步
- 消息前后窗口按分片定位,补齐 wcdb4 定位与分片测试
2026-11-21 15:26:03 +08:00

39 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest'
import { selectMessageLocation, type Wcdb4MessageCursor } from '../../src/main/wcdb4-client'
/**
* 跨分片 localId 重复时的定位回归。
*
* 真实事故:同一会话的 `local_id=31455` 在多个 message_N.db 中命中,
* 只带 localId 的 messageRef 被判 `ambiguous_message`;带 create_time 的
* 复合身份必须能唯一选中。
*/
describe('selectMessageLocation', () => {
const hits: Wcdb4MessageCursor[] = [
{ createTime: 1_795_158_061, localId: 31_455 },
{ createTime: 1_795_158_099, localId: 31_455 }
]
it('同 localId 跨分片命中时,create_time 唯一选中', () => {
expect(selectMessageLocation(hits, 1_795_158_099)).toEqual({
status: 'found',
location: { createTime: 1_795_158_099, localId: 31_455 }
})
})
it('只给 localId(wantedTime=null)时必须报 ambiguous', () => {
expect(selectMessageLocation(hits, null)).toEqual({ status: 'ambiguous' })
})
it('create_time 不匹配时是 not_found,而不是随便挑一条', () => {
expect(selectMessageLocation(hits, 1_795_158_000)).toEqual({ status: 'not_found' })
})
it('单分片唯一命中时仍然可以只靠 localId 定位', () => {
expect(selectMessageLocation([hits[0]], null)).toEqual({
status: 'found',
location: hits[0]
})
})
})