import fs from 'node:fs';
import { expect, test } from '@playwright/test';
import { resultDir, runtime, navigate, screenshot } from './query-support';
test.use({trace:'on',storageState:runtime().storageState});
const items = JSON.parse(fs.readFileSync('qa/issues/4330/dev/checklist.json', 'utf8')).checklist as string[];
for (const item of items)
    test(item, async ({page}, info) => {
        const id = item.split(' ')[0];
        const checks = fs.existsSync(resultDir + '/checks.json') ? JSON.parse(fs.readFileSync(resultDir + '/checks.json', 'utf8')) : {};
        const record = id === 'I02' ? { status: 'BLOCKED', detail: '개발계 빌드 소스에 대상 커밋 포함 확인. 실행 서비스 이미지와 산출물의 연결 증거는 미확보. deployment-evidence.md 참조.' } : checks[id];
        await info.attach('checklist-result.json', { body: Buffer.from(JSON.stringify({ id, ...record }, null, 2)), contentType: 'application/json' });
        if (record)
            expect(record.status, record.detail).not.toBe('FAIL');
        if (record?.status === 'BLOCKED') {
            await navigate(page, id === 'B02' ? '/bond-management-v2' : '/master-accounting/disbursement-accounts');
            await screenshot(page, info, id + '-context.png');
            await info.attach('evidence-limitation.txt', {body:Buffer.from('현재 접근 가능한 화면의 재현 기록입니다. 이 화면만으로 미확인 조건을 검증했다고 판단하지 않습니다. '+record.detail),contentType:'text/plain'});
        }
        test.skip(!record || record.status === 'BLOCKED', 'BLOCKED: ' + (record?.detail ?? '선행 화면 검증에서 해당 항목의 완료 증거가 생성되지 않았습니다.'));
        expect(record?.status).toBe('PASS');
    });
