Skip to content

refactor: Unify OSS update path through OSSUpdateStrategy#414

Merged
JusterZhu merged 6 commits into
masterfrom
issue/409-oss-unify-path
May 25, 2026
Merged

refactor: Unify OSS update path through OSSUpdateStrategy#414
JusterZhu merged 6 commits into
masterfrom
issue/409-oss-unify-path

Conversation

@JusterZhu
Copy link
Copy Markdown
Collaborator

Summary

Removes the dual OSS code path by merging \LaunchOssAsync()\ from \GeneralUpdateBootstrap\ into \OSSUpdateStrategy, making the dispatch consistent across all \AppType\ values.

Changes

OSSUpdateStrategy

  • Added \ExecuteClientAsync()\ — client-side OSS flow: download version config, check for updates, start upgrade process, graceful exit
  • Added \ExecuteUpgradeAsync()\ — upgrade-side flow: download packages, decompress, start main app (existing logic)
  • \ExecuteAsync()\ now detects role via \GlobalConfigInfoOSS\ env var and dispatches

GeneralUpdateBootstrap

  • \AppType.OSS\ now goes through \LaunchWithStrategy(new OSSUpdateStrategy())\ — consistent with Client and Upgrade
  • Deleted \LaunchOssAsync(), \DownloadOssFile(), \IsOssUpgrade()\

Benefits

  • Single OSS code path, same as Client/Upgrade
  • Consistent hooks + reporter invocation via \LaunchWithStrategy\
  • Net -5 lines of code in Bootstrap (+ removed duplication)

Closes #409

Move client-side OSS logic (version config download, upgrade check,
process launch) from LaunchOssAsync() into OSSUpdateStrategy. The
strategy now handles both client and upgrade OSS roles internally.

- OSSUpdateStrategy.ExecuteAsync(): detects role via
  GlobalConfigInfoOSS env var, dispatches to ExecuteClientAsync()
  or ExecuteUpgradeAsync() accordingly
- GeneralUpdateBootstrap: AppType.OSS now goes through
  LaunchWithStrategy(new OSSUpdateStrategy()) — consistent with
  Client and Upgrade paths
- Deleted LaunchOssAsync(), DownloadOssFile(), IsOssUpgrade() from
  GeneralUpdateBootstrap

Closes #409
Copilot AI review requested due to automatic review settings May 25, 2026 10:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the OSS update workflow so both OSS “client-side” and “upgrade-side” execution is routed through OSSUpdateStrategy, removing the separate OSS path previously implemented in GeneralUpdateBootstrap. This aligns OSS behavior with the existing strategy-based dispatch used for Client and Upgrade, including consistent hook/reporter wiring via LaunchWithStrategy.

Changes:

  • Moved the client-side OSS flow (download versions config → version check → launch upgrader → exit) into OSSUpdateStrategy.
  • Updated OSSUpdateStrategy.ExecuteAsync() to detect role via GlobalConfigInfoOSS IPC and dispatch to client vs upgrade execution.
  • Updated GeneralUpdateBootstrap so AppType.OSS uses LaunchWithStrategy(new OSSUpdateStrategy()) and removed the legacy OSS methods.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/c#/GeneralUpdate.Core/Strategy/OSSUpdateStrategy.cs Adds client-side OSS execution and role dispatch within the strategy, consolidating OSS flows.
src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs Routes AppType.OSS through LaunchWithStrategy and deletes the duplicated OSS bootstrap code path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 54 to +70
if (_configInfo == null)
throw new InvalidOperationException("OSSUpdateStrategy not configured. Call Create() first.");

// Upgrade side: GlobalConfigInfoOSS env var was set by the client,
// so we download packages, decompress, and start the main app.
var ossJson = Environments.GetEnvironmentVariable("GlobalConfigInfoOSS");
if (!string.IsNullOrWhiteSpace(ossJson))
{
await ExecuteUpgradeAsync();
return;
}

// Client side: download version config, check for new version,
// start the upgrade process, and exit.
await ExecuteClientAsync();
}

Comment on lines +88 to +90
var versions = JsonSerializer.Deserialize(
File.ReadAllText(versionsFilePath),
JsonContext.VersionOSSJsonContext.Default.ListVersionOSS);
Comment on lines +131 to +140
private static void DownloadOssVersionFile(string url, string path)
{
if (File.Exists(path))
{
File.SetAttributes(path, FileAttributes.Normal);
File.Delete(path);
}
using var httpClient = new HttpClient();
var bytes = httpClient.GetByteArrayAsync(url).GetAwaiter().GetResult();
File.WriteAllBytes(path, bytes);
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
JusterZhu added 5 commits May 25, 2026 19:03
…split

OSS mode no longer needs a separate upgrade process. The strategy
downloads version config, downloads packages from OSS, decompresses,
starts the main app, and exits — all in one process.

- Removed client/upgrade env-var-based dispatch from OSSUpdateStrategy
- Single ExecuteAsync() flow: download config -> download packages -> decompress -> start app -> exit
- Removed GlobalConfigInfoOSS env var bridging (no longer needed)

Related #409
OSS mode uses a separate upgrade process to download packages and
decompress, but does NOT check UpgradeClientVersion (the upgrade
process itself never needs upgrading — differs from standard flow).

Client side (main app):
  Download version config → check update → start upgrade process → exit

Upgrade side (GeneralUpdate.Upgrade.exe):
  Read version config → download OSS packages → decompress → start main app

Related #409
Replace AppType.OSS with explicit OSSClient/OSSUpgrade to match the
Client/Upgrade pattern. OSSUpdateStrategy now accepts AppType via
constructor instead of detecting role via GlobalConfigInfoOSS env var.

- AppType enum: OSS = 3 -> OSSClient = 3, OSSUpgrade = 4
- Bootstrap dispatch: OSSClient/OSSUpgrade through LaunchWithStrategy
- OSSUpdateStrategy: role dispatched by constructor AppType parameter
- Updated tests for new enum values

Closes #409
The upgrade side (ExecuteUpgradeAsync) reads version config directly
from the local JSON file — it never reads GlobalConfigInfoOSS env var.
Writing it in ExecuteClientAsync was dead code.

Removed ossConfig + Environments.SetEnvironmentVariable block.

Related #409
DownloadVersionConfig calls HttpClient which throws
InvalidOperationException when UpdateUrl is empty/null. Skip the
download when UpdateUrl is not configured, then check for local
version config file existence as before.

Fixes OssIntegrationTests.OSSUpdateStrategy_RequiresConfig test.

Related #409
@JusterZhu JusterZhu merged commit 19c3a52 into master May 25, 2026
1 of 3 checks passed
@JusterZhu JusterZhu deleted the issue/409-oss-unify-path branch May 25, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Unify OSS update path through OSSUpdateStrategy

2 participants