Skip to content

Commit 3600cec

Browse files
committed
test: seed channel setup contract registry in helper tests
1 parent f9a8eb0 commit 3600cec

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

src/channels/plugins/setup-helpers.test.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
import { afterEach, describe, expect, it } from "vitest";
1+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
2+
import {
3+
namedAccountPromotionKeys as matrixNamedAccountPromotionKeys,
4+
resolveSingleAccountPromotionTarget as resolveMatrixSingleAccountPromotionTarget,
5+
singleAccountKeysToMove as matrixSingleAccountKeysToMove,
6+
} from "../../../extensions/matrix/contract-api.js";
7+
import { singleAccountKeysToMove as telegramSingleAccountKeysToMove } from "../../../extensions/telegram/contract-api.js";
28
import type { OpenClawConfig } from "../../config/config.js";
9+
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../../plugins/runtime.js";
310
import { DEFAULT_ACCOUNT_ID } from "../../routing/session-key.js";
11+
import {
12+
createChannelTestPluginBase,
13+
createTestRegistry,
14+
} from "../../test-utils/channel-plugins.js";
415
import {
516
applySetupAccountConfigPatch,
617
clearSetupPromotionRuntimeModuleCache,
@@ -14,8 +25,38 @@ function asConfig(value: unknown): OpenClawConfig {
1425
return value as OpenClawConfig;
1526
}
1627

28+
beforeEach(() => {
29+
setActivePluginRegistry(
30+
createTestRegistry([
31+
{
32+
pluginId: "matrix",
33+
source: "test",
34+
plugin: {
35+
...createChannelTestPluginBase({ id: "matrix", label: "Matrix" }),
36+
setup: {
37+
singleAccountKeysToMove: matrixSingleAccountKeysToMove,
38+
namedAccountPromotionKeys: matrixNamedAccountPromotionKeys,
39+
resolveSingleAccountPromotionTarget: resolveMatrixSingleAccountPromotionTarget,
40+
},
41+
},
42+
},
43+
{
44+
pluginId: "telegram",
45+
source: "test",
46+
plugin: {
47+
...createChannelTestPluginBase({ id: "telegram", label: "Telegram" }),
48+
setup: {
49+
singleAccountKeysToMove: telegramSingleAccountKeysToMove,
50+
},
51+
},
52+
},
53+
]),
54+
);
55+
});
56+
1757
afterEach(() => {
1858
clearSetupPromotionRuntimeModuleCache();
59+
resetPluginRuntimeStateForTest();
1960
});
2061

2162
describe("applySetupAccountConfigPatch", () => {

src/channels/plugins/setup-wizard-helpers.test.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
import { describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2+
import {
3+
namedAccountPromotionKeys as matrixNamedAccountPromotionKeys,
4+
resolveSingleAccountPromotionTarget as resolveMatrixSingleAccountPromotionTarget,
5+
singleAccountKeysToMove as matrixSingleAccountKeysToMove,
6+
} from "../../../extensions/matrix/contract-api.js";
7+
import { singleAccountKeysToMove as telegramSingleAccountKeysToMove } from "../../../extensions/telegram/contract-api.js";
28
import {
39
resolveSetupWizardAllowFromEntries,
410
resolveSetupWizardGroupAllowlist,
511
} from "../../../test/helpers/plugins/setup-wizard.js";
612
import type { OpenClawConfig } from "../../config/config.js";
13+
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../../plugins/runtime.js";
714
import { DEFAULT_ACCOUNT_ID } from "../../routing/session-key.js";
15+
import {
16+
createChannelTestPluginBase,
17+
createTestRegistry,
18+
} from "../../test-utils/channel-plugins.js";
819
import {
920
applySingleTokenPromptResult,
1021
buildSingleChannelSecretPromptState,
@@ -60,6 +71,39 @@ import {
6071
splitSetupEntries,
6172
} from "./setup-wizard-helpers.js";
6273

74+
beforeEach(() => {
75+
setActivePluginRegistry(
76+
createTestRegistry([
77+
{
78+
pluginId: "matrix",
79+
source: "test",
80+
plugin: {
81+
...createChannelTestPluginBase({ id: "matrix", label: "Matrix" }),
82+
setup: {
83+
singleAccountKeysToMove: matrixSingleAccountKeysToMove,
84+
namedAccountPromotionKeys: matrixNamedAccountPromotionKeys,
85+
resolveSingleAccountPromotionTarget: resolveMatrixSingleAccountPromotionTarget,
86+
},
87+
},
88+
},
89+
{
90+
pluginId: "telegram",
91+
source: "test",
92+
plugin: {
93+
...createChannelTestPluginBase({ id: "telegram", label: "Telegram" }),
94+
setup: {
95+
singleAccountKeysToMove: telegramSingleAccountKeysToMove,
96+
},
97+
},
98+
},
99+
]),
100+
);
101+
});
102+
103+
afterEach(() => {
104+
resetPluginRuntimeStateForTest();
105+
});
106+
63107
function createPrompter(inputs: string[]) {
64108
return {
65109
text: vi.fn(async () => inputs.shift() ?? ""),

0 commit comments

Comments
 (0)