Skip to content

build: generate the cross-platform constants and binding tables from one source - #683

Merged
sunnylqm merged 2 commits into
masterfrom
claude/native-contract
Oct 16, 2026
Merged

sunnylqm merged 2 commits into
masterfrom
claude/native-contract

Conversation

@sunnylqm

@sunnylqm sunnylqm commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

架构审查"对等性改为单一来源生成"的第一个 PR。

为什么

跨端必须一致的值,原先是手抄到 C++ / Java / ArkTS / JS 几份,再靠正则检查器去对。盘点下来共 20 组,其中有好几组完全没有守卫:状态操作码、补丁类型枚举、宿主结果状态、存储键、ABI 列表、vendored 源文件列表。

怎么做

  • 常量:scripts/contract.ts 是唯一来源。scripts/generate-contract.ts 负责改写各文件里 <generated:NAME> … </generated:NAME> 标记之间的内容,共 36 个区块:
    • 错误码:C++、Java、ArkTS、src/error.ts
    • 解压上限、install record 常量、query 预算
    • 状态操作码
    • 补丁类型:C++ 枚举、Java/ArkTS 任务类型、iOS PushyType
    • Android/鸿蒙共用的存储键、轮次状态
    • Android ABI
    • vendored 解码源文件:Android.mk、CMakeLists.txt、test-patch-core.sh、check-packlist.js
  • 绑定表:由调用侧的声明生成,contract 只补充"背后是哪个 C++ 函数"。
    • Harmony PUSHY_METHODS 和 oldarch NativePushySpec ← src/NativePushy.ts
    • JNI 注册表和 jni_natives.h 原型 ← Java native 声明
    • NAPI 导出 ← NativePatchCore.ts
  • 检查器:
    • bun lint 改跑 generate-contract.ts --check,有区块不是最新时报错并列出文件。
    • check-constant-parity.js 删除。
    • check-native-spec-parity.js 只保留生成器写不了的部分,即三端各自的实现是否存在。
    • jniRegistration 和 NAPI 导出两个测试保留,它们独立解码生成物做交叉验证。jni 测试去掉了写死的数量 19。
  • 平时用法:改 scripts/contract.ts,然后运行 bun run contract。

生成出来的值与原先手写的逐字节一致,JNI 编码表也完全一致,所以 .so 不需要重编。变化只有三处:

  • PUSHY_METHODS 改成按 spec 的顺序排列。
  • jni_natives.h 里的参数名统一成 snake_case。
  • 鸿蒙新增了一个 ARCHIVE_PATCH_TYPE_FULL 常量,目前没有地方用。

验证

  • bun run lint 通过,bun test 458 个用例全部通过。
  • 负向对照:手改一个生成区块,--check 报错并指出文件;改 contract 里的一个值,所有副本一起变。
  • C++ 侧:update_flow_core、patch_core 的测试都通过。
  • iOS:purge-restore 测试和轮次回放通过;.mm 用 Pods 头文件做 -fsyntax-only 通过。
  • 鸿蒙:pushy.cpp 用 DevEco SDK 的 clang 编译通过。
  • Android:testReleaseUnitTest 编译通过,单测全部通过。

下一个 PR 做编码明文登记表:把散在各端的编码字面量和默认服务地址也收进同一来源。

🤖 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

  • Chores
    • Added automated generation and validation for shared settings and native bindings across platforms, helping keep platform implementations aligned.
    • Updated lint checks to verify native method implementations and generated declarations.
    • Existing runtime behavior and shared setting values remain unchanged. No end-user-facing changes are included.

…one source

Values every platform must agree on were copied by hand into C++, Java,
ArkTS and JS and held together by regex checkers, and several groups had no
guard at all (state operation codes, archive patch types, round statuses,
storage keys, the ABI and vendored-source lists).

scripts/contract.ts is now the single source of those values, and
scripts/generate-contract.ts rewrites every `<generated:NAME>` region from
it: error codes (C++, Java, ArkTS, src/error.ts), archive limits, install
record constants, the query budget, state operations, archive patch types
(C++, Java and ArkTS task types, iOS PushyType), the Android/Harmony storage
keys, the round statuses, the Android ABIs and the vendored decoder sources
(Android.mk, CMakeLists.txt, test-patch-core.sh, check-packlist.js).

