Skip to content

Commit 14882ac

Browse files
authored
fix(ci): prevent Telegram test watchdog stalls (#123514)
Bound Telegram extension tests to five files per Vitest process across explicit config, directory, and full-suite routes while preserving serial isolated execution. Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent e7a2d17 commit 14882ac

3 files changed

Lines changed: 89 additions & 43 deletions

File tree

‎scripts/lib/extension-test-plan.mts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ const EXTENSION_TEST_PROCESS_FILE_LIMITS = new Map<string, number>([
9393
// The non-isolated Matrix suite intentionally shares module state within a process.
9494
// Bound its lifetime so Vite's transformed module graph cannot grow across the whole suite.
9595
["test/vitest/vitest.extension-matrix.config.ts", 40],
96+
[
97+
"test/vitest/vitest.extension-telegram.config.ts",
98+
// A 10-file serial worker reached 231s and 2.7 GiB RSS (observed 2026-08).
99+
5,
100+
],
96101
]);
97102
const EXTENSION_TEST_CONFIG_ROUTES: Array<[(root: string) => boolean, string]> = [
98103
[isActiveMemoryExtensionRoot, "test/vitest/vitest.extension-active-memory.config.ts"],

‎scripts/test-projects.test-support.mts‎

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ import {
5050
isProviderOpenAiExtensionRoot,
5151
} from "../test/vitest/vitest.extension-provider-paths.mjs";
5252
import { isQaExtensionRoot } from "../test/vitest/vitest.extension-qa-paths.mjs";
53-
import { isTelegramExtensionRoot } from "../test/vitest/vitest.extension-telegram-paths.mjs";
53+
import {
54+
isTelegramExtensionRoot,
55+
telegramExtensionTestRoots,
56+
} from "../test/vitest/vitest.extension-telegram-paths.mjs";
5457
import { isVoiceCallExtensionRoot } from "../test/vitest/vitest.extension-voice-call-paths.mjs";
5558
import { isWhatsAppExtensionRoot } from "../test/vitest/vitest.extension-whatsapp-paths.mjs";
5659
import { isZaloExtensionRoot } from "../test/vitest/vitest.extension-zalo-paths.mjs";
@@ -255,6 +258,10 @@ const UNIT_FAST_FAKE_TIMERS_VITEST_CONFIG = "test/vitest/vitest.unit-fast-fake-t
255258
const UNIT_SECURITY_VITEST_CONFIG = "test/vitest/vitest.unit-security.config.ts";
256259
const UNIT_SRC_VITEST_CONFIG = "test/vitest/vitest.unit-src.config.ts";
257260
const UNIT_SUPPORT_VITEST_CONFIG = "test/vitest/vitest.unit-support.config.ts";
261+
const EXTENSION_TEST_PROCESS_ROOTS = new Map([
262+
[EXTENSION_MATRIX_VITEST_CONFIG, matrixExtensionTestRoots],
263+
[EXTENSION_TELEGRAM_VITEST_CONFIG, telegramExtensionTestRoots],
264+
]);
258265

259266
const FULL_SUITE_CONFIG_WEIGHT = new Map([
260267
[GATEWAY_VITEST_CONFIG, 180],
@@ -962,16 +969,15 @@ function createBroadToolingScriptPlans(params: VitestRunPlan & { cwd: string })
962969
: null;
963970
}
964971

965-
function createBoundedExtensionPlans(
966-
params: Omit<VitestRunPlan, "includePatterns"> & { roots: string[] },
967-
) {
968-
const { config, forwardedArgs, roots, watchMode } = params;
969-
if (watchMode) {
970-
return null;
972+
function createBoundedExtensionPlans(plan: VitestRunPlan) {
973+
const { config, forwardedArgs, watchMode } = plan;
974+
const roots = EXTENSION_TEST_PROCESS_ROOTS.get(config);
975+
if (watchMode || !roots) {
976+
return [plan];
971977
}
972978
const chunks = createExtensionTestProcessTargetChunks(config, roots, forwardedArgs);
973979
if (chunks.length <= 1) {
974-
return null;
980+
return [plan];
975981
}
976982
return chunks.map((includePatterns) => ({
977983
config,
@@ -3602,12 +3608,14 @@ export function buildVitestRunPlans(
36023608
"watch mode with mixed test suites is not supported; target one suite at a time or use a dedicated suite command",
36033609
);
36043610
}
3605-
return explicitConfigTargets.map((config) => ({
3606-
config,
3607-
forwardedArgs: nonTargetArgs,
3608-
includePatterns: null,
3609-
watchMode,
3610-
}));
3611+
return explicitConfigTargets.flatMap((config) =>
3612+
createBoundedExtensionPlans({
3613+
config,
3614+
forwardedArgs: nonTargetArgs,
3615+
includePatterns: null,
3616+
watchMode,
3617+
}),
3618+
);
36113619
}
36123620

36133621
const groupedTargets = new Map<string, string[]>();
@@ -3718,13 +3726,7 @@ export function buildVitestRunPlans(
37183726
includePatterns: null,
37193727
watchMode,
37203728
};
3721-
const boundedPlans = createBoundedExtensionPlans({
3722-
config,
3723-
forwardedArgs: nonTargetArgs,
3724-
roots: matrixExtensionTestRoots,
3725-
watchMode,
3726-
});
3727-
plans.push(...(boundedPlans ?? [plan]));
3729+
plans.push(...createBoundedExtensionPlans(plan));
37283730
}
37293731
continue;
37303732
}
@@ -3761,9 +3763,12 @@ export function buildVitestRunPlans(
37613763
plans.push(...broadToolingScriptPlans);
37623764
continue;
37633765
}
3766+
const processRoots = EXTENSION_TEST_PROCESS_ROOTS.get(config);
37643767
const boundedExtensionRoots = grouped.flatMap((targetArg) => {
37653768
const root = toRepoRelativeTarget(targetArg, cwd);
3766-
return isMatrixExtensionRoot(root) && isExistingDirectoryTarget(targetArg, cwd) ? [root] : [];
3769+
return processRoots?.includes(root) && isExistingDirectoryTarget(targetArg, cwd)
3770+
? [root]
3771+
: [];
37673772
});
37683773
const boundedRootsCoverGroupedTargets = grouped.every((targetArg) => {
37693774
const relativeTarget = toRepoRelativeTarget(targetArg, cwd);
@@ -3776,7 +3781,7 @@ export function buildVitestRunPlans(
37763781
? createBoundedExtensionPlans({
37773782
config,
37783783
forwardedArgs: forwardedPlanArgs,
3779-
roots: boundedExtensionRoots,
3784+
includePatterns,
37803785
watchMode,
37813786
})
37823787
: null;
@@ -3856,12 +3861,11 @@ export function buildFullSuiteVitestRunPlans(args: string[], cwd = process.cwd()
38563861
listGatewayServerTestTargets(cwd),
38573862
GATEWAY_SERVER_TEST_PROCESS_COUNT,
38583863
);
3859-
} else if (config === EXTENSION_MATRIX_VITEST_CONFIG) {
3860-
chunks = createExtensionTestProcessTargetChunks(
3861-
config,
3862-
matrixExtensionTestRoots,
3863-
forwardedArgs,
3864-
);
3864+
} else {
3865+
const roots = EXTENSION_TEST_PROCESS_ROOTS.get(config);
3866+
if (roots) {
3867+
chunks = createExtensionTestProcessTargetChunks(config, roots, forwardedArgs);
3868+
}
38653869
}
38663870
if (chunks.length > 0) {
38673871
return chunks.map((targets) => ({

‎test/scripts/test-projects.test.ts‎

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,35 @@ import {
4242

4343
const normalizeRepoPath = toRepoPath;
4444
const MATRIX_TEST_PROCESS_FILE_LIMIT = 40;
45+
const TELEGRAM_TEST_PROCESS_FILE_LIMIT = 5;
4546

4647
function expectedMatrixTestProcessCount() {
4748
const testFileCount = listExtensionTestFilesForRoots(["extensions/matrix"]).length;
4849
return Math.max(1, Math.ceil(testFileCount / MATRIX_TEST_PROCESS_FILE_LIMIT));
4950
}
5051

52+
function expectedTelegramTestProcessCount() {
53+
const testFileCount = listExtensionTestFilesForRoots(["extensions/telegram"]).length;
54+
return Math.max(1, Math.ceil(testFileCount / TELEGRAM_TEST_PROCESS_FILE_LIMIT));
55+
}
56+
5157
function listExpectedFullExtensionRunPlans() {
5258
const matrixConfig = "test/vitest/vitest.extension-matrix.config.ts";
53-
const matrixPlans = buildVitestRunPlans(["extensions/matrix"], process.cwd());
54-
return listFullExtensionVitestProjectConfigs().flatMap((config) =>
55-
config === matrixConfig
56-
? matrixPlans
57-
: [
58-
{
59-
config,
60-
forwardedArgs: [],
61-
includePatterns: null,
62-
watchMode: false,
63-
},
64-
],
59+
const telegramConfig = "test/vitest/vitest.extension-telegram.config.ts";
60+
const boundedPlansByConfig = new Map([
61+
[matrixConfig, buildVitestRunPlans(["extensions/matrix"], process.cwd())],
62+
[telegramConfig, buildVitestRunPlans(["extensions/telegram"], process.cwd())],
63+
]);
64+
return listFullExtensionVitestProjectConfigs().flatMap(
65+
(config) =>
66+
boundedPlansByConfig.get(config) ?? [
67+
{
68+
config,
69+
forwardedArgs: [],
70+
includePatterns: null,
71+
watchMode: false,
72+
},
73+
],
6574
);
6675
}
6776

@@ -2084,12 +2093,15 @@ describe("scripts/test-projects changed-target routing", () => {
20842093

20852094
it("routes the top-level extensions target to every extension shard", () => {
20862095
const matrixConfig = "test/vitest/vitest.extension-matrix.config.ts";
2096+
const telegramConfig = "test/vitest/vitest.extension-telegram.config.ts";
20872097
const plans = buildVitestRunPlans(["extensions"], process.cwd());
20882098
const matrixPlans = plans.filter((plan) => plan.config === matrixConfig);
2099+
const telegramPlans = plans.filter((plan) => plan.config === telegramConfig);
2100+
const boundedConfigs = new Set([matrixConfig, telegramConfig]);
20892101

2090-
expect(plans.filter((plan) => plan.config !== matrixConfig)).toEqual(
2102+
expect(plans.filter((plan) => !boundedConfigs.has(plan.config))).toEqual(
20912103
listFullExtensionVitestProjectConfigs()
2092-
.filter((config) => config !== matrixConfig)
2104+
.filter((config) => !boundedConfigs.has(config))
20932105
.map((config) => ({
20942106
config,
20952107
forwardedArgs: [],
@@ -2106,9 +2118,34 @@ describe("scripts/test-projects changed-target routing", () => {
21062118
expect(matrixPlans.flatMap((plan) => plan.includePatterns ?? [])).toEqual(
21072119
listExtensionTestFilesForRoots(["extensions/matrix"]),
21082120
);
2121+
expect(telegramPlans).toHaveLength(expectedTelegramTestProcessCount());
2122+
expect(
2123+
telegramPlans.every(
2124+
(plan) => (plan.includePatterns?.length ?? 0) <= TELEGRAM_TEST_PROCESS_FILE_LIMIT,
2125+
),
2126+
).toBe(true);
2127+
expect(telegramPlans.flatMap((plan) => plan.includePatterns ?? [])).toEqual(
2128+
listExtensionTestFilesForRoots(["extensions/telegram"]),
2129+
);
21092130
expect(plans).toEqual(listExpectedFullExtensionRunPlans());
21102131
});
21112132

2133+
it("bounds an explicit Telegram config target across process lifetimes", () => {
2134+
const config = "test/vitest/vitest.extension-telegram.config.ts";
2135+
const plans = buildVitestRunPlans([config], process.cwd());
2136+
2137+
expect(plans).toHaveLength(expectedTelegramTestProcessCount());
2138+
expect(plans.every((plan) => plan.config === config)).toBe(true);
2139+
expect(
2140+
plans.every(
2141+
(plan) => (plan.includePatterns?.length ?? 0) <= TELEGRAM_TEST_PROCESS_FILE_LIMIT,
2142+
),
2143+
).toBe(true);
2144+
expect(plans.flatMap((plan) => plan.includePatterns ?? [])).toEqual(
2145+
listExtensionTestFilesForRoots(["extensions/telegram"]),
2146+
);
2147+
});
2148+
21122149
it("bounds an explicit Matrix directory target across process lifetimes", () => {
21132150
const plans = buildVitestRunPlans(["extensions/matrix"], process.cwd());
21142151

0 commit comments

Comments
 (0)