From edf45ea7a1a6dd7bbb87f47e6ab7597c50c31c65 Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Mon, 21 Oct 2024 17:39:36 +0100 Subject: [PATCH] Made requested changes --- .../src/Serval.ApiServer/ServalSettings.cs | 6 ---- src/Serval/src/Serval.ApiServer/Startup.cs | 1 - src/Serval/src/Serval.Client/Client.g.cs | 4 +-- .../Serval.Shared/Configuration/ApiOptions.cs | 1 + .../Configuration/ServalSettings.cs | 6 ---- .../Contracts/TranslationBuildDto.cs | 2 +- .../TranslationEnginesController.cs | 8 ++--- .../src/Serval.Translation/Models/Build.cs | 2 +- .../TranslationEngineTests.cs | 13 +++++++-- .../test/Serval.E2ETests/ServalApiTests.cs | 29 ------------------- 10 files changed, 19 insertions(+), 53 deletions(-) delete mode 100644 src/Serval/src/Serval.ApiServer/ServalSettings.cs delete mode 100644 src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs diff --git a/src/Serval/src/Serval.ApiServer/ServalSettings.cs b/src/Serval/src/Serval.ApiServer/ServalSettings.cs deleted file mode 100644 index 20205b01..00000000 --- a/src/Serval/src/Serval.ApiServer/ServalSettings.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Serval.ApiServer; - -public class ServalSettings -{ - public string ReleaseVersion { get; set; } = "1.0.0"; // Default value -} diff --git a/src/Serval/src/Serval.ApiServer/Startup.cs b/src/Serval/src/Serval.ApiServer/Startup.cs index a3856962..d4c5a3cd 100644 --- a/src/Serval/src/Serval.ApiServer/Startup.cs +++ b/src/Serval/src/Serval.ApiServer/Startup.cs @@ -213,7 +213,6 @@ public void ConfigureServices(IServiceCollection services) .AddOpenTelemetry() .WithMetrics(opts => opts.AddAspNetCoreInstrumentation().AddPrometheusExporter()); } - services.Configure(Configuration.GetSection("ServalSettings")); services.Configure(Configuration.GetSection("Bugsnag")); services.AddBugsnag(); } diff --git a/src/Serval/src/Serval.Client/Client.g.cs b/src/Serval/src/Serval.Client/Client.g.cs index f6983221..7a1ade2c 100644 --- a/src/Serval/src/Serval.Client/Client.g.cs +++ b/src/Serval/src/Serval.Client/Client.g.cs @@ -9816,8 +9816,8 @@ public partial class TranslationBuild [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public object? Options { get; set; } = default!; - [Newtonsoft.Json.JsonProperty("servalReleaseVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? ServalReleaseVersion { get; set; } = default!; + [Newtonsoft.Json.JsonProperty("servalVersion", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? ServalVersion { get; set; } = default!; } diff --git a/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs b/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs index 9a998b72..e476ce32 100644 --- a/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs +++ b/src/Serval/src/Serval.Shared/Configuration/ApiOptions.cs @@ -6,4 +6,5 @@ public class ApiOptions public TimeSpan DefaultHttpRequestTimeout { get; set; } = TimeSpan.FromSeconds(58); // must be less than 60 seconds Cloudflare timeout public TimeSpan LongPollTimeout { get; set; } = TimeSpan.FromSeconds(40); // must be less than DefaultHttpRequestTimeout + public string ServalVersion { get; set; } = "1.0.0"; // Default value } diff --git a/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs b/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs deleted file mode 100644 index ab173fe1..00000000 --- a/src/Serval/src/Serval.Shared/Configuration/ServalSettings.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Serval.Shared.Configuration; - -public class ServalSettings -{ - public string ReleaseVersion { get; set; } = "1.0.0"; // Default value -} diff --git a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs index bf77741a..ab57d910 100644 --- a/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -27,5 +27,5 @@ public record TranslationBuildDto /// } /// public object? Options { get; init; } - public string? ServalReleaseVersion { get; init; } + public string? ServalVersion { get; init; } } diff --git a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs index b78c5225..dd2c8fdf 100644 --- a/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -10,8 +10,7 @@ public class TranslationEnginesController( IPretranslationService pretranslationService, IOptionsMonitor apiOptions, IUrlService urlService, - ILogger logger, - IOptions servalSettingsOptions + ILogger logger ) : ServalControllerBase(authService) { private static readonly JsonSerializerOptions ObjectJsonSerializerOptions = @@ -23,7 +22,8 @@ IOptions servalSettingsOptions private readonly IOptionsMonitor _apiOptions = apiOptions; private readonly IUrlService _urlService = urlService; private readonly ILogger _logger = logger; - private readonly ServalSettings _servalSettings = servalSettingsOptions.Value; + + // private readonly ServalSettings _servalSettings = apiOptions.Value; /// /// Get all translation engines @@ -1508,7 +1508,7 @@ private TranslationBuildDto Map(Build source) State = source.State, DateFinished = source.DateFinished, Options = source.Options, - ServalReleaseVersion = _servalSettings.ReleaseVersion + ServalVersion = _apiOptions.CurrentValue.ServalVersion }; } diff --git a/src/Serval/src/Serval.Translation/Models/Build.cs b/src/Serval/src/Serval.Translation/Models/Build.cs index e12607b2..a83bb590 100644 --- a/src/Serval/src/Serval.Translation/Models/Build.cs +++ b/src/Serval/src/Serval.Translation/Models/Build.cs @@ -15,5 +15,5 @@ public record Build : IEntity public JobState State { get; init; } = JobState.Pending; public DateTime? DateFinished { get; init; } public IReadOnlyDictionary? Options { get; init; } - public string? ServalReleaseVersion { get; set; } + public string? ServalVersion { get; set; } } diff --git a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs index 6d0b2df2..6dde416d 100644 --- a/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs +++ b/src/Serval/test/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs @@ -7,7 +7,7 @@ namespace Serval.ApiServer; [TestFixture] [Category("Integration")] -public class TranslationEngineTests +public class TranslationEngineTests(IOptionsMonitor apiOptions, TranslationEngineTests.TestEnvironment env) { private static readonly TranslationCorpusConfig TestCorpusConfig = new() @@ -74,8 +74,9 @@ public class TranslationEngineTests private const string TARGET_CORPUS_ID = "cc0000000000000000000002"; private const string DOES_NOT_EXIST_ENGINE_ID = "e00000000000000000000004"; private const string DOES_NOT_EXIST_CORPUS_ID = "c00000000000000000000001"; + private readonly IOptionsMonitor _apiOptions = apiOptions; - private TestEnvironment _env; + private TestEnvironment _env = env; [SetUp] public async Task SetUp() @@ -1391,6 +1392,12 @@ public async Task StartBuildForEngineByIdAsync(IEnumerable scope, int ex build = await client.GetCurrentBuildAsync(engineId); Assert.That(build, Is.Not.Null); + + // Fetch and assert ServalVersion from ApiOptions + // ApiOptions apiOptions = _env.GetRequiredService>().CurrentValue; + Assert.That(_apiOptions.CurrentValue.ServalVersion, Is.Not.Null); + // Assert.That(apiOptions.ServalVersion, Is.EqualTo("expected_version")); // Replace with the actual expected version + break; case 400: case 403: @@ -1891,7 +1898,7 @@ public void TearDown() _env.Dispose(); } - private class TestEnvironment : DisposableBase + public class TestEnvironment : DisposableBase { private readonly IServiceScope _scope; private readonly MongoClient _mongoClient; diff --git a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs index e532d1f1..0589e53b 100644 --- a/src/Serval/test/Serval.E2ETests/ServalApiTests.cs +++ b/src/Serval/test/Serval.E2ETests/ServalApiTests.cs @@ -46,35 +46,6 @@ public async Task GetEchoPretranslate() Assert.That(pretranslations, Has.Count.GreaterThan(1)); } - [Test] - public async Task GetServalReleaseVersion() - { - string engineId = await _helperClient.CreateNewEngineAsync("Echo", "es", "es", "Echo2"); - string[] books = ["1JN.txt", "2JN.txt"]; - await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", false); - books = ["3JN.txt"]; - string corpusId = await _helperClient.AddTextCorpusToEngineAsync(engineId, books, "es", "es", true); - await _helperClient.BuildEngineAsync(engineId); - IList pretranslations = await _helperClient.TranslationEnginesClient.GetAllPretranslationsAsync( - engineId, - corpusId - ); - Assert.That(pretranslations, Has.Count.GreaterThan(1)); - TranslationBuild build = await _helperClient.TranslationEnginesClient.GetCurrentBuildAsync(engineId); - Assert.That( - build.ServalReleaseVersion, - Is.Not.Null.And.Not.Empty, - "Serval release version should not be null or empty." - ); - - var hasServalReleaseVersionProperty = typeof(TranslationBuild).GetProperty("ServalReleaseVersion") != null; - Assert.That( - hasServalReleaseVersionProperty, - Is.True, - "ServalReleaseVersion property should exist in the build." - ); - } - [Test] public async Task GetSmtTranslation() {