fix(fs): observe absence before guarded recreation

This commit is contained in:
Tianyi Cui
2026-08-09 15:22:50 +08:00
parent 9aa2d07353
commit ceba53edd7
68 changed files with 694 additions and 249 deletions

View File

@@ -196,6 +196,35 @@ describe('tool-str-replace-editor', () => {
expect(await readFile(sample, 'utf8')).toBe('one\nbetween\n\nthree\n')
})
it('a failed view records absence so create can recover after external deletion', async () => {
const { ctx, root, owner } = await setup({}, { fsPolicy: true })
const sample = join(root, 'deleted.txt')
await writeFile(sample, 'original')
expect((await call(ctx, owner, { command: 'view', path: sample })).isError).toBe(false)
await rm(sample)
const missing = await call(ctx, owner, { command: 'view', path: sample })
expect(missing.isError).toBe(true)
expect(missing.error).toMatchObject({ info: { code: 'FS_NOT_FOUND' } })
const edit = await call(ctx, owner, {
command: 'str_replace',
path: sample,
old_str: 'original',
new_str: 'edited',
})
expect(edit.isError).toBe(true)
expect(edit.error).toMatchObject({ info: { code: 'FS_NOT_FOUND' } })
const created = await call(ctx, owner, {
command: 'create',
path: sample,
file_text: 'fresh',
})
expect(created.isError).toBe(false)
expect(await readFile(sample, 'utf8')).toBe('fresh')
})
it('writes replacement text literally', async () => {
const { ctx, root, owner } = await setup()
const sample = join(root, 'literal.txt')