test(fs-local): pin multibyte byte-length gating

This commit is contained in:
ZiyaZhang
2026-08-07 11:56:08 -07:00
parent 16c1eaf546
commit d7705e2dcd
2 changed files with 12 additions and 2 deletions
@@ -438,6 +438,18 @@ describe('writeText', () => {
expect(outcome.after).toBe('12345678')
})
it('gates the NEW content by UTF-8 byte length, not character count', async () => {
// Three CJK characters are 9 UTF-8 bytes: below an 8-byte bound by
// characters but at/above it by bytes, so the basis must be declined.
await remountWithDiffLimit(8)
await writeFile(join(dir, 'cjk.txt'), 'tiny')
const target = await fs.resolve('cjk.txt')
const outcome = await fs.writeText(target, '你好吗')
expect(outcome.operation).toBe('update')
expect(outcome.before).toBeNull()
expect(outcome.after).toBe('你好吗')
})
it('an overwrite with BOTH sides below the whole-file bound keeps its contextual before basis', async () => {
await remountWithDiffLimit(8)
await writeFile(join(dir, 'small.txt'), '1234567')
-2
View File
@@ -367,8 +367,6 @@ describe('readTextForDiff', () => {
})
it('returns null when the opened file grows after descriptor stat', async () => {
// Pins the one-extra-byte EOF probe: with a buffer of exactly openedSize a
// grown file would read openedSize bytes and pass the consistency check.
const file = join(dir, 'growing.txt')
await writeFile(file, 'abcdef')
vi.resetModules()