Binding tables are generated from the calling-side declarations: the Harmony
PUSHY_METHODS table and the old-architecture NativePushySpec from
src/NativePushy.ts, the JNI registration table and prototypes from the Java
`native` declarations, the NAPI exports from NativePatchCore.ts; the
contract only names the C++ function behind each.

`bun lint` runs the generator with --check instead of
check-constant-parity.js (removed); check-native-spec-parity.js keeps only
what no generator can write, the per-platform implementations. Generated
values are byte-identical to the hand-kept ones (the JNI table included);
the method table is reordered to spec order.

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

coderabbitai Bot commented Oct 16, 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: 737fc18d-c642-4da1-b8b8-6bdf32e944f7
📥 Commits

Reviewing files that changed from the base of the PR and between e11c13d and 0e38172.

📒 Files selected for processing: 40
  • .github/workflows/lint.yml
  • android/jni/Android.mk
  • android/jni/Application.mk
  • android/src/main/java/cn/reactnative/modules/update/ArchiveLimits.java
  • android/src/main/java/cn/reactnative/modules/update/BundlePreparationResult.java
  • android/src/main/java/cn/reactnative/modules/update/DownloadTaskParams.java
  • android/src/main/java/cn/reactnative/modules/update/ErrorCodes.java
  • android/src/main/java/cn/reactnative/modules/update/InstallRecord.java
  • android/src/main/java/cn/reactnative/modules/update/SyncCoordinator.java
  • android/src/main/java/cn/reactnative/modules/update/UpdateContext.java
  • android/src/oldarch/cn/reactnative/modules/update/NativePushySpec.java
  • cpp/android_jni/jni_natives.h
  • cpp/android_jni/jni_registration.cpp
  • cpp/patch_core/archive_limits.h
  • cpp/patch_core/archive_patch_core.h
  • cpp/patch_core/error_codes.h
  • cpp/patch_core/install_record.h
  • cpp/patch_core/state_ops.h
  • cpp/update_flow_core/native_round.h
  • harmony/pushy/src/main/cpp/CMakeLists.txt
  • harmony/pushy/src/main/cpp/PushyTurboModule.cpp
  • harmony/pushy/src/main/cpp/pushy.cpp
  • harmony/pushy/src/main/ets/ArchiveLimits.ts
  • harmony/pushy/src/main/ets/DownloadTaskParams.ts
  • harmony/pushy/src/main/ets/ErrorCodes.ts
  • harmony/pushy/src/main/ets/InstallRecord.ts
  • harmony/pushy/src/main/ets/NativePatchCore.ts
  • harmony/pushy/src/main/ets/SyncCoordinator.ts
  • ios/RCTPushy/RCTPushyInternal.h
  • package.json
  • scripts/check-constant-parity.js
  • scripts/check-native-spec-parity.js
  • scripts/check-packlist.js
  • scripts/contract.ts
  • scripts/generate-contract.ts
  • scripts/test-patch-core.sh
  • scripts/verify-android-so.js
  • src/__tests__/jniRegistration.test.ts
  • src/endpoint.ts
  • src/error.ts
💤 Files with no reviewable changes: 1
  • scripts/check-constant-parity.js

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

📝 Walkthrough

The pull request adds a shared TypeScript contract catalog and a generator for marked regions across platform files. It also changes lint and native parity checks, and adds a contract-generation command.

Changes: Shared contract generation

