@@ -194,6 +194,84 @@ class AtumAgentUnitTests extends AnyFunSuiteLike {
194194 assert(agentA.dispatcher ne agentB.dispatcher)
195195 }
196196
197+ test(" currentUser falls back to the JVM user when atum.author is not set" ) {
198+ val agent = AtumAgent .fromConfig(configOf(Map (
199+ " atum.dispatcher.type" -> " capture" ,
200+ " atum.dispatcher.capture.capture-limit" -> 10
201+ )))
202+
203+ assert(agent.currentUser == System .getProperty(" user.name" ))
204+ }
205+
206+ test(" currentUser uses atum.author from config when set (trimmed)" ) {
207+ val agent = AtumAgent .fromConfig(configOf(Map (
208+ " atum.dispatcher.type" -> " capture" ,
209+ " atum.dispatcher.capture.capture-limit" -> 10 ,
210+ " atum.author" -> " my-application "
211+ )))
212+
213+ assert(agent.currentUser == " my-application" )
214+ }
215+
216+ test(" currentUser falls back to the JVM user when atum.author is blank" ) {
217+ val agent = AtumAgent .fromConfig(configOf(Map (
218+ " atum.dispatcher.type" -> " capture" ,
219+ " atum.dispatcher.capture.capture-limit" -> 10 ,
220+ " atum.author" -> " "
221+ )))
222+
223+ assert(agent.currentUser == System .getProperty(" user.name" ))
224+ }
225+
226+ test(" currentUser is resolved independently per config-backed agent" ) {
227+ val agentA = AtumAgent .fromConfig(configOf(Map (
228+ " atum.dispatcher.type" -> " capture" ,
229+ " atum.dispatcher.capture.capture-limit" -> 10 ,
230+ " atum.author" -> " alice"
231+ )))
232+ val agentB = AtumAgent .fromConfig(configOf(Map (
233+ " atum.dispatcher.type" -> " capture" ,
234+ " atum.dispatcher.capture.capture-limit" -> 10
235+ )))
236+
237+ assert(agentA.currentUser == " alice" )
238+ assert(agentB.currentUser == System .getProperty(" user.name" ))
239+ }
240+
241+ test(" currentUser is resolved once and cached for agents that do not override it" ) {
242+ val originalAuthor = Option (System .getProperty(" atum.author" ))
243+ try {
244+ System .setProperty(" atum.author" , " first-app" )
245+ ConfigFactory .invalidateCaches()
246+
247+ // a custom agent that does NOT override currentUser -> relies on the cached trait default
248+ val agent = new AtumAgent {
249+ override val dispatcher : CapturingDispatcher =
250+ AtumAgent .dispatcherFromConfig(configOf(Map (
251+ " atum.dispatcher.type" -> " capture" ,
252+ " atum.dispatcher.capture.capture-limit" -> 10
253+ ))).asInstanceOf [CapturingDispatcher ]
254+ }
255+
256+ // first access resolves and caches the identity
257+ assert(agent.currentUser == " first-app" )
258+
259+ // change the backing system property and invalidate Typesafe caches:
260+ // a recomputing `def` would observe the new value here
261+ System .setProperty(" atum.author" , " second-app" )
262+ ConfigFactory .invalidateCaches()
263+
264+ // the resolved-once value must remain stable for the agent's lifetime
265+ assert(agent.currentUser == " first-app" )
266+ } finally {
267+ originalAuthor match {
268+ case Some (value) => System .setProperty(" atum.author" , value)
269+ case None => System .clearProperty(" atum.author" )
270+ }
271+ ConfigFactory .invalidateCaches()
272+ }
273+ }
274+
197275 private def configOf (configValues : Map [String , Any ]): Config = {
198276 val emptyConfig = ConfigFactory .empty()
199277 configValues.foldLeft(emptyConfig) { case (acc, (configKey, value)) =>
0 commit comments