v0.7.0 d244a03

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

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