refactor(1): detection App->Core + AppPaths (VD_DATA_DIR isolation for deterministic E2E)

This commit is contained in:
Yun Chan 2026-08-15 14:51:16 +09:00
parent 1aab8729fa
commit 9eb988440f
5 changed files with 29 additions and 7 deletions

View file

@ -0,0 +1,14 @@
namespace VideoDownloader.App;
/// <summary>
/// 앱 데이터 디렉터리 결정. 기본 %AppData%/VideoDownloader.
/// 환경변수 VD_DATA_DIR 로 오버라이드 — E2E 테스트가 실사용자 프로필/설정/세션과
/// 격리된 임시 디렉터리에서 실행되도록 한다(결정적 테스트를 위한 공식 후크).
/// </summary>
public static class AppPaths
{
public static string DataDir =>
Environment.GetEnvironmentVariable("VD_DATA_DIR") is { Length: > 0 } env
? env
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VideoDownloader");
}

View file

@ -7,8 +7,7 @@ namespace VideoDownloader.App.Browser;
/// 손상 파일은 백업 후 빈 목록을 반환(다음 저장이 원본을 덮어쓰는 데이터 손실 방지).</summary>
public static class BrowserStore
{
private static string Dir => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VideoDownloader");
private static string Dir => AppPaths.DataDir;
private static string BookmarksPath => Path.Combine(Dir, "bookmarks.json");
private static string HistoryPath => Path.Combine(Dir, "history.json");
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };

View file

@ -6,8 +6,7 @@ namespace VideoDownloader.App.Core;
/// <summary>%AppData%/VideoDownloader/config.json 으로 설정 영속화</summary>
public static class ConfigStore
{
private static string Dir => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VideoDownloader");
private static string Dir => AppPaths.DataDir;
private static string FilePath => Path.Combine(Dir, "config.json");
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };

View file

@ -145,9 +145,8 @@ public partial class MainWindow : Window
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attribute, ref int pvAttribute, int cbAttribute);
/// <summary>WebView2 영속 프로필 경로. 쿠키·세션·localStorage·캐시가 여기 보존되어 앱/빌드 재시작에도 유지.</summary>
internal static string AppDataDir => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VideoDownloader");
/// <summary>앱 데이터 디렉터리(AppPaths.DataDir — VD_DATA_DIR 오버라이드 지원).</summary>
internal static string AppDataDir => AppPaths.DataDir;
internal static string ProfileFolder => Path.Combine(AppDataDir, "webview");

View file

@ -14,6 +14,11 @@ public class MainWindowSmokeE2ETests
[Fact]
public async Task MainWindow_기동_탐색_탭전환_닫기_복원_검색바_전체화면_E2E()
{
// VD_DATA_DIR 격리: 실사용자 설정/세션/프로필과 분리된 임시 데이터 디렉터리 (결정적 테스트)
var dataDir = Path.Combine(Path.GetTempPath(), $"vd_e2e_data_{Guid.NewGuid():N}");
Environment.SetEnvironmentVariable("VD_DATA_DIR", dataDir);
try
{
using var sta = StaDispatcher.Start();
WpfTestApp.Ensure(sta.Dispatcher);
var ok = await sta.InvokeAsync(async () =>
@ -77,6 +82,12 @@ public class MainWindowSmokeE2ETests
Assert.True(ok.findCollapsed, "검색 바 미닫힘");
Assert.True(ok.toolbarHidden, "전체화면에서 크롬 미숨김");
Assert.True(ok.toolbarBack, "전체화면 복원 실패");
}
finally
{
Environment.SetEnvironmentVariable("VD_DATA_DIR", null);
try { Directory.Delete(dataDir, true); } catch { }
}
}
private static Task WaitUntilNavCompleted(Microsoft.Web.WebView2.Core.CoreWebView2 cv)