

















@@ -172,6 +172,18 @@ function installConsoleMethodSpy(method: "log" | "warn") {
172172return spy;
173173}
174174175+function requireConsoleMessage(spy: { mock: { calls: unknown[][] } }, index = 0): string {
176+const call = spy.mock.calls.at(index);
177+if (!call) {
178+throw new Error(`expected console call ${index}`);
179+}
180+expect(typeof call[0]).toBe("string");
181+if (typeof call[0] !== "string") {
182+throw new Error(`expected console call ${index} to contain a string message`);
183+}
184+return call[0];
185+}
186+175187function resolveWithConflictingCoreName(options?: { suppressNameConflicts?: boolean }) {
176188return resolvePluginTools(
177189createResolveToolsParams({
@@ -377,7 +389,7 @@ function mockCallParams(
377389mock: { mock: { calls: unknown[][] } },
378390index = 0,
379391): Record<string, unknown> {
380-const call = mock.mock.calls[index];
392+const call = mock.mock.calls.at(index);
381393if (!call) {
382394throw new Error(`expected mock call ${index}`);
383395}
@@ -1523,7 +1535,7 @@ describe("resolvePluginTools optional tools", () => {
1523153515241536expectResolvedToolNames(tools, ["optional_tool"]);
15251537expect(warnSpy).toHaveBeenCalledTimes(1);
1526-const message = String(warnSpy.mock.calls[0]?.[0] ?? "");
1538+const message = requireConsoleMessage(warnSpy);
15271539expect(message).toContain("[trace:plugin-tools] factory timings");
15281540expect(message).toContain("totalMs=1200");
15291541expect(message).toContain("optional-demo:1200ms@1200ms");
@@ -1553,7 +1565,7 @@ describe("resolvePluginTools optional tools", () => {
1553156515541566expectResolvedToolNames(tools, ["optional_tool"]);
15551567expect(logSpy).toHaveBeenCalledTimes(1);
1556-const message = String(logSpy.mock.calls[0]?.[0] ?? "");
1568+const message = requireConsoleMessage(logSpy);
15571569expect(message).toContain("[trace:plugin-tools] factory timings");
15581570expect(message).toContain("totalMs=5");
15591571expect(message).toContain("optional-demo:5ms@5ms");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。