
































@@ -105,6 +105,14 @@ function fetchInit(source: MockCallSource, callIndex: number) {
105105return requireRecord(mockArg(source, callIndex, 1, `fetch init ${callIndex}`), "fetch init");
106106}
107107108+function fetchUrl(source: MockCallSource, callIndex: number) {
109+const input = mockArg(source, callIndex, 0, `fetch input ${callIndex}`);
110+if (typeof input === "string" || input instanceof URL || input instanceof Request) {
111+return requestUrl(input);
112+}
113+throw new Error(`expected fetch input ${callIndex}`);
114+}
115+108116function makeHost(overrides?: Partial<ChatHost>): ChatHost {
109117const host = {
110118client: null,
@@ -303,14 +311,11 @@ describe("refreshChatAvatar", () => {
303311const host = makeHost({ basePath: "", sessionKey: "agent:main" });
304312await refreshChatAvatar(host);
305313306-expect(fetchMock.mock.calls[0]?.[0]).toBe("/avatar/main?meta=1");
314+expect(fetchUrl(fetchMock as unknown as MockCallSource, 0)).toBe("/avatar/main?meta=1");
307315expect(fetchInit(fetchMock as unknown as MockCallSource, 0).method).toBe("GET");
308-expect(fetchMock.mock.calls[1]?.[0]).toBe("/avatar/main");
316+expect(fetchUrl(fetchMock as unknown as MockCallSource, 1)).toBe("/avatar/main");
309317expect(fetchInit(fetchMock as unknown as MockCallSource, 1).method).toBe("GET");
310-const avatarFetchInit = (
311-fetchMock.mock.calls as Array<[string | URL | Request, RequestInit?]>
312-)[1]?.[1];
313-expect(avatarFetchInit).not.toHaveProperty("headers");
318+expect(fetchInit(fetchMock as unknown as MockCallSource, 1)).not.toHaveProperty("headers");
314319expect(createObjectURL).toHaveBeenCalledTimes(1);
315320expect(revokeObjectURL).not.toHaveBeenCalled();
316321expect(host.chatAvatarUrl).toBe("blob:local-avatar");
@@ -353,12 +358,14 @@ describe("refreshChatAvatar", () => {
353358});
354359await refreshChatAvatar(host);
355360356-expect(fetchMock.mock.calls[0]?.[0]).toBe("/openclaw/avatar/main?meta=1");
361+expect(fetchUrl(fetchMock as unknown as MockCallSource, 0)).toBe(
362+"/openclaw/avatar/main?meta=1",
363+);
357364expect(fetchInit(fetchMock as unknown as MockCallSource, 0).method).toBe("GET");
358365expect(fetchInit(fetchMock as unknown as MockCallSource, 0).headers).toEqual({
359366Authorization: "Bearer device-token",
360367});
361-expect(fetchMock.mock.calls[1]?.[0]).toBe("/avatar/main");
368+expect(fetchUrl(fetchMock as unknown as MockCallSource, 1)).toBe("/avatar/main");
362369expect(fetchInit(fetchMock as unknown as MockCallSource, 1).method).toBe("GET");
363370expect(fetchInit(fetchMock as unknown as MockCallSource, 1).headers).toEqual({
364371Authorization: "Bearer device-token",
@@ -403,12 +410,14 @@ describe("refreshChatAvatar", () => {
403410});
404411await refreshChatAvatar(host);
405412406-expect(fetchMock.mock.calls[0]?.[0]).toBe("/openclaw/avatar/main?meta=1");
413+expect(fetchUrl(fetchMock as unknown as MockCallSource, 0)).toBe(
414+"/openclaw/avatar/main?meta=1",
415+);
407416expect(fetchInit(fetchMock as unknown as MockCallSource, 0).method).toBe("GET");
408417expect(fetchInit(fetchMock as unknown as MockCallSource, 0).headers).toEqual({
409418Authorization: "Bearer session-token",
410419});
411-expect(fetchMock.mock.calls[1]?.[0]).toBe("/avatar/main");
420+expect(fetchUrl(fetchMock as unknown as MockCallSource, 1)).toBe("/avatar/main");
412421expect(fetchInit(fetchMock as unknown as MockCallSource, 1).method).toBe("GET");
413422expect(fetchInit(fetchMock as unknown as MockCallSource, 1).headers).toEqual({
414423Authorization: "Bearer session-token",
@@ -428,7 +437,7 @@ describe("refreshChatAvatar", () => {
428437const host = makeHost({ basePath: "/openclaw/", sessionKey: "agent:ops:main" });
429438await refreshChatAvatar(host);
430439431-expect(fetchMock.mock.calls[0]?.[0]).toBe("/openclaw/avatar/ops?meta=1");
440+expect(fetchUrl(fetchMock as unknown as MockCallSource, 0)).toBe("/openclaw/avatar/ops?meta=1");
432441expect(fetchInit(fetchMock as unknown as MockCallSource, 0).method).toBe("GET");
433442expect(host.chatAvatarUrl).toBeNull();
434443});
@@ -525,11 +534,11 @@ describe("refreshChatAvatar", () => {
525534526535expect(createObjectURL).toHaveBeenCalledTimes(1);
527536expect(host.chatAvatarUrl).toBe("blob:ops-avatar");
528-expect(fetchMock.mock.calls[0]?.[0]).toBe("/avatar/main?meta=1");
537+expect(fetchUrl(fetchMock as unknown as MockCallSource, 0)).toBe("/avatar/main?meta=1");
529538expect(fetchInit(fetchMock as unknown as MockCallSource, 0).method).toBe("GET");
530-expect(fetchMock.mock.calls[1]?.[0]).toBe("/avatar/ops?meta=1");
539+expect(fetchUrl(fetchMock as unknown as MockCallSource, 1)).toBe("/avatar/ops?meta=1");
531540expect(fetchInit(fetchMock as unknown as MockCallSource, 1).method).toBe("GET");
532-expect(fetchMock.mock.calls[2]?.[0]).toBe("/avatar/ops");
541+expect(fetchUrl(fetchMock as unknown as MockCallSource, 2)).toBe("/avatar/ops");
533542expect(fetchInit(fetchMock as unknown as MockCallSource, 2).method).toBe("GET");
534543});
535544});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。