本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { mkdtempSync, readFileSync, rmSync, existsSync, statSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { writeJsonAtomic } from '../../src/commands/test/log-atomic.ts'
|
|
|
|
|
|
describe('log atomic write', () => {
|
|
it('replaces any existing file with the new payload and never leaves a 0-byte artifact', () => {
|
|
const dir = mkdtempSync(join(tmpdir(), 'dacli-log-'))
|
|
const target = join(dir, 'result.json')
|
|
try {
|
|
writeJsonAtomic(target, { attempt: 1, ok: false })
|
|
expect(statSync(target).size).toBeGreaterThan(0)
|
|
|
|
writeJsonAtomic(target, { attempt: 2, ok: true, payload: { id: '852466054494945285', actionableTaskCreated: true, verifyExitCode: 0 } })
|
|
const body = readFileSync(target, 'utf-8')
|
|
expect(body).toContain('"verifyExitCode": 0')
|
|
expect(body).toContain('"actionableTaskCreated": true')
|
|
expect(statSync(target).size).toBeGreaterThan(0)
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('creates the destination directory on first write', () => {
|
|
const dir = mkdtempSync(join(tmpdir(), 'dacli-log-'))
|
|
const target = join(dir, 'nested', 'deep', 'result.json')
|
|
try {
|
|
writeJsonAtomic(target, { ok: true })
|
|
expect(existsSync(target)).toBe(true)
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
})
|