Files
dacli/tests/unit/browser_record.test.ts
sushub f403a7e80e import: ssw/dacli@eea0ebc (2026-08-12) 起点版本
本仓 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,未来以本仓历史为主
2026-08-12 15:58:06 +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)
})
})