// FILE: _St/IG_StYellow/test_ext_auto_v249_regression.js | ROLE: IG_StYellow 회귀 테스트
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const read = (name) => fs.readFileSync(path.join(__dirname, name), 'utf8');
const side = read('side.js');
const background = read('background.js');

assert.ok(side.includes('async function teAutoPyStartOnceFromUi(options)'));
assert.ok(side.includes('자동 시작 활성화'));
assert.ok(!side.includes('teAutoPyAcquireFixedTabSession'));
assert.ok(!side.includes('teAutoRunSessionActive'));
assert.ok(!side.includes('auto_fixed_tab_missing'));
assert.ok(!side.includes('account_dom_not_ready'));
assert.ok(!side.includes('await teSleep(4500)'));
assert.ok(background.includes('igblueWaitForNavigationReady') && background.includes('igblue_navigation_ready_probe'));
assert.ok(side.includes('resume_after_content_main_ready'));
assert.ok(side.includes('teRequestTargetState(true)'));
assert.ok(side.includes('teAutoPyTryCacheDownloadForRank'));
assert.ok(!side.includes('allow_cache_fallback: false'));
assert.ok(side.includes('AD-03-E01') && side.includes('[복구완료]'));
assert.ok(side.includes('S00_SNAPSHOT_START_CURRENT') && side.includes('set_internal_current_no_without_download')); // v278: snapshot Current remains, and exact snapshot cache recovery is allowed when Main active data is incomplete
assert.ok(!side.includes('owner_account_mismatch'));
assert.ok(background.includes('function igblueReadCurrentActiveInstagramTab(callback)'));
assert.ok(background.includes('chrome.tabs.query({active:true, lastFocusedWindow:true}'));
assert.ok(!background.includes('chrome.tabs.query({url:['));
assert.ok(!background.includes('igblueQueryBestInstagramTab'));
assert.ok(!background.includes('IGBLUE_GET_CONNECTED_TARGET_STATE'));

// v261 latest user rule: do not search all Instagram tabs, but preserve the one active Instagram tab captured at auto start.
assert.ok(side.includes('let teAutoPySessionTarget = { active: false'));
assert.ok(side.includes('async function teAutoPyAcquireStartTab(mySeq)'));
assert.ok(side.includes('async function teAutoPyWaitForSessionTarget(mySeq, waitRequired)'));
assert.ok(side.includes('chrome.tabs.get(Number(tabId || 0)'));
assert.ok(side.includes('chrome.windows.getLastFocused'));
assert.ok(side.includes('teAutoPyStartOnceFromUi({ new_session: false, continuation: true'));
assert.ok(!side.includes('chrome.tabs.query({url:['));

console.log('OK test_ext_auto_v249_regression v278');
