mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
* Remove low-value file, runtime and chat test cases * test: remove low-value shared contract and timing suites * test: remove leaking browser IPC mock suite * test: isolate legacy relay bridge transport fixture --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
72 lines
3.6 KiB
TypeScript
72 lines
3.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { getDiskBaselineSignature } from './disk-baseline-signature'
|
|
import {
|
|
compareDiskWritePrecondition,
|
|
diskConflictFromReadFailure
|
|
} from './file-write-disk-precondition'
|
|
|
|
describe('disk write precondition', () => {
|
|
it('compares decoded disk text against the baseline signature', () => {
|
|
const precondition = { expectedSignature: getDiskBaselineSignature('base') }
|
|
expect(compareDiskWritePrecondition(precondition, 'base', 'mine')).toBeNull()
|
|
expect(compareDiskWritePrecondition(precondition, 'newer', 'mine')).toBe('changed')
|
|
expect(compareDiskWritePrecondition(precondition, undefined, 'mine')).toBe('changed')
|
|
expect(compareDiskWritePrecondition(precondition, null, 'mine')).toBe('missing')
|
|
expect(
|
|
compareDiskWritePrecondition({ ...precondition, allowMissing: true }, null, 'mine')
|
|
).toBeNull()
|
|
})
|
|
|
|
it('accepts a changed disk that already holds exactly the text being saved', () => {
|
|
const precondition = { expectedSignature: getDiskBaselineSignature('base') }
|
|
expect(compareDiskWritePrecondition(precondition, 'mine', 'mine')).toBe('identical')
|
|
expect(compareDiskWritePrecondition(precondition, 'base', 'base')).toBe('identical')
|
|
expect(compareDiskWritePrecondition(precondition, 'mine\r\n', 'mine\n')).toBe('changed')
|
|
expect(compareDiskWritePrecondition(precondition, undefined, 'mine')).toBe('changed')
|
|
// A replacement character may stand for bytes the decode dropped, so it proves nothing.
|
|
expect(compareDiskWritePrecondition(precondition, 'a�', 'a�')).toBe('changed')
|
|
})
|
|
|
|
it('refuses ambiguous automatic baseline matches but preserves explicit saves', () => {
|
|
const decoded = Buffer.from([0x61, 0xfe]).toString('utf8')
|
|
const current = Buffer.from([0x61, 0xff]).toString('utf8')
|
|
const precondition = { expectedSignature: getDiskBaselineSignature(decoded) }
|
|
expect(
|
|
compareDiskWritePrecondition({ ...precondition, requireLosslessUtf8: true }, current, decoded)
|
|
).toBe('not-utf8')
|
|
expect(compareDiskWritePrecondition(precondition, current, decoded)).toBeNull()
|
|
})
|
|
|
|
it.each([
|
|
[
|
|
'an ENOENT code with plain wording',
|
|
Object.assign(new Error('File not found'), { code: 'ENOENT' })
|
|
],
|
|
['an SFTP-style message', new Error('No such file or directory')]
|
|
])('treats %s from an older host as a missing file', (_label, error) => {
|
|
const precondition = { expectedSignature: getDiskBaselineSignature('base') }
|
|
expect(diskConflictFromReadFailure(precondition, error)).toBe('missing')
|
|
})
|
|
|
|
it.each([
|
|
"EACCES: permission denied, open '/repo/ENOENT.md'",
|
|
"EACCES: permission denied, open '/repo/ENOENT/notes.md'",
|
|
"EACCES: permission denied, open '/repo/No such file or directory/notes.md'",
|
|
"EACCES: permission denied, open '/repo/Error: ENOENT: no such file or directory.txt'",
|
|
"Error invoking remote method 'fs:readFile': Error: EACCES: permission denied, open '/repo/Error: ENOENT: no such file or directory.txt'"
|
|
])('never reads a path that merely names ENOENT as a missing file: %s', (message) => {
|
|
const precondition = {
|
|
expectedSignature: getDiskBaselineSignature('base'),
|
|
allowMissing: true
|
|
}
|
|
expect(() => diskConflictFromReadFailure(precondition, new Error(message))).toThrow('EACCES')
|
|
})
|
|
|
|
it('trusts a conflicting errno code over not-found wording', () => {
|
|
const error = Object.assign(new Error('ENOENT: no such file or directory'), { code: 'EACCES' })
|
|
expect(() =>
|
|
diskConflictFromReadFailure({ expectedSignature: getDiskBaselineSignature('base') }, error)
|
|
).toThrow('ENOENT')
|
|
})
|
|
})
|