refactor(api): move 17 group-file methods to GroupFileApi (#6 commit 4/13)
Inlines `actions/group-file.ts` into `apis/group-file.ts::GroupFileApi`,
deletes the old action file, removes the matching 17 facade methods
off `Bridge`, and slims `BridgeInterface` accordingly.
Method renaming follows the same "strip the redundant suffix" rule we
applied to GroupAdminApi:
uploadGroupFile → upload
uploadPrivateFile → uploadPrivate
sendGroupFileMessage → publish (OIDB 0x6d9_4)
fetchGroupFiles → list
fetchGroupFileCount → getCount
fetchGroupFileUrl → getUrl
fetchPrivateFileUrl → getPrivateUrl
fetchGroupPttUrlByNode → getPttUrl
fetchPrivatePttUrlByNode → getPrivatePttUrl
fetchGroupVideoUrlByNode → getVideoUrl
fetchPrivateVideoUrlByNode → getPrivateVideoUrl
deleteGroupFile → delete
moveGroupFile → move
createGroupFileFolder → createFolder
deleteGroupFileFolder → deleteFolder
renameGroupFileFolder → renameFolder
`upload`'s atomic upload+publish flow now calls `this.publish(...)`
directly instead of going through `bridge.sendGroupFileMessage`, and
`uploadPrivate` calls `this.ctx.apis.message.sendC2cFile(...)`.
Callers updated: `instance-context.ts`, `media-url-resolver.ts`,
`actions/group-file.ts` (onebot), `actions/extended.ts`,
`modules/{contact,media,message}-actions.ts`.
Tests: `group-file.test.ts` rewritten to use
`new GroupFileApi(bridge as any).method(...)`. The "verify publish was
called" assertions now use `vi.spyOn(api, 'publish').mockResolvedValue()`
since `publish` is an instance method on the same Api. `_helpers.ts`
gains `mockGroupFileApi()` for cross-Api callers and drops the flat
`sendGroupFileMessage` shim. `media-url-resolver.test.ts` and
`send-group-file.test.ts` switched to `bridge.apis.groupFile.*`; the
extended-actions `APIS_ROUTING` map now carries a `[area, newName]`
tuple so renamed methods auto-promote.
587/587 tests pass. The network-manager file remains as the only
failing test file (pre-existing infrastructure issue unrelated to #6).
This commit is contained in:
1 parent
0b91e4db8d
commit
dad501ebc0
17 files changed
+1241
-1185
No files matched your search
@@ -28,23 +28,32 @@ function fakeMeta(overrides: Partial<MessageMeta> = {}): MessageMeta {
|
||||
* pre-stubbed for the test. Same pattern as contact-actions.test.ts —
|
||||
* keeps tests honest about which surface they actually need.
|
||||
*/
|
||||
// Maps flat method names → ApiHub area they moved to under the #6
|
||||
// refactor. Auto-promotion lets tests written against the pre-refactor
|
||||
// flat surface (`fetchGroupRequests: vi.fn()`) keep working without
|
||||
// per-test restructure.
|
||||
const APIS_ROUTING: Record<string, string> = {
|
||||
fetchFriendList: 'contacts', fetchGroupList: 'contacts',
|
||||
fetchGroupMemberList: 'contacts', fetchUserProfile: 'contacts',
|
||||
fetchGroupRequests: 'contacts', fetchDownloadRKeys: 'contacts',
|
||||
// Maps flat method names → [area, newMethodName] on the ApiHub under
|
||||
// the #6 refactor. Auto-promotion lets tests written against the
|
||||
// pre-refactor flat surface (`fetchGroupRequests: vi.fn()`) keep
|
||||
// working without per-test restructure, even when the new method name
|
||||
// drops the redundant `Group`/`File` prefix.
|
||||
const APIS_ROUTING: Record<string, [string, string]> = {
|
||||
fetchFriendList: ['contacts', 'fetchFriendList'],
|
||||
fetchGroupList: ['contacts', 'fetchGroupList'],
|
||||
fetchGroupMemberList: ['contacts', 'fetchGroupMemberList'],
|
||||
fetchUserProfile: ['contacts', 'fetchUserProfile'],
|
||||
fetchGroupRequests: ['contacts', 'fetchGroupRequests'],
|
||||
fetchDownloadRKeys: ['contacts', 'fetchDownloadRKeys'],
|
||||
// GroupFileApi: methods drop `Group`/`File`/`Folder` suffix where
|
||||
// the area name already says it.
|
||||
deleteGroupFileFolder: ['groupFile', 'deleteFolder'],
|
||||
fetchGroupPttUrlByNode: ['groupFile', 'getPttUrl'],
|
||||
};
|
||||
|
||||
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) {
|
||||
const route = APIS_ROUTING[k];
|
||||
if (route) {
|
||||
const [area, newName] = route;
|
||||
if (!apisSynth[area]) apisSynth[area] = {};
|
||||
apisSynth[area][k] = v;
|
||||
apisSynth[area][newName] = v;
|
||||
}
|
||||
}
|
||||
const merged = { ...overrides, apis: { ...apisSynth, ...(overrides.apis ?? {}) } };
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//
|
||||
// Fix: split file segments off at the OneBot layer (same pattern as
|
||||
// the c2c-file split for private messages) and dispatch through
|
||||
// `bridge.sendGroupFileMessage`, which calls dedicated OIDB
|
||||
// `bridge.apis.groupFile.publish`, which calls dedicated OIDB
|
||||
// `OidbSvcTrpcTcp.0x6d9_4` — Lagrange.Core V2's
|
||||
// `GroupSendFileService.cs`.
|
||||
|
||||
@@ -45,7 +45,7 @@ const goodReceipt = {
|
||||
};
|
||||
|
||||
describe('send_group_msg with {type:"file"} segment', () => {
|
||||
it('file-only message routes through sendGroupFileMessage (not sendGroupMessage_bridge)', async () => {
|
||||
it('file-only message routes through apis.groupFile.publish (not apis.message.sendGroup)', async () => {
|
||||
// Pure-file case — the elems[] path used to ship a transElem(24)
|
||||
// and got result=79. The dedicated OIDB-0x6d9_4 route must take
|
||||
// over for group file publishing.
|
||||
@@ -53,10 +53,12 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
// Declare params on the fn so `mock.calls[0]` infers a tuple of
|
||||
// [groupId, fileId] instead of `[]` (which makes the destructuring
|
||||
// a tsc error under noUncheckedIndexedAccess).
|
||||
const sendGroupFileMessage = vi.fn(async (_groupId: number, _fileId: string) => undefined);
|
||||
const publish = vi.fn(async (_groupId: number, _fileId: string) => undefined);
|
||||
const bridge = fakeBridge({
|
||||
apis: { message: { sendGroup: sendGroupMessage_bridge } } as any,
|
||||
sendGroupFileMessage,
|
||||
apis: {
|
||||
message: { sendGroup: sendGroupMessage_bridge },
|
||||
groupFile: { publish },
|
||||
} as any,
|
||||
resolveUserUid: vi.fn(),
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge);
|
||||
@@ -65,20 +67,22 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
type: 'file', data: { file_id: 'gfid-abc', name: 'doc.txt', size: 123 },
|
||||
}] as any, false);
|
||||
|
||||
expect(sendGroupFileMessage).toHaveBeenCalledOnce();
|
||||
expect(publish).toHaveBeenCalledOnce();
|
||||
expect(sendGroupMessage_bridge).not.toHaveBeenCalled();
|
||||
|
||||
const [groupId, fileId] = sendGroupFileMessage.mock.calls[0]!;
|
||||
const [groupId, fileId] = publish.mock.calls[0]!;
|
||||
expect(groupId).toBe(12345);
|
||||
expect(fileId).toBe('gfid-abc');
|
||||
});
|
||||
|
||||
it('mixed text + file splits across two sends (text via elems[], file via OIDB)', async () => {
|
||||
const sendGroupMessage_bridge = vi.fn(async (_gid: number, _elements: any[]) => goodReceipt);
|
||||
const sendGroupFileMessage = vi.fn(async (_groupId: number, _fileId: string) => undefined);
|
||||
const publish = vi.fn(async (_groupId: number, _fileId: string) => undefined);
|
||||
const bridge = fakeBridge({
|
||||
apis: { message: { sendGroup: sendGroupMessage_bridge } } as any,
|
||||
sendGroupFileMessage,
|
||||
apis: {
|
||||
message: { sendGroup: sendGroupMessage_bridge },
|
||||
groupFile: { publish },
|
||||
} as any,
|
||||
resolveUserUid: vi.fn(async () => 'u_peer'),
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge);
|
||||
@@ -89,13 +93,13 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
] as any, false);
|
||||
|
||||
expect(sendGroupMessage_bridge).toHaveBeenCalledOnce();
|
||||
expect(sendGroupFileMessage).toHaveBeenCalledOnce();
|
||||
expect(publish).toHaveBeenCalledOnce();
|
||||
|
||||
const [textGid, textElements] = sendGroupMessage_bridge.mock.calls[0]!;
|
||||
expect(textGid).toBe(12345);
|
||||
expect(textElements).toEqual([{ type: 'text', text: 'here is the file:' }]);
|
||||
|
||||
const [fileGid, fileFileId] = sendGroupFileMessage.mock.calls[0]!;
|
||||
const [fileGid, fileFileId] = publish.mock.calls[0]!;
|
||||
expect(fileGid).toBe(12345);
|
||||
expect(fileFileId).toBe('gfid-xyz');
|
||||
});
|
||||
@@ -104,10 +108,12 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
// Same upload-by-reference contract as the c2c file path —
|
||||
// missing file_id means there's nothing to publish.
|
||||
const sendGroupMessage_bridge = vi.fn(async (_gid: number, _elements: any[]) => goodReceipt);
|
||||
const sendGroupFileMessage = vi.fn();
|
||||
const publish = vi.fn();
|
||||
const bridge = fakeBridge({
|
||||
apis: { message: { sendGroup: sendGroupMessage_bridge } } as any,
|
||||
sendGroupFileMessage,
|
||||
apis: {
|
||||
message: { sendGroup: sendGroupMessage_bridge },
|
||||
groupFile: { publish },
|
||||
} as any,
|
||||
resolveUserUid: vi.fn(),
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge);
|
||||
@@ -118,6 +124,6 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
] as any, false);
|
||||
|
||||
expect(sendGroupMessage_bridge).toHaveBeenCalledOnce();
|
||||
expect(sendGroupFileMessage).not.toHaveBeenCalled();
|
||||
expect(publish).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user