feat: prepare PCL-ISE 0.1.2 update test release
Release PCL-ISE / release (push) Canceled after 0s

This commit is contained in:
Coldsmile_7 committed 2026-10-27 23:57:25 +08:00
1 parent 5d549ff66a
commit e831d0dfe0
28 files changed
+1026 -286

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
using System;
using System.IO;
using System.Reflection;
// Compile with the .NET Framework csc.exe. No UI startup or network calls.
internal static class CheckBuildCredentials {
[STAThread]
private static int Main(string[] args) {
try {
string expectedClientId = (Environment.GetEnvironmentVariable("PCL_MS_CLIENT_ID") ?? "").Trim();
string expectedApiKey = Environment.GetEnvironmentVariable("PCL_CURSEFORGE_API_KEY") ?? "";
string mode = args[1];
if (mode == "override") {
expectedClientId = "11111111-1111-4111-8111-111111111111";
expectedApiKey = "synthetic-override-only-$\"&\\";
Environment.SetEnvironmentVariable("PCL_MS_CLIENT_ID", expectedClientId);
Environment.SetEnvironmentVariable("PCL_CURSEFORGE_API_KEY", expectedApiKey);
} else if (mode == "blank-override") {
Environment.SetEnvironmentVariable("PCL_MS_CLIENT_ID", " ");
Environment.SetEnvironmentVariable("PCL_CURSEFORGE_API_KEY", " ");
} else if (mode == "packaged" || mode == "empty") {
Environment.SetEnvironmentVariable("PCL_MS_CLIENT_ID", null);
Environment.SetEnvironmentVariable("PCL_CURSEFORGE_API_KEY", null);
if (mode == "empty") { expectedClientId = ""; expectedApiKey = ""; }
} else {
throw new ArgumentException("Unknown test mode");
}
Assembly launcher = Assembly.LoadFrom(Path.GetFullPath(args[0]));
using (Stream resource = launcher.GetManifestResourceStream("PCL.BuildCredentials.json")) {
if ((resource == null) != (mode == "empty"))
throw new InvalidDataException("Unexpected build configuration resource");
}
Activator.CreateInstance(launcher.GetType("PCL.Application", true), true);
Type module = launcher.GetType("PCL.ModSecret", true);
string actualClientId = (string)module.GetField("OAuthClientId").GetValue(null);
string actualApiKey = (string)module.GetField("CurseForgeAPIKey").GetValue(null);
if (actualClientId != expectedClientId || actualApiKey != expectedApiKey)
throw new InvalidDataException("Build configuration did not match expected values");
Console.WriteLine("PASS: build configuration " + mode);
return 0;
} catch (Exception ex) {
// Never include credential values in diagnostic output.
Console.Error.WriteLine(ex.GetType().Name + ": build configuration check failed");
return 1;
}
}
}
+78
View File
@@ -0,0 +1,78 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
// Run from a fresh ThemeTest_* directory. Only that directory's synthetic
// Setup.ini is migrated; no launcher window, registry writes or network calls.
internal static class CheckFixedTheme {
private static int passed;
private static void Assert(bool condition, string description) {
if (!condition) throw new Exception("FAIL: " + description);
passed++;
Console.WriteLine("PASS: " + description);
}
[STAThread]
private static int Main(string[] args) {
try {
string isolatedRoot = AppDomain.CurrentDomain.BaseDirectory;
if (!new DirectoryInfo(isolatedRoot).Name.StartsWith("ThemeTest_", StringComparison.Ordinal))
throw new InvalidOperationException("Run the checker from a fresh ThemeTest_* directory");
string configDirectory = Path.Combine(isolatedRoot, "PCL");
Directory.CreateDirectory(configDirectory);
string configPath = Path.Combine(configDirectory, "Setup.ini");
if (File.Exists(configPath)) throw new InvalidOperationException("Use a fresh test directory");
File.WriteAllText(configPath,
"UiLauncherTheme:14\r\nUiLauncherHue:345\r\nUiLauncherSat:25\r\nUiLauncherDelta:175\r\nUiLauncherLight:40\r\n" +
"UiMusicRandom:False\r\nUiBackgroundColorful:False\r\nUiLauncherTransparent:321\r\nSyntheticThemeTestMarker:keep\r\n");
Assembly launcher = Assembly.LoadFrom(Path.GetFullPath(args[0]));
Type appType = launcher.GetType("PCL.Application", true);
Application app = (Application)Activator.CreateInstance(appType, true);
Assembly core = Assembly.Load("MeloongCore");
core.GetType("MeloongCore.Main", true).GetMethod("Init").Invoke(null, new object[] { "PCL" });
string actualRoot = (string)core.GetType("MeloongCore.Paths", true).GetProperty("Base").GetValue(null, null);
if (!string.Equals(Path.GetFullPath(actualRoot), Path.GetFullPath(isolatedRoot), StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException("Launcher configuration directory is not isolated");
appType.GetMethod("InitializeComponent").Invoke(app, null);
launcher.GetType("PCL.ModBase", true).GetMethod("RunInUi", Type.EmptyTypes).Invoke(null, null);
Type settings = launcher.GetType("PCL.Settings", true);
MethodInfo get = settings.GetMethods().Single(m => m.Name == "Get" && !m.IsGenericMethodDefinition);
Func<string, object> read = key => get.Invoke(null, new object[] { key, null });
Assert((int)read("UiLauncherTheme") == 14, "load a real legacy custom-theme setting from the isolated configuration");
Type theme = launcher.GetType("PCL.ModSecret", true);
MethodInfo migrate = theme.GetMethod("ThemeCheckAll", BindingFlags.NonPublic | BindingFlags.Static);
migrate.Invoke(null, new object[] { false });
Assert((int)read("UiLauncherTheme") == 0, "legacy theme selection migrates to Cat Blue");
string afterMigration = File.ReadAllText(configPath);
string[] legacyKeys = { "UiLauncherTheme:", "UiLauncherHue:", "UiLauncherSat:", "UiLauncherDelta:", "UiLauncherLight:" };
Assert(legacyKeys.All(key => !afterMigration.Contains(key)), "remove only obsolete theme and tuning overrides from Setup.ini");
Assert(!(bool)read("UiMusicRandom") && !(bool)read("UiBackgroundColorful") && (int)read("UiLauncherTransparent") == 321 && afterMigration.Contains("SyntheticThemeTestMarker:keep"), "preserve background, music, opacity and unrelated configuration");
MethodInfo refresh = theme.GetMethod("ThemeRefresh");
refresh.Invoke(null, new object[] { 0 });
Color blue = ((SolidColorBrush)app.Resources["ColorBrush3"]).Color;
Assert(blue.B > blue.R && blue.B > blue.G, "render the default palette with a blue primary color");
foreach (int legacyTheme in new[] { 1, 5, 8, 12, 14 }) {
refresh.Invoke(null, new object[] { legacyTheme });
Assert(((SolidColorBrush)app.Resources["ColorBrush3"]).Color == blue, "legacy theme argument " + legacyTheme + " retains Cat Blue");
}
migrate.Invoke(null, new object[] { true });
Assert(File.ReadAllText(configPath) == afterMigration, "repeated initialization leaves migrated configuration unchanged");
Console.WriteLine(passed + " fixed-theme checks passed. Isolated configuration: " + configPath);
return 0;
} catch (Exception ex) {
Console.Error.WriteLine(ex);
return 1;
}
}
}
+4 -1
View File
@@ -12,6 +12,9 @@ internal static class CheckLauncherRelease {
[STAThread]
private static int Main(string[] args) {
try {
if (args.Length < 3) throw new ArgumentException("Usage: Check-LauncherRelease.exe <installed launcher> <expected release exe> <expected tag>");
string expectedTag = args[2];
string expectedVersion = AssemblyName.GetAssemblyName(Path.GetFullPath(args[1])).Version.ToString();
Assembly launcher = Assembly.LoadFrom(Path.GetFullPath(args[0]));
Activator.CreateInstance(launcher.GetType("PCL.Application", true), true);
Assembly core = Assembly.Load("MeloongCore");
@@ -37,7 +40,7 @@ internal static class CheckLauncherRelease {
throw new InvalidDataException("Release SHA256 does not match local build");
}
}
if (tag != "v0.1.1" || version != "0.1.1.0") throw new InvalidDataException("Unexpected test release version");
if (tag != expectedTag || version != expectedVersion) throw new InvalidDataException("Unexpected test release version");
bool newer = (bool)module.GetMethod("IsUpdateNewer", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { info });
bool expectedNewer = new Version(version) > launcher.GetName().Version;
if (newer != expectedNewer) throw new InvalidDataException("Unexpected update comparison result");
+108
View File
@@ -0,0 +1,108 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
// Exercises the real selector with isolated synthetic release pages. No release is
// created or downloaded, and the main launcher window is never started.
// Optional --live also queries the configured public Gitea endpoints.
internal static class CheckSnapshotUpdates {
private static int passed;
private static void Assert(bool condition, string description) {
if (!condition) throw new Exception("FAIL: " + description);
passed++;
Console.WriteLine("PASS: " + description);
}
private static string Tag(object release) {
if (release == null) return null;
return release.GetType().GetProperty("Item", new[] { typeof(string) })
.GetValue(release, new object[] { "tag_name" }).ToString();
}
private static bool Throws<T>(Action action) where T : Exception {
try { action(); }
catch (TargetInvocationException ex) { return ex.InnerException is T; }
return false;
}
[STAThread]
private static int Main(string[] args) {
try {
Assembly launcher = Assembly.LoadFrom(Path.GetFullPath(args[0]));
Activator.CreateInstance(launcher.GetType("PCL.Application", true), true);
Assembly.Load("MeloongCore").GetType("MeloongCore.Main", true).GetMethod("Init")
.Invoke(null, new object[] { "PCL" });
launcher.GetType("PCL.ModBase", true).GetMethod("RunInUi", Type.EmptyTypes).Invoke(null, null);
Type module = launcher.GetType("PCL.ModSecret", true);
MethodInfo select = module.GetMethod("GetLatestSnapshotRelease", BindingFlags.NonPublic | BindingFlags.Static);
int requests = 0;
Func<int, string> pages = page => {
requests++;
switch (page) {
case 1: return "[{\"tag_name\":\"v9.0.0\",\"prerelease\":false,\"draft\":false},{\"tag_name\":\"v0.2.9\",\"prerelease\":true,\"draft\":false},{\"tag_name\":\"v99.0.0\",\"prerelease\":true,\"draft\":true}]";
case 2: return "[{\"tag_name\":\"v0.2.10\",\"prerelease\":true,\"draft\":false},{\"tag_name\":\"invalid\",\"prerelease\":true,\"draft\":false},{\"tag_name\":\"v0.1.2\",\"prerelease\":true,\"draft\":false}]";
default: return "[]";
}
};
object selected = select.Invoke(null, new object[] { pages });
Assert(Tag(selected) == "v0.2.10", "select highest numeric snapshot version across unsorted pages; ignore stable, draft and invalid releases");
Assert(requests == 3, "continue short server pages until the first empty page");
selected = select.Invoke(null, new object[] { new Func<int, string>(page => "[]") });
Assert(selected == null, "empty release list has no snapshot update");
selected = select.Invoke(null, new object[] { new Func<int, string>(page => page == 1 ? "[{\"tag_name\":\"v0.1.1\",\"prerelease\":false,\"draft\":false}]" : "[]") });
Assert(selected == null, "stable-only repository is not offered as a snapshot update");
selected = select.Invoke(null, new object[] { new Func<int, string>(page => page == 1 ? "[{\"tag_name\":\"v0.3.0\",\"prerelease\":true,\"draft\":true}]" : "[]") });
Assert(selected == null, "unpublished draft snapshot is never offered");
MethodInfo compare = launcher.GetType("PCL.ModLauncherUpdate", true).GetMethod("ParseLauncherVersion");
Version installed = (Version)compare.Invoke(null, new object[] { launcher.GetType("PCL.ModBase", true).GetField("VersionBaseName").GetRawConstantValue() });
Type infoType = module.GetNestedType("LauncherUpdateInfo", BindingFlags.NonPublic);
object info = Activator.CreateInstance(infoType, true);
MethodInfo isNewer = module.GetMethod("IsUpdateNewer", BindingFlags.NonPublic | BindingFlags.Static);
infoType.GetField("VersionNumber").SetValue(info, new Version(0, 0, 0, 0));
Assert(!(bool)isNewer.Invoke(null, new[] { info }), "older release never triggers an automatic downgrade");
infoType.GetField("VersionNumber").SetValue(info, installed);
Assert(!(bool)isNewer.Invoke(null, new[] { info }), "same version is not offered as an update");
infoType.GetField("VersionNumber").SetValue(info, new Version(installed.Major + 1, 0, 0, 0));
Assert((bool)isNewer.Invoke(null, new[] { info }), "newer release is offered through the shared update comparison");
Assert(Throws<IOException>(() => select.Invoke(null, new object[] { new Func<int, string>(page => { throw new IOException("Synthetic network failure"); }) })), "network failure is reported instead of claiming there are no updates");
requests = 0;
Assert(Throws<IOException>(() => select.Invoke(null, new object[] { new Func<int, string>(page => { requests++; return "[{\"tag_name\":\"v0.2.0\",\"prerelease\":true,\"draft\":false}]"; }) })), "bounded pagination never offers a partially inspected release list");
Assert(requests == 100, "pagination has a finite request limit");
Assembly json = Assembly.Load("Newtonsoft.Json");
MethodInfo parseJson = json.GetType("Newtonsoft.Json.Linq.JObject", true).GetMethod("Parse", new[] { typeof(string) });
MethodInfo parseInfo = module.GetMethod("ParseLauncherUpdate", BindingFlags.NonPublic | BindingFlags.Static);
object stableJson = parseJson.Invoke(null, new object[] { "{\"prerelease\":false,\"draft\":false}" });
object snapshotJson = parseJson.Invoke(null, new object[] { "{\"prerelease\":true,\"draft\":false}" });
object draftJson = parseJson.Invoke(null, new object[] { "{\"prerelease\":true,\"draft\":true}" });
Assert(Throws<FormatException>(() => parseInfo.Invoke(null, new[] { stableJson, (object)true })), "snapshot parser rejects a stable release");
Assert(Throws<FormatException>(() => parseInfo.Invoke(null, new[] { snapshotJson, (object)false })), "stable parser rejects a snapshot release");
Assert(Throws<FormatException>(() => parseInfo.Invoke(null, new[] { draftJson, (object)true })), "release parser rejects drafts before downloading or caching");
if (args.Length > 1 && args[1] == "--live") {
object stable = Task.Run(() => module.GetMethod("GetLatestLauncherUpdate", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null)).GetAwaiter().GetResult();
Assert(stable != null, "live stable endpoint resolves a release with verified checksum metadata");
object snapshot = Task.Run(() => module.GetMethod("GetLatestSnapshotLauncherUpdate", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null)).GetAwaiter().GetResult();
if (snapshot == null) {
Console.WriteLine("Live snapshot endpoint: no published pre-release.");
} else {
Console.WriteLine("Live snapshot endpoint: " + infoType.GetField("TagName").GetValue(snapshot));
}
}
Console.WriteLine(passed + " snapshot update checks passed.");
return 0;
} catch (Exception ex) {
Console.Error.WriteLine(ex);
return 1;
}
}
}
+35
View File
@@ -0,0 +1,35 @@
using System;
using System.IO;
// Faults affect only the named target in an isolated functional test directory.
public sealed class TestLauncherUpdateFileOperations : LauncherUpdateFileOperations {
public string TargetPath;
public int CopyFailuresRemaining;
public bool LeavePartialFile;
public bool CorruptInstalledFile;
public bool FailBackup;
public bool FailRestore;
public bool FailCleanup;
public override void CopyFile(string source, string target, bool overwrite) {
bool installsTarget = string.Equals(target, TargetPath, StringComparison.OrdinalIgnoreCase)
&& source.EndsWith(".new", StringComparison.OrdinalIgnoreCase);
if (FailBackup && string.Equals(target, TargetPath + ".bak", StringComparison.OrdinalIgnoreCase))
throw new IOException("Test: backup could not be written");
if (FailRestore && string.Equals(source, TargetPath + ".bak", StringComparison.OrdinalIgnoreCase))
throw new IOException("Test: restore could not be written");
if (installsTarget && CopyFailuresRemaining > 0) {
CopyFailuresRemaining--;
if (LeavePartialFile) File.WriteAllText(target, "incomplete new program");
throw new IOException("Test: new program copy interrupted");
}
base.CopyFile(source, target, overwrite);
if (installsTarget && CorruptInstalledFile) File.WriteAllText(target, "incomplete new program");
}
public override void DeleteFile(string target) {
if (FailCleanup && target.EndsWith(".new", StringComparison.OrdinalIgnoreCase))
throw new IOException("Test: staged file temporarily busy");
base.DeleteFile(target);
}
}
+96 -4
View File
@@ -8,10 +8,11 @@ $testRoot = Join-Path $repoRoot ('artifacts\update-tests\' + [Guid]::NewGuid().T
[IO.Directory]::CreateDirectory($testRoot) | Out-Null
$framework = Join-Path $env:WINDIR 'Microsoft.NET\Framework\v4.0.30319'
$testLibrary = Join-Path $testRoot 'LauncherUpdateTests.dll'
$testLibrary = Join-Path $testRoot ('LauncherUpdateTests_' + (Split-Path $testRoot -Leaf) + '.dll')
& (Join-Path $framework 'vbc.exe') /nologo /target:library "/out:$testLibrary" $sourcePath
if ($LASTEXITCODE -ne 0) { throw 'Update module compilation failed' }
$updateType = [Reflection.Assembly]::LoadFile($testLibrary).GetType('ModLauncherUpdate')
$testAssembly = [Reflection.Assembly]::LoadFrom($testLibrary)
$updateType = $testAssembly.GetType('ModLauncherUpdate')
$parse = $updateType.GetMethod('ParseLauncherVersion')
$replace = $updateType.GetMethod('ReplaceLauncherFile')
$testState = @{ Passed = 0 }
@@ -20,8 +21,8 @@ function Assert-True([bool]$Condition, [string]$Description) {
$testState.Passed++
Write-Host "PASS: $Description"
}
function Replace-File([int]$PreviousId, [string]$Target, [string]$Source, [int]$Timeout = 30000) {
$replace.Invoke($null, @($PreviousId, $Target, $Source, $Timeout))
function Replace-File([int]$PreviousId, [string]$Target, [string]$Source, [int]$Timeout = 30000, $Operations = $null) {
$replace.Invoke($null, @($PreviousId, $Target, $Source, $Timeout, $Operations))
}
foreach ($inputVersion in @('0.1.1', 'v0.1.1', '0.1.1-dev', '0.1.1+build')) {
@@ -63,6 +64,78 @@ Replace-File 0 $newTarget $download
Assert-True ([IO.File]::ReadAllText($newTarget) -eq 'new version') 'install into absent target'
Assert-True (@(Get-ChildItem $testRoot -Filter '*.new').Count -eq 0) 'no staged files left behind'
$faultLibrary = Join-Path $testRoot 'UpdateFileOperationsTests.dll'
& $csc /nologo /target:library "/reference:$testLibrary" "/out:$faultLibrary" (Join-Path $repoRoot 'tests\LauncherUpdateFileOperations.cs')
if ($LASTEXITCODE -ne 0) { throw 'Fault operation compilation failed' }
$faultType = [Reflection.Assembly]::LoadFrom($faultLibrary).GetType('TestLauncherUpdateFileOperations')
function New-FaultOperations([string]$TargetPath) {
$operations = [Activator]::CreateInstance($faultType)
$operations.TargetPath = $TargetPath
$operations.RetryTimeoutMilliseconds = 0
return $operations
}
function Get-ReplaceFailure([string]$TargetPath, $Operations) {
try { Replace-File 0 $TargetPath $download 30000 $Operations } catch { return $_.Exception.InnerException }
throw 'Expected a file operation failure'
}
$backupFailureTarget = Join-Path $testRoot 'backup-failure.exe'
[IO.File]::WriteAllText($backupFailureTarget, 'old version')
$fault = New-FaultOperations $backupFailureTarget
$fault.FailBackup = $true
$failure = Get-ReplaceFailure $backupFailureTarget $fault
Assert-True ([IO.File]::ReadAllText($backupFailureTarget) -eq 'old version') 'backup failure never deletes old program'
$copyFailureTarget = Join-Path $testRoot 'copy-failure.exe'
[IO.File]::WriteAllText($copyFailureTarget, 'old version')
$fault = New-FaultOperations $copyFailureTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$failure = Get-ReplaceFailure $copyFailureTarget $fault
Assert-True ([IO.File]::ReadAllText($copyFailureTarget) -eq 'old version') 'interrupted copy restores old program over a partial target'
Assert-True ([IO.File]::ReadAllText($copyFailureTarget + '.bak') -eq 'old version') 'rollback retains backup'
$hashFailureTarget = Join-Path $testRoot 'hash-failure.exe'
[IO.File]::WriteAllText($hashFailureTarget, 'old version')
$fault = New-FaultOperations $hashFailureTarget
$fault.CorruptInstalledFile = $true
$failure = Get-ReplaceFailure $hashFailureTarget $fault
Assert-True ([IO.File]::ReadAllText($hashFailureTarget) -eq 'old version') 'installed file hash failure restores old program'
$restoreFailureTarget = Join-Path $testRoot 'restore-failure.exe'
[IO.File]::WriteAllText($restoreFailureTarget, 'old version')
$fault = New-FaultOperations $restoreFailureTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$fault.FailRestore = $true
$failure = Get-ReplaceFailure $restoreFailureTarget $fault
Assert-True ($failure -is [AggregateException]) 'failed restore reports installation and restoration failures'
Assert-True ([IO.File]::ReadAllText($restoreFailureTarget + '.bak') -eq 'old version') 'failed restore retains backup for manual recovery'
Assert-True ([IO.File]::ReadAllText($download) -eq 'new version') 'failed restore retains source download'
$retryTarget = Join-Path $testRoot 'retry.exe'
[IO.File]::WriteAllText($retryTarget, 'old version')
$fault = New-FaultOperations $retryTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$fault.RetryTimeoutMilliseconds = 1000
Replace-File 0 $retryTarget $download 30000 $fault
Assert-True ([IO.File]::ReadAllText($retryTarget) -eq 'new version') 'temporary copy failure retries successfully'
$newFailedTarget = Join-Path $testRoot 'failed-first-install.exe'
$fault = New-FaultOperations $newFailedTarget
$fault.CopyFailuresRemaining = 1
$fault.LeavePartialFile = $true
$failure = Get-ReplaceFailure $newFailedTarget $fault
Assert-True (-not [IO.File]::Exists($newFailedTarget)) 'failed first install removes partial target'
$cleanupTarget = Join-Path $testRoot 'cleanup.exe'
[IO.File]::WriteAllText($cleanupTarget, 'old version')
$fault = New-FaultOperations $cleanupTarget
$fault.FailCleanup = $true
Replace-File 0 $cleanupTarget $download 30000 $fault
Assert-True ([IO.File]::ReadAllText($cleanupTarget) -eq 'new version') 'cleanup failure does not report a successful installation as failed'
if ($LauncherPath) {
$LauncherPath = (Resolve-Path $LauncherPath).Path
$liveTarget = Join-Path $testRoot 'RunningLauncher.exe'
@@ -76,6 +149,25 @@ if ($LauncherPath) {
Assert-True ($helper.ExitCode -eq 5) 'real launcher update helper exits successfully'
Assert-True ((Get-FileHash $liveTarget).Hash -eq (Get-FileHash $LauncherPath).Hash) 'real helper replaces running old launcher after it exits'
Assert-True ((Get-FileHash ($liveTarget + '.bak')).Hash -eq (Get-FileHash $oldExe).Hash) 'real helper preserves previous launcher'
$resultPath = $updateType.GetMethod('GetLauncherUpdateResultPath').Invoke($null, @([string]$liveTarget))
$receipt = Get-Content -LiteralPath $resultPath -Raw | ConvertFrom-Json
Assert-True ($receipt.Succeeded -and $receipt.HelperProcessId -eq $helper.Id -and $receipt.TargetPath -eq $liveTarget) 'real helper saves a successful update receipt for the next startup'
$lockedTarget = Join-Path $testRoot 'locked-target.exe'
Copy-Item -LiteralPath $oldExe -Destination $lockedTarget
$originalHash = (Get-FileHash $lockedTarget).Hash
$lockStream = [IO.File]::Open($lockedTarget, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::None)
try {
$arguments = '--update 0 "{0}" "{1}" false' -f $lockedTarget, $LauncherPath
$helper = Start-Process -FilePath $LauncherPath -ArgumentList $arguments -WorkingDirectory $testRoot -WindowStyle Hidden -PassThru
if (-not $helper.WaitForExit(20000)) { throw 'Failed update helper did not finish within 20 seconds' }
$helper.Refresh()
Assert-True ($helper.ExitCode -ne 5) 'real helper reports file replacement failure without a modal dialog'
} finally { $lockStream.Dispose() }
Assert-True ((Get-FileHash $lockedTarget).Hash -eq $originalHash) 'real helper failure leaves old executable intact'
$resultPath = $updateType.GetMethod('GetLauncherUpdateResultPath').Invoke($null, @([string]$lockedTarget))
$receipt = Get-Content -LiteralPath $resultPath -Raw | ConvertFrom-Json
Assert-True (-not $receipt.Succeeded -and -not [string]::IsNullOrWhiteSpace($receipt.ErrorMessage)) 'real helper saves an error receipt for the next startup'
}
Write-Host "$($testState.Passed) checks passed. Artifacts: $testRoot"