Files
zeekayandHanzo Dev acb9f38d95 zap: make the rename shippable, and give the golden fixture its generator
The rename to `zapwire` was inert: `cargo publish` refused the manifest
outright with

    all dependencies must have a version requirement specified when
    publishing. dependency `zapc` does not specify a version

so nothing could leave the workspace, and crates.io still resolved
`hanzo-zap` to THIS repo via 0.2.1 — the collision the rename exists to
end. The build-dependency now carries both a path and a version: the
path is what the workspace builds against, the version is what a
published `zapwire` resolves from crates.io. `zapc` gains the
`repository` link it was missing, since a crate whose repository field
points at the wrong source is precisely how the `hanzo-zap` confusion
started (0.2.1 declares `repository = hanzoai/zap` from a zap-proto/spec
checkout).

crosswire.rs told the reader to regenerate its golden hex with
`tests/gen_golden.go` — a file that does not exist, leaving hand-editing
hex as the only option the comment explicitly forbids. `interop/golden`
is that generator, and it emits the finished Rust `const` lines rather
than bare hex so there is no transcription step to get wrong. Its output
reproduces the committed fixture byte-for-byte.

`go vet ./interop` -> `go vet ./...`, so the new package is covered by
the same gate rather than needing its own line.

make test: 27 lib + 10 crosswire + 2 live-Go interop, green, exit 0.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 23:18:52 -07:00

64 lines
1.8 KiB
Go

// Regenerates the golden hex constants in rust/tests/crosswire.rs from the
// canonical Go runtime, so the fixture is never hand-written:
//
// go run ./interop/golden
//
// It prints the Rust `const` lines verbatim — paste them over the ones in
// crosswire.rs and run `make fmt` to normalise the wrapping. Run this when
// github.com/zap-proto/go changes the envelope; if the bytes move, the
// crosswire tests go red until Rust is brought back into line.
//
// The generator emits the finished `const` line rather than a bare hex
// string on purpose: transcribing hex by hand is the one way this fixture
// could silently drift away from the runtime it is supposed to pin.
package main
import (
"encoding/hex"
"fmt"
"github.com/zap-proto/go/rpc"
)
// A golden case: the Rust const it produces, the doc line above it, and
// the bytes the Go runtime emits for it.
type golden struct {
name string
doc string
bytes []byte
}
func main() {
for _, g := range []golden{
{
"GO_REQ",
`rpc.Call{Method: 7, PromiseID: 1, Target: NO_TARGET, Cap: "cap-token", Payload: "hello-zap"}`,
rpc.BuildRequest(rpc.Call{
Method: 7,
PromiseID: 1,
Target: rpc.NoTarget,
Cap: []byte("cap-token"),
Payload: []byte("hello-zap"),
}),
},
{
"GO_REQ_EMPTY",
`rpc.Call{Method: 2, PromiseID: 9, Target: 1, Cap: nil, Payload: nil}`,
rpc.BuildRequest(rpc.Call{Method: 2, PromiseID: 9, Target: 1}),
},
{
"GO_RESP",
`rpc.BuildResponse(STATUS_OK, 1, "world")`,
rpc.BuildResponse(rpc.StatusOK, 1, []byte("world")),
},
{
"GO_RESP_EMPTY",
`rpc.BuildResponse(STATUS_NOT_FOUND, 42, nil)`,
rpc.BuildResponse(rpc.StatusNotFound, 42, nil),
},
} {
fmt.Printf("/// %s\nconst %s: &str = \"%s\";\n\n",
g.doc, g.name, hex.EncodeToString(g.bytes))
}
}