Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions sdk/src/__tests__/read-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,5 +848,56 @@ describe('getFiles', () => {
expect(result['src/big.ts']).toContain('showing lines 10-14 of 3000')
expect(result['src/big.ts']).toContain('showing lines 2500-2504 of 3000')
})

test('resolves fileWindows keyed by relative path when filePaths has leading dot-slash', async () => {
const mockFs = createMockFs({
files: { '/project/src/big.ts': { content: bigFile } },
})

const result = await getFiles({
filePaths: ['./src/big.ts'],
cwd: '/project',
fs: mockFs,
fileWindows: { 'src/big.ts': [{ offset: 2500, limit: 10 }] },
})

expect(result['src/big.ts']).toContain('line 2500')
expect(result['src/big.ts']).toContain('showing lines 2500-2509 of 3000')
expect(result['src/big.ts']).not.toContain('line 100\n')
})

test('resolves fileWindows keyed by relative path when filePaths has absolute path', async () => {
const mockFs = createMockFs({
files: { '/project/src/big.ts': { content: bigFile } },
})

const result = await getFiles({
filePaths: ['/project/src/big.ts'],
cwd: '/project',
fs: mockFs,
fileWindows: { 'src/big.ts': [{ offset: 2500, limit: 10 }] },
})

expect(result['src/big.ts']).toContain('line 2500')
expect(result['src/big.ts']).toContain('showing lines 2500-2509 of 3000')
expect(result['src/big.ts']).not.toContain('line 100\n')
})

test('resolves fileWindows keyed by absolute path when filePaths has relative path', async () => {
const mockFs = createMockFs({
files: { '/project/src/big.ts': { content: bigFile } },
})

const result = await getFiles({
filePaths: ['src/big.ts'],
cwd: '/project',
fs: mockFs,
fileWindows: { '/project/src/big.ts': [{ offset: 2500, limit: 10 }] },
})

expect(result['src/big.ts']).toContain('line 2500')
expect(result['src/big.ts']).toContain('showing lines 2500-2509 of 3000')
expect(result['src/big.ts']).not.toContain('line 100\n')
})
})
})
5 changes: 4 additions & 1 deletion sdk/src/tools/read-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ export async function getFiles(params: {

const content = await fs.readFile(fullPath, 'utf8')

const windows = fileWindows?.[filePath]
const windows =
fileWindows?.[filePath] ??
fileWindows?.[relativePath] ??
(fullPath ? fileWindows?.[fullPath] : undefined)
const windowedContent =
limitContent && fileWindows !== undefined
? (windows?.length ? windows : [{}])
Expand Down
Loading