Skip to content

feat(api): Generate* wrappers and consistency runners for the remaining nine bindings - #385

Merged
Peefy merged 7 commits into
mainfrom
feat/generate-rpc-parity-and-consistency
Oct 5, 2026
Merged

Peefy merged 7 commits into
mainfrom
feat/generate-rpc-parity-and-consistency

Conversation

@Peefy

@Peefy Peefy commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #383, which covered go/python/java/.NET/node. This does the
other nine — c, cpp, dart, julia, lua, ruby, swift, wasm, zig — bringing
each to the same shape: the five Generate* RPCs behind typed wrappers,
and a runner over the shared goldens in tests/consistency/cases.json.

What it does

Wrappers. Each follows the dispatch contract the existing calls
already use: encode the args, invoke libkcl.call, decode the reply,
surface an ERROR:-prefixed payload as the language's own error type.
Kotlin additionally gets FormatTestReport, which its DSL wrappers had
no coverage for at all.

Consistency runners. All nine drive the same 13 cases; the seven
new_core ones skip on a core that predates them, through the existing
listMethod probe.

How many of the 13 actually run

Worth being precise about, because the number is a property of the
core
, not of the wrapper — and it varies by runner:

how the binding gets its core bindings cases run
vendored prebuilt, darwin-arm64 — rebuilt in #383 dart, julia, zig 13/13
vendored prebuilt, other platforms — still the older runtime dart, julia, zig on Linux; nodejs, python, go 6/13
built from a Cargo lock at da01314 or later cpp, lua 13/13
built from an older lock / explicit old rev c (842b02b), ruby (931e6a9), swift 6/13
prebuilt kcl.wasm wasm 6/13

The same binding therefore gets different coverage on different runners,
which is worth knowing before reading a 6/13 as a wrapper gap. swift was
separately verified at 13/13 by relinking against a newer core, so its
skips are the pin and not the wrapper.

Also fills the last two shape gaps: the facade (dart) and the plugin
layer (ruby, wasm).

Four bugs found along the way

dart dispatched listMethod to the wrong service. spec.proto
declares that one RPC under BuiltinService; the wrapper used
KclService.ListMethod. The dispatcher logged unknown method name,
panicked on a Rust background thread, and returned an empty payload,
which protobuf happily decoded into a default-valued message. It failed
silently, and several bindings had tests that tolerated that emptiness
and so could never have caught it.

The prebuilt cores disagree about whether ListMethod exists at all.
#383 rebuilt only darwin-arm64 and said so. On Linux the vendored runtime
does not implement the RPC:

thread '<unnamed>' panicked at .../capi.rs:229:14:
unknown method name : BuiltinService.ListMethod

So the dart/julia/zig guards asserting a non-empty table passed on my
machine and failed on every Linux leg. Each now asserts the one thing
that holds whatever the core is — that the table never names
KclService.ListMethod — and checks the rest only when there is a table
to inspect. The residual gap is inherent: on a core with no ListMethod
there is nothing in the reply to tell "too old" from "misrouted".

lua's schema.lua had drifted to 20 messages and 6 RPCs. Every
message added since was simply absent, and a caller reaching for one got
a nil index rather than an error. Regenerated, with make proto to keep
it from drifting again.

ruby's MethodArgs.parse documents @raise [ArgumentError] but let
JSON::ParserError through, surfacing the parser's own wording —
unexpected token 'not' at line 1 column 1 for a payload of not json,
which echoes none of the payload and does not say which of the two was at
fault.

A fifth turned up only in CI: lua's generate_openapi asserted
components.schemas.AppConfig, but the runtime qualifies schema names
with their package, so the key is AppConfig___main__. It passed locally
only because my rock predates the RPC and the case pends; CI builds from
source and actually executed it.

CI

hack/ast_diff.rb compares what each binding's AST decoder actually
produces against a single golden and reports disagreement across
bindings. It had never run in CI. New ast-diff-test.yaml runs it on a
ten-binding matrix — all ten green, and 10 agreed, 0 disagreed, 0
vacuous
.

