CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow) and pe-check. BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
176 lines
9.4 KiB
C#
176 lines
9.4 KiB
C#
using System.Collections;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
using System.Resources;
|
|
using System.Text.RegularExpressions;
|
|
using Chronos.Core.Advice;
|
|
using Chronos.Core.Analysis;
|
|
using Chronos.Core.Analysis.Deep;
|
|
using Chronos.Core.Diagnostics.Synthetic;
|
|
using Chronos.Core.Localization;
|
|
using Chronos.Core.Project;
|
|
using Chronos.Core.Tests.Analysis.Deep;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Core.Tests.Advice;
|
|
|
|
|
|
public sealed partial class AdvisorLocalizationTests(TestContext context)
|
|
{
|
|
private static readonly CultureInfo English = CultureInfo.GetCultureInfo("en");
|
|
private static readonly CultureInfo Italian = CultureInfo.GetCultureInfo("it");
|
|
private const string LogPrefix = "Advisor.Log.";
|
|
|
|
[Test]
|
|
public void EveryAdvisorKeyHasEnglishAndItalianTextWithTheSamePlaceholders()
|
|
{
|
|
var manager = new ResourceManager("Chronos.Core.i18n.Advisor", typeof(Loc).Assembly);
|
|
var english = Entries(manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: false)!);
|
|
var italian = Entries(manager.GetResourceSet(Italian, createIfNotExists: true, tryParents: false)!);
|
|
// Job log lines (Advisor.Log.*) are written by the analysis job handlers in Chronos.Data, not by the advisor itself.
|
|
var keys = Keys(typeof(AdvisorKeys)).Concat(Keys(typeof(FindingKeys))).Concat(Keys(typeof(DeepFindingKeys)))
|
|
.Concat(english.Keys.Where(k => k.StartsWith(LogPrefix, StringComparison.Ordinal))).ToList();
|
|
Assert.Greater(keys.Count, 90);
|
|
var forms = 0;
|
|
foreach (var key in keys)
|
|
{
|
|
// A key that counts something is a plural stem (BRIEF §16) whose count is its first argument.
|
|
string[] names = english.ContainsKey(key) ? [key] : [key + ".one", key + ".other"];
|
|
if (names.Length == 2) Assert.Contains("0", Placeholders(english.GetValueOrDefault(key + ".other") ?? string.Empty), $"{key}.other counts with {{0}}");
|
|
foreach (var name in names)
|
|
{
|
|
Assert.True(english.TryGetValue(name, out var en), $"English text missing for {name}");
|
|
Assert.True(italian.TryGetValue(name, out var it), $"Italian text missing for {name}");
|
|
Assert.SequenceEqual(Placeholders(en!), Placeholders(it!), name);
|
|
Assert.LessOrEqual(en!.Length, 200);
|
|
forms++;
|
|
}
|
|
}
|
|
Assert.Equal(english.Count, forms);
|
|
}
|
|
|
|
[Test]
|
|
public void ACountOfOneReadsInTheSingularInBothLanguages()
|
|
{
|
|
Assert.Equal("1 frame is black (lens cap or missed exposure).", Loc.Text(DeepFindingKeys.BlackFrames, [1.0], English));
|
|
Assert.Equal("3 frames are black (lens cap or missed exposure).", Loc.Text(DeepFindingKeys.BlackFrames, [3.0], English));
|
|
Assert.Equal("1 fotogramma è nero (tappo sull'obiettivo o scatto mancato).", Loc.Text(DeepFindingKeys.BlackFrames, [1.0], Italian));
|
|
Assert.Equal("The lens changes once.", Loc.Text(FindingKeys.LensChanged, [1], English));
|
|
Assert.Equal("L'obiettivo cambia 2 volte.", Loc.Text(FindingKeys.LensChanged, [2], Italian));
|
|
Assert.Equal("2 exposure changes reached the pixels: each is spread over a smooth transition.", Loc.Text(AdvisorKeys.HolyGrailReceived, [2], English));
|
|
// Advisor windows are measured in tenths of a frame: a fraction takes the plural.
|
|
Assert.Equal("Flicker stays correlated over 1.5 frames: a 7-frame window spans four times that.", Loc.Text(AdvisorKeys.WindowCorrelation, [1.5, 7], English));
|
|
Assert.Equal("Flicker stays correlated over 1 frame: a 5-frame window spans four times that.", Loc.Text(AdvisorKeys.WindowCorrelation, [1.0, 5], English));
|
|
// Keys without a count read as before.
|
|
Assert.Equal("Clouds cover about 42% of the sky on average.", Loc.Text(DeepFindingKeys.Clouds, [42.0], English));
|
|
}
|
|
|
|
[Test]
|
|
public void ASingleExposureChangeHasNoSpacing()
|
|
{
|
|
var frames = Enumerable.Range(0, 20).Select(i => new LightFrame
|
|
{
|
|
Index = i,
|
|
CapturedAt = new DateTime(2026, 6, 1, 20, 0, 0, DateTimeKind.Utc).AddSeconds(10 * i),
|
|
ExposureTime = i < 12 ? 1.0 / 250 : 1.0 / 125,
|
|
FNumber = 8,
|
|
Iso = 100,
|
|
}).ToList();
|
|
var single = LightAnalyzer.Analyze(frames).Findings.Single(f => f.Key == FindingKeys.ExposureStep);
|
|
Assert.SequenceEqual([12], single.Frames);
|
|
Assert.Equal("One exposure change of -1.0 EV.", Loc.Text(single.Key, single.Arguments, English));
|
|
Assert.Equal("Un solo cambio di esposizione di -1,0 EV.", Loc.Text(single.Key, single.Arguments, Italian));
|
|
Assert.DoesNotContain(FindingKeys.ExposureSteps, LightAnalyzer.Analyze(frames).Findings.Select(f => f.Key));
|
|
}
|
|
|
|
[Test]
|
|
public async Task EveryReasonAndFindingOfTheGoldenScenesFormatsInBothLanguages()
|
|
{
|
|
var scenes = new List<(SyntheticFrameSource Source, DeepAnalysisReport? Deep)>
|
|
{
|
|
(new SyntheticFrameSource(DeepScenes.NightSky()), await DeepReports.Night),
|
|
(new SyntheticFrameSource(DeepScenes.NightSky(jitter: 2), 2), await DeepReports.NightJitter),
|
|
(new SyntheticFrameSource(DeepScenes.HolyGrail()), await DeepReports.HolyGrail),
|
|
(new SyntheticFrameSource(DeepScenes.HolyGrail()) { StripExposure = true }, null),
|
|
};
|
|
var rendered = 0;
|
|
foreach (var (source, deep) in scenes)
|
|
{
|
|
var frames = Enumerable.Range(0, source.Count).Select(source.Metadata).ToList();
|
|
var light = LightAnalyzer.Analyze(frames);
|
|
var sequence = new SequenceContext { FrameCount = frames.Count, SourceWidth = 6000, SourceHeight = 4000, MedianExposureSeconds = 1.0 / 250 };
|
|
var result = Advisor.Recommend(light, deep, sequence);
|
|
foreach (var r in result.Recommendations) rendered += Render(r.ReasonKey, [.. r.ReasonArgs]);
|
|
foreach (var f in result.Findings) rendered += Render(f.Key, f.Arguments);
|
|
foreach (var p in SequencePresets.Generate(light, deep, sequence))
|
|
{
|
|
rendered += Render(p.NameKey, [.. p.NameArgs]);
|
|
rendered += Render(p.ReasonKey!, [.. p.ReasonArgs]);
|
|
}
|
|
// Stored reasons (culture-neutral strings) render with the current culture's numbers.
|
|
var applied = Advisor.Apply(new ProjectSettings(), result);
|
|
Assert.DoesNotContain('⟦', Advisor.Explain(applied.Exposure.HolyGrail.ReasonKey!, applied.Exposure.HolyGrail.ReasonArgs));
|
|
}
|
|
context.Log($"{rendered} texts rendered");
|
|
Assert.Greater(rendered, 80);
|
|
}
|
|
|
|
[Test]
|
|
public void StoredNumericArgumentsAreLocalisedWhenExplained()
|
|
{
|
|
var text = Format(Loc.Get(AdvisorKeys.DeflickerOn, Italian)!, Italian, 0.125);
|
|
Assert.Contains("0,125", text);
|
|
Assert.Contains("0.125", Format(Loc.Get(AdvisorKeys.DeflickerOn, English)!, English, 0.125));
|
|
}
|
|
|
|
[Test]
|
|
public async Task PresetsRoundTripAsJsonAndSaveAsUserPresets()
|
|
{
|
|
var source = new SyntheticFrameSource(DeepScenes.NightSky(jitter: 2), 2);
|
|
var frames = Enumerable.Range(0, source.Count).Select(source.Metadata).ToList();
|
|
var presets = SequencePresets.Generate(LightAnalyzer.Analyze(frames), await DeepReports.NightJitter, new SequenceContext { SourceWidth = 6000, SourceHeight = 4000 });
|
|
foreach (var preset in presets)
|
|
{
|
|
var json = preset.ToJson();
|
|
Assert.Equal(json, SequencePreset.FromJson(json).ToJson());
|
|
}
|
|
var user = presets[0].AsUserPreset(" My night ");
|
|
Assert.True(user.IsUser);
|
|
Assert.Equal("My night", user.Name);
|
|
Assert.NotEqual(presets[0].Id, user.Id);
|
|
var restored = SequencePreset.FromJson(user.ToJson());
|
|
Assert.Equal("My night", restored.DisplayName());
|
|
Assert.Equal(presets[0].Settings.ToJson(), restored.Settings.ToJson());
|
|
Assert.Equal(presets[0].ExportPresetId, restored.ExportPresetId);
|
|
}
|
|
|
|
private static int Render(string key, object?[] args)
|
|
{
|
|
foreach (var culture in new[] { English, Italian })
|
|
{
|
|
var text = Loc.Text(key, args, culture);
|
|
Assert.False(text.Contains('⟦'), $"{key} has no {culture.Name} text");
|
|
Assert.False(text.Contains('{'), $"{key} left a placeholder: {text}");
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
private static string Format(string format, CultureInfo culture, params object?[] args) => string.Format(culture, format, args);
|
|
|
|
private static Dictionary<string, string> Entries(ResourceSet set)
|
|
{
|
|
var entries = new Dictionary<string, string>(StringComparer.Ordinal);
|
|
foreach (DictionaryEntry entry in set) entries[(string)entry.Key] = (string)entry.Value!;
|
|
return entries;
|
|
}
|
|
|
|
private static IEnumerable<string> Keys(Type type) =>
|
|
type.GetFields(BindingFlags.Public | BindingFlags.Static).Where(f => f.IsLiteral && f.FieldType == typeof(string) && f.Name != nameof(AdvisorKeys.MissingPrefix)).Select(f => (string)f.GetRawConstantValue()!)
|
|
.Concat(type.GetProperties(BindingFlags.Public | BindingFlags.Static).Where(p => p.PropertyType == typeof(string)).Select(p => (string)p.GetValue(null)!));
|
|
|
|
private static IEnumerable<string> Placeholders(string text) => PlaceholderRegex().Matches(text).Select(m => m.Groups[1].Value).Order();
|
|
|
|
[GeneratedRegex(@"\{(\d+)(?:[,:][^}]*)?\}")]
|
|
private static partial Regex PlaceholderRegex();
|
|
}
|