Skip to content

refactor(harmony): drive the native round through the shared round engine - #677

Merged
sunnylqm merged 2 commits into
masterfrom
claude/round-engine-harmony
Oct 15, 2026
Merged

sunnylqm merged 2 commits into
masterfrom
claude/round-engine-harmony

Conversation

@sunnylqm

@sunnylqm sunnylqm commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RoundEngine 系列的最后一步:鸿蒙接入共享轮次引擎。本 PR 基于 #669 合入后的 master。

改了什么

  • 新增 NAPI 绑定 NativePatchCore.stepRound(stateJson?, eventJson),同步调用 flowcore::StepRoundJson。它经 fix(native): catch C++ exceptions at the HarmonyOS NAPI and iOS entry points #674 的 Guarded<> 导出,C++ 异常不会进 NAPI。
  • SyncCoordinator.ts 删掉了手写的 runConfiguredRound、runQueryRequest、performAttempts、runWithinDeadline 和结果映射。runOnce 改为循环调用引擎,逐条执行它返回的命令:
    • perform:处理 env、HTTP、checkInstalled
    • download:用引擎给的 deadline 计时,超时回报 timedOut,失败回报错误码
    • commit:提交
    • finishRound:映射结果
  • 每一步引擎调用都是毫秒级的同步调用,HTTP 和下载仍在 ArkTS 异步执行,单线程不会被阻塞。
  • 宿主等待后的取消判定改为 C1 等价,原来是字符串全等。这样与 Android、iOS 一致,也与引擎的 HostCancellation 规则相同。
  • SyncCoordinator.ts 净删 78 行(+225 / −303)。

测试

  • 新增 harmonySyncRound.test.ts。它把 round-engine-vectors.json 当作脚本化的引擎:向量里的命令代替引擎输出,IO 的结果取自向量的下一个事件。逐步核对适配器回给引擎的事件和最终映射结果,共回放 23 条轨迹。crash hold、forceActivate、轮次预算、下载超时这几类鸿蒙不会产生的轨迹,以及故意制造协议错误的轨迹,没有纳入。
  • 负向对照:去掉适配器里 config_changed 的分支,对应用例会失败。
  • 这个新测试取代了 harmonySyncQuery、harmonySyncAttempts,它们测的函数已经删除。
  • nativeHostApi.test.ts 改为用按场景出命令的假引擎来驱动宿主 API。12 个用例的断言保持不变。
  • 本地全部通过:bun test(456 个)、bun run lint(含 DevEco SDK 的鸿蒙类型检查)。pushy.cpp 用 SDK 的 clang 编译通过。

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Updates
    • Harmony update checks now follow a coordinated flow from configuration checks through downloading and installation.
    • Update downloads observe request and overall time limits, and report timeouts or download failures.
    • Cancellation and configuration changes are handled separately during update operations.
  • Reliability
    • Harmony update flows are verified against shared scenarios, including successful completion and failure cases.

…gine

SyncCoordinator.ts's hand-written round (runConfiguredRound, the endpoint
query walk, the two-budget performAttempts loop, runWithinDeadline and the
result mapping) becomes a loop over NativePatchCore.stepRound (new
synchronous NAPI binding over flowcore::StepRoundJson) that runs the
commands it returns: the breadcrumb, the launch env, HTTP, the installed
check, downloads and the commit. HTTP and downloads stay asynchronous
ArkTS; each engine step is a cheap synchronous call, so nothing blocks the
single thread. The host's post-wait check compares configs by C1
equivalence (was string equality), matching Android and iOS.

Tests: harmonySyncRound.test.ts replays the round-engine vectors against
the adapter (the vectors' commands stand in for the engine, the IO answers
come from the next vector event) and checks every event the adapter sends
back plus the mapped result; it replaces the query-walk and attempt-loop
tests of the deleted functions. nativeHostApi.test.ts drives the host API
through a scripted engine instead of the removed functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 12417616-5f10-42b7-ac2d-592dc1e5fd26
📥 Commits

Reviewing files that changed from the base of the PR and between bf4522c and eaa1a15.

📒 Files selected for processing: 8
  • docs/NATIVE_CHECKUPDATE_DESIGN.md
  • harmony/pushy/src/main/cpp/pushy.cpp
  • harmony/pushy/src/main/ets/NativePatchCore.ts
  • harmony/pushy/src/main/ets/SyncCoordinator.ts
  • src/__tests__/harmonySyncAttempts.test.ts
  • src/__tests__/harmonySyncQuery.test.ts
  • src/__tests__/harmonySyncRound.test.ts
  • src/__tests__/nativeHostApi.test.ts
💤 Files with no reviewable changes: 2
  • src/tests/harmonySyncAttempts.test.ts
  • src/tests/harmonySyncQuery.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Walkthrough

Harmony now uses NativePatchCore.stepRound to drive update rounds. SyncCoordinator executes the engine’s commands for host IO and maps the final result. Tests replay shared round vectors and use a scripted engine for host API coverage.

Changes: Harmony round-engine adapter

Layer / File(s) Summary
Expose the native round step
harmony/pushy/src/main/cpp/pushy.cpp, harmony/pushy/src/main/ets/NativePatchCore.ts
The native module exports synchronous stepRound, which calls StepRoundJson. The TypeScript binding accepts an optional state and an event JSON string.
Drive rounds through the engine
harmony/pushy/src/main/ets/SyncCoordinator.ts
runOnce passes events and state to stepRound, executes emitted commands, and tracks reset and configuration generations. Cancellation checks use configuration equivalence and stored-config validation.
Execute commands and report outcomes
harmony/pushy/src/main/ets/SyncCoordinator.ts
The coordinator executes engine-selected downloads, commits results, maps final statuses, and uses request-specific HTTP timeouts. It no longer implements query planning or download retries locally.
Validate the Harmony adapter
src/__tests__/harmonySyncRound.test.ts, src/__tests__/nativeHostApi.test.ts, src/__tests__/harmonySyncAttempts.test.ts, src/__tests__/harmonySyncQuery.test.ts, docs/NATIVE_CHECKUPDATE_DESIGN.md
Round-vector tests replay eligible rounds and check adapter results. Host API tests use a scripted engine. The previous query and attempt test suites are deleted. The design progress note records the adapter and cancellation behavior.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant SyncCoordinator
  participant NativePatchCore
  participant HarmonyHostIO
  loop Until the engine finishes the round
    SyncCoordinator->>NativePatchCore: stepRound with state and event
    NativePatchCore-->>SyncCoordinator: state and commands
    SyncCoordinator->>HarmonyHostIO: execute emitted command
    HarmonyHostIO-->>SyncCoordinator: return command result as an event
  end
Loading
Merge Risk: ⚪ Minimal · up to f331f

Merge Risk: ⚪ Minimal · up to f331f

No actionable merge-blocking risk remains from the inspected round loop or download deadline behavior; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: Harmony now drives the native round through the shared round engine.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 5 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…atforms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sunnylqm
sunnylqm merged commit 14f1b2f into master Oct 15, 2026
14 checks passed
@sunnylqm
sunnylqm deleted the claude/round-engine-harmony branch October 15, 2026 14:20
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