Skip to content

fix(updater): verify replacement and rollback before restart - #120

Draft
dwgx wants to merge 8 commits into
RoutineMiku:mainfrom
dwgx:fix/verified-update-apply
Draft

dwgx wants to merge 8 commits into
RoutineMiku:mainfrom
dwgx:fix/verified-update-apply

Conversation

@dwgx

@dwgx dwgx commented Nov 21, 2026

Copy link
Copy Markdown

Problem

The update-apply path needs to distinguish verified replacement, successful recovery, and a successful request to restart. A matching executable length or package.json version alone is insufficient evidence that all required files were installed. The current incremental app path also needs verified recovery before restarting an old installation.

Dependency and review range

This draft depends on #117. It preserves that branch's release-identity and cached-resume changes. The additional apply changes are 79338bb...8136876. The full PR diff against upstream main includes the dependency; please review/land #117 first. No upstream merge or release is performed here.

Changes

  • Stage and hash required ZIP/app files, including hidden files. App updates replace the complete resources/app tree, removing obsolete old-only files while preserving the Electron shell, runtime and user data.
  • Verify committed files and restored old bytes. Retain payload/backups on apply or recovery failure; suppress restart when recovery cannot be verified.
  • Separate helper outcomes: 0 verified apply plus successful restart request; 1 apply/installer failure; 2 apply verified but restart request failed; 3 recovery failed. A successful restart request does not establish application health. Cleanup failures remain separate warnings.
  • Require a real zero installer exit status before treating setup as successful.
  • Dispatch the full helper through a short encoded bootstrap. Read helper bytes once, check their SHA-256, and execute those same decoded bytes. Keep the existing synchronous missing-PowerShell failure contract.
  • Normalize Windows 8.3 path aliases before payload identity checks and relative-path calculation; reject paths outside the expected root.

Validation

Exact head: 8136876c622372c1a8aef8f93c2ddc2423cd87e6.

  • Fork CI 44886107794: Windows Node 20 and 22 passed, including the configured full test command, 24/24 Windows apply cases on each job, and pointer-hook smoke.
  • Independent Windows runs: 24/24 under native TEMP and 24/24 with an 8.3 TEMP alias. Cases cover ZIP9 + app7 + setup4 + dispatch4; file operations/locks use private TEMP fixtures.
  • The same final test file against development head b4ee5b7 reproduces 5/24 under the short alias. This matches the preserved first failed CI, and establishes the path fix without removing cases or weakening assertions.
  • Three additional real -EncodedCommand cases pass: Unicode/quotes/spaces, a longer path, and helper tampering refused before helper waits/launches. Eight independent relative-path boundary checks pass.
  • Resume-identity 44/44, incremental 11/11, and a controlled late async failure correctly returns native exit1.

Limits

All app, installer, cmd-launch and process-wait calls are intercepted in the private test processes. Real PowerShell and TEMP file operations run; applications/installers, Android boot and a live user's upgrade do not. The partial-replace/restore faults are explicit test injections, not claims of reproducing an actual OS error1177.

The optional APK fixture case still explicitly skips when no external APK is supplied. Fork CI success is separate from upstream workflow approval. No security severity or CWE/CVE claim is made from these functional tests.

dwgx added 8 commits November 17, 2026 21:16
downloadMulti 在 dedup/单源检查后、并行探测前早退:无 expectSha256 时走 downloadAnyParallel 逐源整包尝试,换源前 discardPartial,返回 sources:1/multi:false/resumed:false,且不读写 .chunks.json;有锚路径字节不变。新增 6 个无锚/取消/能力保留测试到 range-validation-test.js(RED: 混块与 stale resume 两例失败;GREEN: 19/19)。带宽代价:无锚时不再叠加多镜像带宽,但所有排名源仍逐个可用。auto-test.js:1764/:1808/:1907 re-anchored — old assertions pinned no-anchor cross-mirror mixing (the removed BUG-NOANCHOR contract); capability coverage preserved on the anchored path.
Carry GitHub asset SHA-256 with its source identity into runtime and full update downloads. Preserve unanchored compatibility and avoid applying a GitHub digest to a separately repacked asset.
Validate release identity before rebuilding cached full or incremental payloads, serialize update operations, and preserve verified archives on failure. Select the app asset separately, support app-only archives, and await every asynchronous regression before reporting success.
- Stage every payload file (Hidden included) and verify SHA256 before committing;
  app mode replaces resources/app as a whole tree, so old-only files do not accumulate.
- Verify the committed tree bytes after commit; restore the pre-change tree and verify
  its bytes before allowing an old-version relaunch.
- Exit 3 and suppress relaunch when restoration cannot be verified; exit 2 when the
  replacement is verified but both launch requests fail.
- Keep payload/version dir and write .apkstart-force-full on apply failure; cleanup
  failures are warnings only, not rollback.
- Treat only installer exit 0 as success; no relaunch after installer failure.
- Keep production -EncodedCommand dispatch under the Windows command-line limit
  (strip indentation for the inline script, guard encoded length).
- Add seven app TEMP fixture cases and retain thirteen zip/setup cases; wire the
  Windows suite into npm test.
- Keep the ~12k-char helper out of the CreateProcess command line; the frozen ROOT-R5-DISPATCH probe failed 4/4 after the transactional port because UTF-16LE base64 reached 32108-34156 chars.
- Write the BOM-prefixed UTF-8 helper to a unique file under the update dir, pass path plus SHA-256 in a bounded bootstrap, read bytes once, verify, then decode and execute the same buffer; delete the helper after the verified read.
- Add production-dispatch Windows cases (long path with quote/spaces, Chinese path, short path, tampered-helper refusal) and assert the captured spawn command stays bounded; keep the 20 existing app/zip/setup cases.
- Record the installed tree digest in the launch stub so A04 proves the old tree was restored before the old-version launch request.
- Fix the $rollbackAllowed typo in the relaunch-reason guard (undefined variable was always truthy; no transaction behavior depended on it).
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.

1 participant