Files
zzet--gortex/internal/indexer/temporal_javaconst_test.go
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

95 lines
3.2 KiB
Go

package indexer
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"github.com/zzet/gortex/internal/config"
"github.com/zzet/gortex/internal/graph"
"github.com/zzet/gortex/internal/parser"
"github.com/zzet/gortex/internal/parser/languages"
)
// TestTemporalE2E_JavaInvokerConstRef exercises Java invoker priority 4:
// the dispatch name is a constant reference (`Constants.WORKFLOW_TYPE`).
// The Java extractor records temporal_name=WORKFLOW_TYPE,
// temporal_env_source=const_ref; the constant's literal value lives in a
// Java `public static final String` field. For the edge to resolve, that
// Java constant must reach the resolver's constVal index (Java string
// constants are KindField nodes, so the parser must stamp Meta["value"]
// and buildTemporalIndex must ingest KindField + the resolver derefs
// WORKFLOW_TYPE → "ProcessOrderWorkflow" → the registered Go workflow).
//
// KEYWORDS: temporal, java, const_ref, constVal, cross-language, P1
func TestTemporalE2E_JavaInvokerConstRef(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "Constants.java"), `package com.example;
public final class Constants {
public static final String WORKFLOW_TYPE = "ProcessOrderWorkflow";
}
`)
writeFile(t, filepath.Join(dir, "OrderManager.java"), `package com.example;
import io.temporal.workflow.WorkflowOptions;
public class OrderManager {
private final Invoker invoker;
public String startOrder(Object input) {
WorkflowOptions options = WorkflowOptions.newBuilder()
.setTaskQueue("order-workflow").build();
return invoker.invokeAsync(Constants.WORKFLOW_TYPE, options, input).block();
}
}
`)
writeFile(t, filepath.Join(dir, "workflow.go"), `package main
import "go.temporal.io/sdk/workflow"
func ProcessOrderWorkflow(ctx workflow.Context, input string) error { return nil }
`)
writeFile(t, filepath.Join(dir, "main.go"), `package main
func setup(w Worker) { w.RegisterWorkflow(ProcessOrderWorkflow) }
`)
g := graph.New()
reg := parser.NewRegistry()
reg.Register(languages.NewGoExtractor())
reg.Register(languages.NewJavaExtractor())
languages.ConfigureTemporalJavaInvokers(reg, []string{"Invoker"}, nil)
cfg := config.Default().Index
cfg.Workers = 2
idx := New(g, reg, cfg, zap.NewNop())
_, err := idx.Index(dir)
require.NoError(t, err)
goWf := g.FindNodesByName("ProcessOrderWorkflow")
require.NotEmpty(t, goWf)
nodes := g.FindNodesByName("startOrder")
require.NotEmpty(t, nodes)
var stub *graph.Edge
for _, e := range g.GetOutEdges(nodes[0].ID) {
if e != nil && e.Meta != nil && e.Meta["via"] == "temporal.stub" {
stub = e
break
}
}
require.NotNil(t, stub, "const-ref invoker dispatch must emit a temporal.stub")
assert.Equal(t, "WORKFLOW_TYPE", stub.Meta["temporal_name"])
assert.Equal(t, "const_ref", stub.Meta["temporal_env_source"])
assert.Equal(t, goWf[0].ID, stub.To,
"Java const_ref dispatch must resolve via Java constVal to the Go workflow")
// main stamps the dereferenced literal under temporal_const_deref (the
// orphan-line key was temporal_const_value; adapted to main's convention).
assert.Equal(t, "ProcessOrderWorkflow", stub.Meta["temporal_const_deref"])
}