Files
Chronos/tests/Chronos.App.Tests/About/UpdateCheckTests.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
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 and the system SQLite. 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; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

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>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

125 lines
6.4 KiB
C#

using System.Net;
using System.Net.Http;
using System.Text;
using Chronos.App.About;
using Chronos.App.Infrastructure;
using Chronos.Testing;
namespace Chronos.App.Tests.About;
public sealed class UpdateCheckTests
{
[Theory]
[Case("v1.2.3", "1.2.3")]
[Case("1.2", "1.2.0")]
[Case("V0.10.0-beta.2", "0.10.0")]
[Case("v2.0.1+abc", "2.0.1")]
public void TagsParseToVersions(string tag, string expected) =>
Assert.Equal(Version.Parse(expected), UpdateCheck.ParseVersion(tag));
[Theory]
[Case(new object?[] { null })]
[Case("")]
[Case("latest")]
[Case("v-one")]
public void OtherTagsAreIgnored(string? tag) => Assert.Null(UpdateCheck.ParseVersion(tag));
[Test]
public void TheLatestReleaseIsComparedWithTheRunningVersion()
{
var release = UpdateCheck.Parse("""{ "tag_name": "v0.2.0", "html_url": "https://gitea.example/o/r/releases/tag/v0.2.0", "draft": false, "prerelease": false }""");
Assert.NotNull(release);
Assert.Equal(new Version(0, 2, 0), release!.Version);
Assert.True(UpdateCheck.IsNewer(release, UpdateCheck.RunningVersion("0.1.0")));
Assert.False(UpdateCheck.IsNewer(release, UpdateCheck.RunningVersion("0.2.0+local")));
Assert.False(UpdateCheck.IsNewer(release, new Version(0, 2, 0, 0)));
Assert.False(UpdateCheck.IsNewer(release, UpdateCheck.RunningVersion("1.0.0")));
Assert.Equal("0.2.0", UpdateCheck.Display(release.Version));
}
[Test]
public void APreReleaseBuildIsOfferedTheFinalReleaseOfItsVersion()
{
var final = UpdateCheck.Parse("""{ "tag_name": "v0.1.0", "html_url": "https://gitea.example/o/r/releases/tag/v0.1.0" }""")!;
Assert.True(UpdateCheck.IsPrerelease("0.1.0-rc.1"));
Assert.True(UpdateCheck.IsPrerelease("v0.1.0-beta+abc"));
Assert.False(UpdateCheck.IsPrerelease("0.1.0+abc-def"));
Assert.False(UpdateCheck.IsPrerelease("0.1.0"));
Assert.True(UpdateCheck.IsNewer(final, UpdateCheck.RunningVersion("0.1.0-rc.1"), UpdateCheck.IsPrerelease("0.1.0-rc.1")));
Assert.False(UpdateCheck.IsNewer(final, UpdateCheck.RunningVersion("0.1.0"), UpdateCheck.IsPrerelease("0.1.0")));
Assert.False(UpdateCheck.IsNewer(final, UpdateCheck.RunningVersion("0.2.0-rc.1"), UpdateCheck.IsPrerelease("0.2.0-rc.1")));
}
[Test]
public void DraftsPrereleasesAndOddLinksAreIgnored()
{
Assert.Null(UpdateCheck.Parse("""{ "tag_name": "v9.0.0", "html_url": "https://x", "prerelease": true }"""));
Assert.Null(UpdateCheck.Parse("""{ "tag_name": "v9.0.0", "html_url": "https://x", "draft": true }"""));
Assert.Null(UpdateCheck.Parse("""{ "tag_name": "v9.0.0", "html_url": "javascript:alert(1)" }"""));
Assert.Null(UpdateCheck.Parse("""{ "html_url": "https://x" }"""));
Assert.Null(UpdateCheck.Parse("[]"));
}
[Test]
public async Task FetchReadsTheApiAndToleratesMissingReleases()
{
// Gitea lists the most recently created first: a re-published 0.9.0 must not hide 1.0.0.
using var ok = new HttpClient(new Reply(HttpStatusCode.OK, """
[ { "tag_name": "v0.9.0", "html_url": "https://gitea.example/o/r/releases/tag/v0.9.0" },
{ "tag_name": "v1.0.0", "html_url": "https://gitea.example/o/r/releases/tag/v1.0.0" },
{ "tag_name": "v2.0.0", "html_url": "https://gitea.example/o/r/releases/tag/v2.0.0", "prerelease": true } ]
"""));
var release = await UpdateCheck.FetchAsync(ok, Api, "0.1.0", CancellationToken.None);
Assert.Equal(new Version(1, 0, 0), release!.Version);
using var none = new HttpClient(new Reply(HttpStatusCode.OK, "[]"));
Assert.Null(await UpdateCheck.FetchAsync(none, Api, "0.1.0", CancellationToken.None));
using var garbage = new HttpClient(new Reply(HttpStatusCode.OK, "<html>"));
Assert.Null(await UpdateCheck.FetchAsync(garbage, Api, "0.1.0", CancellationToken.None));
using var broken = new HttpClient(new Reply(HttpStatusCode.InternalServerError, "{}"));
await Assert.ThrowsAsync<HttpRequestException>(() => UpdateCheck.FetchAsync(broken, Api, "0.1.0", CancellationToken.None));
}
[Test]
public async Task ARepositoryThatCannotBeSeenIsAFailedCheckNotUpToDate()
{
using var hidden = new HttpClient(new Reply(HttpStatusCode.NotFound, """{ "message": "not found" }"""));
var error = await Assert.ThrowsAsync<HttpRequestException>(() => UpdateCheck.FetchAsync(hidden, Api, "0.1.0", CancellationToken.None));
Assert.Equal(HttpStatusCode.NotFound, error.StatusCode);
}
private const string Api = "https://gitea.example/api/v1/repos/o/r/releases?draft=false&pre-release=false&limit=50";
[Theory]
[Case("https://gitea.example/BalboSoft/Chronos", "https://gitea.example/api/v1/repos/BalboSoft/Chronos/releases?draft=false&pre-release=false&limit=50")]
[Case("https://example.org:8443/git/BalboSoft/Chronos", "https://example.org:8443/git/api/v1/repos/BalboSoft/Chronos/releases?draft=false&pre-release=false&limit=50")]
public void TheReleasesAreAskedOfTheGiteaApiOfTheRepository(string repository, string expected) =>
Assert.Equal(expected, ProductLinks.StableReleasesApiOf(repository));
[Theory]
[Case(" https://gitea.example/o/r/ ", "https://gitea.example/o/r")]
[Case("https://gitea.example/o/r.git", "https://gitea.example/o/r")]
[Case("", null)]
public void TheReleasesRepositoryAddressIsNormalised(string address, string? expected) =>
Assert.Equal(expected, ProductLinks.Normalise(address));
[Test]
public void LocalBuildsLinkTheRepositoryTheBuildPropertiesName()
{
Assert.Equal(ProductLinks.DefaultRepository, ProductLinks.Repository);
Assert.Equal(ProductLinks.DefaultRepository + "/src/branch/main/EULA.md", ProductLinks.Licence);
Assert.Throws<ArgumentException>(() => ProductLinks.StableReleasesApiOf("https://gitea.example/only-owner"));
}
private sealed class Reply(HttpStatusCode status, string body) : HttpMessageHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Assert.True(request.Headers.UserAgent.ToString().StartsWith("Chronos/", StringComparison.Ordinal), "the update requests identify the program");
return Task.FromResult(new HttpResponseMessage(status) { Content = new StringContent(body, Encoding.UTF8, "application/json") });
}
}
}