From 3ff2a79c82ca7a3c2e7cf9fda2cd9b10183c5215 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Wed, 4 Mar 2026 10:39:02 -0500 Subject: [PATCH] Tests: restore matrix-js bind integration coverage --- .../agents.bind.matrix-js.integration.test.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/commands/agents.bind.matrix-js.integration.test.ts diff --git a/src/commands/agents.bind.matrix-js.integration.test.ts b/src/commands/agents.bind.matrix-js.integration.test.ts new file mode 100644 index 00000000000..0c1ea91b6b0 --- /dev/null +++ b/src/commands/agents.bind.matrix-js.integration.test.ts @@ -0,0 +1,52 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { matrixPlugin } from "../../extensions/matrix-js/src/channel.js"; +import { setActivePluginRegistry } from "../plugins/runtime.js"; +import { createTestRegistry } from "../test-utils/channel-plugins.js"; +import { agentsBindCommand } from "./agents.js"; +import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js"; +import { baseConfigSnapshot, createTestRuntime } from "./test-runtime-config-helpers.js"; + +const readConfigFileSnapshotMock = vi.hoisted(() => vi.fn()); +const writeConfigFileMock = vi.hoisted(() => vi.fn().mockResolvedValue(undefined)); + +vi.mock("../config/config.js", async (importOriginal) => ({ + ...(await importOriginal()), + readConfigFileSnapshot: readConfigFileSnapshotMock, + writeConfigFile: writeConfigFileMock, +})); + +describe("agents bind matrix-js integration", () => { + const runtime = createTestRuntime(); + + beforeEach(() => { + readConfigFileSnapshotMock.mockClear(); + writeConfigFileMock.mockClear(); + runtime.log.mockClear(); + runtime.error.mockClear(); + runtime.exit.mockClear(); + + setActivePluginRegistry( + createTestRegistry([{ pluginId: "matrix-js", plugin: matrixPlugin, source: "test" }]), + ); + }); + + afterEach(() => { + setDefaultChannelPluginRegistryForTests(); + }); + + it("uses matrix-js plugin binding resolver when accountId is omitted", async () => { + readConfigFileSnapshotMock.mockResolvedValue({ + ...baseConfigSnapshot, + config: {}, + }); + + await agentsBindCommand({ agent: "main", bind: ["matrix-js"] }, runtime); + + expect(writeConfigFileMock).toHaveBeenCalledWith( + expect.objectContaining({ + bindings: [{ agentId: "main", match: { channel: "matrix-js", accountId: "main" } }], + }), + ); + expect(runtime.exit).not.toHaveBeenCalled(); + }); +});