Просмотр исходного кода

test: 增加设置网关架构护栏

5151561 3 месяцев назад
Родитель
Сommit
90c61237df
2 измененных файлов с 22 добавлено и 1 удалено
  1. 8 0
      AGENTS.md
  2. 14 1
      build.gradle.kts

+ 8 - 0
AGENTS.md

@@ -30,6 +30,14 @@ This file provides guidance to Codex (Codex.ai/code) when working with code in t
 - Remove imports/variables/functions that YOUR changes made unused.
 - Don't remove pre-existing dead code unless asked.
 
+### Settings Gateway Conventions
+
+- Ordinary settings gateways mutate state through `update { current -> current.copy(...) }`.
+- Do not introduce `*SettingsUpdate` dispatch types or `updateAll` on settings gateways.
+- Submit related multi-field changes in one `copy(...)` transform so the SSOT can apply them atomically.
+- Keep specialized APIs such as `ReadStyleMutation`, `ThemePackageSettingsGateway.applyAndAwait`,
+  `ThemeStateTransaction`, and `AppUiConfigurationGateway` in their dedicated shapes.
+
 ### Goal-Driven Execution
 
 Transform tasks into verifiable goals:

+ 14 - 1
build.gradle.kts

@@ -37,6 +37,10 @@ abstract class VerifyConfigArchitectureTask : DefaultTask() {
         val readBookConfigMutationCall = Regex(
             """\bReadBookConfig\.durConfig\.set[A-Za-z0-9_]*\s*\("""
         )
+        val settingsUpdateDeclaration = Regex(
+            """\b(?:class|interface|object|typealias)\s+[A-Za-z0-9_]*SettingsUpdate\b"""
+        )
+        val updateAllDeclaration = Regex("""\bfun\s+(?:<[^>\n]+>\s*)?updateAll\s*\(""")
         val injectedConfigFiles = setOf(
             "io/legado/app/help/config/AppConfig.kt",
             "io/legado/app/help/config/ReadBookConfig.kt",
@@ -81,6 +85,15 @@ abstract class VerifyConfigArchitectureTask : DefaultTask() {
             if (relativePath in injectedConfigFiles && "GlobalContext" in text) {
                 violations += "$displayPath: 配置所有者必须显式注入依赖,禁止 GlobalContext"
             }
+            if (settingsUpdateDeclaration.containsMatchIn(text)) {
+                violations += "$displayPath: 设置网关禁止重新引入 *SettingsUpdate 分发类型"
+            }
+            if (relativePath.startsWith("io/legado/app/domain/gateway/") &&
+                file.name.endsWith("SettingsGateway.kt") &&
+                updateAllDeclaration.containsMatchIn(text)
+            ) {
+                violations += "$displayPath: 设置网关批量修改必须使用单次 update { copy(...) }"
+            }
 
             val preferenceCalls = preferenceCall.findAll(text).count()
             val allowedCalls = preferenceBaseline[relativePath] ?: 0
@@ -124,7 +137,7 @@ val verifyConfigArchitecture = tasks.register<VerifyConfigArchitectureTask>(
     "verifyConfigArchitecture"
 ) {
     group = "verification"
-    description = "禁止配置 Snapshot 桥、跨层全局 Config 直读和新增旧偏好调用"
+    description = "禁止配置 Snapshot 桥、SettingsUpdate 分发、跨层全局 Config 直读和新增旧偏好调用"
     sourceRoot.set(layout.projectDirectory.dir("app/src/main/java"))
     legacyPreferenceCallBaseline.set(
         mapOf(