Every binding's workflow also filtered pull requests on its own
directory, so a change to tests/consistency/ or testdata/ast/ — the
goldens the runners and the differ both read — would not trigger any of
them. All fifteen now include tests/consistency/**.

Getting the new workflow green took four fixes that only a real runner
would have surfaced: maturin develop with no virtualenv,
setup-swift on Linux (a limitation swift-test.yaml already
documents, so swift gets its own runner), setup-zig with no version,
and gh-actions-lua defaulting to 5.5 against a rockspec requiring < 5.5.

Verification

Every binding, from the CI logs for this branch:

dart 124 pass (macOS) / 115 + 9 skip (Linux) ruby 145 runs, 645 assertions, 0 fail, 9 skip
zig 284 pass, 0 leaks swift 102 pass, 1 skip
c 6 pass / 7 skip of 13 wasm 145 pass, 17 suites
cpp 21 pass, 13/13 consistency go ok
julia 419 pass; 13/13 (macOS), 6 run / 7 skip (Linux) nodejs 109 pass
kotlin 106 pass, 7 skip python 162 pass
java 75 pass, 0 skip lua 119 pass, 0 pending

dotnet was not run locally — it is not installed here — but its
workflow and its AST-diff leg both pass in CI.

Non-vacuity was proven rather than assumed: tampering a manifest golden
makes the c and ruby runners fail, and the manifests restore
byte-identically afterwards.

License Compliance reports error, but identically on main — FOSSA
finds the same 3 issues on both, so this PR adds none.

Reviewer notes

  • lua/hack/schema_header.lua + make proto: hack/generate_pb.lua is
    not deterministic across runs, so a diff in schema.lua is only
    meaningful if the header still matches.
  • Commits fix(dart,julia), fix(lua) and fix(ruby) are pure bug
    fixes and reviewable independently of the feature work.

🤖 Generated with Claude Code

Peefy and others added 5 commits October 5, 2026 13:59
spec.proto declares ListMethod under BuiltinService, but every other RPC
is registered under KclService regardless. Dart's listMethod() was the one
place that followed neither: it called KclService.ListMethod, which the
dispatcher does not know. The call did not raise — the dispatcher logs
`unknown method name`, panics on a Rust background thread and returns an
empty payload, which protobuf decodes into a default-valued message. So
listMethod() silently reported "this core implements nothing" while
printing a panic to stderr. Route it to BuiltinService.ListMethod, which
is what the other 14 bindings already do.

That silent failure is why the Dart and Julia tests wrapped the assertion
in "if the list is non-empty". Both cores return the full 28-name table
(verified against go/lib/darwin-arm64/libkcl.dylib and the vendored
libkcl.jll), so the guard only ever hid a real regression. Assert the
table unconditionally now; an empty result means the wrapper picked the
wrong service name again, which is exactly what these pin down.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Peefy <xpf6677@163.com>
… 6 RPCs

The checked-in descriptor table was stale relative to spec.proto, so
any message added since it was written was simply absent — the
Generate* Args/Result pairs among them. A caller reaching for one got a
nil index rather than an error.

Regenerated in full and added `make proto` so it does not drift again.
`hack/generate_pb.lua` emits the bare descriptor blob, so the target
re-prepends `hack/schema_header.lua` afterwards; the header is what
documents where the file came from and how to rebuild it.

Worth knowing before touching this file: the generator is not
deterministic across runs — it emits messages in a different order each
time — so a diff here is only meaningful if the header still matches.

Also adds `make test`, which was missing.

Signed-off-by: Peefy <xpf6677@163.com>
…ng bindings

Brings the nine bindings #383 did not cover — c, cpp, dart, julia, lua,
ruby, swift, wasm, zig — to the same shape as go/python/java/.NET/node:
the five Generate* RPCs behind typed wrappers, and a runner over the
shared goldens in tests/consistency/cases.json.

Wrappers follow the dispatch contract the existing calls already use:
encode the args, invoke libkcl.call, decode the reply, surface an
`ERROR:`-prefixed payload as the language's own error type. Kotlin
additionally gets FormatTestReport, which its DSL wrappers had no
coverage for at all.

The consistency runners drive the same 13 cases. The seven new_core
cases skip on runtimes that predate them through the existing
listMethod probe, so this lands green everywhere:

  13 run   dart, julia, zig      prebuilt 28-RPC core
   6 run   c, cpp, lua, ruby,    pinned kcl-api revs / stale kcl.wasm
           swift, wasm

swift was separately verified at 13/13 by relinking against a core
built from a newer kcl-api, so its skips are the pin and not the
wrapper.

Also fills the last two gaps against the reference shape: the facade
(dart) and the plugin layer (ruby, wasm).

Signed-off-by: Peefy <xpf6677@163.com>
…en changes

Two gaps in the pipeline.

hack/ast_diff.rb compares what each binding's AST decoder actually
produces against a single golden, and reports disagreement across
bindings. It had never run in CI, so a decoder could drift and nothing
would notice until someone noticed. New ast-diff-test.yaml runs it on a
ten-binding matrix; on the current tree it is 10 agreed, 0 disagreed,
0 vacuous.

The other gap: every binding's workflow filtered pull requests on its
own directory, so a change to tests/consistency/ or testdata/ast/ — the
goldens the runners and the differ both read — would not trigger any
of them. All fifteen now include tests/consistency/** in their path
filters.

The dart job needs the prebuilt core on its library path. Resolving it
from go/lib/<platform>/ rather than checking it out separately, since
that is where the repo already vendors it; the directory is
linux-amd64, following the Go embed dirs rather than the Rust/NuGet
target names.

Signed-off-by: Peefy <xpf6677@163.com>
MethodArgs.parse documents `@raise [ArgumentError] when a payload is not
JSON of the expected shape`, and handles the wrong-shape half of that
by naming the offending payload. The malformed half fell straight
through to JSON.parse, so it raised JSON::ParserError instead — a
different type than the one documented — and surfaced the underlying
parser's wording rather than anything a plugin author can act on:

  unexpected token 'not' at line 1 column 1

for a payload of `not json`, which neither echoes the payload nor says
whether the positional or the keyword argument was at fault.

Route both payloads through one helper so a parse failure is reported
the same way a shape failure is.

Signed-off-by: Peefy <xpf6677@163.com>
@Peefy
Peefy force-pushed the feat/generate-rpc-parity-and-consistency branch from e35812b to 4932199 Compare October 5, 2026 06:00
Peefy added 2 commits October 5, 2026 14:27
… cores

Five of these were found by CI on the platforms I could not test locally,
and two of them contradict a comment the first commit got wrong.

**The assumption that was wrong.** 8c9fceb rebuilt only darwin-arm64 and
said so: "Other platforms keep skipping new-core cases until their
prebuilt runtimes are refreshed." That is still true — the linux-amd64
runtime this repo ships does not implement BuiltinService.ListMethod at
all. Asking it prints

  thread '<unnamed>' panicked at .../capi.rs:229:14:
  unknown method name : BuiltinService.ListMethod

and returns an empty table. So the dart/julia/zig guards asserting a
non-empty table passed on my machine and failed on every Linux leg. Each
now asserts the one thing that holds whatever the core is — that the
table never names KclService.ListMethod, which is what a regression to
the wrong service would produce — and checks the rest only when there
is a table to inspect. The residual gap is inherent: on a core with no
ListMethod at all there is nothing in the reply to distinguish "too old"
from "misrouted".

**A lua test that had never run.** generate_openapi asserted
`components.schemas.AppConfig`, but the runtime qualifies schema names
with their package, so the key is `AppConfig___main__`. It passed
locally because my rock predates the RPC and the case pends; CI builds
from source and actually executed it. Match the prefix instead — the
exact key is the core's naming policy, not this fixture's business.

**ast-diff-test.yaml setup, four ways.** All four only ever ran on my
machine: `maturin develop` with no virtualenv, `setup-swift` on a Linux
runner (the limitation swift-test.yaml already documents), `setup-zig`
with no version, and gh-actions-lua defaulting to 5.5 against a rockspec
that requires < 5.5. Each now mirrors the working per-binding workflow;
swift gets its own runner.

Signed-off-by: Peefy <xpf6677@163.com>
The swift leg moved to macos-latest so setup-swift could provision it, but
"Install protobuf" is unconditional and the runner has no apt:

  sudo: apt-get: command not found

Guard it to Linux. Nothing on the swift leg needs protoc — the dump
driver compiles the AST sources standalone with swiftc — and the Linux
bindings that do are covered by this step or by arduino/setup-protoc.

Signed-off-by: Peefy <xpf6677@163.com>
@Peefy
Peefy merged commit e11e04b into main Oct 5, 2026
89 of 90 checks passed
@Peefy
Peefy deleted the feat/generate-rpc-parity-and-consistency branch October 5, 2026 09:42
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