Repository navigation
chore(herdr-core): type hc calls from hc's own OpenRPC schema - #2671
Conversation
Generate server/herdr-core/hc-api.generated.ts from a snapshot of `hc schema` (scripts/hc-schema.json, hc 0.1.14, the version the live contract pins) in the same generate:types run and --check as herdr's wire types. HcConnection.call and open are typed by the generated HcMethods map, and the hand-written hc record types derive from the generated ones. The herdr-core live job now fails when the pinned hc publishes a schema other than the snapshot.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 30 minutes. View limit details
Summary
Pre-merge checks:
|
- A union with a variant that admits any value now renders as unknown, instead of dropping that variant and narrowing the type. - The hc drift test moves into generate-protocol-types.test.ts: both files rewrite the generated outputs, and tests of one file run one at a time while separate files may run side by side.
|
Adversarial review (Codex, gpt-6.1-terra, xhigh) at 33aed87. What it found and what changed in c564175:
Checks: |
|
Merge note: CodeRabbit was rate-limited for the latest head (c564175), so this merges on the omo review (CLEAR receipt at c564175), the Codex Terra adversarial review (2 reproduced MEDIUMs fixed; 1 MEDIUM - the live drift job is not a required check - and 1 LOW left as notes) and green required checks. |
…echeck (#2693) ## Summary origin/main (12a7c63) fails `bun run typecheck` with four errors in `server/herdr-core/adapter.ts`. #2671 typed `HcConnection.call` and `open` by hc method name, generated from hc's own schema. #2674, merged right after it, added a `hc.open<{ channel: number; terminal?: HcTerminal }>("terminal.attach", ...)` and a `hc.call<{ text: string }>("terminal.read", ...)` written for the old untyped signature, where the type argument was the result type. This drops those two type arguments. The method name now types both calls: `terminal.attach` gives `AttachResult` (whose `terminal.rows` the code reads) and `terminal.read` gives `ReadResult` (whose `text` it reads). Nothing changes at runtime. No changelog fragment: users notice nothing. ## Validation - `bun run typecheck`: clean (four errors on main before). - `HERDR_TEST_MODE=unit bun test server/herdr-core`: 90 pass, 0 fail. - `bun run check fast`: not run locally. The heavy-run slots were all held by other lanes, so the lead chose to let CI's Fast checks gate this PR. - Not run: Integration and browser lanes, and Windows. CI runs them.
…hod name Main now types HcConnection.call by the hc method (#2671); the test written before that passed a result type instead.
Summary
Ovis's herdr-core (
hc) client was typed by hand (hc.call<{ terminals: HcTerminal[] }>(...)), while herdr's own API types are generated from herdr's schema. This PR generates the hc side too, from hc's own OpenRPC document, in the samebun run generate:typesrun and--check.scripts/hc-schema.json:hc schemafrom hc 0.1.14, the version ci.yml'sherdr-core-livejob pins. herdr-core's schema is Apache-2.0 (itsinfo.license), taken straight from thehcbinary.scripts/hc-types.tsemitsserver/herdr-core/hc-api.generated.ts: params and results for the 13 methods Ovis calls (HC_METHODS), the records they name, and anHcMethodsmap. String enums widen with(string & {})as herdr's do.HcConnection.call/openare typed byHcMethods, so a method name, a param or a result field hc does not have is now a type error.HcTerminal,HcStatusandHcForegroundderive from the generated records.generate:types --check(Fast checks) fails when the generated file is stale;server/herdr-core/live.test.ts(theherdr-core-livejob) now fails when the pinned hc publishes a schema other than the snapshot. Refresh withOVIS_HC_BIN=<hc> bun run generate:types --refresh-hc.Things the generated types surfaced:
terminal.getanswers theTerminalrecord itself (checked against a real hc 0.1.14). The adapter accepted a{ terminal }wrapper too, and only the fake cores inadapter.test.tssent that shape. The fakes now answer like hc does, and the adapter's hedge is gone.server/conventions.test.tsforbids the string"events.subscribe"outside two files. The generated types, their generator and the connection'sHcStreamMethodtype only name hc's method, so they are exempted, and the reason is in a comment.Note: hc 0.1.17's
hc schemais byte-identical to 0.1.14's (itsinfo.versionstill says 0.1.14), although herdr-core'sv0.1.17tag has a largerhc.openrpc.json. That is why the snapshot is not tied toinfo.versionand only the live job holds it to the binary.Design idea credit: the "generate client types from hc's OpenRPC schema and fail CI on drift" idea came from a study of another project. No code was taken from it; this follows Ovis's existing
generate-protocol-types.ts.Validation
bun run check fast: all green (workflow syntax, generated types, generated themes, typecheck, build, unit tests: 10890 pass, 0 fail).OVIS_TEST_HC_BIN=<hc 0.1.14> bun test ./server/herdr-core/live.test.ts: 4 pass, run against an isolated core (its ownHC_SESSION, state, config and runtime dirs). With one method removed from the snapshot, the new schema test fails and the other 3 pass.bun test scripts/hc-types.test.ts: the--checkdrift test fails withhc-api.generated.ts is STALE, then restores the file.