Skip to content

fix: rework project properties access - #3424

Open
Anty0 wants to merge 15 commits into
mainfrom
jirikuchynka/fix-properties-achitecture
Open

Anty0 wants to merge 15 commits into
mainfrom
jirikuchynka/fix-properties-achitecture

Conversation

@Anty0

@Anty0 Anty0 commented Jan 28, 2026 •

Copy link
Copy Markdown
Member

This changeset refactors the Tolgee backend to centralize property access through a single TolgeeProperties holder instead of injecting individual *Properties classes via Spring's @ConfigurationProperties scanning.

Summary

  • Switch from @ConfigurationPropertiesScan to @EnableConfigurationProperties(TolgeeProperties::class); remove @ConfigurationProperties from the sub-property classes
  • Replace direct sub-property injections with TolgeeProperties injection + delegated getters (holder pattern), including the webhook consumers
  • Add @NestedConfigurationProperty to nested config so Spring binding/metadata keeps working
  • Restore config-properties validation (SelfValidatingProperties / validateNestedProperties) and content-delivery cache-purging wiring that the bean refactor had dropped
  • Keep method-param injection in initInitialUser
  • Rename rateLimit → rateLimits and llmProperties → llm; MtServiceType now uses lambda property getters instead of class references
  • Behavior change: machine-translation services' default enablement now follows configured values instead of a previous unconditional default
  • Tests: replace the manual per-test TolgeeProperties snapshot/restore boilerplate with a ConfigurationPropertiesResetListener that auto-restores every io.tolgee @ConfigurationProperties root before/after each test (Jackson in-place merge preserving nested-instance identity; covers Tolgee/Ee/Billing roots)

Summary by CodeRabbit

  • Refactor
    • Configuration access unified into a single central properties holder; behavior preserved but internal wiring simplified.
  • Behavior change
    • Machine translation services' default enablement now follows configured values instead of a previous unconditional default.
  • Tests
    • Test suites improved with clearer setup/teardown and fewer scattered property spies/mocks to reduce cross-test leakage and increase reliability.

@coderabbitai

coderabbitai Bot commented Jan 28, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
Walkthrough

Centralized configuration access: classes now receive a single TolgeeProperties and read nested configs via getters. Many @ConfigurationProperties annotations were replaced with @DocProperty and @NestedConfigurationProperty. MtServiceType switched from a propertyClass model to propertiesGetter lambdas.

Changes

