From f80fc148bf124ac4404dd6b16f0e5ad526be54dc Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Fri, 23 Oct 2026 14:39:10 +0200 Subject: [PATCH] fix(app): build update links from the releases repository address (#7) Gitea writes a release's html_url and browser_download_url with its ROOT_URL, which on the owner's server is the plain-http LAN address http://192.168.30.23:3000. The update check accepts only https links, so it ignored v0.1.0-rc.1 entirely. The page and download links now come from ChronosReleasesUrl, the address the build names for its users; only the tags, file names and sizes are read from Gitea's answer. The lease renewal test's timer periods follow TestTiming too: on the shared CI host a 100 ms renewal timer came 700 ms late once. Co-Authored-By: Claude Opus 5.5 Co-authored-by: Alberto Balbo --- docs/BRIEF.md | 3 +- docs/CHANGELOG.md | 5 ++ docs/DECISIONS.md | 3 +- src/Chronos.App/About/UpdateCheck.cs | 47 +++++++++++++------ src/Chronos.App/Infrastructure/AppServices.cs | 2 +- .../About/UpdateCheckTests.cs | 25 ++++++++++ .../Archiving/LeaseFileTests.cs | 8 ++-- 7 files changed, 73 insertions(+), 20 deletions(-) diff --git a/docs/BRIEF.md b/docs/BRIEF.md index a49f0ca3..7a181027 100644 --- a/docs/BRIEF.md +++ b/docs/BRIEF.md @@ -1134,7 +1134,8 @@ for HEIC/RAW so the server can render without a node. repository** (§19.4), `/api/v1/repos///releases?draft=false&pre-release=false`, takes the highest version (a pre-release build is offered the final release of its own version; a 404, a repository the client cannot see, is a failed check, not "up to date"), - and shows a one-line notice with "Download" (P1: download + builds the release page and download links from `ChronosReleasesUrl` (Gitea writes its own + with its ROOT_URL, which clients may not reach), and shows a one-line notice with "Download" (P1: download installer, verify SHA-256 from `SHA256SUMS`, run it). The repository is the build property `ChronosReleasesUrl` (default `https://gitea.encke-hake.ts.net/BalboSoft/Chronos`), which also gives the licence link (`/src/branch/main/EULA.md`), the issues diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a3b7ec87..420c115b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,11 @@ commits follow Conventional Commits (release notes are generated from them by `C ## [Unreleased] +### Fixed +- Update check: the release page and the download links come from the repository address the build names + (`ChronosReleasesUrl`), not from Gitea's answer, whose links use Gitea's ROOT_URL; with the owner's plain-http LAN + ROOT_URL every release was ignored (the check accepts only https links). + ## [0.1.0-rc.1] — 2026-10-23 First pre-release, built and published by Gitea Actions. diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 254f5b46..9016cf49 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -427,4 +427,5 @@ One line per decision: date · decision · alternative · reason. | 2026-10-23 | The server image is built for linux/amd64 only and pushed to the Gitea container registry (`//chronos-server`) with the `REGISTRY_TOKEN` secret; `:latest` moves only to the highest stable version among the published releases, read back after publishing. The workflow's own token is refused by the organisation's registry (measured), so without the secret the image job fails with instructions while the release itself is already published. (R3.) | Multi-arch with QEMU; fail the whole release | Multi-arch needs QEMU's binfmt handlers installed on the owner's host, a change to the host outside the repository; the Windows programs should not wait on a registry credential. | | 2026-10-23 | The Windows-only CI (Core.Windows and App tests, screenshots and their diff, the installer test) is the `windows` job, run only when the repository variable `WINDOWS_RUNNER` names a Windows act_runner in host mode; until then those tests run on a Windows PC before a merge. The Definition of Done says so (CLAUDE.md, BRIEF Appendix A). (R3.) | Drop them; fail CI without a Windows runner | They are the only automatic proof of the installer and the screens; a job that waits for a runner that does not exist would hold every run. | | 2026-10-23 | Update check: the client reads the published stable releases and takes the highest version, because Gitea's `releases/latest` is the most recently created release (a re-published older tag or a backport would become it); a pre-release build (`0.1.0-rc.1`) is offered the final release of its own version, which it used to call "up to date" forever; a 404 is a failed check, because Gitea answers 404 for a repository the client may not see (the `BalboSoft` organisation is private today) and that used to read as "up to date". The release workflow picks `:latest` the same way. `gitea-release` checks every file's size before it publishes, and when it replaces the files of a release clients can already see it removes the old `SHA256SUMS` first and uploads the new one last. (R2, R3; independent review of this change.) | Trust `releases/latest`; leave the pre-release rule as it was | The first release is a pre-release: its testers must be told when 0.1.0 is out; a download checked against the checksums of another build would be refused. | -| 2026-10-23 | Timed tests (bulk insert, JPEG and RAW decode, resampler, light analysis, metadata robustness, scroll smoke) take their budget from `TestTiming.Budget`, stretched by `CHRONOS_TEST_TIME_FACTOR` (at least 1, default 1); ci.yml and release.yml set 3, perf.yml nothing. On the owner's runner, which shares its CPU and disks with Gitea and the server's other containers, the 100k-frame SQLite bulk insert took 10–19 s against 15 s from one run to the next. (R3.) | Raise the budgets; move the timed tests to perf.yml | The budgets stay what a developer's PC must meet and the weekly performance gates measure them unstretched; a CI run fails on a real regression, not on a busy host. | +| 2026-10-23 | Timed tests (bulk insert, JPEG and RAW decode, resampler, light analysis, metadata robustness, scroll smoke, and the lease renewal test's timer periods) take their budget from `TestTiming.Budget`, stretched by `CHRONOS_TEST_TIME_FACTOR` (at least 1, default 1); ci.yml and release.yml set 3, perf.yml nothing. On the owner's runner, which shares its CPU and disks with Gitea and the server's other containers, the 100k-frame SQLite bulk insert took 10–19 s against 15 s from one run to the next. (R3.) | Raise the budgets; move the timed tests to perf.yml | The budgets stay what a developer's PC must meet and the weekly performance gates measure them unstretched; a CI run fails on a real regression, not on a busy host. | +| 2026-10-23 | The update check builds the release page (`/releases/tag/`) and the download links (`/releases/download//`) from `ChronosReleasesUrl` and takes only the tags, names and sizes from Gitea's answer: Gitea writes `html_url` and `browser_download_url` with its ROOT_URL, the owner's being `http://192.168.30.23:3000`, so the first release's links were plain http on a LAN address and the https-only check ignored the release. Without a repository address (tests) the answer's links are used as before. (R2, after the first release.) | Ask the owner to set ROOT_URL to the public https name | The build already names the address its users reach; the client then works whatever Gitea's ROOT_URL is, and a ROOT_URL change stays the owner's choice. | diff --git a/src/Chronos.App/About/UpdateCheck.cs b/src/Chronos.App/About/UpdateCheck.cs index e64193b0..f6407010 100644 --- a/src/Chronos.App/About/UpdateCheck.cs +++ b/src/Chronos.App/About/UpdateCheck.cs @@ -16,7 +16,10 @@ public sealed record ReleaseAsset(string Name, string DownloadUrl, long Size); /// /// Update check against the Gitea releases API of the releases repository (BRIEF §18, §19.4, amended 2026-10-23, R2): /// reads the published stable releases, takes the highest version (Gitea's own "latest" is the most recently created -/// one, which a re-published older tag or a backport would become), and compares it with the running version. +/// one, which a re-published older tag or a backport would become), and compares it with the running version. The +/// release page and download links are built from the repository address the build names (ChronosReleasesUrl), not +/// taken from the answer: Gitea writes its links with its ROOT_URL, which may be an address clients cannot reach +/// (the owner's is a plain-http LAN address). /// public static class UpdateCheck { @@ -35,30 +38,36 @@ public static class UpdateCheck /// /// The newest release of a releases-list response (an array: the highest version wins) or of one release object; - /// null when there is none. Drafts, pre-releases, unparsable tags and pages without an https link are skipped, and - /// so are assets without an https download link. + /// null when there is none. With ("https://host/owner/name"), the release page and + /// the download links are that repository's (/releases/tag/<tag>, /releases/download/<tag>/<name>); + /// without it, the ones in the answer. Drafts, pre-releases, unparsable tags and pages without an https link are + /// skipped, and so are assets without an https download link. /// - public static ReleaseInfo? Parse(string json) + public static ReleaseInfo? Parse(string json, string? repository = null) { + var baseUrl = repository?.Trim().TrimEnd('/'); using var document = JsonDocument.Parse(json); var root = document.RootElement; return root.ValueKind switch { - JsonValueKind.Array => root.EnumerateArray().Select(ParseRelease).OfType().MaxBy(r => r.Version), - JsonValueKind.Object => ParseRelease(root), + JsonValueKind.Array => root.EnumerateArray().Select(r => ParseRelease(r, baseUrl)).OfType().MaxBy(r => r.Version), + JsonValueKind.Object => ParseRelease(root, baseUrl), _ => null, }; } - private static ReleaseInfo? ParseRelease(JsonElement root) + private static ReleaseInfo? ParseRelease(JsonElement root, string? repository) { if (root.ValueKind != JsonValueKind.Object) return null; if (Flag(root, "draft") || Flag(root, "prerelease")) return null; var tag = root.TryGetProperty("tag_name", out var t) && t.ValueKind == JsonValueKind.String ? t.GetString() : null; - var url = root.TryGetProperty("html_url", out var u) && u.ValueKind == JsonValueKind.String ? u.GetString() : null; var version = ParseVersion(tag); - if (version is null || tag is null || url is null || !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) return null; - return new ReleaseInfo(version, tag, url) { Assets = ParseAssets(root) }; + if (version is null || tag is null) return null; + var url = repository is not null + ? $"{repository}/releases/tag/{Uri.EscapeDataString(tag)}" + : root.TryGetProperty("html_url", out var u) && u.ValueKind == JsonValueKind.String ? u.GetString() : null; + if (url is null || !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) return null; + return new ReleaseInfo(version, tag, url) { Assets = ParseAssets(root, repository, tag) }; } /// @@ -91,7 +100,15 @@ public static class UpdateCheck /// that is a failed check, never "up to date". /// /// The request failed, or the repository was not found. - public static async Task FetchAsync(HttpClient http, string apiUrl, string userAgentVersion, CancellationToken ct) + public static Task FetchAsync(HttpClient http, string apiUrl, string userAgentVersion, CancellationToken ct) => + FetchAsync(http, apiUrl, null, userAgentVersion, ct); + + /// + /// As , with the release page and download + /// links built from (see ). + /// + /// The request failed, or the repository was not found. + public static async Task FetchAsync(HttpClient http, string apiUrl, string? repository, string userAgentVersion, CancellationToken ct) { using var request = new HttpRequestMessage(HttpMethod.Get, apiUrl); request.Headers.UserAgent.Add(new ProductInfoHeaderValue("Chronos", userAgentVersion)); @@ -103,7 +120,7 @@ public static class UpdateCheck var json = await response.Content.ReadAsStringAsync(ct).ConfigureAwait(false); try { - return Parse(json); + return Parse(json, repository); } catch (JsonException) { @@ -111,7 +128,7 @@ public static class UpdateCheck } } - private static List ParseAssets(JsonElement root) + private static List ParseAssets(JsonElement root, string? repository, string tag) { var assets = new List(); if (!root.TryGetProperty("assets", out var list) || list.ValueKind != JsonValueKind.Array) return assets; @@ -119,7 +136,9 @@ public static class UpdateCheck { if (a.ValueKind != JsonValueKind.Object) continue; var name = a.TryGetProperty("name", out var n) && n.ValueKind == JsonValueKind.String ? n.GetString() : null; - var link = a.TryGetProperty("browser_download_url", out var d) && d.ValueKind == JsonValueKind.String ? d.GetString() : null; + var link = repository is not null && !string.IsNullOrEmpty(name) + ? $"{repository}/releases/download/{Uri.EscapeDataString(tag)}/{Uri.EscapeDataString(name)}" + : a.TryGetProperty("browser_download_url", out var d) && d.ValueKind == JsonValueKind.String ? d.GetString() : null; var size = a.TryGetProperty("size", out var z) && z.ValueKind == JsonValueKind.Number && z.TryGetInt64(out var bytes) ? bytes : -1; if (string.IsNullOrEmpty(name) || link is null || !link.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) continue; assets.Add(new ReleaseAsset(name, link, size)); diff --git a/src/Chronos.App/Infrastructure/AppServices.cs b/src/Chronos.App/Infrastructure/AppServices.cs index 2bdf1777..a2f01164 100644 --- a/src/Chronos.App/Infrastructure/AppServices.cs +++ b/src/Chronos.App/Infrastructure/AppServices.cs @@ -71,7 +71,7 @@ public sealed class AppServices : IAsyncDisposable Server = new ServerSession(settings, saveSettings, new ChronosServerApiFactory(), new DpapiTokenProtector()); Encoders = new MediaFoundationInventory(); Formats = new WicFormatInventory(() => _wic); - CheckForUpdateAsync = ct => UpdateCheck.FetchAsync(Http.Value, ProductLinks.StableReleasesApi, VersionText, ct); + CheckForUpdateAsync = ct => UpdateCheck.FetchAsync(Http.Value, ProductLinks.StableReleasesApi, ProductLinks.Repository, VersionText, ct); DownloadUpdateAsync = (release, progress, ct) => UpdateDownload.DownloadAsync(DownloadHttp.Value, release, environment.IsPortable, UpdateDownload.Root(Path.GetTempPath()), VersionText, progress, UpdateDownload.IdleTimeout, ct); diff --git a/tests/Chronos.App.Tests/About/UpdateCheckTests.cs b/tests/Chronos.App.Tests/About/UpdateCheckTests.cs index 1c05855d..947d9879 100644 --- a/tests/Chronos.App.Tests/About/UpdateCheckTests.cs +++ b/tests/Chronos.App.Tests/About/UpdateCheckTests.cs @@ -82,6 +82,31 @@ public sealed class UpdateCheckTests await Assert.ThrowsAsync(() => UpdateCheck.FetchAsync(broken, Api, "0.1.0", CancellationToken.None)); } + [Test] + public async Task LinksComeFromTheRepositoryAddressNotFromGiteasRootUrl() + { + // The owner's Gitea writes its links with its ROOT_URL, a plain-http LAN address clients cannot use. + const string json = """ + [ { "tag_name": "v1.0.0", "html_url": "http://192.168.30.23:3000/BalboSoft/Chronos/releases/tag/v1.0.0", + "assets": [ { "name": "Chronos-Setup-1.0.0.exe", "size": 5, "browser_download_url": "http://192.168.30.23:3000/BalboSoft/Chronos/releases/download/v1.0.0/Chronos-Setup-1.0.0.exe" }, + { "name": "Read me.txt", "size": 2, "browser_download_url": "http://192.168.30.23:3000/x" } ] } ] + """; + Assert.Null(UpdateCheck.Parse(json)); + + var release = UpdateCheck.Parse(json, "https://gitea.example/BalboSoft/Chronos/")!; + Assert.Equal("https://gitea.example/BalboSoft/Chronos/releases/tag/v1.0.0", release.PageUrl); + Assert.SequenceEqual( + ["https://gitea.example/BalboSoft/Chronos/releases/download/v1.0.0/Chronos-Setup-1.0.0.exe", + "https://gitea.example/BalboSoft/Chronos/releases/download/v1.0.0/Read%20me.txt"], + release.Assets.Select(a => a.DownloadUrl)); + Assert.Equal(5L, release.Assets[0].Size); + Assert.Null(UpdateCheck.Parse(json, "http://gitea.example/BalboSoft/Chronos")); + + using var ok = new HttpClient(new Reply(HttpStatusCode.OK, json)); + var fetched = await UpdateCheck.FetchAsync(ok, Api, "https://gitea.example/BalboSoft/Chronos", "0.1.0", CancellationToken.None); + Assert.Equal("https://gitea.example/BalboSoft/Chronos/releases/tag/v1.0.0", fetched!.PageUrl); + } + [Test] public async Task ARepositoryThatCannotBeSeenIsAFailedCheckNotUpToDate() { diff --git a/tests/Chronos.Core.Tests/Archiving/LeaseFileTests.cs b/tests/Chronos.Core.Tests/Archiving/LeaseFileTests.cs index e0980c2d..9280b5e5 100644 --- a/tests/Chronos.Core.Tests/Archiving/LeaseFileTests.cs +++ b/tests/Chronos.Core.Tests/Archiving/LeaseFileTests.cs @@ -66,12 +66,14 @@ public sealed class LeaseFileTests(TestContext context) public async Task AHeldLeaseIsRenewedPastItsDuration() { var locks = context.CreateTempDirectory(); - using var lease = LeaseFile.TryAcquire(locks, "seq-1", "server", TimeSpan.FromMilliseconds(300)); + // Renewals run on timers: a busy CI host delays them, so the lease's duration stretches with the time budgets. + var duration = TimeSpan.FromSeconds(TestTiming.Budget(0.3)); + using var lease = LeaseFile.TryAcquire(locks, "seq-1", "server", duration); Assert.NotNull(lease); - await Task.Delay(900); + await Task.Delay(duration * 3); Assert.True(lease.IsHeld); Assert.Greater((LeaseFile.Read(lease.Path)!.Expires - DateTimeOffset.UtcNow).TotalMilliseconds, 0); - Assert.Null(LeaseFile.TryAcquire(locks, "seq-1", "client", TimeSpan.FromMilliseconds(300))); + Assert.Null(LeaseFile.TryAcquire(locks, "seq-1", "client", duration)); } [Test]