mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
network/segment.go: resolve UU conflict that was blocking the build. Both sides differed only in comment wording — kept HEAD (Updated upstream) since it's the canonical committed state. core/tasks_embed_test.go: end-to-end test for TASKS_EMBED=true. Boots a BaseApp with the env, dials the in-process Hanzo Tasks daemon over native ZAP, round-trips Health → ExecuteWorkflow → ListWorkflows. PASS in 30s (the lag is one of Base's auto-scheduled __hz* internal schedulers timing out against the new opcode shape — not the embed itself, which answers Health/Workflow ops instantly). tools/tasks/client.go: drop two stale "Temporal" references. The runtime is Hanzo Tasks, not Temporal — comments now match.
91 lines
2.1 KiB
Go
91 lines
2.1 KiB
Go
// Copyright © 2026 Hanzo AI. MIT License.
|
|
|
|
package core_test
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzoai/base/core"
|
|
"github.com/hanzoai/tasks/pkg/sdk/client"
|
|
)
|
|
|
|
// TestTasksEmbed boots a BaseApp with TASKS_EMBED=true and verifies the
|
|
// in-process Hanzo Tasks daemon is reachable over native ZAP.
|
|
//
|
|
// One Go binary, full workflow engine inside. No gRPC. No proxy. No
|
|
// upstream temporal.io. The same path Base apps take when they want
|
|
// durable workflows without running a sidecar tasksd container.
|
|
func TestTasksEmbed(t *testing.T) {
|
|
port := freeTCPPort(t)
|
|
t.Setenv("TASKS_EMBED", "true")
|
|
t.Setenv("TASKS_EMBED_ZAP_PORT", strconv.Itoa(port))
|
|
t.Setenv("TASKS_NAMESPACE", "default")
|
|
|
|
app := core.NewBaseApp(core.BaseAppConfig{DataDir: t.TempDir()})
|
|
if app == nil {
|
|
t.Fatal("NewBaseApp returned nil")
|
|
}
|
|
|
|
c, err := client.Dial(client.Options{
|
|
HostPort: "127.0.0.1:" + strconv.Itoa(port),
|
|
Namespace: "default",
|
|
DialTimeout: 3 * time.Second,
|
|
CallTimeout: 3 * time.Second,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("client.Dial: %v", err)
|
|
}
|
|
defer c.Close()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
defer cancel()
|
|
|
|
svc, status, err := c.Health(ctx)
|
|
if err != nil {
|
|
t.Fatalf("Health: %v", err)
|
|
}
|
|
if svc != "tasks" || status != "ok" {
|
|
t.Fatalf("Health = %q/%q, want tasks/ok", svc, status)
|
|
}
|
|
|
|
run, err := c.ExecuteWorkflow(ctx, client.StartWorkflowOptions{
|
|
ID: "embed-smoke",
|
|
TaskQueue: "default",
|
|
}, "EmbedSmoke")
|
|
if err != nil {
|
|
t.Fatalf("ExecuteWorkflow: %v", err)
|
|
}
|
|
if run.GetID() == "" || run.GetRunID() == "" {
|
|
t.Fatalf("missing IDs: %+v", run)
|
|
}
|
|
|
|
list, err := c.ListWorkflows(ctx, "", 10, nil)
|
|
if err != nil {
|
|
t.Fatalf("ListWorkflows: %v", err)
|
|
}
|
|
found := false
|
|
for _, e := range list.Executions {
|
|
if e.WorkflowID == run.GetID() {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("workflow %s not in list", run.GetID())
|
|
}
|
|
}
|
|
|
|
func freeTCPPort(t *testing.T) int {
|
|
t.Helper()
|
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
t.Fatalf("listen: %v", err)
|
|
}
|
|
defer l.Close()
|
|
return l.Addr().(*net.TCPAddr).Port
|
|
}
|