// FILE: _St/IG_StYellow/test_ext_home_injection_source_diagnostic.js | ROLE: IG_StYellow 회귀 테스트
const fs=require('fs'),path=require('path'),assert=require('assert');
const read=n=>fs.readFileSync(path.join(__dirname,n),'utf8');
const inject=read('js/instagram_inject.js');
const manifest=JSON.parse(read('manifest.json'));
assert.strictEqual(manifest.version,'2.3.8.2810');
for(const source of ['H_IMAGE_LINK','D_VIDEO_LINK','B_HOME_ARTICLE','B_DETAIL','B_REELS','UNKNOWN']) {
  assert.ok(inject.includes(source),`missing creation source: ${source}`);
}
assert.ok(inject.includes('setAttribute("data-igblue-create-source"'), 'card creation source attribute missing');
assert.ok(inject.includes('n=k(e,t,"H_IMAGE_LINK")'), 'image-link creation route missing');
assert.ok(inject.includes('n=k(t.firstChild,t.firstChild,"D_VIDEO_LINK")'), 'video-link creation route missing');
assert.ok(inject.includes('B(n||t,e,"B_HOME_ARTICLE")'), 'home article creation route missing');
assert.ok(inject.includes('B(e,t,"B_DETAIL")'), 'detail creation route missing');
assert.ok(inject.includes('B(e||n.parentNode,o,"B_REELS")'), 'Reels creation route missing');
for(const selector of [
  'data-igblue-create-source="H_IMAGE_LINK"',
  'data-igblue-create-source="D_VIDEO_LINK"',
  'data-igblue-create-source="B_HOME_ARTICLE"',
  'data-igblue-create-source="B_DETAIL"',
  'data-igblue-create-source="B_REELS"'
]) assert.ok(inject.includes(selector),`source color selector missing: ${selector}`);
const sourceColorPos=inject.indexOf('data-igblue-create-source="H_IMAGE_LINK"');
const hoverColorPos=inject.indexOf('data-igblue-account-hover="1"');
assert.ok(sourceColorPos>=0&&hoverColorPos>sourceColorPos,'confirmed hover cyan must override diagnostic source color');
for(const token of ['igblue_dom_diagnostic_v268','duplicate_codes','create_sources','same_parent','same_article','content_visible_link_count','create_source','near_post_href','near_reels_href','card_rect']) {
  assert.ok(inject.includes(token),`DOM diagnostic field missing: ${token}`);
}
// Diagnostic version records duplicate paths but intentionally does not globally delete same-code cards yet.
assert.ok(inject.includes('let n=e.parentNode.querySelector("div.ndy_ins_info")'), 'local parent duplicate guard missing');
assert.ok(!inject.includes('querySelectorAll(`.ndy_ins_info[data-code="${'), 'global same-code suppression must wait for actual Chrome source diagnosis');
console.log('OK test_ext_home_injection_source_diagnostic v272');
