From e5b348bb9bea3471de3e48ac75198f49b99a7e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=88=AA=E5=AE=87?= <3364451258@qq.com> Date: Fri, 29 May 2026 23:23:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20e2e=20=E7=B1=BB=E5=9E=8B=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=20+=20ESLint=20=E8=A6=86=E7=9B=96=20e2e=20+=20backup?= =?UTF-8?q?=20=E8=B7=AF=E5=BE=84=E6=A0=A1=E9=AA=8C=20+=20DX=20=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - e2e/global.d.ts: Window.__TAURI_INTERNALS__ 类型声明 - e2e search-clean: 未使用参数 _args 前缀 - tsconfig.test.json: include e2e/ - CI: ESLint 扫描范围扩展到 e2e/ - backup_registry: 拒绝写入系统目录 (C:\Windows\, C:\Program Files\) - package.json: 新增 lint:fix / format 脚本 Co-Authored-By: Claude Opus 4.7 --- .github/workflows/ci.yml | 2 +- core/src/backup.rs | 9 ++++++++- e2e/global.d.ts | 5 +++++ e2e/tests/search-clean.spec.ts | 3 +-- package.json | 2 ++ tsconfig.test.json | 2 +- 6 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 e2e/global.d.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9be3e6..430fe29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: run: npx tsc -b --noEmit - name: ESLint - run: npx eslint src/ tests/ + run: npx eslint src/ tests/ e2e/ - name: Vitest 测试 run: npm test diff --git a/core/src/backup.rs b/core/src/backup.rs index b52cfde..8919b2a 100644 --- a/core/src/backup.rs +++ b/core/src/backup.rs @@ -19,7 +19,14 @@ pub fn get_appdata_dir() -> String { /// 在保存前调用,备份的是注册表中的当前值(保存前的状态) pub fn backup_registry(custom_dir: Option) -> Result { let backup_dir = match custom_dir { - Some(ref dir) if !dir.is_empty() => std::path::PathBuf::from(dir), + Some(ref dir) if !dir.is_empty() => { + let p = std::path::PathBuf::from(dir); + let normalized = dir.replace('/', "\\").to_lowercase(); + if normalized.starts_with("c:\\windows\\") || normalized.starts_with("c:\\program files\\") { + return Err("不允许备份到系统目录".into()); + } + p + } _ => backup_base_dir(), }; diff --git a/e2e/global.d.ts b/e2e/global.d.ts new file mode 100644 index 0000000..ce2d538 --- /dev/null +++ b/e2e/global.d.ts @@ -0,0 +1,5 @@ +interface Window { + __TAURI_INTERNALS__?: { + invoke: (cmd: string, args?: Record) => Promise; + }; +} diff --git a/e2e/tests/search-clean.spec.ts b/e2e/tests/search-clean.spec.ts index 50da331..b703d11 100644 --- a/e2e/tests/search-clean.spec.ts +++ b/e2e/tests/search-clean.spec.ts @@ -3,8 +3,7 @@ import { test, expect } from '@playwright/test'; test.beforeEach(async ({ page }) => { await page.addInitScript(() => { window.__TAURI_INTERNALS__ = { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - invoke: async (cmd, args) => { + invoke: async (cmd, _args) => { switch (cmd) { case 'check_admin': return true; case 'load_system_paths': return ['C:\\\\Windows', 'invalid_path', 'C:\\\\Temp']; diff --git a/package.json b/package.json index 5aa86ad..dfee81f 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "dev": "vite", "build": "tsc -b && vite build", "lint": "eslint .", + "lint:fix": "eslint . --fix", + "format": "cargo fmt", "preview": "vite preview", "test": "vitest run", "test:watch": "vitest", diff --git a/tsconfig.test.json b/tsconfig.test.json index 2c4a96c..8351320 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -4,5 +4,5 @@ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.test.tsbuildinfo", "types": ["vite/client", "vitest/globals"] }, - "include": ["src", "tests"] + "include": ["src", "tests", "e2e"] }