Files
ssw-mvp/dacli/tests/unit/browser_record.test.ts
T
admin 4d096dd97e chore(dacli): 提交 dacli CLI 工具源码并过滤敏感/噪声文件
- dacli/ 整目录被 .gitignore 忽略,本次 force-add 其业务源码(766 文件)
- 排除 node_modules/.env(含 PGPASSWORD 等敏感信息)/.DS_Store/__pycache__/*.pyc
- 新增 dacli/.gitignore 长期管理内部噪声,新增文件仍需 git add -f
- 根 .gitignore 补充 .cache/ 与诊断脚本忽略,并加 dacli 段说明
2026-08-06 19:02:39 +08:00

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)
})
})