// dacli/tests/integration/verify-runner.test.ts /** * Phase 4 Task 4.1: verify-runner 集成测试 (3 case) * * - checkDeps 真实 JNPF 探测 * - runVerify 真实 paymentapply form 跑 verify-form.ts 子进程 * - archiveScreenshots 从 /tmp 归档到 docs/{app}/verification/ * * 注: workSystem /model/{enCode} 路由 404 已知, runVerify 期望 ok=false */ import { describe, it, expect } from 'vitest' import { checkDeps, runVerify, archiveScreenshots } from '../../src/core/verify-runner' import { existsSync, mkdirSync, writeFileSync, unlinkSync, statSync, readdirSync } from 'node:fs' import { join } from 'node:path' describe('checkDeps 集成', () => { it('workSystem JNPF 可达时 jnpf=true', async () => { const deps = await checkDeps() expect(deps.jnpf).toBe(true) expect(deps.playwright).toBe(true) expect(deps.chromium).toBe(true) }) }) describe('runVerify 集成 (workSystem + paymentapply)', () => { it('真实 JNPF + paymentapply form: ok=false (路由 404 已知), 但结构完整', async () => { const result = await runVerify('585398402720727621', 'paymentapply', 'workSystem', { timeout: 90_000, }) expect(result).toHaveProperty('ok') expect(result).toHaveProperty('steps') expect(result).toHaveProperty('screenshots') expect(result).toHaveProperty('durationMs') // workSystem 路由 404 已知, ok 应为 false expect(result.ok).toBe(false) expect(result.error).toBeDefined() }, 120_000) it('form 不存在时返 ok=false', async () => { const result = await runVerify('999999999999999999', 'nonexist', 'workSystem', { timeout: 30_000, }) expect(result.ok).toBe(false) }, 60_000) }) describe('archiveScreenshots 集成', () => { it('从 /tmp 归档到 docs/{app}/verification/{enCode}-{ts}/', () => { const tmpDir = `/tmp/test-archive-${Date.now()}` mkdirSync(tmpDir, { recursive: true }) writeFileSync(join(tmpDir, 'list.png'), 'fake-png-content') writeFileSync(join(tmpDir, 'after-create.png'), 'fake-png-content') const archived = archiveScreenshots(tmpDir, 'workSystem', 'paymentapply_test') expect(archived.length).toBe(2) expect(archived[0]).toContain('docs/workSystem/verification/paymentapply_test-') // 验证归档目录存在 + 文件 copy OK const targetDir = join(archived[0], '..') expect(existsSync(targetDir)).toBe(true) const files = readdirSync(targetDir) expect(files.length).toBe(2) expect(files).toContain('list.png') expect(files).toContain('after-create.png') // 清理 archived.forEach(f => { if (existsSync(f)) unlinkSync(f) }) }) })