Skip to content

Commit 09cb77e

Browse files
committed
fix(ci): harden telegram seams and cap job timeouts
1 parent 6eafa2e commit 09cb77e

8 files changed

Lines changed: 95 additions & 10 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
docs-scope:
2222
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
2323
runs-on: blacksmith-16vcpu-ubuntu-2404
24+
timeout-minutes: 20
2425
outputs:
2526
docs_only: ${{ steps.check.outputs.docs_only }}
2627
docs_changed: ${{ steps.check.outputs.docs_changed }}
@@ -48,6 +49,7 @@ jobs:
4849
needs: [docs-scope]
4950
if: needs.docs-scope.outputs.docs_only != 'true'
5051
runs-on: blacksmith-16vcpu-ubuntu-2404
52+
timeout-minutes: 20
5153
outputs:
5254
run_node: ${{ steps.scope.outputs.run_node }}
5355
run_macos: ${{ steps.scope.outputs.run_macos }}
@@ -86,6 +88,7 @@ jobs:
8688
needs: [docs-scope, changed-scope]
8789
if: needs.docs-scope.outputs.docs_only != 'true' && needs.changed-scope.outputs.run_node == 'true'
8890
runs-on: blacksmith-16vcpu-ubuntu-2404
91+
timeout-minutes: 20
8992
outputs:
9093
has_changed_extensions: ${{ steps.changed.outputs.has_changed_extensions }}
9194
changed_extensions_matrix: ${{ steps.changed.outputs.changed_extensions_matrix }}
@@ -129,6 +132,7 @@ jobs:
129132
secrets:
130133
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
131134
runs-on: blacksmith-16vcpu-ubuntu-2404
135+
timeout-minutes: 20
132136
steps:
133137
- name: Checkout
134138
uses: actions/checkout@v6
@@ -209,6 +213,7 @@ jobs:
209213
needs: [docs-scope, changed-scope, changed-extensions, secrets]
210214
if: always() && needs.docs-scope.result == 'success' && (needs.changed-scope.result == 'success' || needs.changed-scope.result == 'skipped') && (needs.changed-extensions.result == 'success' || needs.changed-extensions.result == 'skipped') && needs.secrets.result == 'success'
211215
runs-on: blacksmith-16vcpu-ubuntu-2404
216+
timeout-minutes: 20
212217
outputs:
213218
docs_only: ${{ needs.docs-scope.outputs.docs_only }}
214219
docs_changed: ${{ needs.docs-scope.outputs.docs_changed }}
@@ -230,6 +235,7 @@ jobs:
230235
needs: [preflight]
231236
if: github.event_name == 'push' && needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_node == 'true'
232237
runs-on: blacksmith-16vcpu-ubuntu-2404
238+
timeout-minutes: 20
233239
steps:
234240
- name: Checkout
235241
uses: actions/checkout@v6
@@ -264,6 +270,7 @@ jobs:
264270
needs: [preflight, build-artifacts]
265271
if: github.event_name == 'push' && needs.preflight.outputs.docs_only != 'true'
266272
runs-on: blacksmith-16vcpu-ubuntu-2404
273+
timeout-minutes: 20
267274
steps:
268275
- name: Checkout
269276
uses: actions/checkout@v6
@@ -289,6 +296,7 @@ jobs:
289296
needs: [preflight, build-artifacts]
290297
if: always() && needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_node == 'true' && (github.event_name != 'push' || needs.build-artifacts.result == 'success')
291298
runs-on: blacksmith-16vcpu-ubuntu-2404
299+
timeout-minutes: 20
292300
strategy:
293301
fail-fast: false
294302
matrix:
@@ -384,6 +392,7 @@ jobs:
384392
needs: [preflight]
385393
if: needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_node == 'true' && needs.preflight.outputs.has_changed_extensions == 'true'
386394
runs-on: blacksmith-16vcpu-ubuntu-2404
395+
timeout-minutes: 20
387396
strategy:
388397
fail-fast: false
389398
matrix: ${{ fromJson(needs.preflight.outputs.changed_extensions_matrix) }}
@@ -410,6 +419,7 @@ jobs:
410419
needs: [preflight]
411420
if: needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_node == 'true'
412421
runs-on: blacksmith-16vcpu-ubuntu-2404
422+
timeout-minutes: 20
413423
steps:
414424
- name: Checkout
415425
uses: actions/checkout@v6
@@ -433,6 +443,7 @@ jobs:
433443
needs: [preflight]
434444
if: needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_node == 'true'
435445
runs-on: blacksmith-16vcpu-ubuntu-2404
446+
timeout-minutes: 20
436447
steps:
437448
- name: Checkout
438449
uses: actions/checkout@v6
@@ -530,6 +541,7 @@ jobs:
530541
needs: [preflight, build-artifacts]
531542
if: always() && needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_node == 'true' && (github.event_name != 'push' || needs.build-artifacts.result == 'success')
532543
runs-on: blacksmith-16vcpu-ubuntu-2404
544+
timeout-minutes: 20
533545
steps:
534546
- name: Checkout
535547
uses: actions/checkout@v6
@@ -570,6 +582,7 @@ jobs:
570582
needs: [preflight]
571583
if: needs.preflight.outputs.docs_changed == 'true'
572584
runs-on: blacksmith-16vcpu-ubuntu-2404
585+
timeout-minutes: 20
573586
steps:
574587
- name: Checkout
575588
uses: actions/checkout@v6
@@ -589,6 +602,7 @@ jobs:
589602
needs: [preflight]
590603
if: needs.preflight.outputs.docs_only != 'true' && (github.event_name == 'push' || needs.preflight.outputs.run_skills_python == 'true')
591604
runs-on: blacksmith-16vcpu-ubuntu-2404
605+
timeout-minutes: 20
592606
steps:
593607
- name: Checkout
594608
uses: actions/checkout@v6
@@ -615,7 +629,7 @@ jobs:
615629
needs: [preflight, build-artifacts]
616630
if: always() && needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_windows == 'true' && (github.event_name != 'push' || needs.build-artifacts.result == 'success')
617631
runs-on: blacksmith-32vcpu-windows-2025
618-
timeout-minutes: 45
632+
timeout-minutes: 20
619633
env:
620634
NODE_OPTIONS: --max-old-space-size=6144
621635
# Keep total concurrency predictable on the 32 vCPU runner.
@@ -755,6 +769,7 @@ jobs:
755769
needs: [preflight]
756770
if: github.event_name == 'pull_request' && needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_macos == 'true'
757771
runs-on: macos-latest
772+
timeout-minutes: 20
758773
steps:
759774
- name: Checkout
760775
uses: actions/checkout@v6
@@ -831,6 +846,7 @@ jobs:
831846
needs: [preflight]
832847
if: needs.preflight.outputs.docs_only != 'true' && needs.preflight.outputs.run_android == 'true'
833848
runs-on: blacksmith-16vcpu-ubuntu-2404
849+
timeout-minutes: 20
834850
strategy:
835851
fail-fast: false
836852
matrix:

