Files
gen/out/go/tasks/client_test.go
zeekay fd4da20ec5 test(gen): commit end-to-end proof artifacts (TS + OpenAPI + Go)
Force-added past .gitignore's out/ as reproducible proof that one .zap
schema mechanically produces every surface:
- out/ts/tasks/tasks_zap.ts   Tier-2 zero-copy View/Client/Server; tsc --noEmit
  clean against @zap-proto/zap under strict (noUnusedLocals, verbatimModuleSyntax).
- out/{ts,go}/tasks/tasks.openapi.json  OpenAPI 3.1.0; openapi-spec-validator OK;
  4/4 methods as POST /tasks/<method>; 9 referenced structs in components.schemas.
- out/go/tasks  oapi-codegen Tier-1 client + go.mod + offline request-forming
  test: go vet/build/test all green (forms POST https://api.hanzo.ai/tasks/*).
- out/docs/{ts,go}/tasks.mdx  generated SDK doc stubs.

Regenerate: bin/zapsdk ts schemas/tasks.zap ; bin/zapsdk go schemas/tasks.zap
2026-07-05 13:29:14 -07:00

103 lines
3.2 KiB
Go

// Tier-1 proof for the ZAP-first SDK generator: the Go HTTP client below is
// generated by oapi-codegen from schemas/tasks.zap's emitted OpenAPI 3.1 doc
// (bin/zapsdk go schemas/tasks.zap). This test compiles that generated client
// and drives it offline through a capturing transport to prove it forms the
// exact POST /tasks/<method> requests the ZAP HTTP surface serves — no live
// call required (the public gateway may 404 these routes).
package tasks
import (
"context"
"encoding/json"
"io"
"net/http"
"strings"
"testing"
)
const baseURL = "https://api.hanzo.ai"
// capturingDoer records the last request instead of sending it, so request
// construction is verified without any network.
type capturingDoer struct{ last *http.Request }
func (d *capturingDoer) Do(req *http.Request) (*http.Response, error) {
d.last = req
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader("{}")),
Header: http.Header{"Content-Type": []string{"application/json"}},
Request: req,
}, nil
}
// TestFormsStartWorkflowRequest proves the generated client targets the exact
// route the ZAP HTTP transport serves (POST /tasks/start-workflow) with the
// declared JSON body, built from the .zap-derived StartWorkflowRequest model.
func TestFormsStartWorkflowRequest(t *testing.T) {
doer := &capturingDoer{}
c, err := NewClient(baseURL, WithHTTPClient(doer))
if err != nil {
t.Fatalf("NewClient: %v", err)
}
in := StartWorkflowRequest{
Namespace: "default",
WorkflowId: "wf-42",
TaskQueue: "critical",
Input: []byte("payload"),
}
if _, err := c.TasksStartWorkflow(context.Background(), in); err != nil {
t.Fatalf("TasksStartWorkflow: %v", err)
}
req := doer.last
if req == nil {
t.Fatal("no request was formed")
}
if req.Method != http.MethodPost {
t.Errorf("method = %q, want POST", req.Method)
}
if got, want := req.URL.String(), baseURL+"/tasks/start-workflow"; got != want {
t.Errorf("url = %q, want %q", got, want)
}
if ct := req.Header.Get("Content-Type"); ct != "application/json" {
t.Errorf("content-type = %q, want application/json", ct)
}
body, _ := io.ReadAll(req.Body)
var out StartWorkflowRequest
if err := json.Unmarshal(body, &out); err != nil {
t.Fatalf("body is not the StartWorkflowRequest JSON schema: %v", err)
}
if out.Namespace != in.Namespace || out.WorkflowId != in.WorkflowId || out.TaskQueue != in.TaskQueue {
t.Errorf("round-tripped body = %+v, want %+v", out, in)
}
}
// TestFormsHealthRequest proves the no-body method also forms its route.
func TestFormsHealthRequest(t *testing.T) {
doer := &capturingDoer{}
c, err := NewClient(baseURL, WithHTTPClient(doer))
if err != nil {
t.Fatalf("NewClient: %v", err)
}
if _, err := c.TasksHealth(context.Background()); err != nil {
t.Fatalf("TasksHealth: %v", err)
}
if got, want := doer.last.URL.String(), baseURL+"/tasks/health"; got != want {
t.Errorf("url = %q, want %q", got, want)
}
}
// ExampleNewClient shows the intended construction against the live gateway.
// It has no Output comment, so `go test` compiles it but never sends it.
func ExampleNewClient() {
c, err := NewClient(baseURL)
if err != nil {
panic(err)
}
_, _ = c.TasksHealth(context.Background())
}