v0.4.0 72f8f2e

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

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