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 错误
54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { createHash } from 'node:crypto'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { buildBrowserScreenshotPlan, hasDistinctScreenshotHashes } from '../../src/commands/test/browser-evidence.ts'
|
|
|
|
function md5Of(value: string): string {
|
|
return createHash('md5').update(value).digest('hex')
|
|
}
|
|
|
|
describe('browser record plan', () => {
|
|
it('plans three checkpoints with stable distinct filenames', () => {
|
|
const dir = mkdtempSync(join(tmpdir(), 'dacli-shots-'))
|
|
try {
|
|
const plan = buildBrowserScreenshotPlan(dir, 'workflow', '852451069744119813')
|
|
expect(plan).toHaveLength(3)
|
|
expect(plan[0]).toContain('workflow-852451069744119813-01-page-loaded.png')
|
|
expect(plan[1]).toContain('workflow-852451069744119813-02-after-checks.png')
|
|
expect(plan[2]).toContain('workflow-852451069744119813-03-final.png')
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('treats three identical captures as a degenerate artifact set', () => {
|
|
const dir = mkdtempSync(join(tmpdir(), 'dacli-shots-'))
|
|
try {
|
|
mkdirSync(dir, { recursive: true })
|
|
const plan = buildBrowserScreenshotPlan(dir, 'workflow', '852451069744119813')
|
|
const artifacts: Array<{ path: string; md5: string }> = []
|
|
for (const path of plan) {
|
|
writeFileSync(path, 'aaaa')
|
|
artifacts.push({ path, md5: md5Of(readFileSync(path, 'utf-8')) })
|
|
}
|
|
expect(artifacts).toHaveLength(3)
|
|
expect(hasDistinctScreenshotHashes(artifacts)).toBe(false)
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('browser record md5', () => {
|
|
it('marks distinct content as distinct even when filenames repeat', () => {
|
|
const artifacts: Array<{ path: string; md5: string }> = [
|
|
{ path: 'a.png', md5: md5Of('payload-1') },
|
|
{ path: 'b.png', md5: md5Of('payload-2') },
|
|
{ path: 'c.png', md5: md5Of('payload-3') },
|
|
]
|
|
expect(hasDistinctScreenshotHashes(artifacts)).toBe(true)
|
|
})
|
|
})
|