Harvests the sound ideas from PR #128 while KEEPING origSeqs[0] as the c2c reply sequence (on-target capture in #114/#124 proved origSeqs[0] == the quoted message's head.sequence; pbReserve.friendSequence is a small unrelated counter that makes reply.id miss). The PR's friendSequence override is intentionally NOT taken. - rich-body-decoder: enrich the reply element with replySenderUin/replyTime and the quoted message's own decoded elements (SrcMsg.elems, field 5); recover a c2c quoted FILE from sourceMsg (field 9 -> RichText.notOnlineFile) when elems carried none, so a quoted file survives into get_msg (#124). - backfillReplyTarget: tiered fallback — Tier 0 local store, Tier 1 server fetch (correct seq = origSeqs[0]), Tier 2 reconstruct from the embedded quoted elements (no round-trip), Tier 3 minimal '[引用消息]' placeholder so get_msg never returns 'message not found'. - to-segment: per-element try/catch (logged, not silent) so one bad element doesn't drop the whole message. - actions/message: log get_msg misses. - tests: fix request-actions getGroupInviteCardSequence mock (gap from #125); cover backfill Tier 2 (reconstruct) + Tier 3 (placeholder); flip the stale c2c reply test to assert origSeqs[0] (was asserting the disproven friendSequence). Validated on-target (Docker): get_msg on group reply, private text reply, and a private quoted FILE all return correct content (file with name/size/id); full onebot + protocol suites green.
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { handleGroupAddRequest } from '../src/modules/request-actions';
|
|
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
|
import type { GroupRequestInfo } from '@snowluma/protocol/qq-info';
|
|
|
|
// See `contact-actions.test.ts` for the auto-promotion rationale.
|
|
const APIS_ROUTING: Record<string, string> = {
|
|
fetchFriendList: 'contacts', fetchGroupList: 'contacts',
|
|
fetchGroupMemberList: 'contacts', fetchUserProfile: 'contacts',
|
|
fetchGroupRequests: 'contacts', fetchDownloadRKeys: 'contacts',
|
|
getGroupInviteCardSequence: 'contacts',
|
|
};
|
|
|
|
function fakeBridge(overrides: Record<string, any> = {}): BridgeInterface {
|
|
const apisSynth: Record<string, Record<string, any>> = {};
|
|
for (const [k, v] of Object.entries(overrides)) {
|
|
const area = APIS_ROUTING[k];
|
|
if (area) {
|
|
if (!apisSynth[area]) apisSynth[area] = {};
|
|
apisSynth[area][k] = v;
|
|
}
|
|
}
|
|
const merged = { ...overrides, apis: { ...apisSynth, ...(overrides.apis ?? {}) } };
|
|
return new Proxy(merged as BridgeInterface, {
|
|
get(target, prop) {
|
|
if (prop in target) return (target as any)[prop];
|
|
throw new Error(`fakeBridge: '${String(prop)}' was not stubbed`);
|
|
},
|
|
});
|
|
}
|
|
|
|
function fakeRequest(overrides: Partial<GroupRequestInfo> = {}): GroupRequestInfo {
|
|
return {
|
|
groupId: 999,
|
|
groupName: 'g',
|
|
targetUid: 'u_t',
|
|
targetUin: 5555,
|
|
targetName: 'target',
|
|
invitorUid: 'u_i',
|
|
invitorUin: 7777,
|
|
invitorName: 'inviter',
|
|
operatorUid: 'u_o',
|
|
operatorUin: 8888,
|
|
operatorName: 'op',
|
|
sequence: 42,
|
|
state: 1,
|
|
eventType: 7,
|
|
comment: 'pls',
|
|
filtered: false,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
|
|
it('matches add requests by groupId and targetUid', async () => {
|
|
const setAddRequest = vi.fn(async () => {});
|
|
const bridge = fakeBridge({
|
|
fetchGroupRequests: vi.fn(async () => [
|
|
fakeRequest({ groupId: 999, targetUid: 'u_t', sequence: 42, eventType: 7, filtered: false }),
|
|
]),
|
|
apis: { groupAdmin: { setAddRequest } } as any,
|
|
});
|
|
|
|
await handleGroupAddRequest(bridge, 'add:999:u_t', true, 'ok');
|
|
|
|
expect(setAddRequest).toHaveBeenCalledOnce();
|
|
expect(setAddRequest).toHaveBeenCalledWith(999, 42, 7, true, 'ok', false);
|
|
});
|
|
|
|
it('matches invite requests by groupId and invitorUid', async () => {
|
|
const setAddRequest = vi.fn(async () => {});
|
|
const bridge = fakeBridge({
|
|
fetchGroupRequests: vi.fn(async () => [
|
|
fakeRequest({ groupId: 999, invitorUid: 'u_i', sequence: 97, eventType: 8, filtered: false }),
|
|
]),
|
|
getGroupInviteCardSequence: vi.fn(() => null),
|
|
apis: { groupAdmin: { setAddRequest } } as any,
|
|
});
|
|
|
|
await handleGroupAddRequest(bridge, 'invite:999:u_i', false, 'no');
|
|
|
|
expect(setAddRequest).toHaveBeenCalledOnce();
|
|
expect(setAddRequest).toHaveBeenCalledWith(999, 97, 8, false, 'no', false);
|
|
});
|
|
});
|