mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
refactor(tts): reuse the shared atomic write helper for the audio cache
This commit is contained in:
1 parent
169ee25a8a
commit
bda123b6e1
4 files changed
+57
-70
No files matched your search
@@ -2,7 +2,7 @@ import { mkdtemp, readdir, readFile, realpath, rm, stat, writeFile } from 'node:
|
||||
import { tmpdir } from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { canonicalPath, canonicalPathSync, writeFileAtomicSync } from '../../src/utils/fs-safe'
|
||||
import { canonicalPath, canonicalPathSync, writeFileAtomic, writeFileAtomicSync } from '../../src/utils/fs-safe'
|
||||
|
||||
describe('canonicalPath', () => {
|
||||
let workDir = ''
|
||||
@@ -67,3 +67,25 @@ describe('writeFileAtomicSync', () => {
|
||||
await expect(readdir(workDir)).resolves.toEqual(['file.txt'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('writeFileAtomic', () => {
|
||||
let workDir = ''
|
||||
|
||||
beforeEach(async () => {
|
||||
workDir = await mkdtemp(path.join(tmpdir(), 'fs-safe-atomic-async-'))
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await rm(workDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('writes Buffer bytes unchanged and leaves no temp file behind', async () => {
|
||||
const target = path.join(workDir, 'audio.mp3')
|
||||
const bytes = Buffer.from([0xff, 0x00, 0xfe, 0x80])
|
||||
|
||||
await writeFileAtomic(target, bytes)
|
||||
|
||||
expect(await readFile(target)).toEqual(bytes)
|
||||
await expect(readdir(workDir)).resolves.toEqual(['audio.mp3'])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user