Skip to content
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

feat: case name templating #795

Merged
merged 4 commits into from
Jan 7, 2025
Merged

Conversation

ChibiBlasphem
Copy link
Contributor

@ChibiBlasphem ChibiBlasphem commented Jan 6, 2025

  • Added StringTemplate ast evaluation
  • Added a new column decision_to_case_name_template in scenario table
  • Added new endpoint /scenario/:scenarioId/ast-validation to validate an AST node
  • Updated case creation to evaluate its name with AST stored in decision_to_case_name_template

Frontend PR: checkmarble/marble-frontend#647

@ChibiBlasphem ChibiBlasphem force-pushed the christopher/case-name-templating branch 2 times, most recently from fa6c2c6 to 6ec80f2 Compare January 6, 2025 14:25
Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the implementation seems about right to me, as far as I can judge from reading.
I left a few comments, but rather minor. The one thing I'm uneasy with is the refactor that touches "isAuthorizedError".
Can we clarify that the template ast is supposed to stay nullable, and we keep the default case name template hard coded ?

models/ast/ast_node_evaluation.go Outdated Show resolved Hide resolved
models/ast/evaluation_errors.go Outdated Show resolved Hide resolved
usecases/ast_eval/evaluate/eval_string_template.go Outdated Show resolved Hide resolved
astEvaluation, _ := ast_eval.EvaluateAst(ctx, dryRunEnvironment, *astNode)
astEvaluationReturnType := reflect.TypeOf(astEvaluation.ReturnValue)

if len(astEvaluation.FlattenErrors()) == 0 && astEvaluationReturnType != returnType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I rather think that you wanted to first check on len(astEvaluation.FlattenErrors()) > 0 and then on astEvaluationReturnType != returnType?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to append return type error only if there's no other errors in the evaluation. Something I noticed is that when I get an evaluation error I always get the return type wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From how you use the function, I still think that there is a possible case where you get a non-empty astEvaluation.FlattenErrors() but it is passed silently.
That being said, the whole structure of the astEvaluation and functions that use it may benefit from being reworked a bit, especially how we pass errors. But that would be left for another PR and probably rather for me.

usecases/ast_eval/evaluate_ast_expression.go Show resolved Hide resolved
api/handle_scenarios.go Outdated Show resolved Hide resolved
api/handle_scenarios.go Outdated Show resolved Hide resolved
usecases/evaluate_scenario/evaluate_scenario.go Outdated Show resolved Hide resolved
@ChibiBlasphem ChibiBlasphem force-pushed the christopher/case-name-templating branch from 6ec80f2 to da3af7f Compare January 6, 2025 16:10
@@ -82,6 +87,13 @@ func (usecase *ScenarioUsecase) UpdateScenario(
return models.Scenario{}, err
}

if scenarioInput.DecisionToCaseNameTemplate != nil {
if validation, _ := usecase.ValidateScenarioAst(ctx, scenarioInput.Id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValidateScenarioAst can also return a non-nil error, this case should also be handled

Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, I left you two last comments (minor changes) and then it's good to merge for me !

Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ChibiBlasphem ChibiBlasphem merged commit c9f7f77 into main Jan 7, 2025
3 checks passed
@ChibiBlasphem ChibiBlasphem deleted the christopher/case-name-templating branch January 7, 2025 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants