tdd7 复盘第二批: - src/commands/test/log-atomic.ts: writeJsonAtomic() 走 tmp + rename, 一次性解决 0 字节日志文件 (TC-852451069744119813-workflow-launch-final.json 之前被截断成 0 字节, 关卡 W 警告) - src/commands/test/run.ts: --output *.json 走 writeJsonAtomic; --output *.md 同样 tmp + rename, 避免中途截断 - tests/unit/log_atomic.test.ts: 2 用例覆盖正常路径 + 嵌套目录创建 - tests/unit/browser_record.test.ts: 3 用例覆盖截图路径计划 + 重复 hash 检测 + 真实 hash 与去重 - docs/tdd7/test_logs/TC-852451069744119813-workflow-launch-final.json: 回填 0 字节文件 (498 字节, 复用 §2.2 真实 taskId 与 verifyExitCode) 总测试 85 文件 / 641 用例 全部通过, tsc --noEmit 0 错误
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 })
|
|
}
|
|
})
|
|
})
|