Skip to content

Commit 2fdf07e

Browse files
yamadashyclaude
andcommitted
fix(tests): Address CodeRabbit feedback on prewarm-count assertions
Two cold-path tests asserted `(call count) > 1`, which depends on the host having at least 2 vCPUs. On a 1-vCPU CI runner `getWorkerThreadCount(1000).maxThreads` collapses to 1 and the cold path correctly fires a single warm-up task — but the assertion would fail despite the behavior being correct. Switch both tests to assert against the actual computed `maxThreads` from the same heuristic the production path uses, so the cold-path contract is pinned independent of runner vCPU count. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 54f3503 commit 2fdf07e

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

tests/core/metrics/calculateMetrics.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { GitDiffResult } from '../../../src/core/git/gitDiffHandle.js';
77
import { calculateFileMetrics } from '../../../src/core/metrics/calculateFileMetrics.js';
88
import { calculateMetrics, createMetricsTaskRunner } from '../../../src/core/metrics/calculateMetrics.js';
99
import { getRepoSeenMarkerPath } from '../../../src/core/metrics/tokenCountCache.js';
10+
import { getWorkerThreadCount } from '../../../src/shared/processConcurrency.js';
1011
import type { RepomixProgressCallback } from '../../../src/shared/types.js';
1112
import { createMockConfig } from '../../testing/testUtils.js';
1213

@@ -333,25 +334,27 @@ describe('createMetricsTaskRunner — cache-aware prewarm count', () => {
333334
expect(result.taskRunner.run).toHaveBeenCalledWith({ content: '', encoding: 'o200k_base' });
334335
});
335336

336-
it('prewarms maxThreads (>1) workers when cache exists but THIS repo marker is missing', async () => {
337+
it('prewarms the full maxThreads when cache exists but THIS repo marker is missing', async () => {
337338
// Cache file present from some other repo, but no marker for OTHER_REPO_DIR.
338339
await fs.mkdir(path.dirname(cacheFile), { recursive: true });
339340
await fs.writeFile(cacheFile, '{"version":1,"entries":{}}');
340341

341342
const result = createMetricsTaskRunner([OTHER_REPO_DIR], 1000, 'o200k_base');
342343
await result.warmupPromise;
343344

344-
// numOfTasks=1000 yields maxThreads = min(cpu, ceil(1000/100)) = min(cpu, 10).
345-
// On any host with ≥2 vCPUs this is > 1. The test runs in CI on ≥2-core
346-
// runners so the assertion is portable.
347-
expect((result.taskRunner.run as Mock).mock.calls.length).toBeGreaterThan(1);
345+
// Compute the expected `maxThreads` from the same heuristic the production
346+
// path uses (`min(cpu, ceil(N/100))`) so the assertion is portable across
347+
// 1-vCPU / 2-vCPU / N-vCPU CI runners alike.
348+
const { maxThreads } = getWorkerThreadCount(1000);
349+
expect((result.taskRunner.run as Mock).mock.calls.length).toBe(maxThreads);
348350
});
349351

350-
it('prewarms maxThreads (>1) workers when shared cache file is missing (cold)', async () => {
352+
it('prewarms the full maxThreads when shared cache file is missing (cold)', async () => {
351353
// No cache file, no marker.
352354
const result = createMetricsTaskRunner([REPO_DIR], 1000, 'o200k_base');
353355
await result.warmupPromise;
354356

355-
expect((result.taskRunner.run as Mock).mock.calls.length).toBeGreaterThan(1);
357+
const { maxThreads } = getWorkerThreadCount(1000);
358+
expect((result.taskRunner.run as Mock).mock.calls.length).toBe(maxThreads);
356359
});
357360
});

0 commit comments

Comments
 (0)