@@ -169,4 +169,45 @@ public async Task AddSqlPrompt_WhenMaxTokensChanges_ShouldInsertNewVersion()
169169 // Assert
170170 Assert . True ( result , "A new version should be inserted when MaxTokens changes." ) ;
171171 }
172+
173+ [ Fact ]
174+ public async Task GetSqlPromptByName_GivenTwoPromptsOfTheSameNameAreAdded_ShouldRetrieveLatest ( )
175+ {
176+ // Arrange
177+ var entity1 = new SqlPromptEntity
178+ {
179+ PromptName = "noprompt" ,
180+ Model = "gpt4" ,
181+ OutputFormat = "json" ,
182+ MaxTokens = 500 ,
183+ SystemPrompt = "Optimize SQL queries." ,
184+ UserPrompt = "Suggest indexing improvements." ,
185+ Parameters = new Dictionary < string , string > { { "Temperature" , "0.7" } } ,
186+ Default = new Dictionary < string , object > { { "Temperature" , "0.5" } }
187+ } ;
188+
189+ var entity2 = new SqlPromptEntity
190+ {
191+ PromptName = "noprompt" , // Same prompt name
192+ Model = "gpt4" ,
193+ OutputFormat = "json" ,
194+ MaxTokens = 512 , // Changed value
195+ SystemPrompt = "Optimize SQL queries 2." , // changed value
196+ UserPrompt = "Suggest indexing improvements." ,
197+ Parameters = new Dictionary < string , string > { { "Temperature" , "0.7" } } ,
198+ Default = new Dictionary < string , object > { { "Temperature" , "0.5" } }
199+ } ;
200+
201+ await _repository . AddSqlPrompt ( entity1 ) ; // Insert first version
202+
203+ // Act
204+ bool result = await _repository . AddSqlPrompt ( entity2 ) ;
205+
206+ var prompt = await _repository . GetLatestPromptByName ( "noprompt" ) ;
207+
208+ // Assert
209+ Assert . Equal ( entity2 . MaxTokens , prompt . MaxTokens ) ;
210+ Assert . Equal ( entity2 . SystemPrompt , prompt . SystemPrompt ) ;
211+ Assert . Equal ( entity1 . UserPrompt , prompt . UserPrompt ) ;
212+ }
172213}
0 commit comments