* Normalize + bound one call's files: coalesce each file's ranges, then keep * the files that got the most source. A call that renders more files than the * bound has already spread its envelope thin, so the tail files carry the * least — and losing them costs the least.
(files: ReadonlyArray<ExploreFileEmission> | undefined)
| 310 | * least — and losing them costs the least. |
| 311 | */ |
| 312 | private boundFiles(files: ReadonlyArray<ExploreFileEmission> | undefined): ExploreFileEmission[] { |
| 313 | if (!Array.isArray(files) || files.length === 0) return []; |
| 314 | const normalized = files |
| 315 | .filter((f) => f && typeof f.path === 'string' && f.path.length > 0) |
| 316 | .map((f) => { |
| 317 | const { ranges, truncated } = coalesceRanges(f.ranges ?? []); |
| 318 | const out: ExploreFileEmission = { path: f.path, ranges, bytes: Math.max(0, f.bytes || 0) }; |
| 319 | if (typeof f.fingerprint === 'string' && f.fingerprint) out.fingerprint = f.fingerprint; |
| 320 | if (truncated) out.rangesTruncated = true; |
| 321 | return out; |
| 322 | }); |
| 323 | if (normalized.length <= EXPLORE_SESSION_LIMITS.MAX_FILES_PER_CALL) return normalized; |
| 324 | return [...normalized] |
| 325 | .sort((a, b) => b.bytes - a.bytes) |
| 326 | .slice(0, EXPLORE_SESSION_LIMITS.MAX_FILES_PER_CALL); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | function cloneProject(state: MutableProjectState): ExploreProjectState { |
no test coverage detected