




















@@ -13,6 +13,26 @@ import { fetchGraphJson } from "./graph.js";
1313import { getMSTeamsRuntime } from "./runtime.js";
1414import { buildUserAgent, ensureUserAgentHeader, resetUserAgentCache } from "./user-agent.js";
151516+function readFirstFetchInit(mockFetch: { mock: { calls: unknown[][] } }): {
17+headers: Record<string, string>;
18+} {
19+const [call] = mockFetch.mock.calls;
20+if (!call) {
21+throw new Error("Expected Graph fetch call");
22+}
23+const [, init] = call;
24+if (
25+!init ||
26+typeof init !== "object" ||
27+!("headers" in init) ||
28+typeof init.headers !== "object" ||
29+init.headers === null
30+) {
31+throw new Error("Expected Graph fetch init headers");
32+}
33+return init as { headers: Record<string, string> };
34+}
35+1636describe("buildUserAgent", () => {
1737beforeEach(() => {
1838resetUserAgentCache();
@@ -55,7 +75,7 @@ describe("buildUserAgent", () => {
5575await fetchGraphJson({ token: "test-token", path: "/groups" });
56765777expect(mockFetch).toHaveBeenCalledOnce();
58-const [, init] = mockFetch.mock.calls[0];
78+const init = readFirstFetchInit(mockFetch);
5979expect(init.headers["User-Agent"]).toMatch(/^teams\.ts\[apps\]\/.+ OpenClaw\/2026\.3\.19$/);
6080expect(init.headers).toHaveProperty("Authorization", "Bearer test-token");
6181});
@@ -73,7 +93,7 @@ describe("buildUserAgent", () => {
7393headers: { "User-Agent": "custom-agent/1.0" },
7494});
759576-const [, init] = mockFetch.mock.calls[0];
96+const init = readFirstFetchInit(mockFetch);
7797expect(init.headers["User-Agent"]).toBe("custom-agent/1.0");
7898});
7999此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。