mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
Files: 18 applied, 0 deleted (from 6eb70d8370)
Co-authored-by: Orca <help@stably.ai>
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { mkdtempSync, rmSync, truncateSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { nodeFileContentsEqual, nodeFileContentsEqualSync } from './node-file-content-equality'
|
|
|
|
const roots: string[] = []
|
|
|
|
function createFile(contents: string): string {
|
|
const root = mkdtempSync(join(tmpdir(), 'orca-file-content-equality-'))
|
|
roots.push(root)
|
|
const filePath = join(root, 'owned-launcher')
|
|
writeFileSync(filePath, contents)
|
|
return filePath
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const root of roots.splice(0)) {
|
|
rmSync(root, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
describe('Node file content equality', () => {
|
|
it('compares UTF-8 content without changing its bytes', async () => {
|
|
const filePath = createFile('launch 🐋\n')
|
|
|
|
await expect(nodeFileContentsEqual(filePath, 'launch 🐋\n')).resolves.toBe(true)
|
|
expect(nodeFileContentsEqualSync(filePath, 'launch 🐋\n')).toBe(true)
|
|
await expect(nodeFileContentsEqual(filePath, 'different\n')).resolves.toBe(false)
|
|
expect(nodeFileContentsEqualSync(filePath, 'different\n')).toBe(false)
|
|
})
|
|
|
|
it('rejects a large sparse replacement from metadata without reading its payload', async () => {
|
|
const filePath = createFile('owned launcher\n')
|
|
truncateSync(filePath, 256 * 1024 * 1024)
|
|
|
|
await expect(nodeFileContentsEqual(filePath, 'owned launcher\n')).resolves.toBe(false)
|
|
expect(nodeFileContentsEqualSync(filePath, 'owned launcher\n')).toBe(false)
|
|
})
|
|
})
|