From 93cd4dc4fdb8b41b2c209d01803b41bc9da2d4a7 Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Sun, 22 Nov 2026 23:54:13 +0800 Subject: [PATCH 1/2] Connect push packets to update reporting Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/core-execution-flow.md | 18 +++ .../Configuration/AbstractBootstrap.cs | 9 ++ .../Configuration/PushPayload.cs | 13 +++ .../Download/DownloadPlanBuilder.cs | 10 ++ .../Download/Sources/PushDownloadSource.cs | 71 ++++++++++++ .../Strategy/AbstractStrategy.cs | 1 + .../Strategy/ClientStrategy.cs | 10 ++ .../Strategy/UpdateStrategy.cs | 2 + .../Download/PushDownloadSourceTests.cs | 86 ++++++++++++++ tests/CoreTest/Strategy/ReportRoutingTests.cs | 105 ++++++++++++++++++ 10 files changed, 325 insertions(+) create mode 100644 src/GeneralUpdate.Core/Download/Sources/PushDownloadSource.cs create mode 100644 tests/CoreTest/Download/PushDownloadSourceTests.cs diff --git a/docs/core-execution-flow.md b/docs/core-execution-flow.md index c7d21660..09059654 100644 --- a/docs/core-execution-flow.md +++ b/docs/core-execution-flow.md @@ -39,6 +39,24 @@ sidebar_position: 4 ## 1. 架构总览 +### SignalR 推送的宿主接入 + +`UpgradeHubService.AddListenerReceive` 接收服务端 `ReceiveMessage` 的单个字符串参数。 +宿主可先用 `JsonSerializer.Deserialize(message, PushPayloadJsonContext.Default.PushPayload)` +检查 `ProductId`、`Platform`、包格式、来源和适用版本,再为每次推送单独创建 +`new PushDownloadSource(message)`,以 `.DownloadSource(source)` 注册到本次 +`GeneralUpdateBootstrap`(或设置 `ClientStrategy.DownloadSource`)。不要与轮询结果混合: +推送源使用消息中的 `RecordId`,自动选择报告类型 2,并随 IPC 传给 Upgrade 进程。 +老服务端未提供 ID 时仍可处理包,但不会发送记录回执;不会用 Verification 的 ID 代替。 +无效的 AppType、URL 或版本信息会被拒绝。宿主负责连接生命周期、异步调度、 +避免并发升级,以及验证推送包是否适合当前安装(包括差分包的前置版本)。 + +下载沿用 `HttpDownloadExecutor` 的全局认证和额外请求头;本地文件服务的租户包需要宿主 +配置 `X-Tenant-Id`,例如在 `UpdateRequest.CustomHeaders` 中配置。报告请求也使用这些头。 +这些配置是进程级的,宿主必须限制可信下载地址、隔离租户并避免向不可信 URL 泄露凭据; +签名 OBS URL 不代表本地文件服务无需租户认证。消息内的 `Format` 不会自动改变客户端 +配置,宿主应确保包格式与配置的 `Option.Format` 一致。实际 HTTP/数据库链路仍需部署环境验证。 + ### 1.1 三层架构 GeneralUpdate.Core 采用**三层调度 + 两层引擎**的设计: diff --git a/src/GeneralUpdate.Core/Configuration/AbstractBootstrap.cs b/src/GeneralUpdate.Core/Configuration/AbstractBootstrap.cs index 7165d88f..bd3d748e 100644 --- a/src/GeneralUpdate.Core/Configuration/AbstractBootstrap.cs +++ b/src/GeneralUpdate.Core/Configuration/AbstractBootstrap.cs @@ -245,11 +245,20 @@ protected T GetOption(Option? option) /// public TBootstrap DownloadSource() where T : Download.Abstractions.IDownloadSource, new() { + _instances.Remove(typeof(Download.Abstractions.IDownloadSource)); _extensions[typeof(Download.Abstractions.IDownloadSource)] = typeof(T); _extensionFactories[typeof(Download.Abstractions.IDownloadSource)] = () => new T(); return (TBootstrap)this; } + /// Registers a pre-constructed download source for this update. + public TBootstrap DownloadSource(Download.Abstractions.IDownloadSource source) + { + _instances[typeof(Download.Abstractions.IDownloadSource)] = + source ?? throw new ArgumentNullException(nameof(source)); + return (TBootstrap)this; + } + /// /// Registers a custom post-download processing pipeline for performing hash verification, /// decryption, virus scanning, or other post-processing on downloaded files. diff --git a/src/GeneralUpdate.Core/Configuration/PushPayload.cs b/src/GeneralUpdate.Core/Configuration/PushPayload.cs index 09d621b9..39b85209 100644 --- a/src/GeneralUpdate.Core/Configuration/PushPayload.cs +++ b/src/GeneralUpdate.Core/Configuration/PushPayload.cs @@ -8,6 +8,19 @@ namespace GeneralUpdate.Core.Configuration; /// public class PushPayload : VersionIdentity { + /// Push record identifier, absent when sent by older servers. + [JsonPropertyName("RecordId")] + public int? RecordId { get; set; } + + [JsonPropertyName("Size")] + public long Size { get; set; } + + [JsonPropertyName("PackageType")] + public int PackageType { get; set; } + + [JsonPropertyName("Format")] + public string? Format { get; set; } + [JsonPropertyName("IsForcibly")] public bool? IsForcibly { get; set; } diff --git a/src/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs b/src/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs index 1176a43d..37a800f8 100644 --- a/src/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs +++ b/src/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs @@ -180,6 +180,16 @@ public static DownloadPlan Build( .Where(a => a.PackageType == (int)Configuration.PackageType.Full) .ToList(); + if (chainCandidates.Count == 0 && fullCandidates.Count > 0) + { + var latestFulls = fullCandidates + .GroupBy(a => a.AppType) + .Select(g => g.OrderByDescending(a => Lookup(a)).First()) + .OrderBy(a => Lookup(a)) + .ToList(); + return new DownloadPlan(latestFulls, isForcibly); + } + // ── Chain vs Full: count-first heuristic ── if (chainCandidates.Count > 0 && fullCandidates.Count > 0) { diff --git a/src/GeneralUpdate.Core/Download/Sources/PushDownloadSource.cs b/src/GeneralUpdate.Core/Download/Sources/PushDownloadSource.cs new file mode 100644 index 00000000..d7ca1586 --- /dev/null +++ b/src/GeneralUpdate.Core/Download/Sources/PushDownloadSource.cs @@ -0,0 +1,71 @@ +using System; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using GeneralUpdate.Core.Configuration; +using GeneralUpdate.Core.Download.Abstractions; +using GeneralUpdate.Core.Download.Models; +using GeneralUpdate.Core.JsonContext; + +namespace GeneralUpdate.Core.Download.Sources; + +/// +/// A single GeneralSpace SignalR packet, used as the source for one push-triggered update. +/// +public sealed class PushDownloadSource : IDownloadSource +{ + private readonly DownloadAsset _asset; + + /// + /// Parses the single JSON string delivered to the ReceiveMessage listener. + /// The packet must identify its application type, URL and version; a missing push + /// record ID is supported for older servers but cannot be reported. + /// + public PushDownloadSource(string message) + { + if (message == null) throw new ArgumentNullException(nameof(message)); + var packet = JsonSerializer.Deserialize(message, PushPayloadJsonContext.Default.PushPayload) + ?? throw new JsonException("The push packet must not be null."); + if (packet.AppType != (int)AppType.Client && packet.AppType != (int)AppType.Upgrade) + throw new JsonException("The push packet must specify a Client or Upgrade AppType."); + if (string.IsNullOrWhiteSpace(packet.Url) || string.IsNullOrWhiteSpace(packet.Version)) + throw new JsonException("The push packet must include a download URL and version."); + if (packet.RecordId < 0 || packet.Size < 0 || packet.PackageType < 0 || packet.PackageType > 2) + throw new JsonException("The push packet contains invalid record, size or package type values."); + + var name = string.IsNullOrWhiteSpace(packet.Name) ? packet.Version! : packet.Name!; + if (name.EndsWith(Format.Zip.ToExtension(), StringComparison.OrdinalIgnoreCase)) + name = name.Substring(0, name.Length - Format.Zip.ToExtension().Length); + if (string.IsNullOrWhiteSpace(name) || name == "." || name == ".." || + name.IndexOf('/') >= 0 || name.IndexOf('\\') >= 0 || + name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) + throw new JsonException("The push packet contains an invalid package name."); + + if (!packet.RecordId.HasValue || packet.RecordId == 0) + GeneralTracer.Warn("PushDownloadSource: no push record ID; update status cannot be reported."); + + _asset = new DownloadAsset( + Name: name, + Url: packet.Url!, + Size: packet.Size, + SHA256: packet.Hash, + Version: packet.Version!, + PackageType: packet.PackageType, + IsForcibly: packet.IsForcibly == true, + IsFreeze: packet.IsFreeze == true, + RecordId: packet.RecordId ?? 0, + AppType: packet.AppType); + } + + public Task ListAsync(CancellationToken token = default) + { + token.ThrowIfCancellationRequested(); + return Task.FromResult(new DownloadSourceResult + { + Assets = new[] { _asset }, + HasMainUpdate = _asset.AppType == (int)AppType.Client, + HasUpgradeUpdate = _asset.AppType == (int)AppType.Upgrade + }); + } +} diff --git a/src/GeneralUpdate.Core/Strategy/AbstractStrategy.cs b/src/GeneralUpdate.Core/Strategy/AbstractStrategy.cs index 5a837937..97b2bbbc 100644 --- a/src/GeneralUpdate.Core/Strategy/AbstractStrategy.cs +++ b/src/GeneralUpdate.Core/Strategy/AbstractStrategy.cs @@ -284,6 +284,7 @@ public virtual async Task ExecuteAsync() foreach (var record in recordStatuses) { + if (_configinfo.ReportType == 2 && record.Key <= 0) continue; try { await Reporter.ReportAsync(new UpdateReport(record.Key, record.Value, _configinfo.ReportType)).ConfigureAwait(false); diff --git a/src/GeneralUpdate.Core/Strategy/ClientStrategy.cs b/src/GeneralUpdate.Core/Strategy/ClientStrategy.cs index e8fe5da6..5cc33c79 100644 --- a/src/GeneralUpdate.Core/Strategy/ClientStrategy.cs +++ b/src/GeneralUpdate.Core/Strategy/ClientStrategy.cs @@ -433,6 +433,12 @@ private async Task ExecuteStandardWorkflowAsync() _configInfo.BasicUsername, _configInfo.BasicPassword); + if (downloadSource is Download.Sources.PushDownloadSource) + { + _reportType = 2; + _configInfo.ReportType = 2; + } + // Call server validation — returns assets from the two Validate calls var sourceResult = await downloadSource.ListAsync().ConfigureAwait(false); @@ -1130,6 +1136,7 @@ private async Task SafeOnDownloadCompletedAsync(Hooks.HookContext ctx) /// The update context. private async Task SafeReportUpdateStartedAsync(Hooks.HookContext ctx) { + if (_reportType == 2 && _mainRecordId <= 0 && _upgradeRecordId <= 0) return; try { await Reporter @@ -1148,6 +1155,7 @@ await Reporter /// The update context. private async Task SafeReportDownloadCompletedAsync(Hooks.HookContext ctx) { + if (_reportType == 2 && _mainRecordId <= 0 && _upgradeRecordId <= 0) return; try { await Reporter @@ -1167,6 +1175,7 @@ await Reporter /// The exception that caused the update to fail. private async Task SafeReportUpdateFailedAsync(Hooks.HookContext ctx, Exception error) { + if (_reportType == 2 && _mainRecordId <= 0 && _upgradeRecordId <= 0) return; try { await Reporter @@ -1185,6 +1194,7 @@ await Reporter /// The update context. private async Task SafeReportUpdateAppliedAsync(Hooks.HookContext ctx, int recordId) { + if (_reportType == 2 && recordId <= 0) return; try { await Reporter diff --git a/src/GeneralUpdate.Core/Strategy/UpdateStrategy.cs b/src/GeneralUpdate.Core/Strategy/UpdateStrategy.cs index e84e37d5..6f8e446d 100644 --- a/src/GeneralUpdate.Core/Strategy/UpdateStrategy.cs +++ b/src/GeneralUpdate.Core/Strategy/UpdateStrategy.cs @@ -261,6 +261,7 @@ private async Task SafeReportUpdateAppliedAsync(Hooks.HookContext ctx) try { var recordId = _configInfo?.UpdateVersions?.FirstOrDefault()?.RecordId ?? 0; + if (_reportType == 2 && recordId <= 0) return; await Reporter .ReportAsync(new Download.Reporting.UpdateReport(recordId, (int)Download.Reporting.UpdateStatus.Success, _reportType)).ConfigureAwait(false); @@ -276,6 +277,7 @@ private async Task SafeReportUpdateFailedAsync(Hooks.HookContext ctx, Exception try { var recordId = _configInfo?.UpdateVersions?.FirstOrDefault()?.RecordId ?? 0; + if (_reportType == 2 && recordId <= 0) return; await Reporter .ReportAsync(new Download.Reporting.UpdateReport(recordId, (int)Download.Reporting.UpdateStatus.Failure, _reportType)).ConfigureAwait(false); diff --git a/tests/CoreTest/Download/PushDownloadSourceTests.cs b/tests/CoreTest/Download/PushDownloadSourceTests.cs new file mode 100644 index 00000000..df5d3e51 --- /dev/null +++ b/tests/CoreTest/Download/PushDownloadSourceTests.cs @@ -0,0 +1,86 @@ +using GeneralUpdate.Core.Configuration; +using GeneralUpdate.Core.Download; +using GeneralUpdate.Core.Download.Sources; +using System.Text.Json; + +namespace CoreTest.Download; + +public class PushDownloadSourceTests +{ + [Theory] + [InlineData(1, 1, 123)] + [InlineData(2, 2, 456)] + public async Task MapsFlatServerPacketAndBuildsPlan(int appType, int packageType, int recordId) + { + var json = $$""" + {"Name":"pkg","Url":"https://example.test/pkg.zip","Version":"2.0.0", + "Hash":"abc","AppType":{{appType}},"RecordId":{{recordId}},"PackageType":{{packageType}}, + "Size":42,"IsForcibly":true,"IsFreeze":false,"ProductId":"p"} + """; + var result = await new PushDownloadSource(json).ListAsync(); + var asset = Assert.Single(result.Assets); + Assert.Equal(recordId, asset.RecordId); + Assert.Equal(appType, asset.AppType); + Assert.Equal(packageType, asset.PackageType); + Assert.Equal(42, asset.Size); + Assert.Equal("abc", asset.SHA256); + Assert.True(asset.IsForcibly); + Assert.Equal(appType == 1, result.HasMainUpdate); + Assert.Equal(appType == 2, result.HasUpgradeUpdate); + Assert.Single(DownloadPlanBuilder.Build(result.Assets, "1.0.0", "1.0.0").Assets); + } + + [Fact] + public async Task OldPacketWithoutRecordIdCanStillBeDownloaded() + { + var source = new PushDownloadSource("""{"Url":"https://example.test/pkg","Version":"2.0.0","AppType":1}"""); + var asset = Assert.Single((await source.ListAsync()).Assets); + Assert.Equal(0, asset.RecordId); + Assert.Equal(1, asset.AppType); + } + + [Fact] + public async Task ZipSuffixIsNormalizedForDownloadAndApply() + { + var source = new PushDownloadSource("""{"Name":"pkg.ZIP","Url":"https://example.test/pkg","Version":"2.0.0","AppType":1}"""); + Assert.Equal("pkg", Assert.Single((await source.ListAsync()).Assets).Name); + } + + [Fact] + public void FullOnlyPlansSelectLatestPackageForEachAppType() + { + var assets = new[] + { + new GeneralUpdate.Core.Download.Models.DownloadAsset("c1", "c1", 1, null, "2.0.0", PackageType: 2, AppType: 1), + new GeneralUpdate.Core.Download.Models.DownloadAsset("c2", "c2", 1, null, "3.0.0", PackageType: 2, AppType: 1), + new GeneralUpdate.Core.Download.Models.DownloadAsset("u", "u", 1, null, "2.0.0", PackageType: 2, AppType: 2) + }; + var plan = DownloadPlanBuilder.Build(assets, "1.0.0", "1.0.0"); + Assert.Equal(2, plan.Assets.Count); + Assert.Contains(plan.Assets, a => a.Name == "c2"); + Assert.Contains(plan.Assets, a => a.Name == "u"); + } + + [Theory] + [InlineData("""{"Url":"x","Version":"2.0.0"}""")] + [InlineData("""{"Url":"x","Version":"2.0.0","AppType":3}""")] + [InlineData("""{"Version":"2.0.0","AppType":1}""")] + [InlineData("""{"Url":"x","AppType":1}""")] + [InlineData("""{"Url":"x","Version":"2.0.0","AppType":1,"RecordId":-1}""")] + [InlineData("""{"Url":"x","Version":"2.0.0","AppType":1,"PackageType":3}""")] + [InlineData("""{"Name":"../pkg","Url":"x","Version":"2.0.0","AppType":1}""")] + [InlineData("""{"Name":"..\\pkg","Url":"x","Version":"2.0.0","AppType":1}""")] + [InlineData("""{"Name":".zip","Url":"x","Version":"2.0.0","AppType":1}""")] + [InlineData("null")] + public void InvalidPacketsAreRejected(string json) => + Assert.Throws(() => new PushDownloadSource(json)); + + [Fact] + public async Task CancellationIsHonoured() + { + var source = new PushDownloadSource("""{"Url":"x","Version":"2.0.0","AppType":1}"""); + using var cts = new CancellationTokenSource(); + cts.Cancel(); + await Assert.ThrowsAnyAsync(() => source.ListAsync(cts.Token)); + } +} diff --git a/tests/CoreTest/Strategy/ReportRoutingTests.cs b/tests/CoreTest/Strategy/ReportRoutingTests.cs index caa89426..294f9d1c 100644 --- a/tests/CoreTest/Strategy/ReportRoutingTests.cs +++ b/tests/CoreTest/Strategy/ReportRoutingTests.cs @@ -4,10 +4,13 @@ using GeneralUpdate.Core.Download.Abstractions; using GeneralUpdate.Core.Download.Models; using GeneralUpdate.Core.Download.Reporting; +using GeneralUpdate.Core.Download.Sources; +using GeneralUpdate.Core.Download.Executors; using GeneralUpdate.Core.FileSystem; using GeneralUpdate.Core.Ipc; using GeneralUpdate.Core.JsonContext; using GeneralUpdate.Core.Pipeline; +using GeneralUpdate.Core.Network; using GeneralUpdate.Core.Strategy; using Moq; using CoreTest.Shared; @@ -86,6 +89,95 @@ public async Task ClientAndUpdater_RouteReportsAndDoNotMarkStagingSuccessful(int Assert.All(reporter.Reports, r => Assert.Equal(reportType, r.Type)); } + [Theory] + [InlineData(1, 123)] + [InlineData(2, 123)] + [InlineData(1, 0)] + [InlineData(2, 0)] + public async Task PushPacket_RoutesRealRecordOrSuppressesReports(int appType, int recordId) + { + var record = recordId == 0 ? "" : $",\"RecordId\":{recordId}"; + var source = new PushDownloadSource( + $"{{\"Name\":\"push\",\"Url\":\"https://example.test/pkg\",\"Version\":\"2.0.0\",\"AppType\":{appType},\"PackageType\":2{record}}}"); + var orchestrator = new Mock(); + orchestrator.Setup(o => o.ExecuteAsync(It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny>(), It.IsAny())) + .ReturnsAsync((DownloadPlan plan, string _, int _, IProgress? _, CancellationToken _) => + new DownloadReport(Array.Empty(), 0, TimeSpan.Zero, plan.Assets.Count, 0)); + var reporter = new RecordingReporter(); + var ipc = new EncryptedFileProcessContractProvider(Path.Combine(_directory, "push-ipc")); + var client = new ClientStrategy + { + DownloadSource = source, Reporter = reporter, LaunchAfterPrepare = false, ProcessContractProvider = ipc + }; + client.SetOrchestrator(orchestrator.Object); + client.SetOsStrategy(new TestPlatform()); + var context = NewContext(); + client.Create(context); + await client.ExecuteAsync(); + Assert.Equal(2, context.ReportType); + if (appType == 1) + { + Assert.True(client.HasPreparedClientUpdate); + var contract = await ipc.ReceiveAsync(); + Assert.NotNull(contract); + Assert.Equal(2, contract.ReportType); + Assert.Equal(recordId, Assert.Single(contract.UpdateVersions).RecordId); + var updaterContext = NewContext(); + updaterContext.UpdateVersions = contract.UpdateVersions; + updaterContext.ReportType = contract.ReportType; + updaterContext.LaunchClientAfterUpdate = false; + var updater = new UpdateStrategy { Reporter = reporter }; + updater.SetOsStrategy(new TestPlatform()); + updater.Create(updaterContext); + await updater.ExecuteAsync(); + } + else + { + Assert.False(client.HasPreparedClientUpdate); + } + + if (recordId == 0) + Assert.Empty(reporter.Reports); + else + { + Assert.Contains(reporter.Reports, r => r.Status == (int)UpdateStatus.Success); + Assert.All(reporter.Reports, r => { Assert.Equal(recordId, r.RecordId); Assert.Equal(2, r.Type); }); + } + } + + [Fact] + public async Task PushDownloadAndReport_UseConfiguredTenantHeader() + { + var oldProvider = HttpClientProvider.DefaultAuthProvider; + var hadHeader = HttpClientProvider.ExtraHeaders.TryGetValue("X-Tenant-Id", out var oldHeader); + var destination = Path.Combine(_directory, "download"); + var handler = new TenantHandler(); + using var http = new HttpClient(handler); + try + { + HttpClientProvider.DefaultAuthProvider = null; + HttpClientProvider.ExtraHeaders["X-Tenant-Id"] = "tenant-test"; + var source = new PushDownloadSource( + """{"Name":"pkg","Url":"https://example.test/download","Version":"2.0.0","AppType":1,"RecordId":123}"""); + var asset = Assert.Single((await source.ListAsync()).Assets); + var result = await new HttpDownloadExecutor(http, enableResume: false).ExecuteAsync(asset, destination); + Assert.True(result.Success); + await new HttpUpdateReporter(http, "https://example.test/report") + .ReportAsync(new UpdateReport(asset.RecordId, (int)UpdateStatus.Updating, 2)); + Assert.Equal(2, handler.TenantHeaders.Count); + Assert.All(handler.TenantHeaders, value => Assert.Equal("tenant-test", value)); + Assert.Contains("\"recordId\":123", handler.ReportBody); + Assert.Contains("\"type\":2", handler.ReportBody); + } + finally + { + HttpClientProvider.DefaultAuthProvider = oldProvider; + if (hadHeader) HttpClientProvider.ExtraHeaders["X-Tenant-Id"] = oldHeader!; + else HttpClientProvider.ExtraHeaders.TryRemove("X-Tenant-Id", out _); + } + } + [Theory] [InlineData(1, (int)AppType.Upgrade)] [InlineData(2, (int)AppType.Client)] @@ -166,6 +258,19 @@ public Task ReportAsync(UpdateReport report, CancellationToken token = default) } } + private sealed class TenantHandler : HttpMessageHandler + { + public List TenantHeaders { get; } = new(); + public string ReportBody { get; private set; } = ""; + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken token) + { + TenantHeaders.Add(request.Headers.GetValues("X-Tenant-Id").Single()); + if (request.Content != null) ReportBody = await request.Content.ReadAsStringAsync(token); + return new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new StringContent("data") }; + } + } + private sealed class TestPlatform : AbstractStrategy { private int _calls; From c11b91210da25d010540312e6a519c676587a7ba Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Mon, 23 Nov 2026 00:02:04 +0800 Subject: [PATCH 2/2] Exercise push integration in native AOT CI Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/push-aot.yml | 33 ++++++++++++++++++++++++ tests/PushAotSmoke/Program.cs | 35 ++++++++++++++++++++++++++ tests/PushAotSmoke/PushAotSmoke.csproj | 13 ++++++++++ 3 files changed, 81 insertions(+) create mode 100644 .github/workflows/push-aot.yml create mode 100644 tests/PushAotSmoke/Program.cs create mode 100644 tests/PushAotSmoke/PushAotSmoke.csproj diff --git a/.github/workflows/push-aot.yml b/.github/workflows/push-aot.yml new file mode 100644 index 00000000..39725640 --- /dev/null +++ b/.github/workflows/push-aot.yml @@ -0,0 +1,33 @@ +name: Push Native AOT smoke + +on: + pull_request: + paths: + - 'src/GeneralUpdate.Core/**' + - 'src/GeneralUpdate.Differential/**' + - 'tests/PushAotSmoke/**' + - '.github/workflows/push-aot.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + push-aot: + runs-on: windows-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-dotnet@v5 + with: + dotnet-version: '10.0.x' + - name: Publish and run native push smoke + shell: cmd + run: | + for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSROOT=%%i" + if not defined VSROOT exit /b 1 + call "%VSROOT%\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64 + if errorlevel 1 exit /b 1 + dotnet publish tests\PushAotSmoke\PushAotSmoke.csproj -c Release -r win-x64 -o "%RUNNER_TEMP%\push-aot" + if errorlevel 1 exit /b 1 + "%RUNNER_TEMP%\push-aot\PushAotSmoke.exe" + if errorlevel 1 exit /b 1 diff --git a/tests/PushAotSmoke/Program.cs b/tests/PushAotSmoke/Program.cs new file mode 100644 index 00000000..c1254222 --- /dev/null +++ b/tests/PushAotSmoke/Program.cs @@ -0,0 +1,35 @@ +using System.Text.Json; +using GeneralUpdate.Core; +using GeneralUpdate.Core.Configuration; +using GeneralUpdate.Core.Download; +using GeneralUpdate.Core.Download.Sources; +using GeneralUpdate.Core.JsonContext; + +const string packet = """ + {"Name":"pkg.zip","Url":"https://example.test/a","Version":"2.0.0", + "AppType":2,"RecordId":123,"PackageType":2,"Size":42} + """; +var source = new PushDownloadSource(packet); +_ = new GeneralUpdateBootstrap().DownloadSource(source); +var result = await source.ListAsync(); +var asset = result.Assets.Single(); +if (asset.Name != "pkg" || asset.RecordId != 123 || asset.AppType != 2 || asset.Size != 42 || + DownloadPlanBuilder.Build(result.Assets, "1.0.0", "1.0.0").Assets.Count != 1) + throw new InvalidOperationException("Push packet mapping or plan construction failed."); + +var legacy = await new PushDownloadSource( + """{"Url":"https://example.test/a","Version":"2.0.0","AppType":1}""").ListAsync(); +if (legacy.Assets.Single().RecordId != 0) + throw new InvalidOperationException("Legacy packet record ID was not absent."); + +var contract = new ProcessContract +{ + ReportType = 2, + UpdateVersions = new List { new() { AppType = 2, RecordId = 123 } } +}; +var json = JsonSerializer.Serialize(contract, ProcessContractJsonContext.Default.ProcessContract); +var roundTrip = JsonSerializer.Deserialize(json, ProcessContractJsonContext.Default.ProcessContract); +if (roundTrip?.ReportType != 2 || roundTrip.UpdateVersions?.Single().RecordId != 123) + throw new InvalidOperationException("Push IPC serialization failed."); + +Console.WriteLine("Push Native AOT smoke passed."); diff --git a/tests/PushAotSmoke/PushAotSmoke.csproj b/tests/PushAotSmoke/PushAotSmoke.csproj new file mode 100644 index 00000000..18b201a7 --- /dev/null +++ b/tests/PushAotSmoke/PushAotSmoke.csproj @@ -0,0 +1,13 @@ + + + Exe + net10.0 + true + false + enable + enable + + + + +