Layer / File(s) Summary
Define shared contract data
scripts/contract.ts
Defines shared error codes, limits, install-record values, operation and patch types, storage keys, statuses, build inputs, and JNI/NAPI mappings.
Parse inputs and generate regions
scripts/generate-contract.ts
Parses React Native, Java, and Harmony declarations. Generates contract values and native tables, validates configured mappings and marked regions, and supports --check.
Generate shared values across platform files
android/*, cpp/*, harmony/pushy/src/main/*, ios/*, src/*, scripts/check-packlist.js, scripts/test-patch-core.sh, scripts/verify-android-so.js
Marks shared values, native declarations and registrations, build settings, and vendored-source lists for generation. Adds ARCHIVE_PATCH_TYPE_FULL in Harmony and moves three error codes into the native-code group in src/error.ts.
Update native checks and generator commands
.github/workflows/lint.yml, package.json, scripts/check-constant-parity.js, scripts/check-native-spec-parity.js, src/__tests__/jniRegistration.test.ts
Lint checks generated-contract freshness, and a new package command runs the generator. Removes the constant-parity checker. The native parity check no longer checks the old-architecture Android spec or Harmony Promise-return-to-ASYNC matching; the JNI test no longer requires exactly 19 declarations.

Priority: ➖ Normal

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

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Contract as scripts/contract.ts
  participant Spec as NativePushy.ts
  participant Java as Java native declarations
  participant Harmony as Harmony NAPI bindings
  participant Generator as scripts/generate-contract.ts
  participant Regions as Marked generated regions
  Contract->>Generator: Provide shared values and function mappings
  Spec->>Generator: Provide React Native method declarations
  Java->>Generator: Provide native method declarations
  Harmony->>Generator: Provide NAPI binding names
  Generator->>Regions: Rewrite generated content or check for stale content
Loading
Merge Risk: ⚪ Minimal · up to 0e381

No identified issue blocks merging 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 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 34 files. (5 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: generating cross-platform constants and binding tables from a single source.
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 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 34 files. (5 skipped: 5 unsupported.)

  • Fix all pre-merge checks with AI
✨ 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.

A comment line inside the backslash continuation ended the assignment and
turned the source lines into recipe lines (ndk-build: recipe commences
before first target).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sunnylqm
sunnylqm merged commit 72a49c1 into master Oct 16, 2026
16 checks passed
@sunnylqm
sunnylqm deleted the claude/native-contract branch October 16, 2026 08:34
sunnylqm added a commit that referenced this pull request Oct 16, 2026
…ource

error_codes.h is generated from scripts/contract.ts since #683; the reset
contract comment this PR changed by hand belongs in the source, or the
generator's --check fails lint once this lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sunnylqm added a commit that referenced this pull request Oct 16, 2026
… the state is reset (#671)

* test(cpp): compile the shared cores with each platform's release flags

The unit tests build cpp/patch_core and cpp/update_flow_core with the host
c++ (on CI g++/libstdc++), C++17, RTTI and asserts on. No shipped binary is
built that way: Android uses -fno-rtti -fexceptions, iOS compiles with the
C++20 React Native selects, and every release defines NDEBUG. A construct
only one platform rejects first failed in that platform's build.

scripts/test-core-platform-flags.sh syntax-checks every core source with
the three release flag sets under -Werror, preferring clang (the compiler of
every shipped binary). test.yml's C++ job runs it; `bun run test:core-flags`
locally.

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

* ci(test): run the core flag check when a platform's flag file changes

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

* fix(ios): resolve resetToPackagedBundle once the state is reset

Android and HarmonyOS settle the reset promise once the reset state is
persisted and delete the downloaded versions best-effort afterwards; iOS
waited for that cleanup and rejected with RESET_FAILED when it failed (its
comment claimed Android parity). Align iOS with the other two: the reset is
complete once the state is (the next launch resolves to the packaged bundle),
and a directory a failed delete leaves behind is unreferenced, so the regular
cleanup removes it later. Waiting instead would have put Android's and
Harmony's reset behind an in-flight download on their serial queues.

RESET_FAILED now means only that the reset state could not be persisted
(error_codes.h, the client's doc comment); the purge-restore test asserts the
new contract.

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

* test(ios): pin that reset resolves even when its cleanup fails

The cleanup stub now fails: the reset promise must still resolve, and the
cleanup must still run. A reset that waited for the delete again rejects
here (checked by restoring the previous behavior: reset_wins fails).

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

* build(contract): carry the new RESET_FAILED meaning in the contract source

error_codes.h is generated from scripts/contract.ts since #683; the reset
contract comment this PR changed by hand belongs in the source, or the
generator's --check fails lint once this lands.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@sunnylqm sunnylqm mentioned this pull request Oct 16, 2026
sunnylqm added a commit that referenced this pull request Oct 17, 2026
Bump package.json and harmony/pushy/oh-package.json5 together, with the
bilingual release notes. Ships everything since 10.60.0: the shared native
round engine (#673-#681), the cross-platform alignment and fixes (#664,
#666, #671, #687, #688), the JS client fixes and split (#667, #684, #685),
the bounded host prepareBundle (#669), the generated cross-platform contract
(#683, #686) and the trimmed npm package (#670).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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