mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 03:11:10 +00:00
fix(regression): tighten Telegram runtime helper coverage
This commit is contained in:
@@ -79,7 +79,16 @@ function installTelegramRuntime(telegram?: Record<string, unknown>) {
|
||||
} as unknown as PluginRuntime);
|
||||
}
|
||||
|
||||
function installGatewayRuntime(params?: { probeOk?: boolean; botUsername?: string }) {
|
||||
function installGatewayRuntime(params?: {
|
||||
probeOk?: boolean;
|
||||
botUsername?: string;
|
||||
runtimeHelpers?: {
|
||||
probeTelegram?: typeof probeModule.probeTelegram;
|
||||
collectTelegramUnmentionedGroupIds?: typeof auditModule.collectTelegramUnmentionedGroupIds;
|
||||
auditTelegramGroupMembership?: typeof auditModule.auditTelegramGroupMembership;
|
||||
monitorTelegramProvider?: typeof monitorModule.monitorTelegramProvider;
|
||||
};
|
||||
}) {
|
||||
const monitorTelegramProvider = vi
|
||||
.spyOn(monitorModule, "monitorTelegramProvider")
|
||||
.mockImplementation(async () => undefined);
|
||||
@@ -108,10 +117,13 @@ function installGatewayRuntime(params?: { probeOk?: boolean; botUsername?: strin
|
||||
elapsedMs: 0,
|
||||
}));
|
||||
installTelegramRuntime({
|
||||
probeTelegram,
|
||||
collectTelegramUnmentionedGroupIds: collectUnmentionedGroupIds,
|
||||
auditTelegramGroupMembership: auditGroupMembership,
|
||||
monitorTelegramProvider,
|
||||
probeTelegram: params?.runtimeHelpers?.probeTelegram ?? probeTelegram,
|
||||
collectTelegramUnmentionedGroupIds:
|
||||
params?.runtimeHelpers?.collectTelegramUnmentionedGroupIds ?? collectUnmentionedGroupIds,
|
||||
auditTelegramGroupMembership:
|
||||
params?.runtimeHelpers?.auditTelegramGroupMembership ?? auditGroupMembership,
|
||||
monitorTelegramProvider:
|
||||
params?.runtimeHelpers?.monitorTelegramProvider ?? monitorTelegramProvider,
|
||||
});
|
||||
return {
|
||||
monitorTelegramProvider,
|
||||
@@ -171,7 +183,8 @@ function createPluginApprovalRequest(
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
clearTelegramRuntime();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("telegramPlugin groups", () => {
|
||||
@@ -295,6 +308,11 @@ describe("telegramPlugin duplicate token guard", () => {
|
||||
it("falls back to direct probe helpers when Telegram runtime is uninitialized", async () => {
|
||||
try {
|
||||
clearTelegramRuntime();
|
||||
const moduleProbeTelegram = vi.spyOn(probeModule, "probeTelegram").mockResolvedValue({
|
||||
ok: true,
|
||||
bot: { username: "fallbackbot" },
|
||||
elapsedMs: 1,
|
||||
});
|
||||
const cfg = createCfg();
|
||||
const account = resolveAccount(cfg, "ops");
|
||||
|
||||
@@ -304,17 +322,61 @@ describe("telegramPlugin duplicate token guard", () => {
|
||||
timeoutMs: 1234,
|
||||
cfg,
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
ok: expect.any(Boolean),
|
||||
elapsedMs: expect.any(Number),
|
||||
}),
|
||||
);
|
||||
).resolves.toEqual({
|
||||
ok: true,
|
||||
bot: { username: "fallbackbot" },
|
||||
elapsedMs: 1,
|
||||
});
|
||||
expect(moduleProbeTelegram).toHaveBeenCalledWith("token-ops", 1234, {
|
||||
accountId: "ops",
|
||||
proxyUrl: undefined,
|
||||
network: undefined,
|
||||
apiRoot: undefined,
|
||||
});
|
||||
} finally {
|
||||
installTelegramRuntime();
|
||||
}
|
||||
});
|
||||
|
||||
it("prefers runtime Telegram helpers over imported module mocks when runtime is set", async () => {
|
||||
probeTelegramMock.mockReset();
|
||||
const runtimeProbeTelegram = vi.fn(async () => ({
|
||||
ok: true,
|
||||
bot: { username: "runtimebot" },
|
||||
elapsedMs: 7,
|
||||
}));
|
||||
const moduleProbeTelegram = vi.spyOn(probeModule, "probeTelegram").mockResolvedValue({
|
||||
ok: true,
|
||||
bot: { username: "modulebot" },
|
||||
elapsedMs: 1,
|
||||
});
|
||||
installTelegramRuntime({
|
||||
probeTelegram: runtimeProbeTelegram,
|
||||
});
|
||||
|
||||
const cfg = createCfg();
|
||||
const account = resolveAccount(cfg, "ops");
|
||||
|
||||
await expect(
|
||||
telegramPlugin.status!.probeAccount!({
|
||||
account,
|
||||
timeoutMs: 4321,
|
||||
cfg,
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
ok: true,
|
||||
bot: { username: "runtimebot" },
|
||||
elapsedMs: 7,
|
||||
});
|
||||
expect(runtimeProbeTelegram).toHaveBeenCalledWith("token-ops", 4321, {
|
||||
accountId: "ops",
|
||||
proxyUrl: undefined,
|
||||
network: undefined,
|
||||
apiRoot: undefined,
|
||||
});
|
||||
expect(moduleProbeTelegram).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("passes account proxy and network settings into Telegram probes", async () => {
|
||||
installGatewayRuntime();
|
||||
probeTelegramMock.mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user