// FILE: _St/IG_StYellow/test_ext_progress_eta_v279ccc.js | ROLE: No 선택 표시·전체 실행 진행률·최근 20세트 ETA 회귀 검사
const assert = require('assert');
const fs = require('fs');
const path = require('path');

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

assert.strictEqual(manifest.version_name, '2.3.8.314');
for (const token of [
  'function teAutoPyAssetProgressKey(shortcode, kind)',
  'function teAutoPyRegisterExpectedAsset(shortcode, kind)',
  'function teAutoPyRegisterCompletedAsset(shortcode, kind)',
  'function teAutoPyRunFileProgress()',
  'function teAutoPyOverallRunPct()',
  'expected_asset_keys: []',
  'completed_asset_keys: []',
  '`파일 ${runFileProgress.completed}/${runFileProgress.total}`',
  'teAutoPyRegisterExpectedAsset(progressShortcode, kind);',
  'teAutoPyRegisterCompletedAsset(progressShortcode, kind);',
]) assert.ok(side.includes(token), `missing progress token: ${token}`);

assert.ok(side.includes('const pct = hasAutoUi ? (autoTerminal ? 100 : teAutoPyOverallRunPct()) : (done ? 100 : i);'));
assert.ok(!side.includes('[progressNoLabel || "No---", `${pct}%`, sc]'), 'No--- must not be forced into download summary');
assert.ok(!side.includes('return `최근다운 ${no || "No---"}'), 'No--- must not be forced into recent download text');
assert.ok(side.includes('const currentNoPart = curNo ? `  ${teAutoPyNoLabel(curNo)}` : "";'));
assert.ok(!side.includes('현재 주소  계정미확인  No---  0%'), 'idle current address must not force No---');
assert.ok(side.includes('const overallPct = teAutoPyOverallRunPct();'), 'unified auto status must use whole-run percent');
assert.ok(side.includes('const overallPct = autoActive ? teAutoPyOverallRunPct()'), 'active download status must use whole-run percent');

for (const token of [
  'schema: "ig_auto_eta_v279ccc"',
  'sample_limit: 20',
  'samples_ms: []',
  'stats.samples_ms = samples.slice(-20);',
  'teAutoEtaRecordCompletedPost(directSummary, "direct_pair_complete", Date.now() - autoCycleStartedAt);',
  'if (ms == null || !Number.isFinite(Number(ms))) return "계산중";',
  'String(sec).padStart(2, "0")}초`',
  'if (!(averageDownloadMs > 0)) return null;',
  'if (!(d > 0)) return null;',
]) assert.ok(side.includes(token), `missing ETA token: ${token}`);

console.log('OK test_ext_progress_eta_v279ccc');