Cohort / File(s) Summary
Top-level properties & metadata
backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/TolgeeProperties.kt, backend/app/src/main/kotlin/io/tolgee/Application.kt
Enable TolgeeProperties binding (@EnableConfigurationProperties), add many @NestedConfigurationProperty annotations; rename rateLimit→rateLimits, llmProperties→llm.
Replace @ConfigurationProperties with DocProperty
backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/*.kt, .../machineTranslation/*.kt
Removed class-level @ConfigurationProperties, moved prefixes into @DocProperty, and added @NestedConfigurationProperty to nested fields across many config classes (auth, batch, cache, content-delivery, file-storage, mt, posthog, etc.).
Constructor DI -> TolgeeProperties
backend/**/src/main/kotlin/**/*.kt (services, components, controllers, batch processors, websocket, postgres runners, application stopper, etc.)
Replaced many constructors that previously injected individual property beans with TolgeeProperties; added private computed getters (e.g., private val batchProperties get() = tolgeeProperties.batch) to retain call sites.
Machine translation wiring
backend/data/src/main/kotlin/io/tolgee/constants/MtServiceType.kt, .../MtServicesConfiguration.kt, .../MtServiceConfigService.kt, .../PublicConfigurationAssembler.kt
MtServiceType now holds propertiesGetter: (TolgeeProperties) -> MachineTranslationServiceProperties; MT service mapping and public DTO construction use propertiesGetter(tolgeeProperties) rather than resolving property beans by class.
Tests: consolidate/mutate TolgeeProperties
backend/app/src/test/kotlin/**, backend/data/src/test/kotlin/**, backend/testing/src/main/kotlin/io/tolgee/AbstractSpringTest.kt, ee/backend/tests/**
Replaced numerous test-level autowired/spied property beans with a single TolgeeProperties spy or direct mutation of the TolgeeProperties bean; removed many Mockito stubs and added setup/teardown that snapshots and restores TolgeeProperties fields to avoid test leakage.
Test config provisioning
backend/app/src/test/kotlin/io/tolgee/config/BatchJobBaseConfiguration.kt
Replaced two @Primary Mockito-spy beans (MachineTranslationProperties, InternalProperties) with one @Primary TolgeeProperties spy bean.
Small API / controller signature updates
backend/api/src/main/kotlin/io/tolgee/controllers/*.kt, backend/development/**, ee/backend/app/**
Controller/endpoint classes updated to accept TolgeeProperties instead of specific properties (AuthenticationProperties, SlackProperties, etc.) and expose small private getters to preserve previous logic.
Misc: added/changed few properties & helpers
backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/*.kt (MailjetProperties, PlausibleProperties, RabbitmqAutostartProperties, ContentStorageS3Properties, etc.)
Added small property changes (e.g., Mailjet.contactListId, Plausible.scriptUrl, RabbitMQ defaults) and a clear() helper in S3 settings; moved annotation styles as above.
Tests: lifecycle cleanup additions
various backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/*Test.kt
Added @AfterEach teardown hooks calling shared test-base cleanup to avoid state leakage in batch tests.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested reviewers

  • bdshadow
  • JanCizmar
Finishing Touches

🧪 Generate unit tests (beta)

  • Create PR with unit tests
  • Commit unit tests in branch jirikuchynka/fix-properties-achitecture
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@Anty0
Anty0 force-pushed the jirikuchynka/fix-properties-achitecture branch from f872cd3 to 497fcce Compare January 28, 2026 14:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @ConfigurationProperties removed, SsoGlobalProperties is likely no longer a Spring bean, so @PostConstruct may never execute. That would silently skip the required-field checks when enabled = true. Please ensure validate() 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 authorizationUrl is used in GithubOAuthDelegate.kt to exchange the authorization code for an access token via restTemplate.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 how GoogleAuthenticationProperties.kt describes the same property as "URL to Google /token API 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 new tolgeeProperties mock between tests.

tolgeeProperties is stubbed in setupMocks() but never reset; this can leak interactions or stubbing across tests. Add it to resetMocks().

🔧 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 new tolgeeProperties mock between tests.

tolgeeProperties is stubbed in setupMocks() but never reset; add it to resetMocks() 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 updating resetMocks to include all mocks for consistency.

The @AfterEach resets authenticationFacade and userAccount but omits tolgeeProperties and authenticationProperties. While JUnit 5's default PER_METHOD lifecycle 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 RabbitMqAutostartMode appear 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 adding tolgeeProperties to the reset call for consistency.

The tolgeeProperties mock is not included in resetMocks(), while other mocks are. Although the @BeforeEach re-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 null authKey.

The !! operator on line 78 will throw an NPE if authKey is 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @AfterEach method.

The reports when enabled test creates TestData via testDataService.saveTestData(testData.root) but the @AfterEach method doesn't clean it up. Following the pattern used in other tests (e.g., SsoOrganizationsTest, KeyUsageReportingTest), add testDataService.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 of clear().
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 adding tolgeeProperties to resetMocks().

The newly added tolgeeProperties mock is not included in the Mockito.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 adding tolgeeProperties to resetMocks().

Similar to other test files in this PR, the tolgeeProperties mock 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 since TolgeeProperties has 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, and MachineTranslationServiceProperties are 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 in resetMocks() for consistency.

The resetMocks() method omits tolgeeProperties and authenticationProperties from the reset call. While @BeforeEach re-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 a when expression for mode dispatch.

The if-chain can be expressed more idiomatically in Kotlin using a when expression.

♻️ 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 documenting contactListId for 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
 }

@bdshadow

Copy link
Copy Markdown
Member

please, don't merge it before branching

@bdshadow

Copy link
Copy Markdown
Member

and what's the benefit of it?
For example, now instead of just injecting the aws, you need to have

private val awsMachineTranslationProperties get() = tolgeeProperties.machineTranslation.aws

Before this refactoring it was also possible to inject consolidated tolgeeProperties and access all nested layers like this. So this pr just is just prohibits it, leading to more code and injecting whole bunch of properties when you need only a single one.
Maybe i'm wrong, but i don't see it to be beneficial.

@Anty0

Anty0 commented Jan 29, 2026 •

Copy link
Copy Markdown
Member Author

@bdshadow The issue is that we currently have (at least) two instances of each *Properties. I've been burned by this before - you override something in tests through TolgeeProperties, and it doesn't work. You don't know why until you realize the component is accessing the (let's say) AWS properties directly, not through TolgeeProperties, so you need to modify it there, or even worse, both, if different code paths use the property from TolgeeProperties. I wanted to solve this. (This doesn't really affect unit tests, fortunately, as we create the properties there directly, so we create only a single instance of everything. On the contrary, e2e tests can only set properties on the TolgeeProperties, because that's what PropertiesController does. I feel like this is going to bite us.)

Other than this, we currently have two things broken, which I want to fix this way:

  • Rate limits: You may notice that their prefix is set to rate-limits while the property is named rateLimit. On Tuesday, I realized that this means TolgeeProperties are looking for rate-limit, while directly accessing RateLimitProperties will look for rate-limits. The fact that this is even possible is, in my opinion, completely insane. Contrary to most other properties, we access some rate limits through TolgeeProperties, so they don't get set at all (they stay the default).
  • LLM Properties: Same issue. Fortunately, we always access them directly, so there are no configuration issues, but if anyone were to use TolgeeProperties to access them, they would just get default values.

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. ^^
(I'll go and do that anyway, as I want it fixed sooner rather than later; this rework can wait after branching.)

JanCizmar
JanCizmar previously approved these changes Jan 29, 2026

@JanCizmar JanCizmar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. 👍 I would merge it after branching.

@Anty0
Anty0 requested a review from gabrielshanahan January 29, 2026 14:50
@bdshadow

Copy link
Copy Markdown
Member

@Anty0

The fact that this is even possible is, in my opinion, completely insane.

if jakarta validation like @NotNull, @NotEmpty is put on the properties, then it will fail on the start of the app, when thre is such a mistype. So it's easy to fix. And must be fixed like this.

Another thing is about accessing the properties. This seems weird, need to check. But probably this is because fields inside TolgeeProperties are not injected ,they are created by a default constructor. I might be wrong here, but just annotating it with NestedConfigurationProperty and removing initizalization must be enough to solve this problem. (another option is just to declare a constructor of the TolgeeProperties, where all fields will be injected by spring)

@bdshadow
bdshadow self-requested a review January 30, 2026 10:36

@bdshadow bdshadow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll dare to request changes :) Sorry :)
Feel free to ping me

@Anty0

Anty0 commented Jan 30, 2026

Copy link
Copy Markdown
Member Author

@bdshadow

if jakarta validation like @NotNull, @notempty is put on the properties

You mean they won't have default values anymore? I'm not sure I understand this one. ^^

Another thing is about accessing the properties

Yes, please check and let me know (after branching). If there is a different way we can make sure the *Properties instances won't be created multiple times, I'm all ears ^^

@bdshadow

bdshadow commented Feb 2, 2026

Copy link
Copy Markdown
Member

@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 TolgeeProperties would just explode it and it won't be useful. And it will even bigger change.

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

@bdshadow
bdshadow self-requested a review February 2, 2026 15:04
bdshadow
bdshadow previously approved these changes Feb 2, 2026
@github-actions

github-actions Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale label Mar 5, 2026
@Anty0 Anty0 removed the stale label Mar 6, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale label Apr 15, 2026
@Anty0 Anty0 removed the stale label Apr 22, 2026
@Anty0
Anty0 dismissed stale reviews from bdshadow and JanCizmar via 85ab2eb April 23, 2026 13:42
@Anty0
Anty0 force-pushed the jirikuchynka/fix-properties-achitecture branch from 24bb56a to 85ab2eb Compare April 23, 2026 13:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
backend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.kt (1)

21-27: Prevent cross-test leakage from mutable internalProperties state.

At Line 26, internalProperties.fakeMtProviders is forced to true in @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

📥 Commits

Reviewing files that changed from the base of the PR and between 24bb56a and 85ab2eb.

📒 Files selected for processing (51)
  • backend/api/src/main/kotlin/io/tolgee/api/publicConfiguration/PublicConfigurationAssembler.kt
  • backend/api/src/main/kotlin/io/tolgee/controllers/PublicController.kt
  • backend/api/src/main/kotlin/io/tolgee/controllers/resetPassword/PasswordResetController.kt
  • backend/api/src/main/kotlin/io/tolgee/controllers/resetPassword/ResetPasswordRequestHandler.kt
  • backend/api/src/main/kotlin/io/tolgee/util/ApplicationStopper.kt
  • backend/api/src/main/kotlin/io/tolgee/websocket/WebsocketPublisherConfiguration.kt
  • backend/app/src/main/kotlin/io/tolgee/Application.kt
  • backend/app/src/main/kotlin/io/tolgee/commandLineRunners/InitialUserCreatorCommandLineRunner.kt
  • backend/app/src/main/kotlin/io/tolgee/configuration/PostgresAutoStartConfiguration.kt
  • backend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresDockerRunner.kt
  • backend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresEmbeddedRunner.kt
  • backend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresRunnerConfiguration.kt
  • backend/app/src/main/kotlin/io/tolgee/postgresRunners/PostgresStopper.kt
  • backend/app/src/test/kotlin/io/tolgee/StartupImportCommandLineRunnerTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/V2UserControllerTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translationSuggestionController/TranslationSuggestionControllerMtTest.kt
  • backend/app/src/test/kotlin/io/tolgee/batch/AbstractBatchJobConcurrentTest.kt
  • backend/app/src/test/kotlin/io/tolgee/batch/AbstractBatchJobsGeneralTest.kt
  • backend/app/src/test/kotlin/io/tolgee/config/BatchJobBaseConfiguration.kt
  • backend/app/src/test/kotlin/io/tolgee/mcp/McpServerIntegrationTest.kt
  • backend/app/src/test/kotlin/io/tolgee/mcp/tools/McpBatchToolsTest.kt
  • backend/app/src/test/kotlin/io/tolgee/security/EmailVerificationTest.kt
  • backend/app/src/test/kotlin/io/tolgee/service/TelemetryServiceTest.kt
  • backend/data/src/main/kotlin/io/tolgee/MtServicesConfiguration.kt
  • backend/data/src/main/kotlin/io/tolgee/batch/BatchJobCancellationManager.kt
  • backend/data/src/main/kotlin/io/tolgee/batch/BatchJobConcurrentLauncher.kt
  • backend/data/src/main/kotlin/io/tolgee/batch/BatchJobProjectLockingManager.kt
  • backend/data/src/main/kotlin/io/tolgee/batch/cleaning/OldBatchJobCleaner.kt
  • backend/data/src/main/kotlin/io/tolgee/batch/processors/AutoTranslateChunkProcessor.kt
  • backend/data/src/main/kotlin/io/tolgee/batch/processors/MachineTranslationChunkProcessor.kt
  • backend/data/src/main/kotlin/io/tolgee/component/emailContacts/MailJetEmailServiceManager.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/MtServiceManager.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AwsMtValueProvider.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AzureCognitiveApiService.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/AzureCognitiveTranslationProvider.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/BaiduApiService.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/BaiduTranslationProvider.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/DeeplApiService.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/DeeplTranslationProvider.kt
  • backend/data/src/main/kotlin/io/tolgee/component/machineTranslation/providers/GoogleTranslationProvider.kt
  • backend/data/src/main/kotlin/io/tolgee/component/reporting/PlausibleBusinessEventReporter.kt
  • backend/data/src/main/kotlin/io/tolgee/configuration/PostHogConfiguration.kt
  • backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/AuthenticationProperties.kt
  • backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/BatchProperties.kt
  • backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/CacheProperties.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/ContentDeliveryBunnyProperties.kt
  • backend/data/src/main/kotlin/io/tolgee/configuration/tolgee/ContentDeliveryCachePurgingProperties.kt
  • backend/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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; if setup() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 85ab2eb and 6f6c017.

📒 Files selected for processing (13)
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchChangeTranslationStateTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchClearTranslationsTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchCopyTranslationsTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchDeleteKeysTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobTestBase.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchMtTranslateTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchPreTranslateByTmTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchRestoreKeysTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchTagKeysTest.kt
  • backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translationSuggestionController/TranslationSuggestionControllerMtTest.kt
  • 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
  • ee/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

@Anty0
Anty0 marked this pull request as draft May 21, 2026 12:25
@Anty0
Anty0 requested a review from dkrizan June 17, 2026 11:07
@NestedConfigurationProperty
var deepl: DeeplMachineTranslationProperties = DeeplMachineTranslationProperties(),
@NestedConfigurationProperty
var azure: AzureCognitiveTranslationProperties = AzureCognitiveTranslationProperties(),

@dkrizan dkrizan Jun 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale label Jul 25, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

This PR was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions Bot closed this Aug 9, 2026
@Anty0 Anty0 reopened this Aug 10, 2026
@Anty0 Anty0 removed the stale label Aug 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale label Sep 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions Bot closed this Sep 24, 2026
@Anty0 Anty0 removed the stale label Nov 27, 2026
@Anty0 Anty0 reopened this Nov 27, 2026
Anty0 added 14 commits November 27, 2026 19:16
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
@Anty0
Anty0 force-pushed the jirikuchynka/fix-properties-achitecture branch from 4815d92 to c727080 Compare November 27, 2026 18:33
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants