Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/api/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ func CIGetRunStatus(ctx context.Context, token, orgID, runID string) (*civ1.GetR
return resp.Msg, nil
}

// CIGetFailureDiagnosis returns a bounded diagnosis for a run, workflow, job, or attempt.
func CIGetFailureDiagnosis(ctx context.Context, token, orgID string, req *civ1.GetFailureDiagnosisRequest) (*civ1.FailureDiagnosis, error) {
client := newCIServiceClient()
resp, err := client.GetFailureDiagnosis(ctx, WithAuthenticationAndOrg(connect.NewRequest(req), token, orgID))
if err != nil {
return nil, err
}
return resp.Msg, nil
}

// CIGetWorkflow returns curated run/workflow/execution/job/attempt metadata for a single workflow.
func CIGetWorkflow(ctx context.Context, token, orgID, workflowID string) (*civ1.GetWorkflowResponse, error) {
client := newCIServiceClient()
Expand Down
40 changes: 40 additions & 0 deletions pkg/api/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

type ciServiceTestHandler struct {
civ1connect.UnimplementedCIServiceHandler
t *testing.T
}

Expand Down Expand Up @@ -72,6 +73,25 @@ func (h ciServiceTestHandler) GetRunStatus(context.Context, *connect.Request[civ
return nil, connect.NewError(connect.CodeUnimplemented, nil)
}

func (h ciServiceTestHandler) GetFailureDiagnosis(_ context.Context, req *connect.Request[civ1.GetFailureDiagnosisRequest]) (*connect.Response[civ1.FailureDiagnosis], error) {
assertAuthAndOrg(h.t, req.Header())
if req.Msg.TargetId != "job-123" {
h.t.Fatalf("TargetId = %q, want job-123", req.Msg.TargetId)
}
if req.Msg.TargetType != civ1.FailureDiagnosisTargetType_FAILURE_DIAGNOSIS_TARGET_TYPE_JOB {
h.t.Fatalf("TargetType = %v, want job", req.Msg.TargetType)
}
return connect.NewResponse(&civ1.FailureDiagnosis{
OrgId: "org-123",
Target: &civ1.FailureDiagnosisTarget{
TargetId: req.Msg.TargetId,
TargetType: req.Msg.TargetType,
Status: "failed",
},
State: civ1.FailureDiagnosisState_FAILURE_DIAGNOSIS_STATE_FOCUSED_FAILURE,
}), nil
}

func (h ciServiceTestHandler) GetWorkflow(_ context.Context, req *connect.Request[civ1.GetWorkflowRequest]) (*connect.Response[civ1.GetWorkflowResponse], error) {
assertAuthAndOrg(h.t, req.Header())
if req.Msg.WorkflowId != "workflow-123" {
Expand Down Expand Up @@ -150,6 +170,26 @@ func TestCIGetRunWrapper(t *testing.T) {
})
}

func TestCIGetFailureDiagnosisWrapper(t *testing.T) {
withTestCIService(t, func() {
resp, err := CIGetFailureDiagnosis(
context.Background(),
"token-123",
"org-123",
&civ1.GetFailureDiagnosisRequest{
TargetId: "job-123",
TargetType: civ1.FailureDiagnosisTargetType_FAILURE_DIAGNOSIS_TARGET_TYPE_JOB,
},
)
if err != nil {
t.Fatalf("CIGetFailureDiagnosis returned error: %v", err)
}
if resp.GetTarget().GetTargetId() != "job-123" || resp.GetState() != civ1.FailureDiagnosisState_FAILURE_DIAGNOSIS_STATE_FOCUSED_FAILURE {
t.Fatalf("unexpected response: %+v", resp)
}
})
}

func TestCICancelRunWrapper(t *testing.T) {
withTestCIService(t, func() {
resp, err := CICancelRun(context.Background(), "token-123", "org-123", "run-123")
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func NewCmdCI() *cobra.Command {
}

cmd.AddCommand(NewCmdCancel())
cmd.AddCommand(NewCmdDiagnose())
cmd.AddCommand(NewCmdDispatch())
cmd.AddCommand(NewCmdLogs())
cmd.AddCommand(NewCmdMetrics())
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/ci/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestCICommandRegistration(t *testing.T) {
// inspection / interactive
"run",
"status",
"diagnose",
"logs",
"summary",
"ssh",
Expand Down
Loading
Loading