mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 16:03:20 +00:00
* oom(01): A1-shared-readers — reintroduce #10179 subset Files: 18 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(02): A2-shared-image-media — reintroduce #10179 subset Files: 7 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(03): A3-shared-fs-listing — reintroduce #10179 subset Files: 21 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(04): A4-shared-remote-relay — reintroduce #10179 subset Files: 8 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(05): A5-shared-misc — reintroduce #10179 subset Files: 28 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(06): B-shared-wiring — reintroduce #10179 subset Files: 81 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { lstatMock, opendirMock } = vi.hoisted(() => ({
|
|
lstatMock: vi.fn(),
|
|
opendirMock: vi.fn()
|
|
}))
|
|
|
|
vi.mock('node:fs/promises', () => ({
|
|
lstat: lstatMock,
|
|
opendir: opendirMock
|
|
}))
|
|
|
|
import { readQuickOpenDirectoryEntries } from './quick-open-directory-reader'
|
|
import { createQuickOpenReaddirBudget } from './quick-open-readdir-budget'
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
lstatMock.mockResolvedValue({
|
|
isDirectory: () => true,
|
|
isSymbolicLink: () => false
|
|
})
|
|
})
|
|
|
|
describe('quick-open streaming directory reader', () => {
|
|
it('stops a huge directory one entry beyond the exact cap and closes its iterator', async () => {
|
|
let produced = 0
|
|
let closed = false
|
|
opendirMock.mockResolvedValue({
|
|
async *[Symbol.asyncIterator]() {
|
|
try {
|
|
while (produced < 1_000_000) {
|
|
produced += 1
|
|
yield {
|
|
name: `directory-${produced}`,
|
|
isDirectory: () => true,
|
|
isFile: () => false,
|
|
isSymbolicLink: () => false
|
|
}
|
|
}
|
|
} finally {
|
|
closed = true
|
|
}
|
|
}
|
|
})
|
|
|
|
await expect(
|
|
readQuickOpenDirectoryEntries({
|
|
absPath: '/streamed',
|
|
allowSymlinkedRoot: false,
|
|
budget: createQuickOpenReaddirBudget({ maxEntries: 3 })
|
|
})
|
|
).rejects.toThrow('File listing exceeded 3 entries')
|
|
expect(produced).toBe(4)
|
|
expect(closed).toBe(true)
|
|
})
|
|
})
|