// FILE: _St/IG_StYellow/test_ext_cdp_recovery_v301.js | ROLE: v301 CDP handshake·OWNER fallback·하트 marker 미복구 회귀
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const root = __dirname;
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'manifest.json'), 'utf8'));
const content = fs.readFileSync(path.join(root, 'content_instagram.js'), 'utf8');
const background = fs.readFileSync(path.join(root, 'background.js'), 'utf8');
const auto = fs.readFileSync(path.join(root, '..', 'Auto8700', 'auto_service8700_manager.py'), 'utf8');

assert.strictEqual(manifest.version, '2.3.8.3020');
assert.strictEqual(manifest.version_name, '2.3.8.302');
assert.ok(content.includes("window.addEventListener('igblue_auto8700_cdp_gate'"));
assert.ok(content.includes("localStorage.setItem('IGBLUE/cdp_gate'"));
assert.ok(content.includes("'탭 제어 v302'"));
assert.ok(background.includes('const rawHandoffState = String(igblueTabControlState.handoff_state || "IDLE")'));
assert.ok(background.includes('rawHandoffState === "OWNER_LOST" && !pending'));
assert.ok(background.includes('? "OWNER_FALLBACK"'));
assert.ok(background.includes('handoff_state:snapshotHandoffState'));
assert.ok(auto.includes('def notify_instagram_cdp_gate('));
assert.ok(auto.includes('def maybe_reload_changed_extensions('));
assert.ok(auto.includes('chrome.runtime.reload()'));
assert.ok(auto.includes('"Page.reload"'));
for (const removed of ['mark_control_tab_titles', 'ensure_instagram_control_marker', 'control_marker_for_status']) {
  assert.ok(!auto.includes(`def ${removed}(`), `${removed} must remain removed`);
}
console.log('OK test_ext_cdp_recovery_v301');
