v0.11.0 94ffd87

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

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