Repository navigation
Conversation
Signed-off-by: 秋雨落 <i@rain.cx>
Reviewer's GuideImplementationMake
TestsCentralize test access to
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt" line_range="139" />
<code_context>
- // 访问配置不再抛 UninitializedPropertyAccessException,而是返回安全默认配置。
- private var coreConfig: CoreConfig = CoreConfig()
- private var startConfig: StartConfig = StartConfig()
+ private lateinit var coreConfig: CoreConfig
@JvmStatic
</code_context>
<issue_to_address>
**Configuration access throws**
When a caller accesses configuration before `loadCoreConfig()` assigns it, including after startup exits early or a binding test reaches successful attach, `getCoreConfig()` reads the uninitialized `lateinit` field and throws `UninitializedPropertyAccessException`, so callers fail instead of receiving the previous default configuration.
Initialize `coreConfig` with a safe default configuration rather than declaring it `lateinit`.
Also at `velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt:64`.
</issue_to_address>
### Comment 2
<location path="velocity/src/test/kotlin/util/MockStaticUtil.kt" line_range="31-37" />
<code_context>
+ private val instanceField = staticField("instance")
+ private val coreConfigField = staticField("coreConfig")
+
+ fun setCoreConfig(value: CoreConfig) {
+ coreConfigField.set(null, value)
+ }
+
+ fun clear() {
+ instanceField.set(null, null)
+ coreConfigField.set(null, null)
+ }
+
</code_context>
<issue_to_address>
**Parallel tests clear each other’s state**
When the test runner executes these test classes concurrently and one test tears down while another is using the static fields, one test’s `clear()` nulls the shared `HyperZoneLoginMain` fields while another test is using them; the second test then gets an uninitialized-property exception or observes the wrong main instance.
Serialize tests that share this state, or replace the process-wide static test state with isolated state per test.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: velocity/src/main/kotlin/icu/h2l/login/HyperZoneLoginMain.kt:139, velocity/src/test/kotlin/util/MockStaticUtil.kt:37
| fun setCoreConfig(value: CoreConfig) { | ||
| coreConfigField.set(null, value) | ||
| } | ||
|
|
||
| fun clear() { | ||
| instanceField.set(null, null) | ||
| coreConfigField.set(null, null) |
There was a problem hiding this comment.
🟡 Medium · Parallel tests clear each other’s state
When the test runner executes these test classes concurrently and one test tears down while another is using the static fields, one test’s clear() nulls the shared HyperZoneLoginMain fields while another test is using them; the second test then gets an uninitialized-property exception or observes the wrong main instance.
Serialize tests that share this state, or replace the process-wide static test state with isolated state per test.
Prompt for AI agents
In `velocity/src/test/kotlin/util/MockStaticUtil.kt` at lines 31-37:
**Parallel tests clear each other’s state**
When the test runner executes these test classes concurrently and one test tears down while another is using the static fields, one test’s `clear()` nulls the shared `HyperZoneLoginMain` fields while another test is using them; the second test then gets an uninitialized-property exception or observes the wrong main instance.
Serialize tests that share this state, or replace the process-wide static test state with isolated state per test.
A test util for accessing static fields in
HyperZoneLoginMain. It's a simple refactor.Summary by Sourcery
Centralize
HyperZoneLoginMaintest state management and update configuration initialization to support isolated tests.Enhancements:
HyperZoneLoginMainacross Velocity tests.Tests: