forked from Gitlink/gitlink-cli
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package workflow
|
|
|
|
import (
|
|
"testing"
|
|
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
|
|
"github.com/gitlink-org/gitlink-cli/internal/client"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
)
|
|
|
|
func TestDaemonCycleTriageResult(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Return a simple issue list
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Write([]byte(`{"ok":true,"data":{"issues":[{"project_issues_index":"1","title":"fix crash","body":"app crashes on startup"}]}}`))
|
|
}))
|
|
defer server.Close()
|
|
|
|
ctx := &common.RuntimeContext{
|
|
Client: &client.Client{HTTP: server.Client(), BaseURL: server.URL},
|
|
Owner: "test", Repo: "test", Format: "json",
|
|
Args: map[string]string{},
|
|
}
|
|
|
|
wf := &WorkflowDef{
|
|
Name: "test-daemon-cycle",
|
|
Steps: []StepDef{
|
|
{Type: StepTypeCommand, Name: "open-issues", Purpose: "issues", Target: "issue +list --state open"},
|
|
{Type: StepTypeCommand, Name: "labels", Purpose: "labels", Target: "label +list"},
|
|
{Type: StepTypeCommand, Name: "members", Purpose: "members", Target: "member +list"},
|
|
{Type: StepTypeSkill, Name: "triage", Purpose: "triage", Target: "gitlink-triage", DependsOn: []string{"open-issues", "labels", "members"}},
|
|
},
|
|
}
|
|
|
|
// Simulate daemon cycle: dry-run then full run with same ctx
|
|
t.Log("=== Dry run ===")
|
|
dryResult, _ := Run(ctx, wf, true)
|
|
for _, sr := range dryResult.Steps {
|
|
t.Logf("dry %s: ok=%v data=%v", sr.Step, sr.OK, sr.Data)
|
|
}
|
|
|
|
t.Log("=== Full run ===")
|
|
fullResult, _ := Run(ctx, wf, false)
|
|
for _, sr := range fullResult.Steps {
|
|
t.Logf("full %s: ok=%v data=%v", sr.Step, sr.OK, sr.Data)
|
|
if sr.Step == "triage" {
|
|
d, ok := sr.Data.(map[string]interface{})
|
|
if ok {
|
|
a, _ := d["analysis"].(map[string]interface{})
|
|
t.Logf("triage analysis: %v", a)
|
|
if a != nil {
|
|
t.Logf("classified: %v", a["classified"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|