mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
feat: 只读验收模式、文件发送类型与消息定位补全
- 只读验收:TRACEMEMO_READ_ONLY=1 时跳过消息写入、自动发送与退群提示 - 微信发送新增 file 类型,文档、能力探测与 Reader Skill 同步 - 消息前后窗口按分片定位,补齐 wcdb4 定位与分片测试
This commit is contained in:
1 parent
0edbf60b2e
commit
518a9662a7
25 files changed
+1278
-154
No files matched your search
@@ -259,7 +259,13 @@ describe('GET /api/v1/events/messages', () => {
|
||||
const client = await openSse(handle)
|
||||
|
||||
const status = await client.waitFor((frame) => frame.event === 'status')
|
||||
expect(status.data).toMatchObject({ database: 'ready', filter: 'all', backfill: 'enabled' })
|
||||
expect(status.data).toMatchObject({
|
||||
database: 'ready',
|
||||
monitor: 'unknown',
|
||||
wechat: 'unknown',
|
||||
filter: 'all',
|
||||
backfill: 'enabled'
|
||||
})
|
||||
|
||||
broker.publish(normalize(SESSION_A, '1', '实时消息'))
|
||||
const message = await client.waitFor((frame) => frame.event === 'message')
|
||||
@@ -270,10 +276,9 @@ describe('GET /api/v1/events/messages', () => {
|
||||
text: '实时消息',
|
||||
isSelf: false
|
||||
})
|
||||
expect(decodeMessageRef(String(message.data?.messageRef))).toEqual({
|
||||
conversationId: CONVERSATION_A,
|
||||
messageId: '1'
|
||||
})
|
||||
const ref = decodeMessageRef(String(message.data?.messageRef))
|
||||
expect(ref?.conversationId).toBe(CONVERSATION_A)
|
||||
expect(ref?.messageId).toMatch(/^\d+:1$/)
|
||||
})
|
||||
|
||||
it('同一条消息重复发布只推送一次(事件去重)', async () => {
|
||||
@@ -344,10 +349,9 @@ describe('GET /api/v1/events/messages', () => {
|
||||
})
|
||||
const replayed = await second.waitFor((frame) => frame.event === 'message')
|
||||
expect(replayed.data).toMatchObject({ origin: 'replay', text: 'hello' })
|
||||
expect(decodeMessageRef(String(replayed.data?.messageRef))).toEqual({
|
||||
conversationId: CONVERSATION_A,
|
||||
messageId: '2'
|
||||
})
|
||||
const ref = decodeMessageRef(String(replayed.data?.messageRef))
|
||||
expect(ref?.conversationId).toBe(CONVERSATION_A)
|
||||
expect(ref?.messageId).toMatch(/^\d+:2$/)
|
||||
})
|
||||
|
||||
it('缓冲覆盖不到时先发 gap,再从数据库有界回补(origin=db_backfill)', async () => {
|
||||
@@ -373,6 +377,16 @@ describe('GET /api/v1/events/messages', () => {
|
||||
(frame) => frame.event === 'message' && frame.data?.origin === 'db_backfill'
|
||||
)
|
||||
expect(backfilled.data?.text).toBe('补回来的消息')
|
||||
const report = await client.waitFor((frame) => frame.event === 'backfill')
|
||||
expect(report.data).toMatchObject({
|
||||
requestedConversations: 1,
|
||||
processedConversations: 1,
|
||||
delivered: 1,
|
||||
truncated: false,
|
||||
complete: true,
|
||||
messageTruncated: false,
|
||||
conversationTruncated: false
|
||||
})
|
||||
expect(client.frames.findIndex((f) => f.event === 'gap')).toBeLessThan(
|
||||
client.frames.findIndex((f) => f.event === 'message' && f.data?.origin === 'db_backfill')
|
||||
)
|
||||
|
||||
@@ -64,7 +64,7 @@ function capabilityOf(
|
||||
supported: true,
|
||||
ready: true,
|
||||
status: 'ready',
|
||||
capabilities: { text: true, image: true, voice: true },
|
||||
capabilities: { text: true, image: true, voice: true, file: true },
|
||||
senderStatus: {} as PersonalWechatSendCapability['senderStatus'],
|
||||
message: '可以发送',
|
||||
...overrides
|
||||
@@ -164,6 +164,31 @@ describe('POST /api/v1/wechat/send', () => {
|
||||
expect(execute).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('type=file 时接受 filePath 与可选 fileName,并按 file 动作投递', async () => {
|
||||
const filePath = path.join(root, '周报.txt')
|
||||
await fs.writeFile(filePath, 'hello')
|
||||
|
||||
const response = await post({
|
||||
to: 'filehelper',
|
||||
type: 'file',
|
||||
filePath,
|
||||
fileName: '周报.txt'
|
||||
})
|
||||
expect(response.status).toBe(200)
|
||||
expect((await response.json()).success).toBe(true)
|
||||
|
||||
const action = lastAction()
|
||||
expect(action.purpose).toBe('api_file')
|
||||
expect(action.content).toEqual({ type: 'file', path: filePath, name: '周报.txt' })
|
||||
})
|
||||
|
||||
it('type=file 缺少 filePath 时返回 400,不进入投递', async () => {
|
||||
const response = await post({ to: 'filehelper', type: 'file' })
|
||||
expect(response.status).toBe(400)
|
||||
expect((await response.json()).errorCode).toBe('INVALID_REQUEST')
|
||||
expect(execute).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('发送能力未就绪时返回 503', async () => {
|
||||
capability = capabilityOf({
|
||||
ready: false,
|
||||
|
||||
Reference in new issue
Block a user