8000 fix(coderd): ensure agent timings are non-zero on insert by johnstcn · Pull Request #18065 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix(coderd): ensure agent timings are non-zero on insert #18065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address suggestion
  • Loading branch information
johnstcn committed May 28, 2025
commit afe791f3d6c1e8a2011eb906a0467da876577f86
20 changes: 7 additions & 13 deletions coderd/agentapi/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,17 @@ func (s *ScriptsAPI) ScriptCompleted(ctx context.Context, req *agentproto.Worksp
return nil, xerrors.Errorf("script id from bytes: %w", err)
}

if req.GetTiming().GetStart() == nil {
return nil, xerrors.New("script start time is required")
scriptStart := req.GetTiming().GetStart()
if !scriptStart.IsValid() || scriptStart.AsTime().IsZero() {
return nil, xerrors.New("script start time is required and cannot be zero")
}

if req.GetTiming().GetEnd() == nil {
return nil, xerrors.New("script end time is required")
scriptEnd := req.GetTiming().GetEnd()
if !scriptEnd.IsValid() || scriptEnd.AsTime().IsZero() {
return nil, xerrors.New("script end time is required and cannot be zero")
}

if req.GetTiming().GetStart().AsTime().IsZero() {
return nil, xerrors.New("script start time cannot be zero")
}

if req.GetTiming().GetEnd().AsTime().IsZero() {
return nil, xerrors.New("script end time cannot be zero")
}

if req.GetTiming().GetStart().AsTime().After(req.GetTiming().GetEnd().AsTime()) {
if scriptStart.AsTime().After(scriptEnd.AsTime()) {
return nil, xerrors.New("script start time cannot be after end time")
}

Expand Down
8 changes: 4 additions & 4 deletions coderd/agentapi/scripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestScriptCompleted(t *testing.T) {
ExitCode: 0,
},
expectInsert: false,
expectError: "script start time is required",
expectError: "script start time is required and cannot be zero",
},
{
scriptID: uuid.New(),
Expand All @@ -103,7 +103,7 @@ func TestScriptCompleted(t *testing.T) {
ExitCode: 0,
},
expectInsert: false,
expectError: "script end time is required",
expectError: "script end time is required and cannot be zero",
},
{
scriptID: uuid.New(),
Expand All @@ -115,7 +115,7 @@ func TestScriptCompleted(t *testing.T) {
ExitCode: 0,
},
expectInsert: false,
expectError: "script start time cannot be zero",
expectError: "script start time is required and cannot be zero",
},
{
scriptID: uuid.New(),
Expand All @@ -127,7 +127,7 @@ func TestScriptCompleted(t *testing.T) {
ExitCode: 0,
},
expectInsert: false,
expectError: "script end time cannot be zero",
expectError: "script end time is required and cannot be zero",
},
{
scriptID: uuid.New(),
Expand Down
Loading
0