update coding task to align with spec and improve expetion handling
This commit is contained in:
@@ -2,7 +2,6 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -18,15 +17,14 @@ The MongoDB Driver dependency in the file is outdated and needs to be updated to
|
|||||||
This is a common task for developers, and it requires attention to detail and the ability to follow instructions carefully.
|
This is a common task for developers, and it requires attention to detail and the ability to follow instructions carefully.
|
||||||
|
|
||||||
Your task:
|
Your task:
|
||||||
1. Assign this Issue to yourself as "Me" and mark it as "In Progress"
|
1. Create a New Issue and give it these details:
|
||||||
2. Create a New Issue and give it these details:
|
|
||||||
- Title: "Upgrade MongoDB Driver Dependency"
|
- Title: "Upgrade MongoDB Driver Dependency"
|
||||||
- Description: "We need to upgrade the MongoDB Driver dependency to the latest version."
|
- Description: "We need to upgrade the MongoDB Driver dependency to the latest version."
|
||||||
- Status: "In Progress"
|
- Status: "In Progress"
|
||||||
- Issue Type: "Chore"
|
- Issue Type: "Chore"
|
||||||
3. A file will appear in the current directory named "code.txt".
|
2. A file will appear in the current directory named "code.txt".
|
||||||
Open it and follow the instructions inside. And save the file after you are done.
|
Open it and follow the instructions inside. And save the file after you are done.
|
||||||
4. When you are done, mark this and the issue you made as "Closed".`
|
3. When you are done, mark this and the issue you made as "Closed".`
|
||||||
|
|
||||||
var textFileDescription = `
|
var textFileDescription = `
|
||||||
Please upgrade the MongoDB Driver dependency in the go.mod file to the latest version.
|
Please upgrade the MongoDB Driver dependency in the go.mod file to the latest version.
|
||||||
@@ -122,7 +120,7 @@ func (t *CodingTask) Setup(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var codeTaskInProgress = false
|
var codingTaskInProgress = false
|
||||||
|
|
||||||
func (t *CodingTask) Validate(ctx context.Context) ValidationFeedback {
|
func (t *CodingTask) Validate(ctx context.Context) ValidationFeedback {
|
||||||
expect := check.NewExpector()
|
expect := check.NewExpector()
|
||||||
@@ -132,47 +130,31 @@ func (t *CodingTask) Validate(ctx context.Context) ValidationFeedback {
|
|||||||
return expect.ValidationFeedback
|
return expect.ValidationFeedback
|
||||||
}
|
}
|
||||||
|
|
||||||
expect.Assert(t.setupIssue.Assignee == "Me",
|
|
||||||
"The original issue should be assigned to 'Me'.")
|
|
||||||
|
|
||||||
expect.Assert(t.setupIssue.Status == models.StatusInProgress,
|
|
||||||
"The original issue should be marked as In Progress before starting work.")
|
|
||||||
|
|
||||||
expect.Assert(len(issues) > 0,
|
|
||||||
"No new issues created. Please create an issue with the specified details.")
|
|
||||||
|
|
||||||
if len(issues) == 0 {
|
if len(issues) == 0 {
|
||||||
expect.Fail("No new issues created")
|
expect.Fail("No new issues created")
|
||||||
return expect.ValidationFeedback
|
return expect.ValidationFeedback
|
||||||
|
} else {
|
||||||
|
expect.Pass("An issue was created")
|
||||||
}
|
}
|
||||||
|
|
||||||
issue := issues[0]
|
issue := issues[0]
|
||||||
|
|
||||||
expect.Assert(len(issues) < 2,
|
expect.Assert(len(issues) < 2, "Multiple issues were created instead of one")
|
||||||
"Multiple issues were created instead of one. Delete the extra issues and try again.")
|
|
||||||
|
|
||||||
expect.NotEmptyString(issue.Title,
|
expect.NotEmptyAndEqual(issue.Title, "Upgrade MongoDB Driver Dependency", "Issue title")
|
||||||
"Issue title should not be empty")
|
|
||||||
|
|
||||||
expect.Assert(issue.Title == "Upgrade MongoDB Driver Dependency",
|
expect.NotEmptyAndEqual(issue.Description,
|
||||||
fmt.Sprintf("Issue title does not match the expected value 'Upgrade MongoDB Driver Dependency', but was '%s'", issue.Title))
|
"We need to upgrade the MongoDB Driver dependency to the latest version.", "Issue description")
|
||||||
|
|
||||||
expect.NotEmptyString(issue.Description,
|
expect.NotEmptyAndEqual(issue.Assignee, "Me", "Issue Assignee")
|
||||||
"Issue description should not be empty")
|
|
||||||
|
|
||||||
expect.Assert(issue.Description == "We need to upgrade the MongoDB Driver dependency to the latest version.",
|
expect.Equal(issue.IssueType, models.TypeChore, "Issue type")
|
||||||
fmt.Sprintf("Issue description does not match 'We need to upgrade the MongoDB Driver dependency to the latest version.', but was '%s'", issue.Description))
|
|
||||||
|
|
||||||
expect.Assert(issue.IssueType == models.TypeChore,
|
if issue.Status == models.StatusInProgress || codingTaskInProgress {
|
||||||
fmt.Sprintf("Issue type should be 'Chore', but was '%s'", issue.IssueType))
|
codingTaskInProgress = true
|
||||||
|
|
||||||
expect.Assert(issue.Assignee == "Me",
|
|
||||||
fmt.Sprintf("Issue should be assigned to 'Me', but was assigned to '%s'", issue.Assignee))
|
|
||||||
|
|
||||||
if issue.Status == models.StatusInProgress || codeTaskInProgress {
|
|
||||||
codeTaskInProgress = true
|
|
||||||
} else {
|
} else {
|
||||||
expect.Fail("Issue should be marked as In Progress when work starts")
|
expect.Fail("The issue should be marked as In Progress while working on the task.")
|
||||||
|
return expect.ValidationFeedback
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat("./code.txt"); os.IsNotExist(err) {
|
if _, err := os.Stat("./code.txt"); os.IsNotExist(err) {
|
||||||
@@ -195,14 +177,8 @@ func (t *CodingTask) Validate(ctx context.Context) ValidationFeedback {
|
|||||||
expect.Assert(strings.Contains(code, "go.mongodb.org/mongo-driver v1.17.9"),
|
expect.Assert(strings.Contains(code, "go.mongodb.org/mongo-driver v1.17.9"),
|
||||||
"The MongoDB Driver dependency should be updated to version v1.17.9 in the file.")
|
"The MongoDB Driver dependency should be updated to version v1.17.9 in the file.")
|
||||||
|
|
||||||
if !codeTaskInProgress {
|
expect.Assert(codingTaskInProgress && issue.Status == models.StatusClosed,
|
||||||
return expect.ValidationFeedback
|
"The issue should be marked as Closed after completing the task.")
|
||||||
} else if issue.Status != models.StatusClosed {
|
|
||||||
expect.Fail("Issue should be set to Closed once the work is completed")
|
|
||||||
} else {
|
|
||||||
expect.Assert(t.setupIssue.Status == models.StatusClosed,
|
|
||||||
"The original setup issue should be set to Closed once the work is completed")
|
|
||||||
}
|
|
||||||
|
|
||||||
return expect.Complete()
|
return expect.Complete()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,13 @@ func (e *Expector) NotEmptyAndEqual(val, expected string, message string) *Expec
|
|||||||
return e.Pass(message + " is correct")
|
return e.Pass(message + " is correct")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Expector) Equal(val, expected any, message string) *Expector {
|
||||||
|
if val != expected {
|
||||||
|
return e.Fail(fmt.Sprintf(`%s expected "%v", got "%v"`, message, expected, val))
|
||||||
|
}
|
||||||
|
return e.Pass(message + " is correct")
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Expector) Assert(condition bool, message string) *Expector {
|
func (e *Expector) Assert(condition bool, message string) *Expector {
|
||||||
check := NewCheck(message, condition)
|
check := NewCheck(message, condition)
|
||||||
e.Checks = append(e.Checks, check)
|
e.Checks = append(e.Checks, check)
|
||||||
|
|||||||
Reference in New Issue
Block a user