fix(e2b): release bounded read stream locks
Release the Web Stream reader after either completion or cancellation. Strengthen the oversized-file test so a regression that downloads content before applying the stat bound fails directly.
This commit is contained in:
@@ -274,6 +274,7 @@ export class E2BFileSystem extends FileSystem {
|
|||||||
// remote stream adds nothing actionable for the caller.
|
// remote stream adds nothing actionable for the caller.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reader.releaseLock()
|
||||||
}
|
}
|
||||||
const whole = new Uint8Array(bytes)
|
const whole = new Uint8Array(bytes)
|
||||||
let offset = 0
|
let offset = 0
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class FakeRemote {
|
|||||||
readonly links: Array<{ from: string; to: string }> = []
|
readonly links: Array<{ from: string; to: string }> = []
|
||||||
readonly removals: string[] = []
|
readonly removals: string[] = []
|
||||||
readonly commands: string[] = []
|
readonly commands: string[] = []
|
||||||
|
readonly reads: Array<{ path: string; format: 'bytes' | 'stream' }> = []
|
||||||
streamChunks: Uint8Array[] | undefined
|
streamChunks: Uint8Array[] | undefined
|
||||||
streamKeepOpen = false
|
streamKeepOpen = false
|
||||||
readonly streamCancel = vi.fn()
|
readonly streamCancel = vi.fn()
|
||||||
@@ -157,6 +158,7 @@ class FakeRemote {
|
|||||||
},
|
},
|
||||||
read: async (path: string, options: { format: 'bytes' | 'stream'; signal?: AbortSignal }): Promise<Uint8Array | ReadableStream<Uint8Array> | string> => {
|
read: async (path: string, options: { format: 'bytes' | 'stream'; signal?: AbortSignal }): Promise<Uint8Array | ReadableStream<Uint8Array> | string> => {
|
||||||
this.checkAbort(options)
|
this.checkAbort(options)
|
||||||
|
this.reads.push({ path, format: options.format })
|
||||||
if (this.nextReadError !== undefined) {
|
if (this.nextReadError !== undefined) {
|
||||||
const error = this.nextReadError
|
const error = this.nextReadError
|
||||||
this.nextReadError = undefined
|
this.nextReadError = undefined
|
||||||
@@ -478,7 +480,10 @@ describe('E2BFileSystem identity, metadata, and reads', () => {
|
|||||||
const { fs } = await setup(remote)
|
const { fs } = await setup(remote)
|
||||||
const target = await fs.resolve('img.bin')
|
const target = await fs.resolve('img.bin')
|
||||||
expect(Array.from(await fs.readBytes(target, undefined, 4))).toEqual([0x89, 0, 0xff, 0x47])
|
expect(Array.from(await fs.readBytes(target, undefined, 4))).toEqual([0x89, 0, 0xff, 0x47])
|
||||||
|
expect(remote.reads).toEqual([{ path: '/workspace/img.bin', format: 'stream' }])
|
||||||
|
remote.reads.length = 0
|
||||||
await expectCode(fs.readBytes(target, undefined, 3), 'FS_TOO_LARGE')
|
await expectCode(fs.readBytes(target, undefined, 3), 'FS_TOO_LARGE')
|
||||||
|
expect(remote.reads).toEqual([])
|
||||||
await expectCode(fs.readBytes(await fs.resolve('missing'), undefined, 4), 'FS_NOT_FOUND')
|
await expectCode(fs.readBytes(await fs.resolve('missing'), undefined, 4), 'FS_NOT_FOUND')
|
||||||
await expectCode(fs.readBytes(await fs.resolve('directory'), undefined, 4), 'FS_NOT_REGULAR_FILE')
|
await expectCode(fs.readBytes(await fs.resolve('directory'), undefined, 4), 'FS_NOT_REGULAR_FILE')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user