From ff5fc651d09dcc9d63db24e6e5b283c901adcabb Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 19 May 2026 13:00:41 +0800 Subject: [PATCH] fix(tests): declare full vi.fn arg signatures so CI typecheck doesn't trip on tuple length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI's `tsc --noEmit` was rejecting `forward-nested.test.ts` because the `vi.fn(async () => 'RES')` mocks for `bridge.uploadForwardNodes` only inferred zero or one arg from the lambda — so `uploadForwardNodes.mock.calls[0]` came out typed as `[]` or `[nodes: any[]]`, and indexing `[1]` / `[2]` for groupId / userId hit `Tuple type ... has no element at index 'N'`. Local `tsc --noEmit` happened to be looser about this in my version, which is why the bad assertions slipped past `e637647`. Declare the full 3-arg signature on every `uploadForwardNodes` mock — `(_nodes, _groupId?, _userId?)` — matching the real `Bridge.uploadForwardNodes` contract. `mock.calls[i]` now types as a 3-tuple, the index accesses check out, and the assertions stay unchanged. No production code touched, no test behaviour change. 626/626 still passing, typecheck clean. --- packages/core/tests/onebot/forward-nested.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/tests/onebot/forward-nested.test.ts b/packages/core/tests/onebot/forward-nested.test.ts index 2aebd243..9e5979fd 100644 --- a/packages/core/tests/onebot/forward-nested.test.ts +++ b/packages/core/tests/onebot/forward-nested.test.ts @@ -48,7 +48,7 @@ function makeCtx(bridge: BridgeInterface): OneBotInstanceContext { describe('forward — nested {type:"node"} content', () => { it('group: nested forward uploads inner chain first, outer embeds ARK preview pointing at it', async () => { - const uploadForwardNodes = vi.fn(async (nodes: any[]) => { + const uploadForwardNodes = vi.fn(async (nodes: any[], _groupId?: number, _userId?: number) => { // Inner gets uploaded before outer; track the order by inspecting // the elements shape. The inner chain's payload is a plain text // node; the outer chain's only element is a `forward` ARK preview @@ -115,7 +115,7 @@ describe('forward — nested {type:"node"} content', () => { // passes `userId` instead of `groupId` so any inner image/record // uploads can pick up the recipient's UID scene (otherwise the // OIDB private-media upload has no target uid). - const uploadForwardNodes = vi.fn(async () => 'RESID'); + const uploadForwardNodes = vi.fn(async (_nodes: any[], _groupId?: number, _userId?: number) => 'RESID'); const sendPrivateMessage = vi.fn(async () => ({ messageId: 1, sequence: 100, clientSequence: 0, random: 1, timestamp: 1700000000, })); @@ -149,7 +149,7 @@ describe('forward — nested {type:"node"} content', () => { // Build a 4-level nested chain. NapCat caps at 3 too, going further // wastes long-msg uploads and risks one inner upload timing out // and aborting the whole tree. Better to fail loud here. - const uploadForwardNodes = vi.fn(async () => 'X'); + const uploadForwardNodes = vi.fn(async (_nodes: any[], _groupId?: number, _userId?: number) => 'X'); const sendGroupMessage = vi.fn(async () => ({ messageId: 1, sequence: 100, clientSequence: 0, random: 1, timestamp: 0, })); @@ -173,7 +173,7 @@ describe('forward — nested {type:"node"} content', () => { // Backwards-compat: a single-level forward with plain text nodes // calls uploadForwardNodes exactly once and never touches the // recursive branch. - const uploadForwardNodes = vi.fn(async () => 'RES'); + const uploadForwardNodes = vi.fn(async (_nodes: any[], _groupId?: number, _userId?: number) => 'RES'); const sendGroupMessage = vi.fn(async () => ({ messageId: 1, sequence: 100, clientSequence: 0, random: 1, timestamp: 0, })); @@ -201,7 +201,7 @@ describe('forward — nested {type:"node"} content', () => { // through, node parts get parsed via `case 'node':` and then // dropped by element-builder. A user who wants nested forward // should pass a pure node list. - const uploadForwardNodes = vi.fn(async () => 'RES'); + const uploadForwardNodes = vi.fn(async (_nodes: any[], _groupId?: number, _userId?: number) => 'RES'); const sendGroupMessage = vi.fn(async () => ({ messageId: 1, sequence: 100, clientSequence: 0, random: 1, timestamp: 0, }));