Operator-channel client: the bench shapes tested against their written wire, with no mesh-sdk channel import (B6j; ADR 0634 §5; issue 1966)

This commit is contained in:
2026-11-05 16:45:22 +01:00
parent 70da0dd17e
commit 396ccc0e11
@@ -4,38 +4,30 @@ import (
"bytes"
"encoding/json"
"testing"
"time"
seat "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
"git.novox.be/novox/mesh-sdk/go/channel"
)
// TestTheBenchShapesAreTheChannelsWire: each shape the benches channel and intake carry, written by mesh-sdk's channel
// package, reads into the contract's type with no field dropped and reads back as the same wire.
// TestTheBenchShapesAreTheChannelsWire: each shape the benches channel and intake carry, as the wire the benches speak
// (written out here, the contract's own), reads into the contract's type with no field dropped and reads back as the same wire.
func TestTheBenchShapesAreTheChannelsWire(t *testing.T) {
at := time.Date(2026, 11, 5, 12, 0, 0, 0, time.UTC)
who := channel.Sender{Identity: "42", Display: "Op", Authenticated: true}
sender := `{"identity":"42","display":"Op","authenticated":true}`
cases := []struct {
name string
sdk any
wire string
into any
}{
{"message", channel.Message{Handle: "h1", Title: "t", Body: "b", Buttons: []channel.Button{{Label: "Approve", Ticket: "tk"}},
Note: "n", Urgent: true, Silent: true, Reply: "r", To: "42", Secret: true}, &seat.Message{}},
{"a send", channel.Message{Handle: "h2", Title: "t", Body: "b"}, &seat.Message{}},
{"choice", channel.Choice{ID: "c1", Ticket: "tk", Handle: "h1", Sender: who, At: at}, &seat.Choice{}},
{"link", channel.LinkAsked{ID: "l1", Sender: who, At: at}, &seat.LinkAsked{}},
{"failed", channel.Failed{Handle: "h1", Why: "blocked", Permanent: true, At: at}, &seat.Failed{}},
{"standing", channel.Standing{Ready: true, Why: "w", EditsSilently: true, At: at}, &seat.Standing{}},
{"code", channel.Code{Sender: who, Code: "123456", Purpose: "approve"}, &seat.Code{}},
{"proof answer", channel.ProofAnswer{Accepted: true, Words: "ok"}, &seat.ProofAnswer{}},
{"message", `{"handle":"h1","title":"t","body":"b","buttons":[{"label":"Approve","ticket":"tk"}],"note":"n","urgent":true,"silent":true,"reply":"r","to":"42","secret":true}`, &seat.Message{}},
{"a send", `{"handle":"h2","title":"t","body":"b"}`, &seat.Message{}},
{"choice", `{"id":"c1","ticket":"tk","handle":"h1","sender":` + sender + `,"at":"2026-11-05T12:00:00Z"}`, &seat.Choice{}},
{"link", `{"id":"l1","sender":` + sender + `,"at":"2026-11-05T12:00:00Z"}`, &seat.LinkAsked{}},
{"failed", `{"handle":"h1","why":"blocked","permanent":true,"at":"2026-11-05T12:00:00Z"}`, &seat.Failed{}},
{"standing", `{"ready":true,"why":"w","edits-silently":true,"at":"2026-11-05T12:00:00Z"}`, &seat.Standing{}},
{"code", `{"sender":` + sender + `,"code":"123456","purpose":"approve"}`, &seat.Code{}},
{"proof answer", `{"accepted":true,"words":"ok"}`, &seat.ProofAnswer{}},
}
for _, c := range cases {
wire, err := json.Marshal(c.sdk)
if err != nil {
t.Fatal(err)
}
dec := json.NewDecoder(bytes.NewReader(wire))
dec := json.NewDecoder(bytes.NewReader([]byte(c.wire)))
dec.DisallowUnknownFields()
if err := dec.Decode(c.into); err != nil {
t.Errorf("%s: %v", c.name, err)
@@ -44,9 +36,9 @@ func TestTheBenchShapesAreTheChannelsWire(t *testing.T) {
back, _ := json.Marshal(c.into)
var got, want any
_ = json.Unmarshal(back, &got)
_ = json.Unmarshal(wire, &want)
_ = json.Unmarshal([]byte(c.wire), &want)
if !jsonEqual(got, want) {
t.Errorf("%s: reads back as %s, want %s", c.name, back, wire)
t.Errorf("%s: reads back as %s, want %s", c.name, back, c.wire)
}
}
}
@@ -57,17 +49,17 @@ func jsonEqual(a, b any) bool {
return bytes.Equal(x, y)
}
// TestTheBenchSubjectsAreTheChannelsOwn: the subjects and words are mesh-sdk channel's, character for character.
// TestTheBenchSubjectsAreTheChannelsOwn: the subjects and words, character for character.
func TestTheBenchSubjectsAreTheChannelsOwn(t *testing.T) {
for _, c := range [][2]string{
{ChannelSubject(Show, "telegram"), channel.ChannelSubject(channel.Show, "telegram")},
{ChannelSubject(Edit, "desk"), channel.ChannelSubject(channel.Edit, "desk")},
{ChannelSubject(Send, "desk"), channel.ChannelSubject(channel.Send, "desk")},
{IntakeSubject(Chosen, "telegram"), channel.IntakeSubject(channel.Chosen, "telegram")},
{IntakeSubject(Link, "telegram"), channel.IntakeSubject(channel.Link, "telegram")},
{IntakeSubject(FailedWhat, "desk"), channel.IntakeSubject(channel.FailedWhat, "desk")},
{IntakeSubject(StandingWhat, "desk"), channel.IntakeSubject(channel.StandingWhat, "desk")},
{ProofSubject(CodeProof, "telegram"), channel.ProofSubject(channel.CodeProof, "telegram")},
{ChannelSubject(Show, "telegram"), "mesh.seat.channel.accept.show.telegram"},
{ChannelSubject(Edit, "desk"), "mesh.seat.channel.accept.edit.desk"},
{ChannelSubject(Send, "desk"), "mesh.seat.channel.accept.send.desk"},
{IntakeSubject(Chosen, "telegram"), "mesh.seat.intake.event.choice.telegram"},
{IntakeSubject(Link, "telegram"), "mesh.seat.intake.event.link.telegram"},
{IntakeSubject(FailedWhat, "desk"), "mesh.seat.intake.event.failed.desk"},
{IntakeSubject(StandingWhat, "desk"), "mesh.seat.intake.event.standing.desk"},
{ProofSubject(CodeProof, "telegram"), "mesh.seat.intake.proof.code.telegram"},
} {
if c[0] != c[1] {
t.Errorf("subject %q, want %q", c[0], c[1])