Skip to content

Commit

Permalink
fix: QA categories were being used only by the CLI engine (#1156)
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Nayak <[email protected]>
Co-authored-by: Harikrishnan Balagopal <[email protected]>
  • Loading branch information
Akash-Nayak and HarikrishnanBalagopal authored Mar 20, 2024
1 parent c8164a0 commit fd897df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
15 changes: 0 additions & 15 deletions qaengine/cliengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ func (c *CliEngine) FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Errorf("the QA problem object is invalid. Error: %q", err)
return prob, err
}
// return default if the category is skipped
probCategories := qatypes.GetProblemCategories(prob.ID, prob.Categories)
for _, category := range probCategories {
if common.IsStringPresent(common.DisabledCategories, category) {
// if prob.Default == nil {
// // todo: warn instead of returning error
// return prob, errors.New(fmt.Sprintf("category %s is skipped but default doesn't exist", category)) // TODO:
// }
if err := prob.SetAnswer(prob.Default, true); err != nil {
return prob, fmt.Errorf("failed to set the given solution as the answer. Error: %w", err)
}
return prob, nil
}
}

switch prob.Type {
case qatypes.SelectSolutionFormType:
return c.fetchSelectAnswer(prob)
Expand Down
16 changes: 16 additions & 0 deletions qaengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func SetupConfigFile(writeConfigFile string, configStrings, configFiles, presets
}
}

func isQuestionDisabled(prob qatypes.Problem) bool {
isDisabled := false
probCategories := qatypes.GetProblemCategories(prob.ID, prob.Categories)
for _, category := range probCategories {
if common.IsStringPresent(common.DisabledCategories, category) {
logrus.Debugf("Question belongs to the disabled category: %s", category)
isDisabled = true
break
}
}
return isDisabled
}

// FetchAnswer fetches the answer for the question
func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Trace("FetchAnswer start")
Expand All @@ -127,6 +140,9 @@ func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Debugf("Problem already solved.")
return prob, nil
}
if isQuestionDisabled(prob) {
return defaultEngine.FetchAnswer(prob)
}
var err error
logrus.Debug("looping through the engines to try and fetch the answer")
for _, engine := range engines {
Expand Down

0 comments on commit fd897df

Please sign in to comment.