-
Notifications
You must be signed in to change notification settings - Fork 5
fix(api): allow missing required variable when a brick is added + app validation #74
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
base: main
Are you sure you want to change the base?
Conversation
…ate test data feat: add AppFromExample configuration and Python main file for testing
… update test cases
…Create and update test case descriptions
…app descriptor test
…ty and consistency
…responding constant
…d omitted variables
…cases for validation scenarios
… and adjust related tests
…errors instead of the first one
…ted tests for consistency
|
Running this script to test the validation of the example 0.5.0 |
Doesn't this approach risk assigning a non-compatible value for a mandatory variable? What happens in this case? The result is that the required variable is set as an empty string in the app.yaml (see the tests "do not fail if a mandatory variable is not present"). |
Co-authored-by: mirkoCrobu <214636120+mirkoCrobu@users.noreply.github.com>
| if index == nil { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would bricksindex required
| if index == nil { | |
| return nil | |
| } |
| for appBrickVariableName := range appBrick.Variables { | ||
| _, exist := indexBrick.GetVariable(appBrickVariableName) | ||
| if !exist { | ||
| slog.Warn("variable is referenced but not declared in the brick configuration", "variable", appBrickVariableName, "brick", indexBrick.ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add this todo for the future
| slog.Warn("variable is referenced but not declared in the brick configuration", "variable", appBrickVariableName, "brick", indexBrick.ID) | |
| TODO: we should return warnings | |
| slog.Warn("variable is referenced but not declared in the brick configuration", "variable", appBrickVariableName, "brick", indexBrick.ID) |
|
|
||
| err := app.ValidateBricks(appToStart.Descriptor, bricksIndex) | ||
| if err != nil { | ||
| yield(StreamMessage{error: err}) | ||
| return | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this here. The check should be done only before starting and not before stopping
| filename: "all-required-app.yaml", | ||
| expectedError: nil, | ||
| }, | ||
| { | ||
| name: "valid with missing bricks", | ||
| filename: "no-bricks-app.yaml", | ||
| expectedError: nil, | ||
| }, | ||
| { | ||
| name: "valid with empty list of bricks", | ||
| filename: "empty-bricks-app.yaml", | ||
| expectedError: nil, | ||
| }, | ||
| { | ||
| name: "valid if required variable is empty string", | ||
| filename: "empty-required-app.yaml", | ||
| expectedError: nil, | ||
| }, | ||
| { | ||
| name: "invalid if required variable is omitted", | ||
| filename: "omitted-required-app.yaml", | ||
| expectedError: errors.Join( | ||
| errors.New("variable \"ARDUINO_DEVICE_ID\" is required by brick \"arduino:arduino_cloud\""), | ||
| errors.New("variable \"ARDUINO_SECRET\" is required by brick \"arduino:arduino_cloud\""), | ||
| ), | ||
| }, | ||
| { | ||
| name: "invalid if a required variable among two is omitted", | ||
| filename: "omitted-mixed-required-app.yaml", | ||
| expectedError: errors.New("variable \"ARDUINO_SECRET\" is required by brick \"arduino:arduino_cloud\""), | ||
| }, | ||
| { | ||
| name: "invalid if brick id not found", | ||
| filename: "not-found-brick-app.yaml", | ||
| expectedError: errors.New("brick \"arduino:not_existing_brick\" not found"), | ||
| }, | ||
| { | ||
| name: "log a warning if variable does not exist in the brick", | ||
| filename: "not-found-variable-app.yaml", | ||
| expectedError: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, this test is very unreadable; the YAMLs are quite small, so it will be better to include them here instead of storing them in different files.
|
|
||
| func TestValidateAppDescriptorBricks(t *testing.T) { | ||
| bricksIndex, err := bricksindex.GenerateBricksIndexFromFile(paths.New("testdata/validator")) | ||
| require.Nil(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| require.Nil(t, err) | |
| require.NoError(t, err) |
Motivation
Close #68
When a brick with required variables is added to an app created from scratch the operation fails.
This is because the FE (appLab) does not pass the required variables when the
PUT /v1/apps/{appID}/bricks/{brickID}is called.For example, the brick
arduino:arduino_cloudhas theARDUINO_DEVICE_IDandARDUINO_SECRETrequired.When it is added to a scratch app, it fails silently.
Additionally, the issue does not occur when an app with a brick already added is cloned.
This is because when an app is cloned the backend does not check if the required variables are missing.
Change description
The following changes are
Additional notes
arduino_cloud. Starting an app that uses the arduino_cloud without specifying the required variablesARDUINO_SECRETandARDUINO_DEVICE_IDwill raise an error.Examples of errors
Example:
Given the following
app-yaml, where the requiredARDUINO_SECRETvariable ofarduino:arduino_cloudis missing:When an app is started
When an app is restarted
Additional Notes
Reviewer checklist
main.