Merge branch 'review2-p1-fix-release' into claude/owner-review-2-p1

This commit is contained in:
Alby96 committed 2026-10-26 23:40:39 +01:00
commit 5dfd5f93cf
8 files changed
+129 -40

No files matched your search

@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using Chronos.Testing;
using Chronos.Tools.Commands;
@@ -75,6 +76,18 @@ public sealed class ReleaseChannelsCommandTests(TestContext context)
Assert.Equal(Neither, Decide("v2.0.0", """[{"name":"no tag"},{"tag_name":42},{"tag_name":"v3.0.0"},7,null]"""));
}
[Test]
public void EveryPageOfTheListCounts()
{
// Gitea lists 50 releases a page, newest first: 50 pre-releases after v1.0.0 push it to the second page.
var first = Releases([.. Enumerable.Range(1, 50).Reverse().Select(n => $"v1.1.0-rc.{n}")]);
var second = Releases("v1.0.0", "v0.9.0");
Assert.Equal(ImageOnly, Decide("v1.1.0-rc.51", first), "the first page alone shows no stable release");
Assert.Equal(Neither, Decide("v1.1.0-rc.51", first, second));
Assert.Equal(Neither, Decide("v0.9.0", first, second));
Assert.Equal(Both, Decide("v1.1.0", first, second, "[]"));
}
[Test]
public void TheTagCountsAsPublishedWhenTheListIsEmpty()
{
@@ -128,12 +141,39 @@ public sealed class ReleaseChannelsCommandTests(TestContext context)
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--tag", "v1.0.0-rc.01", "--releases", file]));
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--releases", file]));
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--tag", "v1.0.0", "--releases", file + ".missing"]));
// A sign-in page or an API error instead of the list.
// Every page is read: a missing one is refused, not skipped.
Assert.Equal(0, await command.RunAsync(["--tag", "v1.0.0", "--releases", file, "--releases", file]));
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--tag", "v1.0.0", "--releases", file, "--releases", file + ".missing"]));
// A sign-in page or an API error instead of the list, on any page.
Assert.Throws<ToolException>(() => Decide("v1.0.0", "<html>Sign in</html>"));
Assert.Throws<ToolException>(() => Decide("v1.0.0", """{"message":"not found"}"""));
Assert.Throws<ToolException>(() => Decide("v1.0.0", "[]", """{"message":"not found"}"""));
}
private static ReleaseChannels Decide(string tag, string releases) => ReleaseChannelsCommand.Decide(tag, releases);
[Test]
public void TheReleaseWorkflowRefusesTheTagsReleaseChannelsRefuses()
{
// release.yml checks the tag before building, so a tag release-channels would refuse never gets published.
var lines = File.ReadAllLines(Path.Combine(Args.RepoRoot(), ".gitea", "workflows", "release.yml"))
.Select(l => l.Trim()).Where(l => l.StartsWith("semver='", StringComparison.Ordinal) && l.EndsWith('\'')).ToList();
Assert.Count(1, lines);
var check = new Regex(lines[0]["semver='".Length..^1], RegexOptions.CultureInvariant);
string[] tags =
[
"v0.1.0", "v1.2.3", "v10.20.30", "v0.1.0-rc.1", "v1.0.0-alpha.beta", "v1.0.0-0", "v1.0.0-x-y.7z.92", "v1.0.0-rc.1+sha.5",
"v1.0.0+build", "1.0.0", "V1.0.0", "v1.0", "v1.0.0.0", "v01.2.0", "v1.02.0", "v1.2.03", "v1.0.0-", "v1.0.0-rc.",
"v1.0.0-rc..1", "v1.0.0-rc.01", "v1.0.0-rc_1", "latest",
];
foreach (var tag in tags)
{
// Build metadata is refused by the workflow as well: an image tag cannot hold a "+".
var expected = TagVersion.Parse(tag) is not null && !tag.Contains('+', StringComparison.Ordinal);
Assert.Equal(expected, check.IsMatch(tag), tag);
}
}
private static ReleaseChannels Decide(string tag, params string[] releases) => ReleaseChannelsCommand.Decide(tag, releases);
private static string Releases(params string[] tags) => new JsonArray([.. tags.Select(t => Release(t))]).ToJsonString();