@@ -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