|
2 | 2 | // list of packed group plans. Extracted from .github/workflows/ci.yml so the |
3 | 3 | // execution policy is unit-testable and plans can run concurrently. |
4 | 4 | import { spawn } from "node:child_process"; |
5 | | -import { existsSync, mkdtempSync, readdirSync, statSync, unlinkSync, writeFileSync } from "node:fs"; |
| 5 | +import { |
| 6 | + constants, |
| 7 | + cpSync, |
| 8 | + existsSync, |
| 9 | + mkdtempSync, |
| 10 | + readdirSync, |
| 11 | + rmSync, |
| 12 | + statSync, |
| 13 | + unlinkSync, |
| 14 | + writeFileSync, |
| 15 | +} from "node:fs"; |
6 | 16 | import { tmpdir } from "node:os"; |
7 | 17 | import { join } from "node:path"; |
8 | 18 | import { StringDecoder } from "node:string_decoder"; |
@@ -150,6 +160,30 @@ export function pruneFsModuleCache(root, maxBytes = FS_MODULE_CACHE_MAX_BYTES) { |
150 | 160 | return { beforeBytes, afterBytes: totalBytes, removedFiles }; |
151 | 161 | } |
152 | 162 |
|
| 163 | +export function clonePersistentCacheSlots(root, concurrency) { |
| 164 | + if (!root || concurrency <= 1) { |
| 165 | + return 0; |
| 166 | + } |
| 167 | + const seed = join(root, "vitest-cache-0"); |
| 168 | + if (!existsSync(seed)) { |
| 169 | + return 0; |
| 170 | + } |
| 171 | + |
| 172 | + let clonedSlots = 0; |
| 173 | + for (let cacheSlot = 1; cacheSlot < concurrency; cacheSlot += 1) { |
| 174 | + const destination = join(root, `vitest-cache-${cacheSlot}`); |
| 175 | + rmSync(destination, { force: true, recursive: true }); |
| 176 | + // Clone before workers start. Reflinks make the common Linux path cheap; |
| 177 | + // unsupported filesystems transparently fall back to a regular copy. |
| 178 | + cpSync(seed, destination, { |
| 179 | + mode: constants.COPYFILE_FICLONE, |
| 180 | + recursive: true, |
| 181 | + }); |
| 182 | + clonedSlots += 1; |
| 183 | + } |
| 184 | + return clonedSlots; |
| 185 | +} |
| 186 | + |
153 | 187 | const MAX_PENDING_LINE_CHARS = 1_000_000; |
154 | 188 |
|
155 | 189 | function relayChildStream(stream, label) { |
@@ -227,6 +261,12 @@ export async function runShardPlans(plans, options = {}) { |
227 | 261 | const scratchDir = options.scratchDir ?? mkdtempSync(join(tmpdir(), "openclaw-node-shard-")); |
228 | 262 | const persistentCacheRoot = baseEnv[FS_MODULE_CACHE_PATH_ENV_KEY]?.trim(); |
229 | 263 | const nodeCompileCacheRoot = baseEnv[NODE_COMPILE_CACHE_PATH_ENV_KEY]?.trim(); |
| 264 | + const clonedCacheSlots = clonePersistentCacheSlots(persistentCacheRoot, concurrency); |
| 265 | + if (clonedCacheSlots > 0) { |
| 266 | + process.stdout.write( |
| 267 | + `[shard:cache] cloned restored Vitest seed into ${clonedCacheSlots} isolated lane(s)\n`, |
| 268 | + ); |
| 269 | + } |
230 | 270 |
|
231 | 271 | let nextIndex = 0; |
232 | 272 | let exitCode = 0; |
|
0 commit comments