Skip to content

feat(kotlin): 插件 API、统一事件、测试工具与运行时契约(#390) - #498

Merged
eric8810 merged 1 commit into
mainfrom
feat/kotlin-api
Oct 19, 2026
Merged

eric8810 merged 1 commit into
mainfrom
feat/kotlin-api

Conversation

@eric8810

Copy link
Copy Markdown
Contributor

Kotlin SDK K-P1 的第二部分(第一部分 #492 已合并),按设计 §三、§四与运行时契约。

内容

  • 插件 API 3:Rutis.define<C>(name, inject, provides?, schema?) { ctx, config -> };配置是 @Serializable 类型,经 RutisFormat 解码,schema 由 SerialDescriptor 推出(可覆盖);service<T>(sync = …) 声明方法种类(默认 async)。
  • Ctx:行的协程作用域(卸载时取消并等待);use<I>(@RutisClient 代理;同进程提供者实现 I 时得到对象本身;调用对端 sync 方法时帧带 sync: true);provide(没声明的服务以 rows.announce 通告,方法全为 async;宿主比 0.12 旧时按契约提示一次);effect。
  • 运行时:mount(features rows.v2、hosts、leaf、scopes、rows.announce;plugins、implementation、engine)、rows.schema / load / update / unload、hosts.provide / withdraw、release、get、dispose;调用方的行(每行按 isolate 计算自己的服务 id,标签不透明);插件 API 版本检查。
  • 统一事件:on(prepend、global,监听器一律 kind: "sync")、emit / parallel / serial / waterfall / bail / filter;快速路径与 events.dispatch(选择器函数引用、terminal);events.on / off / elsewhere / call 在读线程上按帧序处理;emit 按监听器串行;作用域;卸载时拒绝该行的 events.call、撤下服务、取消并等待正在运行的监听器(RUTIS_SHUTDOWN_TIMEOUT);rutis/* 只可监听;报告行原文;对没有 events-v2 的宿主握手后按原文拒绝。
  • jvm 测试入口 Rutis.serve(args, plugins…)(unix: / 裸路径 / tcp: 加令牌):会话结束卸载全部行;旧宿主或清理超时以 1 退出。
  • 测试工具 arcships.rutis.testing(RutisTest.load):内存通道上的真实会话,测试一方是宿主。
  • rutis-conformance:weather 与 conformance-events 插件;测试工具对 weather.expected.json、events.expected.json(51 个用例)的检查。
  • 期望文件:weather 加 kotlin/* 样例值;events 的语言加 kotlin(Kotlin 监听器是同步的,两个 async-listener 用例与 Go、Swift 一样除外),toolCases 加 kotlin: 51;events.rs 记下 Kotlin 的取消(CancellationException)。
  • Rust:session_matrix 加 Kotlin(回拨 socket 路径、loopback);loader 的测试 feature kotlin,events_conformance 以 Kotlin 为 X 并作其他语言的 Y。
  • CI:runtimes-kotlin 加 session_matrix 与 events_conformance。

与设计的出入

  • 被行卸载取消、而分发仍在进行的监听器以"没有结果"结束:被取消的协程不能正常返回值(Go、Python 的监听器取消后返回,效果相同)。

验证(本机)

  • ./gradlew build:单元测试 22 项(新增运行时测试 4 项),测试工具对 weather 期望全部条目、对 events 期望 51 个用例通过。
  • session_matrix Kotlin 2 项;events_conformance(node、python、kotlin 必需)写定放置 4 项全部通过,抽样放置下 Kotlin 作 X 全部用例通过;events_expected 通过;clippy、fmt 干净。

Refs #390

Kotlin SDK K-P1 的第二部分:

- 插件 API 3:Rutis.define<C>(name, inject, provides?, schema?) { ctx, config -> };
  配置是 @serializable 类型,经 RutisFormat 解码,schema 由 SerialDescriptor 推出
  (可覆盖);service<T>(sync = …) 声明方法种类(默认 async);Ctx 是行的协程
  作用域(卸载时取消并等待),use<I>(@RutisClient 代理;同进程提供者实现 I 时
  得到对象本身)、provide(没声明的服务以 rows.announce 通告,方法全为 async;
  宿主比 0.12 旧时按契约提示一次)、effect(卸载时逆序)。
- 运行时:mount(features rows.v2、hosts、leaf、scopes、rows.announce;
  plugins、implementation、engine)、rows.schema / load / update / unload、
  hosts.provide / withdraw、release、get、dispose;调用方的行(每行按 isolate
  计算自己的服务 id);插件 API 版本检查。
- 统一事件:on(prepend、global,监听器一律 kind sync)、emit / parallel / serial /
  waterfall / bail / filter;快速路径与经宿主的 events.dispatch(filter 为选择器
  函数引用、terminal);events.on / off / elsewhere / call 在读线程上按帧序处理;
  emit 按监听器串行;作用域;卸载时拒绝该行的 events.call、撤下服务、取消并
  等待正在运行的监听器(RUTIS_SHUTDOWN_TIMEOUT);rutis/* 只可监听;
  报告行原文;对没有 events-v2 的宿主握手后按原文拒绝。
- jvm 测试入口 Rutis.serve(args, plugins…)(unix: / 裸路径 / tcp: 加令牌):
  会话结束卸载全部行,清理超过时限或旧宿主时以 1 退出。
- 测试工具 arcships.rutis.testing(RutisTest.load):内存通道上的真实会话,
  测试一方是宿主(服务、总线、行与作用域)。
- rutis-conformance:weather 与 conformance-events 插件、Main(Rutis.serve);
  测试工具对 weather.expected.json 与 events.expected.json 的检查(51 个用例)。
- 期望文件:weather 加 kotlin/* 样例值;events 的语言加 kotlin(Kotlin 监听器
  是同步的,两个 async-listener 用例除外),toolCases 加 kotlin 51;
  events.rs 记下 Kotlin 的取消(CancellationException)。
- Rust:session_matrix 加 Kotlin(回拨 socket 路径、loopback);loader 的测试
  feature kotlin,events_conformance 以 Kotlin 为 X,并作其他语言的 Y。
- CI:runtimes-kotlin 加 session_matrix 与 events_conformance。
@eric8810 eric8810 added this to the 0.14 milestone Oct 19, 2026
@eric8810
eric8810 merged commit 4f0df08 into main Oct 19, 2026
70 of 72 checks passed
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