Files
tasks/pkg/sdk/client/check_health_test.go
zeekay 072ecefbfe feat(sdk): close caller-symbol gap for base/commerce migration
Adds every symbol hanzoai/base/plugins/tasks and hanzoai/commerce
call today that was missing from pkg/sdk/*: SignalWithStartWorkflow,
GetWorkflow, QueryWorkflow, CheckHealth, WorkflowRunGetOptions +
WorkflowRun.GetWithOptions, ExecuteChildWorkflow + ChildWorkflowFuture,
LocalActivityOptions + WithLocalActivityOptions + ExecuteLocalActivity
(Phase-1 remote-path), worker.InterruptCh(), worker.Options rate-limit
fields wired via golang.org/x/time/rate.

New opcodes 0x0066 signalWithStartWorkflow / 0x0067 queryWorkflow
land here; frontend-side handlers were wired in PR-A via the
translate.go dispatch table.

Closes red-review §2 gap table. Dry-run base migration compiles.
2026-04-23 12:53:15 -07:00

83 lines
2.4 KiB
Go

// Copyright © 2026 Hanzo AI. MIT License.
package client
import (
"context"
"errors"
"testing"
)
// TestCheckHealthOpcode confirms CheckHealth uses opcode 0x0090 and
// returns the server-reported service + status.
func TestCheckHealthOpcode(t *testing.T) {
t.Parallel()
st := &stubTransport{
dynamicReply: func(op uint16, _ []byte) (map[string]any, uint32, string, error) {
if op != opHealth {
return nil, 0, "", errors.New("wrong opcode")
}
return map[string]any{"service": "hanzo-tasks", "status": "ok"}, 0, "", nil
},
}
c, _ := Dial(Options{Transport: st})
defer c.Close()
resp, err := c.CheckHealth(context.Background(), &CheckHealthRequest{})
if err != nil {
t.Fatalf("CheckHealth: %v", err)
}
if resp.Service != "hanzo-tasks" {
t.Fatalf("Service = %q", resp.Service)
}
if resp.Status != "ok" {
t.Fatalf("Status = %q", resp.Status)
}
}
// TestCheckHealthNilRequestAccepted treats nil as empty.
func TestCheckHealthNilRequestAccepted(t *testing.T) {
t.Parallel()
st := &stubTransport{respBody: map[string]any{"service": "hanzo-tasks", "status": "ok"}}
c, _ := Dial(Options{Transport: st})
defer c.Close()
if _, err := c.CheckHealth(context.Background(), nil); err != nil {
t.Fatalf("CheckHealth(nil): %v", err)
}
}
// TestCheckHealthMatchesHealth verifies Health (flat strings) and
// CheckHealth (structured response) are shape-consistent.
func TestCheckHealthMatchesHealth(t *testing.T) {
t.Parallel()
st := &stubTransport{respBody: map[string]any{"service": "hanzo-tasks", "status": "ok"}}
c, _ := Dial(Options{Transport: st})
defer c.Close()
svc, status, err := c.Health(context.Background())
if err != nil {
t.Fatalf("Health: %v", err)
}
resp, err := c.CheckHealth(context.Background(), nil)
if err != nil {
t.Fatalf("CheckHealth: %v", err)
}
if svc != resp.Service || status != resp.Status {
t.Fatalf("shape mismatch: (%q,%q) vs %+v", svc, status, resp)
}
}
// TestGetWorkflowHandleOnly exercises GetWorkflow, which issues no RPC
// and simply returns a handle.
func TestGetWorkflowHandleOnly(t *testing.T) {
t.Parallel()
st := &stubTransport{}
c, _ := Dial(Options{Transport: st})
defer c.Close()
run := c.GetWorkflow(context.Background(), "wf-1", "run-1")
if run.GetID() != "wf-1" || run.GetRunID() != "run-1" {
t.Fatalf("handle = %+v", run)
}
if st.callCount != 0 {
t.Fatalf("GetWorkflow must not issue an RPC; calls=%d", st.callCount)
}
}