// FILE: _St/IG_StYellow/test_ext_edit_copy_manual_filename_v315.js | ROLE: v318 수동 1건 편집폴더 복사 + 오프라인 원래 인젝션 회귀
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const root = __dirname;
const read = (name) => fs.readFileSync(path.join(root, name), 'utf8');
const html = read('side.html');
const side = read('side.js');
const bg = read('background.js');
const content = read('content_instagram.js');
const inject = read(path.join('js','instagram_inject.js'));

assert.ok(html.includes('id="igblue_copy_to_edit_folder"'), '편집폴더에 복사 체크가 Side에 없음');
assert.ok(side.includes('TE_EDIT_COPY_ENABLED_KEY'), '편집폴더 체크 chrome storage key 없음');
assert.ok(side.includes('chrome.storage.local.get(TE_EDIT_COPY_ENABLED_KEY'), '편집폴더 체크가 chrome.storage.local에서 복원되지 않음');
assert.ok(!side.includes('teEditCopyResetRun("auto_new_session")'), '자동실행 기준 편집폴더 복사 로직이 남아 있음');
assert.ok(!side.includes('teEditCopyTrackFile(result.file_path)'), '자동 여러 파일 누적 로직이 남아 있음');
assert.ok(bg.includes('function igblueMaybeCopyManualSingleToEditFolder'), '수동 1건 편집폴더 helper 없음');
assert.ok(bg.includes('sourceMode === "MANUAL_SINGLE"'), '수동 1건 한정 조건 없음');
assert.ok(bg.includes('igblueLocalWsRequest("ig_copy_to_edit_folder", {file_paths:[String(finalPath)]'), '방금 받은 MP4 한 개만 편집폴더로 보내지 않음');
assert.ok(bg.includes('chrome.storage.local.get(IGBLUE_EDIT_COPY_ENABLED_KEY'), 'Side가 닫혀도 Background가 체크값을 읽는 구조 없음');

const fallbackStart = bg.indexOf('function igblueDownloadWithChromeFallback');
const fallbackEnd = bg.indexOf('const IGBLUE_EDIT_COPY_ENABLED_KEY', fallbackStart);
const fallback = bg.slice(fallbackStart, fallbackEnd);
assert.ok(fallback.includes('IGBLUE_MANUAL_USE_MAIN_DOWNLOADER'));
assert.ok(!fallback.includes('chrome.downloads.download'));
assert.ok(content.includes('type: "igblue_manual_original_download"'));
assert.ok(inject.includes('function teMainOriginalManualDownload('));
assert.ok(inject.includes('n.download=`${stem}.${ext}`'));
console.log('test_ext_edit_copy_manual_filename_v318: OK');
