// FILE: _St/IG_StYellow/test_ext_download_status_preserve_v279b.js | ROLE: 실제 다운로드 시작 전 상태 보존·시작 시 초기화 회귀 검사
const assert = require('assert');
const fs = require('fs');
const path = require('path');

const root = __dirname;
const side = fs.readFileSync(path.join(root, 'side.js'), 'utf8');
const html = fs.readFileSync(path.join(root, 'side.html'), 'utf8');
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'manifest.json'), 'utf8'));

assert.strictEqual(manifest.version, '2.3.8.3190');
assert.strictEqual(manifest.version_name, '2.3.8.319');
assert.ok(side.includes('const IGBLUE_PACKAGE_VERSION = IGBLUE_BUILD_TAG;'));
assert.ok(html.includes('id="igblue_auto_py_stats"'));
assert.ok(!html.includes('id="igblue_auto_py_stats" title="공통 다운로드 진행상황입니다. 현재 주소 진행률, 전체 주소 목록 진행률, 종료예상을 표시합니다.">자동현황 대기</div>'));

assert.ok(side.includes('let teProgressState =') || side.includes('teProgressState = {'));
assert.ok(side.includes('teDownloadDisplayAwaitingStart = !0'));
assert.ok(side.includes('function teProgressPreserveUntilNextDownload(reason)'));
assert.ok(side.includes('function teProgressBeginActualDownload(event)'));
assert.ok(side.includes('function teProgressCommitCompletedUnifiedSnapshot(reason)'));
assert.ok(side.includes('teProgressCommitCompletedUnifiedSnapshot("post_complete")'));
assert.ok(side.includes('if (status === "start") teProgressBeginActualDownload(e);'));
assert.ok(side.includes('teAutoPyLastDoneText = "";'));
assert.ok(side.includes('if (teDownloadDisplayAwaitingStart && !autoTerminal) return;'));
assert.ok(side.includes('if (teDownloadDisplayAwaitingStart && !(teAutoPyUiState && teAutoPyUiState.automatic_end)) return;'));
assert.ok(side.includes('teProgressPreserveUntilNextDownload("account_navigation")'));
assert.ok(side.includes('teProgressPreserveUntilNextDownload(newSession ? "auto_start_new_run" : "auto_account_continue")'));
assert.ok(!side.includes('teProgressResetForContext("account_navigation")'));
assert.ok(!side.includes('teProgressResetForContext(newSession ? "auto_start_new_run" : "auto_account_continue")'));
assert.ok(!side.includes('자동현황 대기\\n다운로드 진행 없음'));
assert.ok(side.includes('teProgressState.done = status === "done" || status === "already_done";'));
assert.ok(side.includes('if (terminal) {'));
assert.ok(side.includes('teDownloadDisplayAwaitingStart = true;'));

console.log('test_ext_download_status_preserve_v279b: OK');
