test: dedupe extension channel fixtures

This commit is contained in:
Peter Steinberger
2026-03-26 19:47:27 +00:00
parent e8f9d68bec
commit be328e6cd1
8 changed files with 323 additions and 392 deletions

View File

@@ -21,6 +21,15 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
});
}
function expectRecordedRoute(params: { to: string; threadId?: string }) {
const updateLastRoute = getRecordedUpdateLastRoute(0) as
| { threadId?: string; to?: string }
| undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe(params.to);
expect(updateLastRoute?.threadId).toBe(params.threadId);
}
afterEach(() => {
clearRuntimeConfigSnapshot();
recordInboundSessionMock.mockClear();
@@ -46,13 +55,7 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
expect(ctx).not.toBeNull();
expect(recordInboundSessionMock).toHaveBeenCalled();
// Check that updateLastRoute includes threadId
const updateLastRoute = getRecordedUpdateLastRoute(0) as
| { threadId?: string; to?: string }
| undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:1234");
expect(updateLastRoute?.threadId).toBe("42");
expectRecordedRoute({ to: "telegram:1234", threadId: "42" });
});
it("does not pass threadId for regular DM without topic", async () => {
@@ -65,13 +68,7 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
expect(ctx).not.toBeNull();
expect(recordInboundSessionMock).toHaveBeenCalled();
// Check that updateLastRoute does NOT include threadId
const updateLastRoute = getRecordedUpdateLastRoute(0) as
| { threadId?: string; to?: string }
| undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:1234");
expect(updateLastRoute?.threadId).toBeUndefined();
expectRecordedRoute({ to: "telegram:1234" });
});
it("passes threadId to updateLastRoute for forum topic group messages", async () => {
@@ -88,12 +85,7 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
expect(ctx).not.toBeNull();
expect(recordInboundSessionMock).toHaveBeenCalled();
const updateLastRoute = getRecordedUpdateLastRoute(0) as
| { threadId?: string; to?: string }
| undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:-1001234567890");
expect(updateLastRoute?.threadId).toBe("99");
expectRecordedRoute({ to: "telegram:-1001234567890", threadId: "99" });
});
it("passes threadId to updateLastRoute for the forum General topic", async () => {
@@ -109,11 +101,6 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
expect(ctx).not.toBeNull();
expect(recordInboundSessionMock).toHaveBeenCalled();
const updateLastRoute = getRecordedUpdateLastRoute(0) as
| { threadId?: string; to?: string }
| undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:-1001234567890");
expect(updateLastRoute?.threadId).toBe("1");
expectRecordedRoute({ to: "telegram:-1001234567890", threadId: "1" });
});
});

View File

@@ -23,6 +23,25 @@ describe("resolveTelegramToken", () => {
return tokenFile;
}
function createUnknownAccountConfig(): OpenClawConfig {
return {
channels: {
telegram: {
botToken: "wrong-bot-token",
accounts: {
knownBot: { botToken: "known-bot-token" },
},
},
},
} as OpenClawConfig;
}
function expectNoTokenForUnknownAccount(cfg: OpenClawConfig) {
const res = resolveTelegramToken(cfg, { accountId: "unknownBot" });
expect(res.token).toBe("");
expect(res.source).toBe("none");
}
afterEach(() => {
vi.unstubAllEnvs();
for (const dir of tempDirs.splice(0)) {
@@ -207,20 +226,7 @@ describe("resolveTelegramToken", () => {
it("does not fall through to channel-level token when non-default accountId is not in config", () => {
vi.stubEnv("TELEGRAM_BOT_TOKEN", "");
const cfg = {
channels: {
telegram: {
botToken: "wrong-bot-token",
accounts: {
knownBot: { botToken: "known-bot-token" },
},
},
},
} as OpenClawConfig;
const res = resolveTelegramToken(cfg, { accountId: "unknownBot" });
expect(res.token).toBe("");
expect(res.source).toBe("none");
expectNoTokenForUnknownAccount(createUnknownAccountConfig());
});
it("throws when botToken is an unresolved SecretRef object", () => {
@@ -257,20 +263,7 @@ describe("resolveTelegramToken", () => {
it("still blocks fallthrough for unknown accountId when accounts section exists", () => {
vi.stubEnv("TELEGRAM_BOT_TOKEN", "");
const cfg = {
channels: {
telegram: {
botToken: "wrong-bot-token",
accounts: {
knownBot: { botToken: "known-bot-token" },
},
},
},
} as OpenClawConfig;
const res = resolveTelegramToken(cfg, { accountId: "unknownBot" });
expect(res.token).toBe("");
expect(res.source).toBe("none");
expectNoTokenForUnknownAccount(createUnknownAccountConfig());
});
});