Skip to content

Commit 3c0e165

Browse files
committed
chore: remove implicit echo provision responses
1 parent f06a77a commit 3c0e165

File tree

2 files changed

+36
-58
lines changed

2 files changed

+36
-58
lines changed

coderd/workspacebuilds_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,18 +1500,18 @@ func TestPostWorkspaceBuild(t *testing.T) {
15001500
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
15011501
user := coderdtest.CreateFirstUser(t, client)
15021502
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
1503-
ProvisionApply: []*proto.Response{
1503+
ProvisionPlan: []*proto.Response{
15041504
{
1505-
Type: &proto.Response_Apply{
1506-
Apply: &proto.ApplyComplete{
1507-
Error: "failed to import",
1505+
Type: &proto.Response_Plan{
1506+
Plan: &proto.PlanComplete{
1507+
Error: "failed to plan",
15081508
},
15091509
},
15101510
},
15111511
},
15121512
})
15131513
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
1514-
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
1514+
version = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
15151515

15161516
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
15171517
defer cancel()

provisioner/echo/serve.go

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -403,69 +403,47 @@ func TarWithOptions(ctx context.Context, logger slog.Logger, responses *Response
403403
ExtraFiles: nil,
404404
}
405405
}
406-
// source apply from the graph if graph exists
407-
if responses.ProvisionApply == nil && len(responses.ProvisionGraph) > 0 {
408-
for _, resp := range responses.ProvisionGraph {
409-
if resp.GetLog() != nil {
410-
responses.ProvisionApply = append(responses.ProvisionApply, resp)
411-
continue
412-
}
413-
responses.ProvisionApply = append(responses.ProvisionApply, &proto.Response{
414-
Type: &proto.Response_Apply{Apply: &proto.ApplyComplete{
415-
Error: resp.GetGraph().GetError(),
416-
}},
417-
})
418-
}
419-
}
420-
if responses.ProvisionGraph == nil {
421-
for _, resp := range responses.ProvisionApply {
422-
if resp.GetLog() != nil {
423-
responses.ProvisionGraph = append(responses.ProvisionGraph, resp)
424-
continue
425-
}
426-
responses.ProvisionGraph = append(responses.ProvisionGraph, &proto.Response{
427-
Type: &proto.Response_Graph{Graph: &proto.GraphComplete{
428-
Error: resp.GetApply().GetError(),
429-
}},
430-
})
431-
}
406+
407+
// Apply sane defaults for missing responses.
408+
if responses.Parse == nil {
409+
responses.Parse = ParseComplete
432410
}
433411
if responses.ProvisionInit == nil {
434-
for _, resp := range responses.ProvisionGraph {
435-
if resp.GetLog() != nil {
436-
responses.ProvisionInit = append(responses.ProvisionInit, resp)
437-
continue
438-
}
439-
responses.ProvisionInit = append(responses.ProvisionInit, &proto.Response{
440-
Type: &proto.Response_Init{
441-
Init: &proto.InitComplete{
442-
Error: resp.GetGraph().GetError(),
443-
Timings: nil,
444-
Modules: nil,
445-
ModuleFiles: nil,
446-
ModuleFilesHash: nil,
447-
},
448-
},
449-
},
450-
)
451-
}
412+
responses.ProvisionInit = InitComplete
452413
}
453414
if responses.ProvisionPlan == nil {
415+
responses.ProvisionPlan = PlanComplete
416+
417+
// If a graph response exists, make sure it matches the plan.
454418
for _, resp := range responses.ProvisionGraph {
455419
if resp.GetLog() != nil {
456-
responses.ProvisionPlan = append(responses.ProvisionPlan, resp)
457420
continue
458421
}
459-
responses.ProvisionPlan = append(responses.ProvisionPlan, &proto.Response{
460-
Type: &proto.Response_Plan{Plan: &proto.PlanComplete{
461-
Error: resp.GetGraph().GetError(),
462-
Plan: []byte("{}"),
463-
//nolint:gosec // the number of resources will not exceed int32
464-
AiTaskCount: int32(len(resp.GetGraph().GetAiTasks())),
465-
}},
466-
})
422+
if g := resp.GetGraph(); g != nil {
423+
dailycost := int32(0)
424+
for _, r := range g.GetResources() {
425+
dailycost += r.DailyCost
426+
}
427+
responses.ProvisionPlan = []*proto.Response{{
428+
Type: &proto.Response_Plan{
429+
Plan: &proto.PlanComplete{
430+
Plan: []byte("{}"),
431+
//nolint:gosec // the number of resources will not exceed int32
432+
AiTaskCount: int32(len(g.GetAiTasks())),
433+
DailyCost: dailycost,
434+
},
435+
},
436+
}}
437+
break
438+
}
467439
}
468440
}
441+
if responses.ProvisionApply == nil {
442+
responses.ProvisionApply = ApplyComplete
443+
}
444+
if responses.ProvisionGraph == nil {
445+
responses.ProvisionGraph = GraphComplete
446+
}
469447

470448
for _, resp := range responses.ProvisionPlan {
471449
plan := resp.GetPlan()

0 commit comments

Comments
 (0)