v0.13.0 b97dc86

gen_test.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package api_test
4
5import (
6	"errors"
7	"testing"
8
9	"connectrpc.com/connect"
10
11	"google.golang.org/protobuf/proto"
12	"google.golang.org/protobuf/reflect/protoreflect"
13	"google.golang.org/protobuf/types/known/fieldmaskpb"
14
15	"bnema.dev/ermite-api/gen/ermite"
16	"bnema.dev/ermite-api/gen/ermite/ermiteconnect"
17)
18
19// TestProcedures pins the procedure paths: they are the wire contract.
20func TestProcedures(t *testing.T) {
21	tests := []struct{ got, want string }{
22		{ermiteconnect.MirrorServiceGetMirrorKeyProcedure, "/ermite.MirrorService/GetMirrorKey"},
23		{ermiteconnect.MirrorServiceRotateMirrorKeyProcedure, "/ermite.MirrorService/RotateMirrorKey"},
24		{ermiteconnect.MirrorServiceGetMirrorConfigProcedure, "/ermite.MirrorService/GetMirrorConfig"},
25		{ermiteconnect.MirrorServiceSetMirrorConfigProcedure, "/ermite.MirrorService/SetMirrorConfig"},
26		{ermiteconnect.MirrorServiceSetRepoMirrorProcedure, "/ermite.MirrorService/SetRepoMirror"},
27		{ermiteconnect.MirrorServiceRemoveRepoMirrorProcedure, "/ermite.MirrorService/RemoveRepoMirror"},
28		{ermiteconnect.MirrorServiceSetRepoMirrorExcludedProcedure, "/ermite.MirrorService/SetRepoMirrorExcluded"},
29		{ermiteconnect.MirrorServiceGetMirrorStatusProcedure, "/ermite.MirrorService/GetMirrorStatus"},
30		{ermiteconnect.MirrorServiceListMirrorStatusProcedure, "/ermite.MirrorService/ListMirrorStatus"},
31		{ermiteconnect.MirrorServiceSyncMirrorProcedure, "/ermite.MirrorService/SyncMirror"},
32
33		{ermiteconnect.RepoServiceListReposProcedure, "/ermite.RepoService/ListRepos"},
34		{ermiteconnect.RepoServiceGetRepoProcedure, "/ermite.RepoService/GetRepo"},
35		{ermiteconnect.RepoServiceCreateRepoProcedure, "/ermite.RepoService/CreateRepo"},
36		{ermiteconnect.RepoServiceUpdateRepoProcedure, "/ermite.RepoService/UpdateRepo"},
37		{ermiteconnect.RepoServiceDeleteRepoProcedure, "/ermite.RepoService/DeleteRepo"},
38		{ermiteconnect.GitServiceListRefsProcedure, "/ermite.GitService/ListRefs"},
39		{ermiteconnect.GitServiceGetTreeProcedure, "/ermite.GitService/GetTree"},
40		{ermiteconnect.GitServiceListPathsProcedure, "/ermite.GitService/ListPaths"},
41		{ermiteconnect.GitServiceGetBlobProcedure, "/ermite.GitService/GetBlob"},
42		{ermiteconnect.GitServiceListCommitsProcedure, "/ermite.GitService/ListCommits"},
43		{ermiteconnect.GitServiceGetCommitProcedure, "/ermite.GitService/GetCommit"},
44		{ermiteconnect.GitServiceResolveRevisionProcedure, "/ermite.GitService/ResolveRevision"},
45		{ermiteconnect.TokenServiceCreateTokenProcedure, "/ermite.TokenService/CreateToken"},
46		{ermiteconnect.TokenServiceListTokensProcedure, "/ermite.TokenService/ListTokens"},
47		{ermiteconnect.TokenServiceRevokeTokenProcedure, "/ermite.TokenService/RevokeToken"},
48		{ermiteconnect.EventServiceWatchProcedure, "/ermite.EventService/Watch"},
49		{ermiteconnect.MergeRequestServiceCreateMergeRequestProcedure, "/ermite.MergeRequestService/CreateMergeRequest"},
50		{ermiteconnect.MergeRequestServiceListMergeRequestsProcedure, "/ermite.MergeRequestService/ListMergeRequests"},
51		{ermiteconnect.MergeRequestServiceGetMergeRequestProcedure, "/ermite.MergeRequestService/GetMergeRequest"},
52		{ermiteconnect.MergeRequestServiceAddCommentProcedure, "/ermite.MergeRequestService/AddComment"},
53		{ermiteconnect.MergeRequestServiceResolveCommentProcedure, "/ermite.MergeRequestService/ResolveComment"},
54		{ermiteconnect.MergeRequestServiceCloseMergeRequestProcedure, "/ermite.MergeRequestService/CloseMergeRequest"},
55		{ermiteconnect.MergeRequestServiceMergeMergeRequestProcedure, "/ermite.MergeRequestService/MergeMergeRequest"},
56		{ermiteconnect.MergeRequestServiceMarkReadProcedure, "/ermite.MergeRequestService/MarkRead"},
57		{ermiteconnect.SessionServiceCreateLoginLinkProcedure, "/ermite.SessionService/CreateLoginLink"},
58		{ermiteconnect.SessionServiceSignOutEverywhereProcedure, "/ermite.SessionService/SignOutEverywhere"},
59		{ermiteconnect.ServerServiceGetVersionProcedure, "/ermite.ServerService/GetVersion"},
60		{ermiteconnect.ServerServiceGetSigningKeyProcedure, "/ermite.ServerService/GetSigningKey"},
61		{ermiteconnect.ServerServiceRotateOIDCKeyProcedure, "/ermite.ServerService/RotateOIDCKey"},
62		{ermiteconnect.RunnerServiceRegisterRunnerProcedure, "/ermite.RunnerService/RegisterRunner"},
63		{ermiteconnect.RunnerServiceFetchJobProcedure, "/ermite.RunnerService/FetchJob"},
64		{ermiteconnect.RunnerServiceUpdateJobProcedure, "/ermite.RunnerService/UpdateJob"},
65		{ermiteconnect.RunnerServiceAppendLogProcedure, "/ermite.RunnerService/AppendLog"},
66		{ermiteconnect.RunnerServiceHeartbeatProcedure, "/ermite.RunnerService/Heartbeat"},
67		{ermiteconnect.RunnerServiceWatchJobProcedure, "/ermite.RunnerService/WatchJob"},
68		{ermiteconnect.RunnerServiceCompleteJobProcedure, "/ermite.RunnerService/CompleteJob"},
69		{ermiteconnect.RunnerServiceResolveActionsProcedure, "/ermite.RunnerService/ResolveActions"},
70		{ermiteconnect.RunnerServiceUploadSummaryProcedure, "/ermite.RunnerService/UploadSummary"},
71		{ermiteconnect.RunServiceListRunsProcedure, "/ermite.RunService/ListRuns"},
72		{ermiteconnect.RunServiceGetRunProcedure, "/ermite.RunService/GetRun"},
73		{ermiteconnect.RunServiceGetJobProcedure, "/ermite.RunService/GetJob"},
74		{ermiteconnect.RunServiceGetJobLogProcedure, "/ermite.RunService/GetJobLog"},
75		{ermiteconnect.RunServiceListAnnotationsProcedure, "/ermite.RunService/ListAnnotations"},
76		{ermiteconnect.RunServiceGetStepSummariesProcedure, "/ermite.RunService/GetStepSummaries"},
77		{ermiteconnect.RunServiceCancelRunProcedure, "/ermite.RunService/CancelRun"},
78		{ermiteconnect.RunServiceRerunRunProcedure, "/ermite.RunService/RerunRun"},
79		{ermiteconnect.RunServiceDispatchWorkflowProcedure, "/ermite.RunService/DispatchWorkflow"},
80		{ermiteconnect.RunServiceListWorkflowsProcedure, "/ermite.RunService/ListWorkflows"},
81		{ermiteconnect.RunServiceDisableWorkflowProcedure, "/ermite.RunService/DisableWorkflow"},
82		{ermiteconnect.RunServiceEnableWorkflowProcedure, "/ermite.RunService/EnableWorkflow"},
83		{ermiteconnect.RunServiceListChecksProcedure, "/ermite.RunService/ListChecks"},
84		{ermiteconnect.RunServiceListRunnersProcedure, "/ermite.RunService/ListRunners"},
85		{ermiteconnect.RunServiceRemoveRunnerProcedure, "/ermite.RunService/RemoveRunner"},
86		{ermiteconnect.SecretServiceSetSecretProcedure, "/ermite.SecretService/SetSecret"},
87		{ermiteconnect.SecretServiceListSecretsProcedure, "/ermite.SecretService/ListSecrets"},
88		{ermiteconnect.SecretServiceDeleteSecretProcedure, "/ermite.SecretService/DeleteSecret"},
89		{ermiteconnect.VariableServiceSetVariableProcedure, "/ermite.VariableService/SetVariable"},
90		{ermiteconnect.VariableServiceGetVariableProcedure, "/ermite.VariableService/GetVariable"},
91		{ermiteconnect.VariableServiceListVariablesProcedure, "/ermite.VariableService/ListVariables"},
92		{ermiteconnect.VariableServiceDeleteVariableProcedure, "/ermite.VariableService/DeleteVariable"},
93		{ermiteconnect.EnvironmentServiceCreateEnvironmentProcedure, "/ermite.EnvironmentService/CreateEnvironment"},
94		{ermiteconnect.EnvironmentServiceListEnvironmentsProcedure, "/ermite.EnvironmentService/ListEnvironments"},
95		{ermiteconnect.EnvironmentServiceDeleteEnvironmentProcedure, "/ermite.EnvironmentService/DeleteEnvironment"},
96		{ermiteconnect.JobArtifactServiceCreateJobArtifactProcedure, "/ermite.JobArtifactService/CreateJobArtifact"},
97		{ermiteconnect.JobArtifactServiceUploadJobArtifactBlockProcedure, "/ermite.JobArtifactService/UploadJobArtifactBlock"},
98		{ermiteconnect.JobArtifactServiceCommitJobArtifactProcedure, "/ermite.JobArtifactService/CommitJobArtifact"},
99		{ermiteconnect.JobArtifactServiceFinalizeJobArtifactProcedure, "/ermite.JobArtifactService/FinalizeJobArtifact"},
100		{ermiteconnect.JobArtifactServiceListJobArtifactsProcedure, "/ermite.JobArtifactService/ListJobArtifacts"},
101		{ermiteconnect.JobArtifactServiceDownloadJobArtifactProcedure, "/ermite.JobArtifactService/DownloadJobArtifact"},
102		{ermiteconnect.JobArtifactServiceDeleteJobArtifactProcedure, "/ermite.JobArtifactService/DeleteJobArtifact"},
103		{ermiteconnect.ArtifactServiceListArtifactsProcedure, "/ermite.ArtifactService/ListArtifacts"},
104		{ermiteconnect.ArtifactServiceDownloadArtifactProcedure, "/ermite.ArtifactService/DownloadArtifact"},
105		{ermiteconnect.ArtifactServiceDeleteArtifactProcedure, "/ermite.ArtifactService/DeleteArtifact"},
106	}
107	for _, tt := range tests {
108		if tt.got != tt.want {
109			t.Errorf("procedure = %q, want %q", tt.got, tt.want)
110		}
111	}
112}
113
114// TestEnumNumbers pins enum numbers: they are part of the wire contract.
115func TestEnumNumbers(t *testing.T) {
116	if got := ermite.Scope_SCOPE_TOKEN_ADMIN; got != 9 {
117		t.Errorf("SCOPE_TOKEN_ADMIN = %d, want 9", got)
118	}
119	if got := ermite.FileStatus_FILE_STATUS_TYPE_CHANGED; got != 6 {
120		t.Errorf("FILE_STATUS_TYPE_CHANGED = %d, want 6", got)
121	}
122	if got := ermite.Visibility_VISIBILITY_PRIVATE; got != 2 {
123		t.Errorf("VISIBILITY_PRIVATE = %d, want 2", got)
124	}
125	if got := ermite.MergeMode_MERGE_MODE_SQUASH; got != 2 {
126		t.Errorf("MERGE_MODE_SQUASH = %d, want 2", got)
127	}
128	if got := ermite.MergeMode_MERGE_MODE_MERGE_COMMIT; got != 3 {
129		t.Errorf("MERGE_MODE_MERGE_COMMIT = %d, want 3", got)
130	}
131	if got := ermite.MergeabilityState_MERGEABILITY_STATE_CONFLICT; got != 4 {
132		t.Errorf("MERGEABILITY_STATE_CONFLICT = %d, want 4", got)
133	}
134	if got := ermite.MergeRequestState_MERGE_REQUEST_STATE_CLOSED; got != 3 {
135		t.Errorf("MERGE_REQUEST_STATE_CLOSED = %d, want 3", got)
136	}
137	if got := ermite.DiffSide_DIFF_SIDE_NEW; got != 2 {
138		t.Errorf("DIFF_SIDE_NEW = %d, want 2", got)
139	}
140	enums := []struct {
141		name string
142		got  int32
143		want int32
144	}{
145		{"CI_STATUS_UNSPECIFIED", int32(ermite.CiStatus_CI_STATUS_UNSPECIFIED), 0},
146		{"CI_STATUS_QUEUED", int32(ermite.CiStatus_CI_STATUS_QUEUED), 1},
147		{"CI_STATUS_IN_PROGRESS", int32(ermite.CiStatus_CI_STATUS_IN_PROGRESS), 2},
148		{"CI_STATUS_COMPLETED", int32(ermite.CiStatus_CI_STATUS_COMPLETED), 3},
149		{"CI_STATUS_PENDING", int32(ermite.CiStatus_CI_STATUS_PENDING), 4},
150		{"CI_CONCLUSION_UNSPECIFIED", int32(ermite.CiConclusion_CI_CONCLUSION_UNSPECIFIED), 0},
151		{"CI_CONCLUSION_SUCCESS", int32(ermite.CiConclusion_CI_CONCLUSION_SUCCESS), 1},
152		{"CI_CONCLUSION_FAILURE", int32(ermite.CiConclusion_CI_CONCLUSION_FAILURE), 2},
153		{"CI_CONCLUSION_CANCELLED", int32(ermite.CiConclusion_CI_CONCLUSION_CANCELLED), 3},
154		{"CI_CONCLUSION_SKIPPED", int32(ermite.CiConclusion_CI_CONCLUSION_SKIPPED), 4},
155		{"CI_CONCLUSION_TIMED_OUT", int32(ermite.CiConclusion_CI_CONCLUSION_TIMED_OUT), 5},
156		{"CI_CONCLUSION_NEUTRAL", int32(ermite.CiConclusion_CI_CONCLUSION_NEUTRAL), 6},
157		{"CI_CONCLUSION_ACTION_REQUIRED", int32(ermite.CiConclusion_CI_CONCLUSION_ACTION_REQUIRED), 7},
158		{"STEP_STATE_UNSPECIFIED", int32(ermite.StepState_STEP_STATE_UNSPECIFIED), 0},
159		{"STEP_STATE_PENDING", int32(ermite.StepState_STEP_STATE_PENDING), 1},
160		{"STEP_STATE_IN_PROGRESS", int32(ermite.StepState_STEP_STATE_IN_PROGRESS), 2},
161		{"STEP_STATE_COMPLETED", int32(ermite.StepState_STEP_STATE_COMPLETED), 3},
162		{"RUNNER_ISOLATION_UNSPECIFIED", int32(ermite.RunnerIsolation_RUNNER_ISOLATION_UNSPECIFIED), 0},
163		{"RUNNER_ISOLATION_VM", int32(ermite.RunnerIsolation_RUNNER_ISOLATION_VM), 1},
164		{"RUNNER_ISOLATION_CONTAINER_SYSBOX", int32(ermite.RunnerIsolation_RUNNER_ISOLATION_CONTAINER_SYSBOX), 2},
165		{"RUNNER_ISOLATION_CONTAINER_PRIVILEGED", int32(ermite.RunnerIsolation_RUNNER_ISOLATION_CONTAINER_PRIVILEGED), 3},
166		{"CANCEL_REASON_UNSPECIFIED", int32(ermite.CancelReason_CANCEL_REASON_UNSPECIFIED), 0},
167		{"CANCEL_REASON_USER", int32(ermite.CancelReason_CANCEL_REASON_USER), 1},
168		{"CANCEL_REASON_FAIL_FAST", int32(ermite.CancelReason_CANCEL_REASON_FAIL_FAST), 2},
169		{"CANCEL_REASON_TIMEOUT", int32(ermite.CancelReason_CANCEL_REASON_TIMEOUT), 3},
170		{"ANNOTATION_LEVEL_UNSPECIFIED", int32(ermite.AnnotationLevel_ANNOTATION_LEVEL_UNSPECIFIED), 0},
171		{"ANNOTATION_LEVEL_NOTICE", int32(ermite.AnnotationLevel_ANNOTATION_LEVEL_NOTICE), 1},
172		{"ANNOTATION_LEVEL_WARNING", int32(ermite.AnnotationLevel_ANNOTATION_LEVEL_WARNING), 2},
173		{"ANNOTATION_LEVEL_FAILURE", int32(ermite.AnnotationLevel_ANNOTATION_LEVEL_FAILURE), 3},
174		{"ACTION_SOURCE_UNSPECIFIED", int32(ermite.ActionSource_ACTION_SOURCE_UNSPECIFIED), 0},
175		{"ACTION_SOURCE_GITHUB", int32(ermite.ActionSource_ACTION_SOURCE_GITHUB), 1},
176		{"ACTION_SOURCE_ERMITE", int32(ermite.ActionSource_ACTION_SOURCE_ERMITE), 2},
177	}
178	for _, e := range enums {
179		if e.got != e.want {
180			t.Errorf("%s = %d, want %d", e.name, e.got, e.want)
181		}
182	}
183}
184
185// TestEventRoundTrip checks that an event with a oneof kind survives the wire.
186func TestEventRoundTrip(t *testing.T) {
187	in := &ermite.WatchResponse{Event: &ermite.Event{
188		Id: "42",
189		Kind: &ermite.Event_Pushed{Pushed: &ermite.Pushed{
190			Repo: "ermite",
191			RefUpdates: []*ermite.RefUpdate{
192				{Ref: "refs/heads/main", OldId: "a", NewId: "b"},
193			},
194		}},
195	}}
196	b, err := proto.Marshal(in)
197	if err != nil {
198		t.Fatal(err)
199	}
200	var out ermite.WatchResponse
201	if err := proto.Unmarshal(b, &out); err != nil {
202		t.Fatal(err)
203	}
204	if !proto.Equal(in, &out) {
205		t.Errorf("round trip mismatch: %v != %v", &out, in)
206	}
207	if out.GetEvent().GetPushed().GetRefUpdates()[0].GetNewId() != "b" {
208		t.Errorf("unexpected ref update: %v", &out)
209	}
210}
211
212// TestUpdateRepoMask checks that the request carries a field mask.
213func TestUpdateRepoMask(t *testing.T) {
214	req := &ermite.UpdateRepoRequest{
215		Repo:       "ermite",
216		Visibility: ermite.Visibility_VISIBILITY_PUBLIC,
217		UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"visibility"}},
218	}
219	if got := req.GetUpdateMask().GetPaths(); len(got) != 1 || got[0] != "visibility" {
220		t.Errorf("paths = %v", got)
221	}
222}
223
224// TestMergeRequestEventRoundTrip checks the merge request event kinds and the
225// repository settings survive the wire.
226func TestMergeRequestEventRoundTrip(t *testing.T) {
227	in := &ermite.WatchResponse{Event: &ermite.Event{
228		Id: "43",
229		Kind: &ermite.Event_CommentAdded{CommentAdded: &ermite.CommentAdded{
230			Repo:   "ermite",
231			Number: 7,
232			Comment: &ermite.Comment{
233				Id: "c1", Path: "a.go", Line: 3, Side: ermite.DiffSide_DIFF_SIDE_OLD, Text: "hi",
234			},
235		}},
236	}}
237	b, err := proto.Marshal(in)
238	if err != nil {
239		t.Fatal(err)
240	}
241	var out ermite.WatchResponse
242	if err := proto.Unmarshal(b, &out); err != nil {
243		t.Fatal(err)
244	}
245	if !proto.Equal(in, &out) {
246		t.Errorf("round trip mismatch: %v != %v", &out, in)
247	}
248	if got := out.GetEvent().GetCommentAdded().GetNumber(); got != 7 {
249		t.Errorf("number = %d, want 7", got)
250	}
251
252	req := &ermite.UpdateRepoRequest{
253		Repo: "ermite",
254		Settings: &ermite.RepoSettings{
255			AllowedMergeModes:  []ermite.MergeMode{ermite.MergeMode_MERGE_MODE_SQUASH},
256			FailingChecksBlock: true,
257		},
258		UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"settings.allowed_merge_modes", "settings.failing_checks_block"}},
259	}
260	if got := req.GetSettings().GetAllowedMergeModes(); len(got) != 1 || got[0] != ermite.MergeMode_MERGE_MODE_SQUASH {
261		t.Errorf("modes = %v", got)
262	}
263}
264
265// TestCIEventRoundTrip checks that the CI event kinds keep their field numbers
266// and survive the wire.
267func TestCIEventRoundTrip(t *testing.T) {
268	in := &ermite.WatchResponse{Event: &ermite.Event{
269		Id: "44",
270		Kind: &ermite.Event_JobUpdated{JobUpdated: &ermite.JobUpdated{Job: &ermite.RunJob{
271			Id:         "j1",
272			RunId:      9,
273			Attempt:    2,
274			Status:     ermite.CiStatus_CI_STATUS_COMPLETED,
275			Conclusion: ermite.CiConclusion_CI_CONCLUSION_TIMED_OUT,
276			Isolation:  ermite.RunnerIsolation_RUNNER_ISOLATION_VM,
277			Steps:      []*ermite.Step{{Number: 1, Name: "Set up job", LogStart: 0, LogEnd: 3}},
278		}}},
279	}}
280	b, err := proto.Marshal(in)
281	if err != nil {
282		t.Fatal(err)
283	}
284	var out ermite.WatchResponse
285	if err := proto.Unmarshal(b, &out); err != nil {
286		t.Fatal(err)
287	}
288	if !proto.Equal(in, &out) {
289		t.Errorf("round trip mismatch: %v != %v", &out, in)
290	}
291	f := (&ermite.Event{}).ProtoReflect().Descriptor().Fields()
292	for name, num := range map[string]int{"run_updated": 12, "job_updated": 13} {
293		if fd := f.ByName(protoreflect.Name(name)); fd == nil || int(fd.Number()) != num {
294			t.Errorf("event field %s: %v, want number %d", name, fd, num)
295		}
296	}
297}
298
299// TestJobRoundTrip checks the job handed to a runner survives the wire.
300func TestJobRoundTrip(t *testing.T) {
301	in := &ermite.FetchJobResponse{Job: &ermite.Job{
302		JobId: "j1", RunId: 9, Attempt: 1, JobToken: "tok", WorkflowPath: ".github/workflows/ci.yml",
303		WorkflowYaml: "on: push", JobKey: "build", Matrix: "{}", Contexts: "{}",
304		Labels: []string{"self-hosted"}, TimeoutMinutes: 360, Repo: "ermite",
305		Sha: "0123456789012345678901234567890123456789", Ref: "refs/heads/main",
306	}}
307	b, err := proto.Marshal(in)
308	if err != nil {
309		t.Fatal(err)
310	}
311	var out ermite.FetchJobResponse
312	if err := proto.Unmarshal(b, &out); err != nil {
313		t.Fatal(err)
314	}
315	if !proto.Equal(in, &out) {
316		t.Errorf("round trip mismatch: %v != %v", &out, in)
317	}
318}
319
320// TestWatchJobRoundTrip checks the three kinds of WatchJob message and the
321// JobEnded detail.
322func TestWatchJobRoundTrip(t *testing.T) {
323	msgs := []*ermite.WatchJobResponse{
324		{Msg: &ermite.WatchJobResponse_Keepalive{Keepalive: &ermite.Keepalive{}}},
325		{Msg: &ermite.WatchJobResponse_Cancel{Cancel: &ermite.CancelRequest{
326			Reason: ermite.CancelReason_CANCEL_REASON_FAIL_FAST, Message: "m",
327		}}},
328		{Msg: &ermite.WatchJobResponse_Ended{Ended: &ermite.JobEnded{
329			Conclusion: ermite.CiConclusion_CI_CONCLUSION_CANCELLED, Error: "e",
330		}}},
331	}
332	for _, in := range msgs {
333		b, err := proto.Marshal(in)
334		if err != nil {
335			t.Fatal(err)
336		}
337		var out ermite.WatchJobResponse
338		if err := proto.Unmarshal(b, &out); err != nil {
339			t.Fatal(err)
340		}
341		if !proto.Equal(in, &out) {
342			t.Errorf("round trip mismatch: %v != %v", &out, in)
343		}
344	}
345	// The detail travels in a Connect error.
346	d, err := connect.NewErrorDetail(&ermite.JobEnded{Conclusion: ermite.CiConclusion_CI_CONCLUSION_TIMED_OUT})
347	if err != nil {
348		t.Fatal(err)
349	}
350	cerr := connect.NewError(connect.CodeFailedPrecondition, errors.New("job ended"))
351	cerr.AddDetail(d)
352	v, err := cerr.Details()[0].Value()
353	if err != nil {
354		t.Fatal(err)
355	}
356	if got := v.(*ermite.JobEnded).GetConclusion(); got != ermite.CiConclusion_CI_CONCLUSION_TIMED_OUT {
357		t.Errorf("detail conclusion = %v", got)
358	}
359}
360
361// TestCompleteJobRoundTrip checks the final report of a job and its answer.
362func TestCompleteJobRoundTrip(t *testing.T) {
363	in := &ermite.CompleteJobRequest{
364		JobId:          "j1",
365		Conclusion:     ermite.CiConclusion_CI_CONCLUSION_CANCELLED,
366		Outputs:        map[string]string{"a": "b"},
367		RunnerShutdown: true,
368		Steps:          []*ermite.StepUpdate{{Number: 2, State: ermite.StepState_STEP_STATE_COMPLETED}},
369	}
370	b, err := proto.Marshal(in)
371	if err != nil {
372		t.Fatal(err)
373	}
374	var out ermite.CompleteJobRequest
375	if err := proto.Unmarshal(b, &out); err != nil {
376		t.Fatal(err)
377	}
378	if !proto.Equal(in, &out) {
379		t.Errorf("round trip mismatch: %v != %v", &out, in)
380	}
381	r := &ermite.CompleteJobResponse{Applied: false, Conclusion: ermite.CiConclusion_CI_CONCLUSION_TIMED_OUT}
382	if r.GetApplied() || r.GetConclusion() != ermite.CiConclusion_CI_CONCLUSION_TIMED_OUT {
383		t.Errorf("unexpected response %v", r)
384	}
385}
386
387// TestRunNameField pins the number of Run.name, the GitHub name of the run
388// that sits next to workflow_name, and that it survives the wire.
389func TestRunNameField(t *testing.T) {
390	fd := (&ermite.Run{}).ProtoReflect().Descriptor().Fields().ByName("name")
391	if fd == nil || fd.Number() != 19 {
392		t.Fatalf("Run.name = %v, want field 19", fd)
393	}
394	in := &ermite.Run{WorkflowName: "Names Workflow", Name: "run push on branch by someone", Title: "run push on branch by someone"}
395	b, err := proto.Marshal(in)
396	if err != nil {
397		t.Fatal(err)
398	}
399	var out ermite.Run
400	if err := proto.Unmarshal(b, &out); err != nil {
401		t.Fatal(err)
402	}
403	if out.GetName() != in.GetName() || out.GetWorkflowName() != "Names Workflow" {
404		t.Errorf("round trip: name %q, workflow_name %q", out.GetName(), out.GetWorkflowName())
405	}
406}
407
408// TestCI2FieldNumbers pins the numbers of the fields added for CI-2.
409func TestCI2FieldNumbers(t *testing.T) {
410	tests := []struct {
411		msg    proto.Message
412		fields map[string]int
413	}{
414		{&ermite.Job{}, map[string]int{"github_token": 15}},
415		{&ermite.UpdateJobRequest{}, map[string]int{"annotations": 3}},
416		{&ermite.CompleteJobRequest{}, map[string]int{"annotations": 6}},
417		{&ermite.StepUpdate{}, map[string]int{"outcome": 7}},
418		{&ermite.Step{}, map[string]int{"outcome": 9}},
419		{&ermite.Annotation{}, map[string]int{
420			"level": 1, "title": 2, "message": 3, "file": 4, "start_line": 5,
421			"end_line": 6, "start_column": 7, "end_column": 8, "step_number": 9,
422		}},
423		{&ermite.ActionRef{}, map[string]int{"uses": 1}},
424		{&ermite.ResolveActionsRequest{}, map[string]int{"job_id": 1, "refs": 2}},
425		{&ermite.ResolveActionsResponse{}, map[string]int{"actions": 1}},
426		{&ermite.ResolvedAction{}, map[string]int{
427			"ref": 1, "name_with_owner": 2, "path": 3, "resolved_sha": 4,
428			"tarball_url": 5, "token": 6, "source": 7, "error": 8,
429		}},
430		{&ermite.UploadSummaryRequest{}, map[string]int{"job_id": 1, "step_number": 2, "markdown": 3}},
431		{&ermite.ListAnnotationsRequest{}, map[string]int{"repo": 1, "run_id": 2, "attempt": 3, "job_id": 4}},
432		{&ermite.ListAnnotationsResponse{}, map[string]int{"annotations": 1, "truncated": 2}},
433		{&ermite.JobAnnotation{}, map[string]int{"job_id": 1, "annotation": 2}},
434		{&ermite.GetStepSummariesRequest{}, map[string]int{"repo": 1, "job_id": 2, "attempt": 3}},
435		{&ermite.GetStepSummariesResponse{}, map[string]int{"summaries": 1, "truncated": 2}},
436		{&ermite.StepSummary{}, map[string]int{"step_number": 1, "markdown": 2}},
437	}
438	for _, tt := range tests {
439		md := tt.msg.ProtoReflect().Descriptor()
440		for name, num := range tt.fields {
441			if fd := md.Fields().ByName(protoreflect.Name(name)); fd == nil || int(fd.Number()) != num {
442				t.Errorf("%s.%s: %v, want number %d", md.Name(), name, fd, num)
443			}
444		}
445	}
446}
447
448// TestCI2RoundTrip checks that the CI-2 messages survive the wire.
449func TestCI2RoundTrip(t *testing.T) {
450	msgs := []proto.Message{
451		&ermite.Job{JobId: "j1", GithubToken: "ermitegh_x"},
452		&ermite.UpdateJobRequest{
453			JobId: "j1",
454			Steps: []*ermite.StepUpdate{{
455				Number: 2, State: ermite.StepState_STEP_STATE_COMPLETED,
456				Conclusion: ermite.CiConclusion_CI_CONCLUSION_SUCCESS,
457				Outcome:    ermite.CiConclusion_CI_CONCLUSION_FAILURE,
458			}},
459			Annotations: []*ermite.Annotation{{
460				Level: ermite.AnnotationLevel_ANNOTATION_LEVEL_WARNING, Title: "t", Message: "m",
461				File: "a.go", StartLine: 1, EndLine: 2, StartColumn: 3, EndColumn: 4, StepNumber: 2,
462			}},
463		},
464		&ermite.CompleteJobRequest{
465			JobId:       "j1",
466			Conclusion:  ermite.CiConclusion_CI_CONCLUSION_SUCCESS,
467			Annotations: []*ermite.Annotation{{Level: ermite.AnnotationLevel_ANNOTATION_LEVEL_FAILURE, Message: "m", StepNumber: 3}},
468		},
469		&ermite.ResolveActionsRequest{JobId: "j1", Refs: []*ermite.ActionRef{{Uses: "actions/checkout@v4"}, {Uses: "o/r/p@main"}}},
470		&ermite.ResolveActionsResponse{Actions: []*ermite.ResolvedAction{
471			{
472				Ref: "o/r/p@main", NameWithOwner: "o/r", Path: "p", ResolvedSha: "0123456789012345678901234567890123456789",
473				TarballUrl: "https://example.test/o/r.tar.gz", Token: "t", Source: ermite.ActionSource_ACTION_SOURCE_ERMITE,
474			},
475			{Ref: "x/y@z", Error: "Unable to resolve action `x/y@z`, unable to find version `z`"},
476		}},
477		&ermite.UploadSummaryRequest{JobId: "j1", StepNumber: 2, Markdown: "# hi"},
478		&ermite.ListAnnotationsResponse{Annotations: []*ermite.JobAnnotation{{JobId: "j1", Annotation: &ermite.Annotation{Message: "m"}}}, Truncated: true},
479		&ermite.GetStepSummariesResponse{Summaries: []*ermite.StepSummary{{StepNumber: 2, Markdown: "# hi"}}, Truncated: true},
480		&ermite.RunJob{Id: "j1", Steps: []*ermite.Step{{Number: 2, Outcome: ermite.CiConclusion_CI_CONCLUSION_FAILURE}}},
481	}
482	for _, in := range msgs {
483		b, err := proto.Marshal(in)
484		if err != nil {
485			t.Fatal(err)
486		}
487		out := in.ProtoReflect().New().Interface()
488		if err := proto.Unmarshal(b, out); err != nil {
489			t.Fatal(err)
490		}
491		if !proto.Equal(in, out) {
492			t.Errorf("%T: round trip mismatch: %v != %v", in, out, in)
493		}
494	}
495}
496
497// TestCI3FieldNumbers pins the numbers of the fields added for CI-3.
498func TestCI3FieldNumbers(t *testing.T) {
499	tests := []struct {
500		msg    proto.Message
501		fields map[string]int
502	}{
503		{&ermite.Job{}, map[string]int{
504			"secrets": 16, "vars": 17, "environment": 18, "permissions": 19, "cache": 20, "trusted": 21,
505		}},
506		{&ermite.JobPermissions{}, map[string]int{"levels": 1}},
507		{&ermite.JobCache{}, map[string]int{"repository": 1, "write_ref": 2, "read_refs": 3}},
508		{&ermite.Run{}, map[string]int{"trusted": 20}},
509		{&ermite.RunJob{}, map[string]int{"concurrency_group": 20}},
510		{&ermite.DispatchWorkflowRequest{}, map[string]int{"repo": 1, "workflow_path": 2, "ref": 3, "inputs": 4}},
511		{&ermite.DispatchWorkflowResponse{}, map[string]int{"run": 1}},
512		{&ermite.Workflow{}, map[string]int{"path": 1, "name": 2, "state": 3}},
513		{&ermite.ListWorkflowsRequest{}, map[string]int{"repo": 1}},
514		{&ermite.ListWorkflowsResponse{}, map[string]int{"workflows": 1}},
515		{&ermite.DisableWorkflowRequest{}, map[string]int{"repo": 1, "workflow": 2}},
516		{&ermite.DisableWorkflowResponse{}, map[string]int{"workflow": 1}},
517		{&ermite.EnableWorkflowRequest{}, map[string]int{"repo": 1, "workflow": 2}},
518		{&ermite.EnableWorkflowResponse{}, map[string]int{"workflow": 1}},
519		{&ermite.SettingsScope{}, map[string]int{"instance": 1, "repo": 2, "environment": 3}},
520		{&ermite.EnvironmentRef{}, map[string]int{"repo": 1, "name": 2}},
521		{&ermite.Secret{}, map[string]int{"name": 1, "updated_at": 2}},
522		{&ermite.Variable{}, map[string]int{"name": 1, "value": 2, "updated_at": 3}},
523		{&ermite.Environment{}, map[string]int{"repo": 1, "name": 2, "created_at": 3}},
524		{&ermite.SetSecretRequest{}, map[string]int{"scope": 1, "name": 2, "value": 3}},
525		{&ermite.ListSecretsRequest{}, map[string]int{"scope": 1, "page_size": 2, "page_token": 3}},
526		{&ermite.ListSecretsResponse{}, map[string]int{"secrets": 1, "next_page_token": 2}},
527		{&ermite.ListVariablesResponse{}, map[string]int{"variables": 1, "next_page_token": 2}},
528		{&ermite.ListEnvironmentsRequest{}, map[string]int{"repo": 1, "page_size": 2, "page_token": 3}},
529		{&ermite.ListEnvironmentsResponse{}, map[string]int{"environments": 1, "next_page_token": 2}},
530	}
531	for _, tt := range tests {
532		md := tt.msg.ProtoReflect().Descriptor()
533		for name, num := range tt.fields {
534			if fd := md.Fields().ByName(protoreflect.Name(name)); fd == nil || int(fd.Number()) != num {
535				t.Errorf("%s.%s: %v, want number %d", md.Name(), name, fd, num)
536			}
537		}
538	}
539}
540
541// TestCI3RoundTrip checks that the CI-3 messages survive the wire.
542func TestCI3RoundTrip(t *testing.T) {
543	msgs := []proto.Message{
544		&ermite.Job{
545			JobId: "j1", Secrets: map[string]string{"TOKEN": "s3cret"}, Vars: map[string]string{"REGION": "eu"},
546			Environment: "staging", Trusted: true,
547			Permissions: &ermite.JobPermissions{Levels: map[string]string{"contents": "write", "packages": "none"}},
548			Cache: &ermite.JobCache{
549				Repository: "ermite", WriteRef: "refs/pull/7/merge",
550				ReadRefs: []string{"refs/pull/7/merge", "refs/heads/main"},
551			},
552		},
553		&ermite.Run{Id: 9, Event: "workflow_dispatch", Trusted: true},
554		&ermite.RunJob{Id: "j1", Status: ermite.CiStatus_CI_STATUS_PENDING, ConcurrencyGroup: "deploy"},
555		&ermite.DispatchWorkflowRequest{Repo: "ermite", WorkflowPath: "ci.yml", Ref: "main", Inputs: map[string]string{"debug": "true"}},
556		&ermite.DispatchWorkflowResponse{Run: &ermite.Run{Id: 9, Event: "workflow_dispatch"}},
557		&ermite.ListWorkflowsResponse{Workflows: []*ermite.Workflow{{Path: ".github/workflows/release.yml", Name: "Release", State: ermite.WorkflowState_WORKFLOW_STATE_DISABLED}}},
558		&ermite.DisableWorkflowRequest{Repo: "ermite", Workflow: "release.yml"},
559		&ermite.EnableWorkflowResponse{Workflow: &ermite.Workflow{Path: ".github/workflows/release.yml", State: ermite.WorkflowState_WORKFLOW_STATE_ENABLED}},
560		&ermite.SetSecretRequest{Scope: &ermite.SettingsScope{Where: &ermite.SettingsScope_Instance{Instance: true}}, Name: "A", Value: "v"},
561		&ermite.SetSecretRequest{Scope: &ermite.SettingsScope{Where: &ermite.SettingsScope_Repo{Repo: "ermite"}}, Name: "A", Value: "v"},
562		&ermite.SetVariableRequest{
563			Scope: &ermite.SettingsScope{Where: &ermite.SettingsScope_Environment{Environment: &ermite.EnvironmentRef{Repo: "ermite", Name: "prod"}}},
564			Name:  "A", Value: "v",
565		},
566		&ermite.ListSecretsResponse{Secrets: []*ermite.Secret{{Name: "A"}}, NextPageToken: "t"},
567		&ermite.ListEnvironmentsResponse{Environments: []*ermite.Environment{{Repo: "ermite", Name: "prod"}}},
568	}
569	for _, in := range msgs {
570		b, err := proto.Marshal(in)
571		if err != nil {
572			t.Fatal(err)
573		}
574		out := in.ProtoReflect().New().Interface()
575		if err := proto.Unmarshal(b, out); err != nil {
576			t.Fatal(err)
577		}
578		if !proto.Equal(in, out) {
579			t.Errorf("%T: round trip mismatch: %v != %v", in, out, in)
580		}
581	}
582}
583
584// TestMirrorWire pins event numbers and verifies presence of explicit zero patches.
585func TestMirrorWire(t *testing.T) {
586	fields := (&ermite.Event{}).ProtoReflect().Descriptor().Fields()
587	for name, number := range map[protoreflect.Name]protoreflect.FieldNumber{"mirror_failed": 23, "mirror_recovered": 24} {
588		if fd := fields.ByName(name); fd == nil || fd.Number() != number || fd.ContainingOneof().Name() != "kind" {
589			t.Fatalf("Event.%s: %v, want kind field %d", name, fd, number)
590		}
591	}
592	for _, msg := range []proto.Message{&ermite.MirrorFailed{}, &ermite.MirrorRecovered{}} {
593		fields := msg.ProtoReflect().Descriptor().Fields()
594		if fields.ByName("url") != nil || fields.ByName("detail") != nil {
595			t.Fatalf("%T leaks URL or detail", msg)
596		}
597	}
598	for _, in := range []proto.Message{
599		&ermite.SetMirrorConfigRequest{Enabled: proto.Bool(false), UrlTemplate: proto.String(""), Cron: proto.String(""), AllBranches: proto.Bool(false)},
600		&ermite.SetRepoMirrorRequest{Repo: "repo", AllBranches: proto.Bool(false)},
601		&ermite.Event{Kind: &ermite.Event_MirrorFailed{MirrorFailed: &ermite.MirrorFailed{Repo: "repo", State: ermite.MirrorState_MIRROR_STATE_PAUSED, FailureClass: "diverged"}}},
602		&ermite.Event{Kind: &ermite.Event_MirrorRecovered{MirrorRecovered: &ermite.MirrorRecovered{Repo: "repo"}}},
603	} {
604		b, err := proto.Marshal(in)
605		if err != nil {
606			t.Fatal(err)
607		}
608		out := in.ProtoReflect().New().Interface()
609		if err := proto.Unmarshal(b, out); err != nil {
610			t.Fatal(err)
611		}
612		if !proto.Equal(in, out) {
613			t.Errorf("%T: round trip mismatch: %v != %v", in, out, in)
614		}
615	}
616}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 2

Tags 18

↑↓ moveenter openesc close