@@ -4,7 +4,11 @@ import fs from "node:fs";
44import os from "node:os" ;
55import path from "node:path" ;
66import { beforeAll , describe , expect , it , vi } from "vitest" ;
7- import { listExtensionTestFilesForRoots } from "../../scripts/lib/extension-test-plan.mts" ;
7+ import {
8+ listExtensionTestFilesForRoots ,
9+ MATRIX_EXTENSION_TEST_PROCESS_FILE_LIMIT ,
10+ TELEGRAM_EXTENSION_TEST_PROCESS_FILE_LIMIT ,
11+ } from "../../scripts/lib/extension-test-plan.mts" ;
812import {
913 CHANNEL_CONTRACT_CONFIG_PATTERNS ,
1014 DEFAULT_TEST_PROJECTS_VITEST_NO_OUTPUT_HEARTBEAT_MS ,
@@ -41,8 +45,8 @@ import {
4145} from "../vitest/vitest.contracts-shared.ts" ;
4246
4347const normalizeRepoPath = toRepoPath ;
44- const MATRIX_TEST_PROCESS_FILE_LIMIT = 40 ;
45- const TELEGRAM_TEST_PROCESS_FILE_LIMIT = 5 ;
48+ const MATRIX_TEST_PROCESS_FILE_LIMIT = MATRIX_EXTENSION_TEST_PROCESS_FILE_LIMIT ;
49+ const TELEGRAM_TEST_PROCESS_FILE_LIMIT = TELEGRAM_EXTENSION_TEST_PROCESS_FILE_LIMIT ;
4650
4751function expectedMatrixTestProcessCount ( ) {
4852 const testFileCount = listExtensionTestFilesForRoots ( [ "extensions/matrix" ] ) . length ;
@@ -2146,6 +2150,64 @@ describe("scripts/test-projects changed-target routing", () => {
21462150 ) ;
21472151 } ) ;
21482152
2153+ it ( "splits an externally scoped Telegram include file across process lifetimes" , ( ) => {
2154+ const config = "test/vitest/vitest.extension-telegram.config.ts" ;
2155+ const files = listExtensionTestFilesForRoots ( [ "extensions/telegram" ] ) . slice (
2156+ 0 ,
2157+ TELEGRAM_TEST_PROCESS_FILE_LIMIT + 4 ,
2158+ ) ;
2159+ expect ( files . length ) . toBeGreaterThan ( TELEGRAM_TEST_PROCESS_FILE_LIMIT ) ;
2160+
2161+ const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-telegram-include-scope-" ) ) ;
2162+ try {
2163+ const includeFile = path . join ( tempDir , "ci-shard.json" ) ;
2164+ fs . writeFileSync ( includeFile , JSON . stringify ( files ) ) ;
2165+ const plans = buildVitestRunPlans ( [ config ] , process . cwd ( ) , ( ) => [ ] , {
2166+ env : { OPENCLAW_VITEST_INCLUDE_FILE : includeFile } ,
2167+ } ) ;
2168+
2169+ expect ( plans ) . toHaveLength ( files . length ) ;
2170+ expect (
2171+ plans . every (
2172+ ( plan ) =>
2173+ plan . config === config &&
2174+ ( plan . includePatterns ?. length ?? 0 ) === TELEGRAM_TEST_PROCESS_FILE_LIMIT ,
2175+ ) ,
2176+ ) . toBe ( true ) ;
2177+ expect ( plans . flatMap ( ( plan ) => plan . includePatterns ?? [ ] ) ) . toEqual ( files ) ;
2178+ } finally {
2179+ fs . rmSync ( tempDir , { force : true , recursive : true } ) ;
2180+ }
2181+ } ) ;
2182+
2183+ it ( "turns a five-file Telegram include file into five one-file run specs" , ( ) => {
2184+ const config = "test/vitest/vitest.extension-telegram.config.ts" ;
2185+ const files = listExtensionTestFilesForRoots ( [ "extensions/telegram" ] ) . slice ( 0 , 5 ) ;
2186+ expect ( files ) . toHaveLength ( 5 ) ;
2187+
2188+ const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-telegram-include-specs-" ) ) ;
2189+ try {
2190+ const includeFile = path . join ( tempDir , "ci-shard.json" ) ;
2191+ fs . writeFileSync ( includeFile , JSON . stringify ( files ) ) ;
2192+ const specs = createVitestRunSpecs ( [ config ] , {
2193+ baseEnv : { OPENCLAW_VITEST_INCLUDE_FILE : includeFile } ,
2194+ tempDir,
2195+ } ) ;
2196+
2197+ expect ( specs ) . toHaveLength ( 5 ) ;
2198+ expect (
2199+ specs . every ( ( spec ) => spec . config === config && ( spec . includePatterns ?. length ?? 0 ) === 1 ) ,
2200+ ) . toBe ( true ) ;
2201+ expect ( specs . map ( ( spec ) => spec . includePatterns ?. [ 0 ] ) ) . toEqual ( files ) ;
2202+ expect ( new Set ( specs . map ( ( spec ) => spec . env . OPENCLAW_VITEST_INCLUDE_FILE ) ) . size ) . toBe ( 5 ) ;
2203+ expect ( specs . every ( ( spec ) => spec . env . OPENCLAW_VITEST_INCLUDE_FILE !== includeFile ) ) . toBe (
2204+ true ,
2205+ ) ;
2206+ } finally {
2207+ fs . rmSync ( tempDir , { force : true , recursive : true } ) ;
2208+ }
2209+ } ) ;
2210+
21492211 it . each ( [
21502212 {
21512213 channel : "Telegram" ,
@@ -3696,6 +3758,34 @@ describe("scripts/test-projects Vitest stall watchdog", () => {
36963758} ) ;
36973759
36983760describe ( "scripts/test-projects Vitest cache isolation" , ( ) => {
3761+ it ( "keeps same-config process lifetimes on one restored cache" , ( ) => {
3762+ const specs = [
3763+ {
3764+ config : "test/vitest/vitest.extension-telegram.config.ts" ,
3765+ env : { OPENCLAW_VITEST_FS_MODULE_CACHE_PATH : "/tmp/cache" } ,
3766+ includeFilePath : null ,
3767+ includePatterns : [ "extensions/telegram/src/a.test.ts" ] ,
3768+ pnpmArgs : [ ] ,
3769+ watchMode : false ,
3770+ } ,
3771+ {
3772+ config : "test/vitest/vitest.extension-telegram.config.ts" ,
3773+ env : { OPENCLAW_VITEST_FS_MODULE_CACHE_PATH : "/tmp/cache" } ,
3774+ includeFilePath : null ,
3775+ includePatterns : [ "extensions/telegram/src/b.test.ts" ] ,
3776+ pnpmArgs : [ ] ,
3777+ watchMode : false ,
3778+ } ,
3779+ ] ;
3780+
3781+ expect (
3782+ applyDefaultMultiSpecVitestCachePaths ( specs , {
3783+ cwd : "/repo" ,
3784+ env : { OPENCLAW_VITEST_FS_MODULE_CACHE_PATH : "/tmp/cache" } ,
3785+ } ) ,
3786+ ) . toBe ( specs ) ;
3787+ } ) ;
3788+
36993789 it ( "assigns isolated fs-module caches to multi-spec non-watch runs" , ( ) => {
37003790 const specs = applyDefaultMultiSpecVitestCachePaths (
37013791 [
0 commit comments