diff --git a/extensions/telegram/src/bot.command-menu.test.ts b/extensions/telegram/src/bot.command-menu.test.ts index 288c38b302b..45f0ebe6239 100644 --- a/extensions/telegram/src/bot.command-menu.test.ts +++ b/extensions/telegram/src/bot.command-menu.test.ts @@ -49,6 +49,16 @@ function resolveSkillCommands(config: Parameters["skillCommands"]; } +function countMatching(items: readonly T[], predicate: (item: T) => boolean): number { + let count = 0; + for (const item of items) { + if (predicate(item)) { + count += 1; + } + } + return count; +} + describe("createTelegramBot command menu", () => { beforeAll(async () => { ({ normalizeTelegramCommandName } = await import("./command-config.js")); @@ -175,7 +185,8 @@ describe("createTelegramBot command menu", () => { } expect(registered).toContainEqual({ command: "custom_backup", description: "Git backup" }); expect(registered).not.toContainEqual({ command: "status", description: "Custom status" }); - expect(registered.filter((command) => command.command === "status")).toEqual([nativeStatus]); + expect(registered.find((command) => command.command === "status")).toEqual(nativeStatus); + expect(countMatching(registered, (command) => command.command === "status")).toBe(1); expect(errorSpy).toHaveBeenCalled(); }); diff --git a/extensions/zalo/src/monitor.polling.media-reply.test.ts b/extensions/zalo/src/monitor.polling.media-reply.test.ts index 9fe4b91fc11..144d487792e 100644 --- a/extensions/zalo/src/monitor.polling.media-reply.test.ts +++ b/extensions/zalo/src/monitor.polling.media-reply.test.ts @@ -79,6 +79,16 @@ function createHostedMediaResponse() { return { headers, res: res as unknown as ServerResponse & { end: ReturnType } }; } +function countMatching(items: readonly T[], predicate: (item: T) => boolean): number { + let count = 0; + for (const item of items) { + if (predicate(item)) { + count += 1; + } + } + return count; +} + describe("Zalo polling media replies", () => { const finalizeInboundContextMock = vi.fn((ctx: Record) => ctx); const recordInboundSessionMock = vi.fn(async () => undefined); @@ -335,9 +345,12 @@ describe("Zalo polling media replies", () => { firstAbort.abort(); await firstRun; - expect(registry.httpRoutes.filter((route) => route.source === "zalo-hosted-media")).toEqual([ + expect(registry.httpRoutes.find((route) => route.source === "zalo-hosted-media")).toEqual( hostedMediaRoute, - ]); + ); + expect( + countMatching(registry.httpRoutes, (route) => route.source === "zalo-hosted-media"), + ).toBe(1); await writeHostedZaloMediaFixture({ id: "def456def456def456def456", diff --git a/src/daemon/launchd.test.ts b/src/daemon/launchd.test.ts index 01aa3fadd2a..a9543489766 100644 --- a/src/daemon/launchd.test.ts +++ b/src/daemon/launchd.test.ts @@ -55,6 +55,16 @@ const cleanStaleGatewayProcessesSync = vi.hoisted(() => ); const defaultProgramArguments = ["node", "-e", "process.exit(0)"]; +function countMatching(items: readonly T[], predicate: (item: T) => boolean): number { + let count = 0; + for (const item of items) { + if (predicate(item)) { + count += 1; + } + } + return count; +} + function createDefaultLaunchdEnv(): Record { return { HOME: "/Users/test", @@ -417,9 +427,11 @@ describe("launchd bootstrap repair", () => { const { serviceId } = expectLaunchctlEnableBootstrapOrder(env); expect(repair).toEqual({ ok: true, status: "already-loaded" }); - expect(state.launchctlCalls.filter((call) => call[0] === "kickstart")).toEqual([ - ["kickstart", serviceId], + expect(state.launchctlCalls.find((call) => call[0] === "kickstart")).toEqual([ + "kickstart", + serviceId, ]); + expect(countMatching(state.launchctlCalls, (call) => call[0] === "kickstart")).toBe(1); }); it("skips kickstart when already-loaded service is actively running", async () => { @@ -443,9 +455,11 @@ describe("launchd bootstrap repair", () => { const { serviceId } = expectLaunchctlEnableBootstrapOrder(env); expect(repair).toEqual({ ok: true, status: "already-loaded" }); - expect(state.launchctlCalls.filter((call) => call[0] === "kickstart")).toEqual([ - ["kickstart", serviceId], + expect(state.launchctlCalls.find((call) => call[0] === "kickstart")).toEqual([ + "kickstart", + serviceId, ]); + expect(countMatching(state.launchctlCalls, (call) => call[0] === "kickstart")).toBe(1); }); it("keeps genuine bootstrap failures as failures", async () => { diff --git a/src/plugins/discovery.test.ts b/src/plugins/discovery.test.ts index addcab16112..91fffd3e56c 100644 --- a/src/plugins/discovery.test.ts +++ b/src/plugins/discovery.test.ts @@ -28,6 +28,16 @@ function makeTempDir() { const mkdirSafe = mkdirSafeDir; +function countMatching(items: readonly T[], predicate: (item: T) => boolean): number { + let count = 0; + for (const item of items) { + if (predicate(item)) { + count += 1; + } + } + return count; +} + function withOpenClawPackageArgv(packageRoot: string, fn: () => T): T { mkdirSafe(path.join(packageRoot, "bin")); fs.writeFileSync(path.join(packageRoot, "package.json"), '{"name":"openclaw"}\n', "utf-8"); @@ -591,9 +601,10 @@ describe("discoverOpenClawPlugins", () => { }), ); - expect(candidates.filter((candidate) => candidate.idHint === "feishu")).toEqual([ + expect(candidates.find((candidate) => candidate.idHint === "feishu")).toEqual( expect.objectContaining({ origin: "bundled" }), - ]); + ); + expect(countMatching(candidates, (candidate) => candidate.idHint === "feishu")).toBe(1); expect(diagnostics).toEqual([ expect.objectContaining({ level: "warn", @@ -628,9 +639,10 @@ describe("discoverOpenClawPlugins", () => { }), ); - expect(candidates.filter((candidate) => candidate.idHint === "telegram")).toEqual([ + expect(candidates.find((candidate) => candidate.idHint === "telegram")).toEqual( expect.objectContaining({ origin: "bundled" }), - ]); + ); + expect(countMatching(candidates, (candidate) => candidate.idHint === "telegram")).toBe(1); expect(diagnostics).toEqual([ expect.objectContaining({ level: "warn", @@ -725,13 +737,14 @@ describe("discoverOpenClawPlugins", () => { }), ); - expect(candidates.filter((candidate) => candidate.idHint === "synology-chat")).toEqual([ + expect(candidates.find((candidate) => candidate.idHint === "synology-chat")).toEqual( expect.objectContaining({ origin: "bundled", rootDir: fs.realpathSync(bundledPluginDir), source: fs.realpathSync(bundledEntryPath), }), - ]); + ); + expect(countMatching(candidates, (candidate) => candidate.idHint === "synology-chat")).toBe(1); expect(diagnostics).toEqual([]); });