test(core): stabilize glob truncation tests (#3322)
Some checks are pending
Qwen Code CI / Lint (push) Waiting to run
Qwen Code CI / Test (push) Blocked by required conditions
Qwen Code CI / Test-1 (push) Blocked by required conditions
Qwen Code CI / Test-2 (push) Blocked by required conditions
Qwen Code CI / Test-3 (push) Blocked by required conditions
Qwen Code CI / Test-4 (push) Blocked by required conditions
Qwen Code CI / Test-5 (push) Blocked by required conditions
Qwen Code CI / Test-6 (push) Blocked by required conditions
Qwen Code CI / Test-7 (push) Blocked by required conditions
Qwen Code CI / Test-8 (push) Blocked by required conditions
Qwen Code CI / Post Coverage Comment (push) Blocked by required conditions
Qwen Code CI / CodeQL (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run

* test(core): stabilize glob truncation tests

  Mock glob results in truncation-specific tests instead of creating large
  numbers of real files. This keeps the tests focused on GlobTool boundary
  logic and avoids filesystem timing issues on Windows CI.

* test(cli): stabilize selection list scroll test

  Wait for the newly active item to render after rerendering the list so the
  scroll assertions do not read a stale frame on slower Windows CI runs.
This commit is contained in:
Reid 2026-04-16 20:51:24 +08:00 committed by GitHub
parent 662c2abd27
commit 12b24e2d28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 36 deletions

View file

@ -300,7 +300,7 @@ describe('BaseSelectionList', () => {
rerender(<BaseSelectionList {...componentProps} />);
await waitFor(() => {
expect(lastFrame()).toBeTruthy();
expect(lastFrame()).toContain(longList[newIndex]!.label);
});
};

View file

@ -16,6 +16,7 @@ import type { Config } from '../config/config.js';
import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
import { ToolErrorType } from './tool-error.js';
import * as glob from 'glob';
import type { Path as GlobResultPath } from 'glob';
vi.mock('glob', { spy: true });
@ -78,6 +79,23 @@ describe('GlobTool', () => {
await fs.rm(tempRootDir, { recursive: true, force: true });
});
const mockTruncationGlobResults = (prefix: string, count: number) => {
const baseMtimeMs = Date.now();
const entries = Array.from(
{ length: count },
(_, index): GlobResultPath => {
const fileNumber = index + 1;
return {
fullpath: () =>
path.join(tempRootDir, `${prefix}${fileNumber}.trunctest`),
mtimeMs: baseMtimeMs + fileNumber,
} as unknown as GlobResultPath;
},
);
vi.mocked(glob.glob).mockResolvedValueOnce(entries);
};
describe('execute', () => {
it('should find files matching a simple pattern in the root', async () => {
const params: GlobToolParams = { pattern: '*.txt' };
@ -533,13 +551,7 @@ describe('GlobTool', () => {
describe('file count truncation', () => {
it('should truncate results when more than 100 files are found', async () => {
// Create 150 test files
for (let i = 1; i <= 150; i++) {
await fs.writeFile(
path.join(tempRootDir, `file${i}.trunctest`),
`content${i}`,
);
}
mockTruncationGlobResults('file', 150);
const params: GlobToolParams = { pattern: '*.trunctest' };
const invocation = globTool.build(params);
@ -564,13 +576,7 @@ describe('GlobTool', () => {
});
it('should not truncate when exactly 100 files are found', async () => {
// Create exactly 100 test files
for (let i = 1; i <= 100; i++) {
await fs.writeFile(
path.join(tempRootDir, `exact${i}.trunctest`),
`content${i}`,
);
}
mockTruncationGlobResults('exact', 100);
const params: GlobToolParams = { pattern: '*.trunctest' };
const invocation = globTool.build(params);
@ -591,13 +597,7 @@ describe('GlobTool', () => {
});
it('should not truncate when fewer than 100 files are found', async () => {
// Create 50 test files
for (let i = 1; i <= 50; i++) {
await fs.writeFile(
path.join(tempRootDir, `small${i}.trunctest`),
`content${i}`,
);
}
mockTruncationGlobResults('small', 50);
const params: GlobToolParams = { pattern: '*.trunctest' };
const invocation = globTool.build(params);
@ -614,13 +614,7 @@ describe('GlobTool', () => {
});
it('should use correct singular/plural in truncation message for 1 file truncated', async () => {
// Create 101 test files (will truncate 1 file)
for (let i = 1; i <= 101; i++) {
await fs.writeFile(
path.join(tempRootDir, `singular${i}.trunctest`),
`content${i}`,
);
}
mockTruncationGlobResults('singular', 101);
const params: GlobToolParams = { pattern: '*.trunctest' };
const invocation = globTool.build(params);
@ -632,13 +626,7 @@ describe('GlobTool', () => {
});
it('should use correct plural in truncation message for multiple files truncated', async () => {
// Create 105 test files (will truncate 5 files)
for (let i = 1; i <= 105; i++) {
await fs.writeFile(
path.join(tempRootDir, `plural${i}.trunctest`),
`content${i}`,
);
}
mockTruncationGlobResults('plural', 105);
const params: GlobToolParams = { pattern: '*.trunctest' };
const invocation = globTool.build(params);