Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Finishing Touches
|
f872cd3 to
497fcce
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ImportProperties.kt (1)
22-23: Typos in documentation: "foler" → "folder".The documentation contains two instances of "foler" that should be "folder".
📝 Proposed fix
- "└─Project # the foler name is the project name\n" + - " └─validation # the foler name is namespace\n" + + "└─Project # the folder name is the project name\n" + + " └─validation # the folder name is namespace\n" +backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/SsoGlobalProperties.kt (1)
69-80: Ensure SSO validation still runs after de-beaning this class.With
@ConfigurationPropertiesremoved,SsoGlobalPropertiesis likely no longer a Spring bean, so@PostConstructmay never execute. That would silently skip the required-field checks whenenabled = true. Please ensurevalidate()is invoked from a bean lifecycle hook (e.g.,TolgeeProperties@PostConstruct) or migrate to Bean Validation (@Validated+@Valid+@field:NotBlank) on the root properties.backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/GithubAuthenticationProperties.kt (1)
20-25: Update the description to match the actual token endpoint usage.The property
authorizationUrlis used inGithubOAuthDelegate.ktto exchange the authorization code for an access token viarestTemplate.postForObject(). The description incorrectly states "URL to the OAuth authorization screen," but should instead describe it as a token endpoint. This matches the actual implementation and aligns with howGoogleAuthenticationProperties.ktdescribes the same property as "URL to Google/tokenAPI endpoint."Change the description from "URL to the OAuth authorization screen" to "URL to the OAuth token/access token API endpoint. Useful if you want to authenticate against a self-hosted GitHub Enterprise Server."
backend/data/src/test/kotlin/io/tolgee/security/ratelimit/RateLimitServiceTest.kt (1)
62-95: Reset the newtolgeePropertiesmock between tests.
tolgeePropertiesis stubbed insetupMocks()but never reset; this can leak interactions or stubbing across tests. Add it toresetMocks().🔧 Suggested fix
- fun resetMocks() { - Mockito.reset(currentDateProvider, rateLimitProperties, userAccount) - } + fun resetMocks() { + Mockito.reset(currentDateProvider, rateLimitProperties, tolgeeProperties, userAccount) + }backend/security/src/test/kotlin/io/tolgee/security/ratelimit/RateLimitInterceptorTest.kt (1)
49-89: Reset the newtolgeePropertiesmock between tests.
tolgeePropertiesis stubbed insetupMocks()but never reset; add it toresetMocks()to prevent cross‑test leakage.🔧 Suggested fix
- fun resetMocks() { - Mockito.reset(rateLimitProperties, currentDateProvider, authenticationFacade, userAccount) - } + fun resetMocks() { + Mockito.reset(rateLimitProperties, tolgeeProperties, currentDateProvider, authenticationFacade, userAccount) + }
🤖 Fix all issues with AI agents
In
`@backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.kt`:
- Around line 31-59: The setup() method mutates shared TolgeeProperties (via
tolgeeProperties and machineTranslationProperties) which can leak into other
cached Spring test contexts; fix by capturing the original relevant fields
(e.g., tolgeeProperties.internal.fakeMtProviders and fields under
machineTranslationProperties.google and .aws) before mutating and restore them
in an `@AfterEach` teardown method, or alternatively annotate the test class or
individual tests with `@DirtiesContext` to force a fresh context; ensure
restoration targets the exact properties you change in setup() so no mutated
state persists across tests.
🧹 Nitpick comments (4)
backend/security/src/test/kotlin/io/tolgee/security/authentication/AuthenticationInterceptorTest.kt (1)
44-47: Consider updatingresetMocksto include all mocks for consistency.The
@AfterEachresetsauthenticationFacadeanduserAccountbut omitstolgeePropertiesandauthenticationProperties. While JUnit 5's defaultPER_METHODlifecycle creates fresh instances anyway, keeping the reset list consistent avoids confusion if the lifecycle changes or if someone copies this pattern elsewhere.Suggested fix
`@AfterEach` fun resetMocks() { - Mockito.reset(authenticationFacade, userAccount) + Mockito.reset(authenticationFacade, userAccount, tolgeeProperties, authenticationProperties) }backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/RabbitmqAutostartProperties.kt (1)
15-26: Pre-existing documentation error: enum comments reference "postgres" instead of "rabbitmq".The doc comments in
RabbitMqAutostartModeappear to be copy-pasted from a Postgres autostart class. Consider updating them to reference RabbitMQ for clarity.📝 Suggested fix
enum class RabbitMqAutostartMode { /** - * Starts docker container with postgres + * Starts docker container with RabbitMQ */ DOCKER, /** - * Expects that postgres is installed in the same container. - * So the Postgres is started with Tolgee. + * Expects that RabbitMQ is installed in the same container. + * So RabbitMQ is started with Tolgee. */ EMBEDDED, }backend/data/src/test/kotlin/io/tolgee/security/authentication/JwtServiceTest.kt (1)
104-107: Consider addingtolgeePropertiesto the reset call for consistency.The
tolgeePropertiesmock is not included inresetMocks(), while other mocks are. Although the@BeforeEachre-establishes stubs before each test, including it would maintain consistency and prevent potential issues if tests modify the mock's behavior.Proposed fix
`@AfterEach` fun resetMocks() { - Mockito.reset(authenticationProperties, currentDateProvider, userAccountService, authenticationFacade, userAccount) + Mockito.reset(tolgeeProperties, authenticationProperties, currentDateProvider, userAccountService, authenticationFacade, userAccount) }backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/DeeplApiService.kt (1)
77-81: Pre-existing: Potential NPE on nullauthKey.The
!!operator on line 78 will throw an NPE ifauthKeyis null. This is pre-existing behavior not introduced by this PR, but worth noting for future improvement. Consider adding a null check or using the Elvis operator to provide a safer fallback or clearer error message.
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/app/src/test/kotlin/io/tolgee/service/TelemetryServiceTest.kt (1)
37-40: Add TestData cleanup to@AfterEachmethod.The
reports when enabledtest creates TestData viatestDataService.saveTestData(testData.root)but the@AfterEachmethod doesn't clean it up. Following the pattern used in other tests (e.g., SsoOrganizationsTest, KeyUsageReportingTest), addtestDataService.cleanTestData(testData.root)to prevent test pollution.
🧹 Nitpick comments (9)
backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/RabbitmqAutostartProperties.kt (1)
15-26: Pre-existing documentation error: Comments reference Postgres instead of RabbitMQ.The enum documentation incorrectly mentions "postgres" when this is a RabbitMQ configuration class. This is a pre-existing issue but worth fixing while in this file.
📝 Suggested documentation fix
enum class RabbitMqAutostartMode { /** - * Starts docker container with postgres + * Starts docker container with RabbitMQ */ DOCKER, /** - * Expects that postgres is installed in the same container. - * So the Postgres is started with Tolgee. + * Expects that RabbitMQ is installed in the same container. + * So RabbitMQ is started with Tolgee. */ EMBEDDED, }backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentStorageS3Properties.kt (1)
15-22: Optional: document intended use ofclear().
If this is meant for tests or resets only, a short KDoc helps prevent accidental runtime usage.📝 Suggested KDoc
data class ContentStorageS3Properties( override var bucketName: String? = null, override var accessKey: String? = null, override var secretKey: String? = null, override var endpoint: String? = null, override var signingRegion: String? = null, override var path: String? = null, ) : S3Config { + /** + * Resets all S3 properties to null (intended for tests or explicit resets). + */ fun clear() { bucketName = null accessKey = null secretKey = null endpoint = null signingRegion = null path = null } }backend/data/src/test/kotlin/io/tolgee/security/authentication/JwtServiceTest.kt (1)
104-107: Consider addingtolgeePropertiestoresetMocks().The newly added
tolgeePropertiesmock is not included in theMockito.reset()call. While this may not cause issues since the mock's behavior is set up fresh in each@BeforeEach, including it maintains consistency and prevents potential test pollution.♻️ Suggested fix
`@AfterEach` fun resetMocks() { - Mockito.reset(authenticationProperties, currentDateProvider, userAccountService, authenticationFacade, userAccount) + Mockito.reset(tolgeeProperties, authenticationProperties, currentDateProvider, userAccountService, authenticationFacade, userAccount) }backend/security/src/test/kotlin/io/tolgee/security/ratelimit/RateLimitInterceptorTest.kt (1)
87-90: Consider addingtolgeePropertiestoresetMocks().Similar to other test files in this PR, the
tolgeePropertiesmock should be included in the reset call for consistency and to prevent potential test pollution.♻️ Suggested fix
`@AfterEach` fun resetMocks() { - Mockito.reset(rateLimitProperties, currentDateProvider, authenticationFacade, userAccount) + Mockito.reset(tolgeeProperties, rateLimitProperties, currentDateProvider, authenticationFacade, userAccount) }backend/app/src/test/kotlin/io/tolgee/config/BatchJobBaseConfiguration.kt (1)
24-28: Prefer explicit instantiation over class-based spy for clarity.
Mockito.spy(TolgeeProperties::class.java)works correctly sinceTolgeePropertieshas a no-arg constructor with default values. However, being explicit about instantiation improves readability and aligns with modern Mockito conventions:`@Bean` `@Primary` fun tolgeeProperties(): TolgeeProperties { - return Mockito.spy(TolgeeProperties::class.java) + return Mockito.spy(TolgeeProperties()) }backend/data/src/main/kotlin/io/tolgee/service/machineTranslation/MtServiceConfigService.kt (1)
3-10: Remove unused imports (lines 4-10).The imports for
AwsMachineTranslationProperties,AzureCognitiveTranslationProperties,BaiduMachineTranslationProperties,DeeplMachineTranslationProperties,GoogleMachineTranslationProperties,LlmProperties, andMachineTranslationServicePropertiesare not referenced anywhere in the file and can be safely removed.backend/security/src/test/kotlin/io/tolgee/security/authentication/AuthenticationInterceptorTest.kt (1)
44-47: Include all mocks inresetMocks()for consistency.The
resetMocks()method omitstolgeePropertiesandauthenticationPropertiesfrom the reset call. While@BeforeEachre-stubs these mocks, including them ensures clean state and prevents subtle test pollution if future tests verify interactions.♻️ Suggested fix
`@AfterEach` fun resetMocks() { - Mockito.reset(authenticationFacade, userAccount) + Mockito.reset(authenticationFacade, userAccount, tolgeeProperties, authenticationProperties) }backend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresRunnerConfiguration.kt (1)
17-22: Consider using awhenexpression for mode dispatch.The if-chain can be expressed more idiomatically in Kotlin using a
whenexpression.♻️ Suggested refactor
- if (postgresAutostartProperties.mode == PostgresAutostartMode.DOCKER) { - return PostgresDockerRunner(tolgeeProperties) - } - if (postgresAutostartProperties.mode == PostgresAutostartMode.EMBEDDED) { - return PostgresEmbeddedRunner(tolgeeProperties) - } - return null + return when (postgresAutostartProperties.mode) { + PostgresAutostartMode.DOCKER -> PostgresDockerRunner(tolgeeProperties) + PostgresAutostartMode.EMBEDDED -> PostgresEmbeddedRunner(tolgeeProperties) + else -> null + }backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/MailjetProperties.kt (1)
7-9: Consider documentingcontactListIdfor config docs.
If config docs are generated from@DocProperty, add a brief description for the new field.📝 Suggested documentation
class MailjetProperties { var apiKey: String? = null var secretKey: String? = null + `@DocProperty`(description = "Mailjet contact list ID for default subscriptions.") var contactListId: Long? = null }
|
please, don't merge it before branching |
|
and what's the benefit of it? private val awsMachineTranslationProperties get() = tolgeeProperties.machineTranslation.awsBefore this refactoring it was also possible to inject consolidated |
|
@bdshadow The issue is that we currently have (at least) two instances of each Other than this, we currently have two things broken, which I want to fix this way:
I'm not saying we have to fix it like this, but it felt like the best way to make sure we never run into the same issue again. I can also just fix the names of the two broken properties and leave it be for now. ^^ |
JanCizmar
left a comment
There was a problem hiding this comment.
Thanks. 👍 I would merge it after branching.
if jakarta validation like Another thing is about accessing the properties. This seems weird, need to check. But probably this is because fields inside |
bdshadow
left a comment
There was a problem hiding this comment.
I'll dare to request changes :) Sorry :)
Feel free to ping me
You mean they won't have default values anymore? I'm not sure I understand this one. ^^
Yes, please check and let me know (after branching). If there is a different way we can make sure the |
|
@Anty0 my comment was based on my previos experience in java and nested static classes. You can how it works here: https://docs.spring.io/spring-boot/3.5/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.validation In Tolgee there are too many properties. Moving them to nested classes of Also the default values are set right in the koltin code, and before i had it all in properties files. In that case validation perfectly worked. Here it is different. So sorry for delaying this pr, but i'm glad i found it all |
|
This PR is stale because it has been open for 30 days with no activity. |
|
This PR is stale because it has been open for 30 days with no activity. |
24bb56a to
85ab2eb
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.kt (1)
21-27: Prevent cross-test leakage from mutableinternalPropertiesstate.At Line 26,
internalProperties.fakeMtProvidersis forced totruein@BeforeEach, but never restored. If the Spring context is cached, this can leak into other tests and create order-dependent failures.Proposed hardening
class McpBatchToolsTest : AbstractMcpTest() { + private var previousFakeMtProviders: Boolean? = null + `@Autowired` lateinit var batchJobService: BatchJobService @@ `@BeforeEach` fun setup() { @@ - internalProperties.fakeMtProviders = true + previousFakeMtProviders = internalProperties.fakeMtProviders + internalProperties.fakeMtProviders = true } + + `@AfterEach` + fun cleanup() { + previousFakeMtProviders?.let { internalProperties.fakeMtProviders = it } + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.kt` around lines 21 - 27, The test mutates shared mutable state by setting internalProperties.fakeMtProviders = true in the setup() `@BeforeEach` without restoring it; capture the previous value before changing it (e.g., in setup() save oldFakeMt = internalProperties.fakeMtProviders) and restore it in an `@AfterEach` method (or explicitly set internalProperties.fakeMtProviders = false in an `@AfterEach`) so tests do not leak state across the Spring context; locate setup() and add a matching teardown that resets internalProperties.fakeMtProviders.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.kt`:
- Around line 21-27: The test mutates shared mutable state by setting
internalProperties.fakeMtProviders = true in the setup() `@BeforeEach` without
restoring it; capture the previous value before changing it (e.g., in setup()
save oldFakeMt = internalProperties.fakeMtProviders) and restore it in an
`@AfterEach` method (or explicitly set internalProperties.fakeMtProviders = false
in an `@AfterEach`) so tests do not leak state across the Spring context; locate
setup() and add a matching teardown that resets
internalProperties.fakeMtProviders.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 06366a2c-8b41-4f38-9570-3ba2490cf982
📒 Files selected for processing (51)
backend/api/src/main/kotlin/io/tolgee/api/publicConfiguration/PublicConfigurationAssembler.ktbackend/api/src/main/kotlin/io/tolgee/controllers/PublicController.ktbackend/api/src/main/kotlin/io/tolgee/controllers/resetPassword/PasswordResetController.ktbackend/api/src/main/kotlin/io/tolgee/controllers/resetPassword/ResetPasswordRequestHandler.ktbackend/api/src/main/kotlin/io/tolgee/util/ApplicationStopper.ktbackend/api/src/main/kotlin/io/tolgee/websocket/WebsocketPublisherConfiguration.ktbackend/app/src/main/kotlin/io/tolgee/Application.ktbackend/app/src/main/kotlin/io/tolgee/commandLineRunners/InitialUserCreatorCommandLineRunner.ktbackend/app/src/main/kotlin/io/tolgee/configuration/PostgresAutoStartConfiguration.ktbackend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresDockerRunner.ktbackend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresEmbeddedRunner.ktbackend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresRunnerConfiguration.ktbackend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresStopper.ktbackend/app/src/test/kotlin/io/tolgee/StartupImportCommandLineRunnerTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/V2UserControllerTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translationSuggestionController/TranslationSuggestionControllerMtTest.ktbackend/app/src/test/kotlin/io/tolgee/batch/AbstractBatchJobConcurrentTest.ktbackend/app/src/test/kotlin/io/tolgee/batch/AbstractBatchJobsGeneralTest.ktbackend/app/src/test/kotlin/io/tolgee/config/BatchJobBaseConfiguration.ktbackend/app/src/test/kotlin/io/tolgee/mcp/McpServerIntegrationTest.ktbackend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.ktbackend/app/src/test/kotlin/io/tolgee/security/EmailVerificationTest.ktbackend/app/src/test/kotlin/io/tolgee/service/TelemetryServiceTest.ktbackend/data/src/main/kotlin/io/tolgee/MtServicesConfiguration.ktbackend/data/src/main/kotlin/io/tolgee/batch/BatchJobCancellationManager.ktbackend/data/src/main/kotlin/io/tolgee/batch/BatchJobConcurrentLauncher.ktbackend/data/src/main/kotlin/io/tolgee/batch/BatchJobProjectLockingManager.ktbackend/data/src/main/kotlin/io/tolgee/batch/cleaning/OldBatchJobCleaner.ktbackend/data/src/main/kotlin/io/tolgee/batch/processors/AutoTranslateChunkProcessor.ktbackend/data/src/main/kotlin/io/tolgee/batch/processors/MachineTranslationChunkProcessor.ktbackend/data/src/main/kotlin/io/tolgee/component/emailContacts/MailJetEmailServiceManager.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/MtServiceManager.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AwsMtValueProvider.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AzureCognitiveApiService.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AzureCognitiveTranslationProvider.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/BaiduApiService.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/BaiduTranslationProvider.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/DeeplApiService.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/DeeplTranslationProvider.ktbackend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/GoogleTranslationProvider.ktbackend/data/src/main/kotlin/io/tolgee/component/reporting/PlausibleBusinessEventReporter.ktbackend/data/src/main/kotlin/io/tolgee/configuration/PostHogConfiguration.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/AuthenticationProperties.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/BatchProperties.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/CacheProperties.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryAWSCloudFrontProperties.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryAzureFrontDoorProperties.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryBunnyProperties.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryCachePurgingProperties.ktbackend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryCloudflareProperties.kt
💤 Files with no reviewable changes (3)
- backend/app/src/test/kotlin/io/tolgee/StartupImportCommandLineRunnerTest.kt
- backend/app/src/test/kotlin/io/tolgee/security/EmailVerificationTest.kt
- backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/V2UserControllerTest.kt
✅ Files skipped from review due to trivial changes (8)
- backend/app/src/test/kotlin/io/tolgee/service/TelemetryServiceTest.kt
- backend/data/src/main/kotlin/io/tolgee/configuration/PostHogConfiguration.kt
- backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryAWSCloudFrontProperties.kt
- backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryAzureFrontDoorProperties.kt
- backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/CacheProperties.kt
- backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AwsMtValueProvider.kt
- backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryBunnyProperties.kt
- backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryCachePurgingProperties.kt
🚧 Files skipped from review as they are similar to previous changes (23)
- backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryCloudflareProperties.kt
- backend/app/src/main/kotlin/io/tolgee/commandLineRunners/InitialUserCreatorCommandLineRunner.kt
- backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/MtServiceManager.kt
- backend/api/src/main/kotlin/io/tolgee/controllers/resetPassword/ResetPasswordRequestHandler.kt
- backend/app/src/main/kotlin/io/tolgee/Application.kt
- backend/api/src/main/kotlin/io/tolgee/controllers/resetPassword/PasswordResetController.kt
- backend/data/src/main/kotlin/io/tolgee/batch/cleaning/OldBatchJobCleaner.kt
- backend/data/src/main/kotlin/io/tolgee/component/reporting/PlausibleBusinessEventReporter.kt
- backend/api/src/main/kotlin/io/tolgee/websocket/WebsocketPublisherConfiguration.kt
- backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/BaiduApiService.kt
- backend/data/src/main/kotlin/io/tolgee/MtServicesConfiguration.kt
- backend/api/src/main/kotlin/io/tolgee/controllers/PublicController.kt
- backend/app/src/main/kotlin/io/tolgee/configuration/PostgresAutoStartConfiguration.kt
- backend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresStopper.kt
- backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AzureCognitiveTranslationProvider.kt
- backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/GoogleTranslationProvider.kt
- backend/data/src/main/kotlin/io/tolgee/batch/processors/MachineTranslationChunkProcessor.kt
- backend/data/src/main/kotlin/io/tolgee/batch/processors/AutoTranslateChunkProcessor.kt
- backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.kt
- backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/AuthenticationProperties.kt
- backend/data/src/main/kotlin/io/tolgee/component/emailContacts/MailJetEmailServiceManager.kt
- backend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresRunnerConfiguration.kt
- backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translationSuggestionController/TranslationSuggestionControllerMtTest.kt
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.kt (1)
82-90: Make teardown resilient to partial/failed setup.
tearDown()always restores from fields that have default initial values; ifsetup()exits early, this can overwrite shared singleton config with unintended defaults. Add a “snapshot captured” guard.Proposed hardening diff
class BatchJobTestBase { + private var mtSnapshotCaptured = false private var fakeMtProvidersBefore: Boolean = false private var googleApiKeyBefore: String? = null private var googleDefaultEnabledBefore: Boolean = false @@ fun setup() { batchJobOperationQueue.clear() testData = BatchJobsTestData() + mtSnapshotCaptured = false // Snapshot current values before mutating, so tearDown() can restore them fakeMtProvidersBefore = tolgeeProperties.internal.fakeMtProviders @@ awsDefaultEnabledBefore = machineTranslationProperties.aws.defaultEnabled awsAccessKeyBefore = machineTranslationProperties.aws.accessKey awsSecretKeyBefore = machineTranslationProperties.aws.secretKey + mtSnapshotCaptured = true @@ fun tearDown() { + if (!mtSnapshotCaptured) return // Restore shared TolgeeProperties singleton to avoid cross-test leakage tolgeeProperties.internal.fakeMtProviders = fakeMtProvidersBefore @@ machineTranslationProperties.aws.defaultEnabled = awsDefaultEnabledBefore machineTranslationProperties.aws.accessKey = awsAccessKeyBefore machineTranslationProperties.aws.secretKey = awsSecretKeyBefore + mtSnapshotCaptured = false }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.kt` around lines 82 - 90, The tearDown() restores various shared properties unconditionally which can overwrite globals if setup() failed; add a "snapshot captured" guard boolean set when setup() successfully saves the original values and check it in tearDown() before restoring. Specifically, modify the setup/snapshot logic to set a flag (e.g., snapshotCaptured) when you copy values for tolgeeProperties.internal.fakeMtProviders and the machineTranslationProperties.google.{apiKey,defaultEnabled,defaultPrimary} and machineTranslationProperties.aws.{defaultEnabled,accessKey,secretKey}; then in tearDown() return early unless snapshotCaptured is true so you only restore when the snapshot exists. Ensure the flag is reset after restoration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translationSuggestionController/TranslationSuggestionControllerMtTest.kt`:
- Around line 94-95: The test currently initializes originalFreeCreditsAmount to
0 and snapshots it after the test mutates the shared MT credits, causing
teardown to restore an incorrect value; change originalFreeCreditsAmount to be
captured before any mutation (take the snapshot at the start of the test
setup/before altering the shared property) and initialize it so it cannot
clobber state if setup aborts (make it nullable or use a safe sentinel and
assert it's set), and in teardown restore the captured value defensively (only
write back if a valid original was captured) — refer to the
originalFreeCreditsAmount variable and the test setup/teardown surrounding the
mutation (the block that modifies the shared MT credits in the 104-116 region)
to locate and update the code.
In
`@ee/backend/tests/src/test/kotlin/io/tolgee/ee/selfHostedLimitsAndReporting/CreditLimitTest.kt`:
- Around line 61-71: Move the snapshot of the original value so teardown can
restore it correctly: capture the current internalProperties.fakeMtProviders
into fakeMtProvidersBefore before calling initMachineTranslationProperties(...)
(or any call that sets internalProperties.fakeMtProviders to false) in the
setup, so the `@AfterEach` tearDown method restores the true pre-test value;
update references in the test setup (fakeMtProvidersBefore, internalProperties,
and initMachineTranslationProperties) accordingly.
---
Nitpick comments:
In
`@backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.kt`:
- Around line 82-90: The tearDown() restores various shared properties
unconditionally which can overwrite globals if setup() failed; add a "snapshot
captured" guard boolean set when setup() successfully saves the original values
and check it in tearDown() before restoring. Specifically, modify the
setup/snapshot logic to set a flag (e.g., snapshotCaptured) when you copy values
for tolgeeProperties.internal.fakeMtProviders and the
machineTranslationProperties.google.{apiKey,defaultEnabled,defaultPrimary} and
machineTranslationProperties.aws.{defaultEnabled,accessKey,secretKey}; then in
tearDown() return early unless snapshotCaptured is true so you only restore when
the snapshot exists. Ensure the flag is reset after restoration.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 30ac3705-030e-402a-b6df-d94ecc9163e7
📒 Files selected for processing (13)
backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchChangeTranslationStateTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchClearTranslationsTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchCopyTranslationsTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchDeleteKeysTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchMtTranslateTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchPreTranslateByTmTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchRestoreKeysTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchTagKeysTest.ktbackend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translationSuggestionController/TranslationSuggestionControllerMtTest.ktbackend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.ktee/backend/tests/src/test/kotlin/io/tolgee/ee/api/v2/controllers/slack/OrganizationSlackControllerTest.ktee/backend/tests/src/test/kotlin/io/tolgee/ee/selfHostedLimitsAndReporting/CreditLimitTest.kt
✅ Files skipped from review due to trivial changes (1)
- backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchMtTranslateTest.kt
🚧 Files skipped from review as they are similar to previous changes (2)
- backend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.kt
- ee/backend/tests/src/test/kotlin/io/tolgee/ee/api/v2/controllers/slack/OrganizationSlackControllerTest.kt
| @NestedConfigurationProperty | ||
| var deepl: DeeplMachineTranslationProperties = DeeplMachineTranslationProperties(), | ||
| @NestedConfigurationProperty | ||
| var azure: AzureCognitiveTranslationProperties = AzureCognitiveTranslationProperties(), |
There was a problem hiding this comment.
As far as I can tell, on main the key is tolgee.machine-translation.azurecognitive.* (from the injected AzureCognitiveTranslationProperties prefix), but after the refactor it binds from the field name machineTranslation.azure → tolgee.machine-translation.azure.*. So existing self-hosted configs using azurecognitive would just silently stop working? And azurecognitive only seems to live on as a @DocProperty string now.
If that's right, maybe rename the field back to azurecognitive to keep it backwards compatible ?
|
This PR is stale because it has been open for 30 days with no activity. |
|
This PR was closed because it has been inactive for 14 days since being marked as stale. |
|
This PR is stale because it has been open for 30 days with no activity. |
|
This PR was closed because it has been inactive for 14 days since being marked as stale. |
Extends the refactor to newly-added consumers that were introduced on main since this branch was opened. Every *Properties subclass is now accessed exclusively through TolgeeProperties to guarantee a single instance at runtime and uniform test-override semantics via PropertiesController. - Convert lateinit @Autowired / by-lazy sub-property fields in tests to delegating getters on TolgeeProperties - Convert direct InternalProperties / BatchProperties injections in UrlSecurity and BatchJobProjectLockingManager - Rewrite tests that constructed consumers with standalone sub-property instances to use TolgeeProperties(x = ...)
Taking tolgeeProperties as a method parameter (instead of reading the field) restores the original Spring injection ordering. With @Autowired methods, Spring resolves method args fresh at call time, while field values may not yet reflect @spybean replacement from MockitoTestExecutionListener. Subclasses using @spybean override lateinit var tolgeeProperties would otherwise hit an uninitialized-property exception on method entry. Fixes AssignCloudPlanTrialTest bean-creation failure in billing tests.
Tests converted from Mockito stubs (@spybean + whenever) to direct mutation of tolgeeProperties must restore the singleton on teardown in non context recreating tests. Otherwise mutations leak into subsequent tests sharing the same Spring ApplicationContext, causing flakiness. Applied the snapshot-in-setup / restore-in-teardown pattern to every test that the rebase/sweep introduced as a regression: - BatchJobTestBase (+ wire tearDown() in 8 consumer classes) - TranslationSuggestionControllerMtTest - McpBatchToolsTest - OrganizationSlackControllerTest - CreditLimitTest Pre existing mutation leaks on main that also affect non context recreating tests are left in place as out of scope; fixing them is tracked separately.
Use literal defaults for fields not overridden by test yaml, drop redundant snapshot fields for no-op mutations, and keep snapshots (with a justifying comment) for fields where the test yaml overrides the declared default.
WebhookProperties and SsoGlobalProperties carried @PostConstruct validation that only ran while they were Spring beans. After the refactor demoted them to plain nested objects, the validation silently stopped — misconfigured values would pass unchecked. Add SelfValidatingProperties plus a shared validateNestedProperties() that each @ConfigurationProperties root (TolgeeProperties, EeProperties, BillingProperties) invokes from @PostConstruct. It walks @NestedConfigurationProperty fields across the full class hierarchy, including through collections and maps, calling validate() on every nested implementation.
Dropping @ConfigurationProperties from the cache-purging property classes left ContentDeliveryCachePurgingProvider's injected List<ContentDeliveryPurgingConfig> empty (no beans implement the interface anymore), so no CDN cache was ever purged — silently, with no startup error. Bunny and AWS CloudFront also lost their binding path entirely. Derive the configs from TolgeeProperties via a single ContentDeliveryCachePurgingProperties.all() registry, and nest bunny + awsCloudFront so all four providers bind again.
The webhook local-addresses feature merged to main after this branch was opened added new direct injections of WebhookProperties, which the bean refactor demoted from a Spring bean to a plain nested object. These would fail Spring DI at context load (no WebhookProperties bean), and compile cleanly so the breakage is invisible until startup. - WebhookConfigService: inject TolgeeProperties, read webhook via holder getter - WebhookConfigUrlSecurityTest / LlmProviderControllerTest: drop @Autowired WebhookProperties in favour of the shared base getter - AbstractSpringTest: add webhookProperties holder getter alongside the existing internalProperties / llmProperties getters
…istener Replace the manual per-test snapshot/restore of TolgeeProperties with a ConfigurationPropertiesResetListener that snapshots every io.tolgee @ConfigurationProperties root before each test method and restores it afterwards. Removes the hand-written teardown boilerplate from the batch, MT-suggestion, MCP, slack and credit-limit tests. Restore uses Jackson readerForUpdating + merge to update the existing object graph in place, preserving nested-instance identity so beans that captured a sub-properties reference at construction (e.g. the OAuth delegates) keep observing restored values. Collections/maps are replaced (values restored exactly). Snapshot and restore are guarded to fail loud and attributable, and unknown keys fail rather than silently leaking. Covers all our config roots generically (TolgeeProperties, EeProperties, Billing); framework roots and @Bean-method infra beans are excluded.
Main moved to Jackson 3, whose mapper is built immutably and no longer writes final fields or fails on unknown properties by default. Both are enabled explicitly so a `val` collection property is still restored and a snapshot that does not match the bean still fails loudly.
Main gained property classes and consumers that still relied on the removed configuration properties scanning: - AsyncProperties, ReviewAskProperties, OAuth2ServerProperties and AzureBlobSettings drop their own @ConfigurationProperties and are bound as nested properties of TolgeeProperties - the OAuth2 server, CIMD, SSRF-safe request factory, MCP auth filter, embedded Postgres deprecation runner, RestTemplate configuration and deleted organization project purge scheduler read their settings through TolgeeProperties - tests build TolgeeProperties instead of the sub-property classes
4815d92 to
c727080
Compare
- keep documented config keys: bind Azure MT at tolgee.machine-translation.azurecognitive and CloudFront cache purging at tolgee.content-delivery.cache-purging.aws-cloudfront - convert BatchMtTranslatePartialFailureTest to direct property assignment - do not reload a context closed by @DirtiesContext just to restore properties - drop the validation hook from EeProperties, which has nothing to validate - small cleanups in the validation walker, MtServiceType, comments and tests
This changeset refactors the Tolgee backend to centralize property access through a single
TolgeePropertiesholder instead of injecting individual*Propertiesclasses via Spring's@ConfigurationPropertiesscanning.Summary
@ConfigurationPropertiesScanto@EnableConfigurationProperties(TolgeeProperties::class); remove@ConfigurationPropertiesfrom the sub-property classesTolgeePropertiesinjection + delegated getters (holder pattern), including the webhook consumers@NestedConfigurationPropertyto nested config so Spring binding/metadata keeps workingSelfValidatingProperties/validateNestedProperties) and content-delivery cache-purging wiring that the bean refactor had droppedinitInitialUserrateLimit→rateLimitsandllmProperties→llm;MtServiceTypenow uses lambda property getters instead of class referencesTolgeePropertiessnapshot/restore boilerplate with aConfigurationPropertiesResetListenerthat auto-restores everyio.tolgee@ConfigurationPropertiesroot before/after each test (Jackson in-place merge preserving nested-instance identity; covers Tolgee/Ee/Billing roots)Summary by CodeRabbit