@@ -478,6 +478,91 @@ models:
478478 // we ignore HOST_IP since it's dynamic
479479}
480480
481+ func TestGetAppEnvironmentVariablesWithCustomModelOverrides (t * testing.T ) {
482+ cfg := setTestOrchestratorConfig (t )
483+ idProvider := app .NewAppIDProvider (cfg )
484+
485+ docker , err := dockerClient .NewClientWithOpts (
486+ dockerClient .FromEnv ,
487+ dockerClient .WithAPIVersionNegotiation (),
488+ )
489+ require .NoError (t , err )
490+ dockerCli , err := command .NewDockerCli (
491+ command .WithAPIClient (docker ),
492+ command .WithBaseContext (t .Context ()),
493+ )
494+ require .NoError (t , err )
495+
496+ err = dockerCli .Initialize (& flags.ClientOptions {})
497+ require .NoError (t , err )
498+
499+ appId := createApp (t , "app1" , false , idProvider , cfg )
500+ appDesc , err := app .Load (appId .ToPath ().String ())
501+ require .NoError (t , err )
502+ appDesc .Descriptor .Bricks = []app.Brick {
503+ {
504+ ID : "arduino:object_detection" ,
505+ Variables : map [string ]string {
506+ "EI_OBJ_DETECTION_MODEL" : "/home/arduino/.arduino-bricks/ei-models/face-det.eim" ,
507+ }, // override the default model via ENV variable
508+ },
509+ }
510+
511+ bricksIndexContent := []byte (`
512+ bricks:
513+ - id: arduino:object_detection
514+ name: Object Detection
515+ description: "Brick for object detection using a pre-trained model. It processes\
516+ \ images and returns the predicted class label, bounding-boxes and confidence\
517+ \ score.\nBrick is designed to work with pre-trained models provided by framework\
518+ \ or with custom object detection models trained on Edge Impulse platform. \n"
519+ require_container: true
520+ require_model: true
521+ require_devices: false
522+ category: video
523+ model_name: yolox-object-detection
524+ variables:
525+ - name: CUSTOM_MODEL_PATH
526+ default_value: /home/arduino/.arduino-bricks/ei-models
527+ description: path to the custom model directory
528+ - name: EI_OBJ_DETECTION_MODEL
529+ default_value: /models/ootb/ei/yolo-x-nano.eim
530+ description: path to the model file
531+ ` )
532+ err = cfg .AssetsDir ().Join ("bricks-list.yaml" ).WriteFile (bricksIndexContent )
533+ require .NoError (t , err )
534+ bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (cfg .AssetsDir ())
535+ assert .NoError (t , err )
536+
537+ modelsIndexContent := []byte (`
538+ models:
539+ - yolox-object-detection:
540+ runner: brick
541+ name : "General purpose object detection - YoloX"
542+ description: "General purpose object detection model based on YoloX Nano. This model is trained on the COCO dataset and can detect 80 different object classes."
543+ model_configuration:
544+ "EI_OBJ_DETECTION_MODEL": "/models/ootb/ei/yolo-x-nano.eim"
545+ metadata:
546+ source: "edgeimpulse"
547+ ei-project-id: 717280
548+ source-model-id: "YOLOX-Nano"
549+ source-model-url: "https://github.com/Megvii-BaseDetection/YOLOX"
550+ bricks:
551+ - arduino:object_detection
552+ - arduino:video_object_detection
553+ ` )
554+ err = cfg .AssetsDir ().Join ("models-list.yaml" ).WriteFile (modelsIndexContent )
555+ require .NoError (t , err )
556+ modelIndex , err := modelsindex .GenerateModelsIndexFromFile (cfg .AssetsDir ())
557+ require .NoError (t , err )
558+
559+ env := getAppEnvironmentVariables (appDesc , bricksIndex , modelIndex )
560+ require .Equal (t , cfg .AppsDir ().Join ("app1" ).String (), env ["APP_HOME" ])
561+ require .Equal (t , "/home/arduino/.arduino-bricks/ei-models/face-det.eim" , env ["EI_OBJ_DETECTION_MODEL" ])
562+ require .Equal (t , "/home/arduino/.arduino-bricks/ei-models" , env ["CUSTOM_MODEL_PATH" ])
563+ // we ignore HOST_IP since it's dynamic
564+ }
565+
481566func TestValidateDevice (t * testing.T ) {
482567
483568 t .Run ("valid" , func (t * testing.T ) {
0 commit comments