Files
orca/src/shared/node-markdown-document-discovery.test.ts
T
NeilandOrca 879aad7dd6 oom(foundation): bound shared readers/limits + add BoundedMap primitive (#10299)
* oom(01): A1-shared-readers — reintroduce #10179 subset

Files: 18 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(02): A2-shared-image-media — reintroduce #10179 subset

Files: 7 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(03): A3-shared-fs-listing — reintroduce #10179 subset

Files: 21 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(04): A4-shared-remote-relay — reintroduce #10179 subset

Files: 8 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(05): A5-shared-misc — reintroduce #10179 subset

Files: 28 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(06): B-shared-wiring — reintroduce #10179 subset

Files: 81 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-24 21:36:57 -07:00

75 lines
2.4 KiB
TypeScript

import type { Dirent } from 'node:fs'
import { describe, expect, it } from 'vitest'
import { MarkdownDocumentListingCapacityError } from './markdown-document-listing-limits'
import { discoverMarkdownRelativePaths } from './node-markdown-document-discovery'
function entry(name: string, kind: 'directory' | 'file' | 'symlink' = 'file'): Dirent {
return {
name,
isDirectory: () => kind === 'directory',
isFile: () => kind === 'file',
isSymbolicLink: () => kind === 'symlink'
} as Dirent
}
function reader(entriesByPath: Record<string, Dirent[]>) {
return async (path: string): Promise<AsyncIterable<Dirent>> => ({
async *[Symbol.asyncIterator]() {
yield* entriesByPath[path] ?? []
}
})
}
describe('bounded Markdown document discovery', () => {
it('preserves depth-first discovery and skips excluded and symlinked directories', async () => {
const result = await discoverMarkdownRelativePaths('/repo', {
readDirectory: reader({
'/repo': [
entry('README.md'),
entry('.git', 'directory'),
entry('docs', 'directory'),
entry('linked', 'symlink')
],
'/repo/docs': [entry('guide.mdx'), entry('app.ts')]
}),
shouldDescend: (_relativePath, name) => name !== '.git'
})
expect(result).toEqual(['README.md', 'docs/guide.mdx'])
})
it('stops consuming a wide directory at the visited-entry limit', async () => {
let yielded = 0
const readDirectory = async (): Promise<AsyncIterable<Dirent>> => ({
async *[Symbol.asyncIterator]() {
for (let index = 0; index < 10_000; index += 1) {
yielded += 1
yield entry(`source-${index}.ts`)
}
}
})
await expect(
discoverMarkdownRelativePaths('/repo', {
limits: { maxVisitedEntries: 2 },
readDirectory,
shouldDescend: () => true
})
).rejects.toBeInstanceOf(MarkdownDocumentListingCapacityError)
expect(yielded).toBe(3)
})
it('rejects a directory deeper than the configured traversal limit', async () => {
await expect(
discoverMarkdownRelativePaths('/repo', {
limits: { maxDepth: 1 },
readDirectory: reader({
'/repo': [entry('one', 'directory')],
'/repo/one': [entry('two', 'directory')]
}),
shouldDescend: () => true
})
).rejects.toBeInstanceOf(MarkdownDocumentListingCapacityError)
})
})