refactor(runtime): collapse speculative portability layers
Remove the one-consumer bounded-read primitive and shared terminal lifecycle controller, make terminal cleanup one awaited provider operation, and reuse one Code Runtime contract suite. Keep only reproduced cancellation and policy fixes; defer unproven replacement, prompt-attribution, and streaming-frame concerns to scoped markers.
This commit is contained in:
@@ -218,15 +218,6 @@ describe('readText / streamText', () => {
|
||||
expect(await fs.readText(await fs.resolve('a.txt'))).toBe('one\ntwo\nthree')
|
||||
})
|
||||
|
||||
it('reads complete text through the stable byte bound', async () => {
|
||||
await writeFile(join(dir, 'bounded.txt'), '€abc')
|
||||
const target = await fs.resolve('bounded.txt')
|
||||
expect(await fs.readTextBounded(target, 6)).toBe('€abc')
|
||||
await expect(fs.readTextBounded(target, 5)).rejects.toThrow('exceeds the 5-byte limit')
|
||||
await expect(fs.readTextBounded(target, 0)).rejects.toThrow('positive safe integer')
|
||||
await expect(fs.readTextBounded(target, 6, AbortSignal.abort())).rejects.toMatchObject({ code: 'FS_ABORTED' })
|
||||
})
|
||||
|
||||
it('streams the same text', async () => {
|
||||
await writeFile(join(dir, 'a.txt'), 'one\ntwo\nthree')
|
||||
const target = await fs.resolve('a.txt')
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* policy and lives in `dsh-fs-policy`, so it is not tested here.
|
||||
*/
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { chmod, mkdtemp, readFile, rename, rm, stat, symlink, unlink, writeFile, mkdir, readdir, realpath } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
@@ -17,7 +17,6 @@ import {
|
||||
probeNoFollow,
|
||||
readForEdit,
|
||||
readWholeText,
|
||||
readWholeTextBounded,
|
||||
resolveLocalTarget,
|
||||
restoreLineEndings,
|
||||
streamWholeText,
|
||||
@@ -317,66 +316,6 @@ describe('readWholeText', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('readWholeTextBounded', () => {
|
||||
it('rejects non-files, binary text, and initial oversize without a full read', async () => {
|
||||
await expect(readWholeTextBounded(localTarget(dir), 10)).rejects.toMatchObject({ code: 'FS_NOT_REGULAR_FILE' })
|
||||
await writeFile(join(dir, 'large'), '12345')
|
||||
await expect(readWholeTextBounded(localTarget(join(dir, 'large')), 4)).rejects.toThrow('exceeds the 4-byte limit')
|
||||
await writeFile(join(dir, 'binary'), Buffer.from([0x61, 0x00, 0x62]))
|
||||
await expect(readWholeTextBounded(localTarget(join(dir, 'binary')), 3)).rejects.toMatchObject({ code: 'FS_NOT_TEXT' })
|
||||
})
|
||||
|
||||
it('detects growth past the bound on the same open handle', async () => {
|
||||
const close = vi.fn(async () => {})
|
||||
const read = vi.fn(async (buffer: Buffer, offset: number, length: number, position: number) => {
|
||||
const bytes = position === 0 ? Buffer.from('abc') : Buffer.from('d')
|
||||
bytes.copy(buffer, offset, 0, Math.min(length, bytes.length))
|
||||
return { bytesRead: Math.min(length, bytes.length), buffer }
|
||||
})
|
||||
vi.resetModules()
|
||||
vi.doMock('node:fs/promises', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('node:fs/promises')>()
|
||||
return {
|
||||
...actual,
|
||||
open: async () => ({
|
||||
stat: async () => ({ isFile: () => true, size: 3 }),
|
||||
read,
|
||||
close,
|
||||
}),
|
||||
}
|
||||
})
|
||||
try {
|
||||
const isolated = await import('../src/fsio.ts')
|
||||
await expect(isolated.readWholeTextBounded(localTarget('/virtual/growing'), 3))
|
||||
.rejects.toThrow('grew past the 3-byte limit')
|
||||
expect(close).toHaveBeenCalledOnce()
|
||||
} finally {
|
||||
vi.doUnmock('node:fs/promises')
|
||||
vi.resetModules()
|
||||
}
|
||||
})
|
||||
|
||||
it('translates permission and generic open failures', async () => {
|
||||
const failure: { current: Error & { code?: string } } = { current: Object.assign(new Error('denied'), { code: 'EACCES' }) }
|
||||
vi.resetModules()
|
||||
vi.doMock('node:fs/promises', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('node:fs/promises')>()
|
||||
return { ...actual, open: async () => { throw failure.current } }
|
||||
})
|
||||
try {
|
||||
const isolated = await import('../src/fsio.ts')
|
||||
await expect(isolated.readWholeTextBounded(localTarget('/virtual/denied'), 3))
|
||||
.rejects.toMatchObject({ code: 'FS_PERMISSION_DENIED' })
|
||||
failure.current = new Error('open broke')
|
||||
await expect(isolated.readWholeTextBounded(localTarget('/virtual/broken'), 3))
|
||||
.rejects.toMatchObject({ code: 'FS_IO_ERROR' })
|
||||
} finally {
|
||||
vi.doUnmock('node:fs/promises')
|
||||
vi.resetModules()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('streamWholeText', () => {
|
||||
it('streams the whole file as decoded text', async () => {
|
||||
const file = join(dir, 'a.txt')
|
||||
|
||||
Reference in New Issue
Block a user