‎extensions/telegram/src/allowed-updates.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { API_CONSTANTS } from "grammy";
22
import { describe, expect, it } from "vitest";
3-
import { resolveTelegramAllowedUpdates } from "./allowed-updates.js";
3+
import { DEFAULT_TELEGRAM_UPDATE_TYPES, resolveTelegramAllowedUpdates } from "./allowed-updates.js";
44

55
describe("resolveTelegramAllowedUpdates", () => {
66
it("includes the default update types plus reaction and channel post support", () => {
77
const updates = resolveTelegramAllowedUpdates();
88

9-
expect(updates).toEqual(expect.arrayContaining([...API_CONSTANTS.DEFAULT_UPDATE_TYPES]));
9+
expect(updates).toEqual(
10+
expect.arrayContaining([
11+
...DEFAULT_TELEGRAM_UPDATE_TYPES,
12+
...(API_CONSTANTS?.DEFAULT_UPDATE_TYPES ?? []),
13+
]),
14+
);
1015
expect(updates).toContain("message_reaction");
1116
expect(updates).toContain("channel_post");
1217
expect(new Set(updates).size).toBe(updates.length);

‎extensions/telegram/src/allowed-updates.ts‎

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
11
import { API_CONSTANTS } from "grammy";
22

3-
type TelegramUpdateType = (typeof API_CONSTANTS.ALL_UPDATE_TYPES)[number];
3+
const FALLBACK_ALL_UPDATE_TYPES = [
4+
"message",
5+
"edited_message",
6+
"channel_post",
7+
"edited_channel_post",
8+
"business_connection",
9+
"business_message",
10+
"edited_business_message",
11+
"deleted_business_messages",
12+
"message_reaction",
13+
"message_reaction_count",
14+
"inline_query",
15+
"chosen_inline_result",
16+
"callback_query",
17+
"shipping_query",
18+
"pre_checkout_query",
19+
"poll",
20+
"poll_answer",
21+
"my_chat_member",
22+
"chat_member",
23+
"chat_join_request",
24+
] as const;
25+
26+
const FALLBACK_DEFAULT_UPDATE_TYPES = [
27+
"message",
28+
"edited_message",
29+
"channel_post",
30+
"edited_channel_post",
31+
"business_connection",
32+
"business_message",
33+
"edited_business_message",
34+
"deleted_business_messages",
35+
"message_reaction",
36+
"message_reaction_count",
37+
"inline_query",
38+
"chosen_inline_result",
39+
"callback_query",
40+
"shipping_query",
41+
"pre_checkout_query",
42+
"poll",
43+
"poll_answer",
44+
"my_chat_member",
45+
"chat_member",
46+
"chat_join_request",
47+
] as const;
48+
49+
export type TelegramUpdateType =
50+
| (typeof FALLBACK_ALL_UPDATE_TYPES)[number]
51+
| (typeof API_CONSTANTS.ALL_UPDATE_TYPES)[number];
52+
53+
export const DEFAULT_TELEGRAM_UPDATE_TYPES: ReadonlyArray<TelegramUpdateType> =
54+
API_CONSTANTS?.DEFAULT_UPDATE_TYPES ?? FALLBACK_DEFAULT_UPDATE_TYPES;
455

556
export function resolveTelegramAllowedUpdates(): ReadonlyArray<TelegramUpdateType> {
6-
const updates = [...API_CONSTANTS.DEFAULT_UPDATE_TYPES] as TelegramUpdateType[];
57+
const updates = [...DEFAULT_TELEGRAM_UPDATE_TYPES] as TelegramUpdateType[];
758
if (!updates.includes("message_reaction")) {
859
updates.push("message_reaction");
960
}

‎extensions/telegram/src/audit.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ vi.mock("undici", async (importOriginal) => {
88
const actual = await importOriginal<typeof import("undici")>();
99
return {
1010
...actual,
11+
Agent:
12+
actual.Agent ??
13+
class Agent {
14+
close() {}
15+
destroy() {}
16+
},
1117
fetch: undiciFetch,
1218
};
1319
});

‎extensions/telegram/src/bot-deps.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type TelegramBotDeps = {
1717
upsertChannelPairingRequest: typeof upsertChannelPairingRequest;
1818
enqueueSystemEvent: typeof enqueueSystemEvent;
1919
dispatchReplyWithBufferedBlockDispatcher: typeof dispatchReplyWithBufferedBlockDispatcher;
20-
loadWebMedia: typeof loadWebMedia;
20+
loadWebMedia?: typeof loadWebMedia;
2121
buildModelsProviderData: typeof buildModelsProviderData;
2222
listSkillCommandsForAgents: typeof listSkillCommandsForAgents;
2323
wasSentByBot: typeof wasSentByBot;

‎extensions/telegram/src/bot/delivery.replies.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import {
4343

4444
const VOICE_FORBIDDEN_RE = /VOICE_MESSAGES_FORBIDDEN/;
4545
const CAPTION_TOO_LONG_RE = /caption is too long/i;
46+
const GrammyErrorCtor: typeof GrammyError | undefined =
47+
typeof GrammyError === "function" ? GrammyError : undefined;
4648

4749
type DeliveryProgress = ReplyThreadDeliveryProgress & {
4850
deliveredCount: number;
@@ -175,14 +177,14 @@ async function sendPendingFollowUpText(params: {
175177
}
176178

177179
function isVoiceMessagesForbidden(err: unknown): boolean {
178-
if (err instanceof GrammyError) {
180+
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
179181
return VOICE_FORBIDDEN_RE.test(err.description);
180182
}
181183
return VOICE_FORBIDDEN_RE.test(formatErrorMessage(err));
182184
}
183185

184186
function isCaptionTooLong(err: unknown): boolean {
185-
if (err instanceof GrammyError) {
187+
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
186188
return CAPTION_TOO_LONG_RE.test(err.description);
187189
}
188190
return CAPTION_TOO_LONG_RE.test(formatErrorMessage(err));

‎extensions/telegram/src/bot/delivery.resolve-media.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import { resolveTelegramMediaPlaceholder } from "./helpers.js";
1515
import type { StickerMetadata, TelegramContext } from "./types.js";
1616

1717
const FILE_TOO_BIG_RE = /file is too big/i;
18+
const GrammyErrorCtor: typeof GrammyError | undefined =
19+
typeof GrammyError === "function" ? GrammyError : undefined;
20+
1821
function buildTelegramMediaSsrfPolicy(apiRoot?: string) {
1922
const hostnames = ["api.telegram.org"];
2023
if (apiRoot) {
@@ -41,7 +44,7 @@ function buildTelegramMediaSsrfPolicy(apiRoot?: string) {
4144
* Unlike network errors, this is a permanent error and should not be retried.
4245
*/
4346
function isFileTooBigError(err: unknown): boolean {
44-
if (err instanceof GrammyError) {
47+
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
4548
return FILE_TOO_BIG_RE.test(err.description);
4649
}
4750
return FILE_TOO_BIG_RE.test(formatErrorMessage(err));

‎extensions/telegram/src/bot/delivery.send.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import { buildTelegramThreadParams, type TelegramThreadSpec } from "./helpers.js
99
const PARSE_ERR_RE = /can't parse entities|parse entities|find end of the entity/i;
1010
const EMPTY_TEXT_ERR_RE = /message text is empty/i;
1111
const THREAD_NOT_FOUND_RE = /message thread not found/i;
12+
const GrammyErrorCtor: typeof GrammyError | undefined =
13+
typeof GrammyError === "function" ? GrammyError : undefined;
1214

1315
function isTelegramThreadNotFoundError(err: unknown): boolean {
14-
if (err instanceof GrammyError) {
16+
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
1517
return THREAD_NOT_FOUND_RE.test(err.description);
1618
}
1719
return THREAD_NOT_FOUND_RE.test(formatErrorMessage(err));

0 commit comments

Comments
 (0)