chore(build/compiler): Enable a bunch of strict TS compiler options. (#6138)

This commit is contained in:
Richie Foreman
2025-08-13 16:17:38 -04:00
committed by GitHub
parent 8fae227e8d
commit a90aeb3d8f
28 changed files with 141 additions and 84 deletions

View File

@@ -13,8 +13,6 @@ import { AuthType } from '../core/contentGenerator.js';
import { StructuredError } from '../core/turn.js';
describe('parseAndFormatApiError', () => {
const _enterpriseMessage =
'upgrade to a Gemini Code Assist Standard or Enterprise plan with higher limits';
const vertexMessage = 'request a quota increase through Vertex';
const geminiMessage = 'request a quota increase through AI Studio';

View File

@@ -289,7 +289,7 @@ export class FileSearch {
* Builds the in-memory cache for fast pattern matching.
*/
private buildResultCache(): void {
this.resultCache = new ResultCache(this.allFiles, this.absoluteDir);
this.resultCache = new ResultCache(this.allFiles);
// The v1 algorithm is much faster since it only looks at the first
// occurence of the pattern. We use it for search spaces that have >20k
// files, because the v2 algorithm is just too slow in those cases.

View File

@@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
import path from 'node:path';
import { test, expect } from 'vitest';
import { ResultCache } from './result-cache.js';
@@ -17,7 +16,7 @@ test('ResultCache basic usage', async () => {
'subdir/other.js',
'subdir/nested/file.md',
];
const cache = new ResultCache(files, path.resolve('.'));
const cache = new ResultCache(files);
const { files: resultFiles, isExactMatch } = await cache.get('*.js');
expect(resultFiles).toEqual(files);
expect(isExactMatch).toBe(false);
@@ -25,7 +24,7 @@ test('ResultCache basic usage', async () => {
test('ResultCache cache hit/miss', async () => {
const files = ['foo.txt', 'bar.js', 'baz.md'];
const cache = new ResultCache(files, path.resolve('.'));
const cache = new ResultCache(files);
// First call: miss
const { files: result1Files, isExactMatch: isExactMatch1 } =
await cache.get('*.js');
@@ -44,7 +43,7 @@ test('ResultCache cache hit/miss', async () => {
test('ResultCache best base query', async () => {
const files = ['foo.txt', 'foobar.js', 'baz.md'];
const cache = new ResultCache(files, path.resolve('.'));
const cache = new ResultCache(files);
// Cache a broader query
cache.set('foo', ['foo.txt', 'foobar.js']);

View File

@@ -13,10 +13,7 @@ export class ResultCache {
private hits = 0;
private misses = 0;
constructor(
private readonly allFiles: string[],
private readonly absoluteDir: string,
) {
constructor(private readonly allFiles: string[]) {
this.cache = new Map();
}

View File

@@ -11,7 +11,7 @@ import { marked } from 'marked';
import { processImports, validateImportPath } from './memoryImportProcessor.js';
// Helper function to create platform-agnostic test paths
const testPath = (...segments: string[]) => {
function testPath(...segments: string[]): string {
// Start with the first segment as is (might be an absolute path on Windows)
let result = segments[0];
@@ -27,9 +27,8 @@ const testPath = (...segments: string[]) => {
}
return path.normalize(result);
};
}
// Mock fs/promises
vi.mock('fs/promises');
const mockedFs = vi.mocked(fs);
@@ -509,21 +508,21 @@ describe('memoryImportProcessor', () => {
expect(result.importTree.imports).toHaveLength(2);
// First import: nested.md
// Prefix with underscore to indicate they're intentionally unused
const _expectedNestedPath = testPath(projectRoot, 'src', 'nested.md');
const _expectedInnerPath = testPath(projectRoot, 'src', 'inner.md');
const _expectedSimplePath = testPath(projectRoot, 'src', 'simple.md');
// Check that the paths match using includes to handle potential absolute/relative differences
expect(result.importTree.imports![0].path).toContain('nested.md');
const expectedNestedPath = testPath(projectRoot, 'src', 'nested.md');
expect(result.importTree.imports![0].path).toContain(expectedNestedPath);
expect(result.importTree.imports![0].imports).toHaveLength(1);
const expectedInnerPath = testPath(projectRoot, 'src', 'inner.md');
expect(result.importTree.imports![0].imports![0].path).toContain(
'inner.md',
expectedInnerPath,
);
expect(result.importTree.imports![0].imports![0].imports).toBeUndefined();
// Second import: simple.md
expect(result.importTree.imports![1].path).toContain('simple.md');
const expectedSimplePath = testPath(projectRoot, 'src', 'simple.md');
expect(result.importTree.imports![1].path).toContain(expectedSimplePath);
expect(result.importTree.imports![1].imports).toBeUndefined();
});
@@ -724,21 +723,20 @@ describe('memoryImportProcessor', () => {
expect(result.importTree.imports).toHaveLength(2);
// First import: nested.md
// Prefix with underscore to indicate they're intentionally unused
const _expectedNestedPath = testPath(projectRoot, 'src', 'nested.md');
const _expectedInnerPath = testPath(projectRoot, 'src', 'inner.md');
const _expectedSimplePath = testPath(projectRoot, 'src', 'simple.md');
const expectedNestedPath = testPath(projectRoot, 'src', 'nested.md');
const expectedInnerPath = testPath(projectRoot, 'src', 'inner.md');
const expectedSimplePath = testPath(projectRoot, 'src', 'simple.md');
// Check that the paths match using includes to handle potential absolute/relative differences
expect(result.importTree.imports![0].path).toContain('nested.md');
expect(result.importTree.imports![0].path).toContain(expectedNestedPath);
expect(result.importTree.imports![0].imports).toHaveLength(1);
expect(result.importTree.imports![0].imports![0].path).toContain(
'inner.md',
expectedInnerPath,
);
expect(result.importTree.imports![0].imports![0].imports).toBeUndefined();
// Second import: simple.md
expect(result.importTree.imports![1].path).toContain('simple.md');
expect(result.importTree.imports![1].path).toContain(expectedSimplePath);
expect(result.importTree.imports![1].imports).toBeUndefined();
});
@@ -899,7 +897,7 @@ describe('memoryImportProcessor', () => {
// Test relative paths - resolve them against basePath
const relativePath = './file.md';
const _resolvedRelativePath = path.resolve(basePath, relativePath);
path.resolve(basePath, relativePath);
expect(validateImportPath(relativePath, basePath, [basePath])).toBe(true);
// Test parent directory access (should be allowed if parent is in allowed paths)
@@ -907,12 +905,12 @@ describe('memoryImportProcessor', () => {
if (parentPath !== basePath) {
// Only test if parent is different
const parentRelativePath = '../file.md';
const _resolvedParentPath = path.resolve(basePath, parentRelativePath);
path.resolve(basePath, parentRelativePath);
expect(
validateImportPath(parentRelativePath, basePath, [parentPath]),
).toBe(true);
const _resolvedSubPath = path.resolve(basePath, 'sub');
path.resolve(basePath, 'sub');
const resultSub = validateImportPath('sub', basePath, [basePath]);
expect(resultSub).toBe(true);
}

View File

@@ -261,7 +261,7 @@ export async function processImports(
// Process imports in reverse order to handle indices correctly
for (let i = imports.length - 1; i >= 0; i--) {
const { start, _end, path: importPath } = imports[i];
const { start, path: importPath } = imports[i];
// Skip if inside a code region
if (