Skip to content

Commit eb5a3dc

Browse files
committed
no penalty on fail
1 parent 99bfebc commit eb5a3dc

File tree

7 files changed

+56
-28
lines changed

7 files changed

+56
-28
lines changed

checks/runner.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,27 @@ func sendHTTPRequestResults(ch chan tea.Msg, req api.CLIStepHTTPRequest, result
111111
}
112112
}
113113

114-
func ApplySubmissionResults(cliData api.CLIData, failure *api.VerificationResultStructuredErrCLI, ch chan tea.Msg) {
114+
func ApplySubmissionResults(cliData api.CLIData, result api.VerificationResult, ch chan tea.Msg) {
115+
failure := result.StructuredErrCLI
116+
noop := result.StructuredNoopCLI
117+
118+
var failedStepIndex int
119+
var failedTestIndex int
120+
if failure != nil {
121+
failedStepIndex = failure.FailedStepIndex
122+
failedTestIndex = failure.FailedTestIndex
123+
}
124+
if noop != nil {
125+
failedStepIndex = noop.FailedStepIndex
126+
failedTestIndex = noop.FailedTestIndex
127+
}
128+
115129
for i, step := range cliData.Steps {
116130
stepPass := true
117131
isFailedStep := false
118-
if failure != nil {
119-
stepPass = i < failure.FailedStepIndex
120-
isFailedStep = i == failure.FailedStepIndex
132+
if failure != nil || noop != nil {
133+
stepPass = i < failedStepIndex
134+
isFailedStep = i == failedStepIndex
121135
}
122136

123137
ch <- messages.ResolveStepMsg{
@@ -127,11 +141,11 @@ func ApplySubmissionResults(cliData api.CLIData, failure *api.VerificationResult
127141

128142
if step.CLICommand != nil {
129143
for j := range step.CLICommand.Tests {
130-
if isFailedStep && j > failure.FailedTestIndex {
144+
if isFailedStep && j > failedTestIndex {
131145
break
132146
}
133147

134-
testPass := stepPass || (isFailedStep && j < failure.FailedTestIndex)
148+
testPass := stepPass || (isFailedStep && j < failedTestIndex)
135149
ch <- messages.ResolveTestMsg{
136150
StepIndex: i,
137151
TestIndex: j,
@@ -141,11 +155,11 @@ func ApplySubmissionResults(cliData api.CLIData, failure *api.VerificationResult
141155
}
142156
if step.HTTPRequest != nil {
143157
for j := range step.HTTPRequest.Tests {
144-
if isFailedStep && j > failure.FailedTestIndex {
158+
if isFailedStep && j > failedTestIndex {
145159
break
146160
}
147161

148-
testPass := stepPass || (isFailedStep && j < failure.FailedTestIndex)
162+
testPass := stepPass || (isFailedStep && j < failedTestIndex)
149163
ch <- messages.ResolveTestMsg{
150164
StepIndex: i,
151165
TestIndex: j,

client/lessons.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const BaseURLOverrideRequired = "override"
2222

2323
type CLIData struct {
2424
// ContainsCompleteDir bool
25+
// NoPenaltyOnFail bool
2526
BaseURLDefault string
2627
Steps []CLIStep
2728
AllowedOperatingSystems []string
@@ -189,12 +190,14 @@ type lessonSubmissionCLI struct {
189190
CLIResults []CLIStepResult
190191
}
191192

192-
type verificationResult struct {
193-
ResultSlug string
193+
type VerificationResult struct {
194+
// ResultSlug string
194195
// user friendly message to put in the toast
195196
ResultMessage string
196197
// only present if the lesson is an CLI type
197198
StructuredErrCLI *VerificationResultStructuredErrCLI
199+
// for "noop" on "noPenaltyOnFail" CLI lessons
200+
StructuredNoopCLI *VerificationResultStructuredErrCLI
198201
}
199202

200203
type VerificationResultStructuredErrCLI struct {
@@ -203,27 +206,27 @@ type VerificationResultStructuredErrCLI struct {
203206
FailedTestIndex int `json:"FailedTestIndex"`
204207
}
205208

206-
func SubmitCLILesson(uuid string, results []CLIStepResult) (*VerificationResultStructuredErrCLI, error) {
209+
func SubmitCLILesson(uuid string, results []CLIStepResult) (VerificationResult, error) {
207210
bytes, err := json.Marshal(lessonSubmissionCLI{CLIResults: results})
208211
if err != nil {
209-
return nil, err
212+
return VerificationResult{}, err
210213
}
211214
endpoint := fmt.Sprintf("/v1/lessons/%v/", uuid)
212215
resp, code, err := fetchWithAuthAndPayload("POST", endpoint, bytes)
213216
if err != nil {
214-
return nil, err
217+
return VerificationResult{}, err
215218
}
216219
if code == 402 {
217-
return nil, fmt.Errorf("to run and submit the tests for this lesson, you must have an active Boot.dev membership\nhttps://boot.dev/pricing")
220+
return VerificationResult{}, fmt.Errorf("to run and submit the tests for this lesson, you must have an active Boot.dev membership\nhttps://boot.dev/pricing")
218221
}
219222
if code != 200 {
220-
return nil, fmt.Errorf("failed to submit CLI lesson (code %v): %s", code, string(resp))
223+
return VerificationResult{}, fmt.Errorf("failed to submit CLI lesson (code %v): %s", code, string(resp))
221224
}
222225

223-
result := verificationResult{}
226+
result := VerificationResult{}
224227
err = json.Unmarshal(resp, &result)
225228
if err != nil {
226-
return nil, err
229+
return VerificationResult{}, err
227230
}
228-
return result.StructuredErrCLI, nil
231+
return result, nil
229232
}

cmd/submit.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,17 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
6868
// StartRenderer and returns immediately, finalise function blocks the execution until the renderer is closed.
6969
finalise := render.StartRenderer(data, isSubmit, ch)
7070

71-
results := checks.CLIChecks(data, overrideBaseURL, ch)
71+
cliResults := checks.CLIChecks(data, overrideBaseURL, ch)
7272

7373
if isSubmit {
74-
failure, err := api.SubmitCLILesson(lessonUUID, results)
74+
submissionResults, err := api.SubmitCLILesson(lessonUUID, cliResults)
7575
if err != nil {
7676
return err
7777
}
78-
checks.ApplySubmissionResults(data, failure, ch)
79-
80-
finalise(failure)
78+
checks.ApplySubmissionResults(data, submissionResults, ch)
79+
finalise(submissionResults)
8180
} else {
82-
finalise(nil)
81+
finalise(api.VerificationResult{})
8382
}
8483
return nil
8584
}

messages/messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type ResolveTestMsg struct {
2222

2323
type DoneStepMsg struct {
2424
Failure *api.VerificationResultStructuredErrCLI
25+
Noop *api.VerificationResultStructuredErrCLI
2526
}
2627

2728
type ResolveStepMsg struct {

render/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type rootModel struct {
2525
steps []stepModel
2626
spinner spinner.Model
2727
failure *api.VerificationResultStructuredErrCLI
28+
noop *api.VerificationResultStructuredErrCLI
2829
isSubmit bool
2930
success bool
3031
finalized bool

render/render.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func (m rootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
3131
switch msg := msg.(type) {
3232
case messages.DoneStepMsg:
3333
m.failure = msg.Failure
34-
if m.failure == nil && m.isSubmit {
34+
m.noop = msg.Noop
35+
if m.failure == nil && m.noop == nil && m.isSubmit {
3536
m.success = true
3637
}
3738
m.clear = true
@@ -93,7 +94,7 @@ func (m rootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9394
}
9495
}
9596

96-
func StartRenderer(data api.CLIData, isSubmit bool, ch chan tea.Msg) func(*api.VerificationResultStructuredErrCLI) {
97+
func StartRenderer(data api.CLIData, isSubmit bool, ch chan tea.Msg) func(api.VerificationResult) {
9798
var wg sync.WaitGroup
9899
p := tea.NewProgram(initModel(isSubmit), tea.WithoutSignalHandler())
99100

@@ -117,8 +118,11 @@ func StartRenderer(data api.CLIData, isSubmit bool, ch chan tea.Msg) func(*api.V
117118
}
118119
}()
119120

120-
return func(failure *api.VerificationResultStructuredErrCLI) {
121-
ch <- messages.DoneStepMsg{Failure: failure}
121+
return func(result api.VerificationResult) {
122+
ch <- messages.DoneStepMsg{
123+
Failure: result.StructuredErrCLI,
124+
Noop: result.StructuredNoopCLI,
125+
}
122126
wg.Wait()
123127
}
124128
}

render/view.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,16 @@ func (m rootModel) View() string {
161161
str.WriteString(printHTTPRequestResult(*step.result.HTTPRequestResult))
162162
}
163163
}
164+
164165
if m.failure != nil {
165166
str.WriteString("\n\n" + red.Render("Tests failed! ❌"))
166167
str.WriteString(red.Render(fmt.Sprintf("\n\nFailed Step: %v", m.failure.FailedStepIndex+1)))
167168
str.WriteString(red.Render("\nError: "+m.failure.ErrorMessage) + "\n\n")
169+
} else if m.noop != nil {
170+
str.WriteString("\n\n" + red.Render("Tests failed! ❌"))
171+
str.WriteString(red.Render(fmt.Sprintf("\n\nFailed Step: %v", m.noop.FailedStepIndex+1)))
172+
str.WriteString(red.Render("\nError: " + m.noop.ErrorMessage + "\n"))
173+
str.WriteString(red.Render("\nYou haven't passed, but you also haven't been penalized.") + "\n\n")
168174
} else if m.success {
169175
str.WriteString("\n\n" + green.Render("All tests passed! 🎉") + "\n\n")
170176
str.WriteString(green.Render("Return to your browser to continue with the next lesson.") + "\n\n")

0 commit comments

Comments
 (0)