From 454ecb30e19f7779eaed5849454ba601ba936eab Mon Sep 17 00:00:00 2001 From: dido18 Date: Fri, 24 Oct 2025 15:13:14 +0200 Subject: [PATCH 1/7] feat(models): add model_labels field and update test data for models --- .../orchestrator/modelsindex/models_index.go | 1 + .../modelsindex/modelsindex_test.go | 111 +++++++++++++++++ .../modelsindex/testdata/invalid-models.yaml | 8 ++ .../modelsindex/testdata/models-list.yaml | 112 ++++++++++++++++++ 4 files changed, 232 insertions(+) create mode 100644 internal/orchestrator/modelsindex/modelsindex_test.go create mode 100644 internal/orchestrator/modelsindex/testdata/invalid-models.yaml create mode 100644 internal/orchestrator/modelsindex/testdata/models-list.yaml diff --git a/internal/orchestrator/modelsindex/models_index.go b/internal/orchestrator/modelsindex/models_index.go index a966a678..e18797f1 100644 --- a/internal/orchestrator/modelsindex/models_index.go +++ b/internal/orchestrator/modelsindex/models_index.go @@ -48,6 +48,7 @@ type AIModel struct { ModuleDescription string `yaml:"description"` Runner string `yaml:"runner"` Bricks []string `yaml:"bricks,omitempty"` + ModelLabels []string `yaml:"model_labels,omitempty"` Metadata map[string]string `yaml:"metadata,omitempty"` ModelConfiguration map[string]string `yaml:"model_configuration,omitempty"` } diff --git a/internal/orchestrator/modelsindex/modelsindex_test.go b/internal/orchestrator/modelsindex/modelsindex_test.go new file mode 100644 index 00000000..d64f2431 --- /dev/null +++ b/internal/orchestrator/modelsindex/modelsindex_test.go @@ -0,0 +1,111 @@ +package modelsindex + +import ( + "testing" + + "github.com/arduino/go-paths-helper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGenerateModelsIndexFromFile(t *testing.T) { + testdataPath := paths.New("testdata") + + t.Run("Valid Model list", func(t *testing.T) { + modelsIndex, err := GenerateModelsIndexFromFile(testdataPath) + require.NoError(t, err) + require.NotNil(t, modelsIndex) + + models := modelsIndex.GetModels() + assert.Len(t, models, 3, "Expected 3 models to be parsed") + + // Test first model + model1, found := modelsIndex.GetModelByID("face-detection") + assert.Equal(t, "brick", model1.Runner) + require.True(t, found, "face-detection should be found") + assert.Equal(t, "face-detection:", model1.ID) + assert.Equal(t, "Lightweight-Face-Detection", model1.Name) + assert.Equal(t, "Face bounding box detection. This model is trained on the WIDER FACE dataset and can detect faces in images.", model1.ModuleDescription) + assert.Equal(t, []string{"arduino:object_detection", "arduino:video_object_detection"}, model1.L) + assert.Equal(t, []string{"arduino:object_detection", "arduino:video_object_detection"}, model1.Bricks) + assert.Equal(t, "1.0.0", model1.Metadata["version"]) + assert.Equal(t, "Test Author", model1.Metadata["author"]) + assert.Equal(t, "1000", model1.ModelConfiguration["max_tokens"]) + assert.Equal(t, "0.7", model1.ModelConfiguration["temperature"]) + + // // Test second model + // model2, found := modelsIndex.GetModelByID("test_model_2") + // // require.True(t, found, "test_model_2 should be found") + // // assert.Equal(t, "test_model_2", model2.ID) + // // assert.Equal(t, "Test Model 2", model2.Name) + // // assert.Equal(t, "Another test AI model", model2.ModuleDescription) + // // assert.Equal(t, "another_runner", model2.Runner) + // // assert.Equal(t, []string{"brick2", "brick3"}, model2.Bricks) + // // assert.Equal(t, "2.0.0", model2.Metadata["version"]) + // // assert.Equal(t, "MIT", model2.Metadata["license"]) + + // // Test minimal model + // model3, found := modelsIndex.GetModelByID("minimal_model") + // require.True(t, found, "minimal_model should be found") + // assert.Equal(t, "minimal_model", model3.ID) + // assert.Equal(t, "Minimal Model", model3.Name) + // assert.Equal(t, "Minimal model with no optional fields", model3.ModuleDescription) + // assert.Equal(t, "minimal_runner", model3.Runner) + // assert.Empty(t, model3.Bricks) + // assert.Empty(t, model3.Metadata) + // assert.Empty(t, model3.ModelConfiguration) + }) + + // Test file not found error + t.Run("FileNotFound", func(t *testing.T) { + nonExistentPath := paths.New("nonexistent") + modelsIndex, err := GenerateModelsIndexFromFile(nonExistentPath) + assert.Error(t, err) + assert.Nil(t, modelsIndex) + }) + + // Test invalid YAML parsing + t.Run("InvalidYAML", func(t *testing.T) { + // Create a temporary invalid YAML file + invalidPath := testdataPath.Join("invalid-models.yaml") + + // We expect this to either fail parsing or handle gracefully + // Since the current implementation may be lenient with missing fields + modelsIndex, err := GenerateModelsIndexFromFile(testdataPath.Parent().Join("testdata-invalid")) + if err != nil { + // If it fails, that's expected for invalid files + assert.Error(t, err) + assert.Nil(t, modelsIndex) + } + // Note: Some invalid YAML might still parse successfully depending on the YAML library's behavior + _ = invalidPath // Avoid unused variable warning + }) + + // Test brick filtering functionality + t.Run("BrickFiltering", func(t *testing.T) { + modelsIndex, err := GenerateModelsIndexFromFile(testdataPath) + require.NoError(t, err) + + // Test GetModelsByBrick + brick1Models := modelsIndex.GetModelsByBrick("brick1") + assert.Len(t, brick1Models, 1) + assert.Equal(t, "test_model_1", brick1Models[0].ID) + + brick2Models := modelsIndex.GetModelsByBrick("brick2") + assert.Len(t, brick2Models, 2) + modelIDs := []string{brick2Models[0].ID, brick2Models[1].ID} + assert.Contains(t, modelIDs, "test_model_1") + assert.Contains(t, modelIDs, "test_model_2") + + // Test GetModelsByBricks + multiModels := modelsIndex.GetModelsByBricks([]string{"brick1", "brick3"}) + assert.Len(t, multiModels, 2) + multiModelIDs := []string{multiModels[0].ID, multiModels[1].ID} + assert.Contains(t, multiModelIDs, "test_model_1") + assert.Contains(t, multiModelIDs, "test_model_2") + + // Test non-existent brick + nonExistentModels := modelsIndex.GetModelsByBrick("nonexistent_brick") + assert.Nil(t, nonExistentModels) + }) +} diff --git a/internal/orchestrator/modelsindex/testdata/invalid-models.yaml b/internal/orchestrator/modelsindex/testdata/invalid-models.yaml new file mode 100644 index 00000000..d78d2c80 --- /dev/null +++ b/internal/orchestrator/modelsindex/testdata/invalid-models.yaml @@ -0,0 +1,8 @@ +models: + - invalid_model: + name: "Invalid Model" + description: "Missing required fields" + # Missing runner field + invalid_field: "this should cause parsing issues" + - another_invalid: + name: 123 # Invalid type for name field \ No newline at end of file diff --git a/internal/orchestrator/modelsindex/testdata/models-list.yaml b/internal/orchestrator/modelsindex/testdata/models-list.yaml new file mode 100644 index 00000000..56757a09 --- /dev/null +++ b/internal/orchestrator/modelsindex/testdata/models-list.yaml @@ -0,0 +1,112 @@ +models: + - face-detection: + runner: brick + name : "Lightweight-Face-Detection" + description: "Face bounding box detection. This model is trained on the WIDER FACE dataset and can detect faces in images." + model_configuration: + "EI_OBJ_DETECTION_MODEL": "/models/ootb/ei/lw-face-det.eim" + model_labels: + - face + bricks: + - arduino:object_detection + - arduino:video_object_detection + metadata: + source: "qualcomm-ai-hub" + ei-gpu-mode: false + source-model-id: "face-det-lite" + source-model-url: "https://aihub.qualcomm.com/models/face_det_lite" + - yolox-object-detection: + runner: brick + name : "General purpose object detection - YoloX" + 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." + model_configuration: + "EI_OBJ_DETECTION_MODEL": "/models/ootb/ei/yolo-x-nano.eim" + model_labels: + - airplane + - apple + - backpack + - banana + - baseball bat + - baseball glove + - bear + - bed + - bench + - bicycle + - bird + - boat + - book + - bottle + - bowl + - broccoli + - bus + - cake + - car + - carrot + - cat + - cell phone + - chair + - clock + - couch + - cow + - cup + - dining table + - dog + - donut + - elephant + - fire hydrant + - fork + - frisbee + - giraffe + - hair drier + - handbag + - hot dog + - horse + - keyboard + - kite + - knife + - laptop + - microwave + - motorcycle + - mouse + - orange + - oven + - parking meter + - person + - pizza + - potted plant + - refrigerator + - remote + - sandwich + - scissors + - sheep + - sink + - skateboard + - skis + - snowboard + - spoon + - sports ball + - stop sign + - suitcase + - surfboard + - teddy bear + - tennis racket + - tie + - toaster + - toilet + - toothbrush + - traffic light + - train + - truck + - tv + - umbrella + - vase + - wine glass + - zebra + metadata: + source: "edgeimpulse" + ei-project-id: 717280 + source-model-id: "YOLOX-Nano" + source-model-url: "https://github.com/Megvii-BaseDetection/YOLOX" + bricks: + - arduino:object_detection + - arduino:video_object_detection From e3eec7bf4ff799f654cd0c0811428bde0aa76684 Mon Sep 17 00:00:00 2001 From: dido18 Date: Fri, 24 Oct 2025 15:53:42 +0200 Subject: [PATCH 2/7] refactor(tests): update model index tests for clarity and accuracy --- .../modelsindex/modelsindex_test.go | 115 ++++++------------ .../modelsindex/testdata/invalid-models.yaml | 8 -- .../modelsindex/testdata/models-list.yaml | 1 - 3 files changed, 40 insertions(+), 84 deletions(-) delete mode 100644 internal/orchestrator/modelsindex/testdata/invalid-models.yaml diff --git a/internal/orchestrator/modelsindex/modelsindex_test.go b/internal/orchestrator/modelsindex/modelsindex_test.go index d64f2431..fc62fb8b 100644 --- a/internal/orchestrator/modelsindex/modelsindex_test.go +++ b/internal/orchestrator/modelsindex/modelsindex_test.go @@ -9,102 +9,67 @@ import ( ) func TestGenerateModelsIndexFromFile(t *testing.T) { - testdataPath := paths.New("testdata") - - t.Run("Valid Model list", func(t *testing.T) { - modelsIndex, err := GenerateModelsIndexFromFile(testdataPath) + t.Run("it parses a valid model-list.yaml", func(t *testing.T) { + modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) require.NoError(t, err) require.NotNil(t, modelsIndex) models := modelsIndex.GetModels() - assert.Len(t, models, 3, "Expected 3 models to be parsed") - - // Test first model - model1, found := modelsIndex.GetModelByID("face-detection") - assert.Equal(t, "brick", model1.Runner) - require.True(t, found, "face-detection should be found") - assert.Equal(t, "face-detection:", model1.ID) - assert.Equal(t, "Lightweight-Face-Detection", model1.Name) - assert.Equal(t, "Face bounding box detection. This model is trained on the WIDER FACE dataset and can detect faces in images.", model1.ModuleDescription) - assert.Equal(t, []string{"arduino:object_detection", "arduino:video_object_detection"}, model1.L) - assert.Equal(t, []string{"arduino:object_detection", "arduino:video_object_detection"}, model1.Bricks) - assert.Equal(t, "1.0.0", model1.Metadata["version"]) - assert.Equal(t, "Test Author", model1.Metadata["author"]) - assert.Equal(t, "1000", model1.ModelConfiguration["max_tokens"]) - assert.Equal(t, "0.7", model1.ModelConfiguration["temperature"]) + assert.Len(t, models, 2, "Expected 2 models to be parsed") + }) - // // Test second model - // model2, found := modelsIndex.GetModelByID("test_model_2") - // // require.True(t, found, "test_model_2 should be found") - // // assert.Equal(t, "test_model_2", model2.ID) - // // assert.Equal(t, "Test Model 2", model2.Name) - // // assert.Equal(t, "Another test AI model", model2.ModuleDescription) - // // assert.Equal(t, "another_runner", model2.Runner) - // // assert.Equal(t, []string{"brick2", "brick3"}, model2.Bricks) - // // assert.Equal(t, "2.0.0", model2.Metadata["version"]) - // // assert.Equal(t, "MIT", model2.Metadata["license"]) + t.Run("it gets a model by ID", func(t *testing.T) { + modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) + require.NoError(t, err) - // // Test minimal model - // model3, found := modelsIndex.GetModelByID("minimal_model") - // require.True(t, found, "minimal_model should be found") - // assert.Equal(t, "minimal_model", model3.ID) - // assert.Equal(t, "Minimal Model", model3.Name) - // assert.Equal(t, "Minimal model with no optional fields", model3.ModuleDescription) - // assert.Equal(t, "minimal_runner", model3.Runner) - // assert.Empty(t, model3.Bricks) - // assert.Empty(t, model3.Metadata) - // assert.Empty(t, model3.ModelConfiguration) + model, found := modelsIndex.GetModelByID("face-detection") + assert.Equal(t, "brick", model.Runner) + require.True(t, found, "face-detection should be found") + assert.Equal(t, "face-detection", model.ID) + assert.Equal(t, "Lightweight-Face-Detection", model.Name) + assert.Equal(t, "Face bounding box detection. This model is trained on the WIDER FACE dataset and can detect faces in images.", model.ModuleDescription) + assert.Equal(t, []string{"face"}, model.ModelLabels) + assert.Equal(t, "/models/ootb/ei/lw-face-det.eim", model.ModelConfiguration["EI_OBJ_DETECTION_MODEL"]) + assert.Equal(t, []string{"arduino:object_detection", "arduino:video_object_detection"}, model.Bricks) + assert.Equal(t, "qualcomm-ai-hub", model.Metadata["source"]) + assert.Equal(t, "false", model.Metadata["ei-gpu-mode"]) + assert.Equal(t, "face-det-lite", model.Metadata["source-model-id"]) + assert.Equal(t, "https://aihub.qualcomm.com/models/face_det_lite", model.Metadata["source-model-url"]) }) - // Test file not found error - t.Run("FileNotFound", func(t *testing.T) { - nonExistentPath := paths.New("nonexistent") + t.Run("it fails if model-list.yaml does not exist", func(t *testing.T) { + nonExistentPath := paths.New("nonexistent.yaml") modelsIndex, err := GenerateModelsIndexFromFile(nonExistentPath) assert.Error(t, err) assert.Nil(t, modelsIndex) }) - // Test invalid YAML parsing - t.Run("InvalidYAML", func(t *testing.T) { - // Create a temporary invalid YAML file - invalidPath := testdataPath.Join("invalid-models.yaml") + t.Run("it filters models by a single brick", func(t *testing.T) { + modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) + require.NoError(t, err) + + brick1Models := modelsIndex.GetModelsByBrick("arduino:object_detection") + assert.Len(t, brick1Models, 1) + assert.Equal(t, "face-detection", brick1Models[0].ID) - // We expect this to either fail parsing or handle gracefully - // Since the current implementation may be lenient with missing fields - modelsIndex, err := GenerateModelsIndexFromFile(testdataPath.Parent().Join("testdata-invalid")) - if err != nil { - // If it fails, that's expected for invalid files - assert.Error(t, err) - assert.Nil(t, modelsIndex) - } - // Note: Some invalid YAML might still parse successfully depending on the YAML library's behavior - _ = invalidPath // Avoid unused variable warning + brick1Models = modelsIndex.GetModelsByBrick("not-existing-brick") + assert.Nil(t, brick1Models) }) - // Test brick filtering functionality - t.Run("BrickFiltering", func(t *testing.T) { - modelsIndex, err := GenerateModelsIndexFromFile(testdataPath) + t.Run("it filters models by multiple bricks", func(t *testing.T) { + modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) require.NoError(t, err) - // Test GetModelsByBrick - brick1Models := modelsIndex.GetModelsByBrick("brick1") - assert.Len(t, brick1Models, 1) - assert.Equal(t, "test_model_1", brick1Models[0].ID) - - brick2Models := modelsIndex.GetModelsByBrick("brick2") + brick2Models := modelsIndex.GetModelsByBrick("arduino:video_object_detection") assert.Len(t, brick2Models, 2) - modelIDs := []string{brick2Models[0].ID, brick2Models[1].ID} - assert.Contains(t, modelIDs, "test_model_1") - assert.Contains(t, modelIDs, "test_model_2") + assert.Equal(t, "face-detection", brick2Models[0].ID) + assert.Equal(t, "yolox-object-detection", brick2Models[1].ID) - // Test GetModelsByBricks - multiModels := modelsIndex.GetModelsByBricks([]string{"brick1", "brick3"}) - assert.Len(t, multiModels, 2) - multiModelIDs := []string{multiModels[0].ID, multiModels[1].ID} - assert.Contains(t, multiModelIDs, "test_model_1") - assert.Contains(t, multiModelIDs, "test_model_2") + bricks2Models := modelsIndex.GetModelsByBricks([]string{"arduino:object_detection", "arduino:video_object_detection"}) + assert.Len(t, bricks2Models, 2) + assert.Equal(t, "face-detection", bricks2Models[0].ID) + assert.Equal(t, "yolox-object-detection", bricks2Models[1].ID) - // Test non-existent brick nonExistentModels := modelsIndex.GetModelsByBrick("nonexistent_brick") assert.Nil(t, nonExistentModels) }) diff --git a/internal/orchestrator/modelsindex/testdata/invalid-models.yaml b/internal/orchestrator/modelsindex/testdata/invalid-models.yaml deleted file mode 100644 index d78d2c80..00000000 --- a/internal/orchestrator/modelsindex/testdata/invalid-models.yaml +++ /dev/null @@ -1,8 +0,0 @@ -models: - - invalid_model: - name: "Invalid Model" - description: "Missing required fields" - # Missing runner field - invalid_field: "this should cause parsing issues" - - another_invalid: - name: 123 # Invalid type for name field \ No newline at end of file diff --git a/internal/orchestrator/modelsindex/testdata/models-list.yaml b/internal/orchestrator/modelsindex/testdata/models-list.yaml index 56757a09..7d0aefb5 100644 --- a/internal/orchestrator/modelsindex/testdata/models-list.yaml +++ b/internal/orchestrator/modelsindex/testdata/models-list.yaml @@ -108,5 +108,4 @@ models: source-model-id: "YOLOX-Nano" source-model-url: "https://github.com/Megvii-BaseDetection/YOLOX" bricks: - - arduino:object_detection - arduino:video_object_detection From 1e19ef02563fce6ac8c052fa8576fc2bea666bcf Mon Sep 17 00:00:00 2001 From: dido18 Date: Fri, 24 Oct 2025 16:27:03 +0200 Subject: [PATCH 3/7] fix(tests): correct model retrieval order in TestGenerateModelsIndexFromFile --- internal/orchestrator/modelsindex/modelsindex_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/orchestrator/modelsindex/modelsindex_test.go b/internal/orchestrator/modelsindex/modelsindex_test.go index fc62fb8b..f9e72302 100644 --- a/internal/orchestrator/modelsindex/modelsindex_test.go +++ b/internal/orchestrator/modelsindex/modelsindex_test.go @@ -22,7 +22,11 @@ func TestGenerateModelsIndexFromFile(t *testing.T) { modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) require.NoError(t, err) - model, found := modelsIndex.GetModelByID("face-detection") + model, found := modelsIndex.GetModelByID("not-existing-model") + assert.False(t, found) + assert.Nil(t, model) + + model, found = modelsIndex.GetModelByID("face-detection") assert.Equal(t, "brick", model.Runner) require.True(t, found, "face-detection should be found") assert.Equal(t, "face-detection", model.ID) From 0dfbbc252b1513b3a8bb2a7cecbc117a55398921 Mon Sep 17 00:00:00 2001 From: Davide Date: Wed, 29 Oct 2025 10:06:03 +0100 Subject: [PATCH 4/7] Update internal/orchestrator/modelsindex/modelsindex_test.go Co-authored-by: mirkoCrobu --- internal/orchestrator/modelsindex/modelsindex_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/orchestrator/modelsindex/modelsindex_test.go b/internal/orchestrator/modelsindex/modelsindex_test.go index f9e72302..0a44ec1e 100644 --- a/internal/orchestrator/modelsindex/modelsindex_test.go +++ b/internal/orchestrator/modelsindex/modelsindex_test.go @@ -42,7 +42,7 @@ func TestGenerateModelsIndexFromFile(t *testing.T) { }) t.Run("it fails if model-list.yaml does not exist", func(t *testing.T) { - nonExistentPath := paths.New("nonexistent.yaml") + nonExistentPath := paths.New("nonexistentdir") modelsIndex, err := GenerateModelsIndexFromFile(nonExistentPath) assert.Error(t, err) assert.Nil(t, modelsIndex) From c8cae04ca80dad72c3cbcb176d4ce4c6e3655e12 Mon Sep 17 00:00:00 2001 From: dido18 Date: Thu, 30 Oct 2025 16:22:38 +0100 Subject: [PATCH 5/7] refactor(tests): streamline model index test structure for clarity --- .../modelsindex/modelsindex_test.go | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/internal/orchestrator/modelsindex/modelsindex_test.go b/internal/orchestrator/modelsindex/modelsindex_test.go index 0a44ec1e..e464ca4c 100644 --- a/internal/orchestrator/modelsindex/modelsindex_test.go +++ b/internal/orchestrator/modelsindex/modelsindex_test.go @@ -9,19 +9,16 @@ import ( ) func TestGenerateModelsIndexFromFile(t *testing.T) { - t.Run("it parses a valid model-list.yaml", func(t *testing.T) { - modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) - require.NoError(t, err) - require.NotNil(t, modelsIndex) + modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) + require.NoError(t, err) + require.NotNil(t, modelsIndex) + t.Run("it parses a valid model-list.yaml", func(t *testing.T) { models := modelsIndex.GetModels() assert.Len(t, models, 2, "Expected 2 models to be parsed") }) t.Run("it gets a model by ID", func(t *testing.T) { - modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) - require.NoError(t, err) - model, found := modelsIndex.GetModelByID("not-existing-model") assert.False(t, found) assert.Nil(t, model) @@ -48,10 +45,7 @@ func TestGenerateModelsIndexFromFile(t *testing.T) { assert.Nil(t, modelsIndex) }) - t.Run("it filters models by a single brick", func(t *testing.T) { - modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) - require.NoError(t, err) - + t.Run("it gets models by a single brick", func(t *testing.T) { brick1Models := modelsIndex.GetModelsByBrick("arduino:object_detection") assert.Len(t, brick1Models, 1) assert.Equal(t, "face-detection", brick1Models[0].ID) @@ -60,11 +54,12 @@ func TestGenerateModelsIndexFromFile(t *testing.T) { assert.Nil(t, brick1Models) }) - t.Run("it filters models by multiple bricks", func(t *testing.T) { - modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) - require.NoError(t, err) + t.Run("it gets models by multiple bricks", func(t *testing.T) { + brick2Models := modelsIndex.GetModelsByBrick("arduino:non_existing") + assert.Len(t, brick2Models, 0) + assert.Nil(t, brick2Models) - brick2Models := modelsIndex.GetModelsByBrick("arduino:video_object_detection") + brick2Models = modelsIndex.GetModelsByBrick("arduino:video_object_detection") assert.Len(t, brick2Models, 2) assert.Equal(t, "face-detection", brick2Models[0].ID) assert.Equal(t, "yolox-object-detection", brick2Models[1].ID) From e972973bc5c4cf3450f46b5f6fc9bd1f1412fb21 Mon Sep 17 00:00:00 2001 From: dido18 Date: Thu, 30 Oct 2025 16:28:26 +0100 Subject: [PATCH 6/7] refactor(tests): simplify model retrieval tests for clarity and consistency --- .../modelsindex/modelsindex_test.go | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/internal/orchestrator/modelsindex/modelsindex_test.go b/internal/orchestrator/modelsindex/modelsindex_test.go index e464ca4c..0d6141bb 100644 --- a/internal/orchestrator/modelsindex/modelsindex_test.go +++ b/internal/orchestrator/modelsindex/modelsindex_test.go @@ -45,31 +45,28 @@ func TestGenerateModelsIndexFromFile(t *testing.T) { assert.Nil(t, modelsIndex) }) - t.Run("it gets models by a single brick", func(t *testing.T) { - brick1Models := modelsIndex.GetModelsByBrick("arduino:object_detection") - assert.Len(t, brick1Models, 1) - assert.Equal(t, "face-detection", brick1Models[0].ID) + t.Run("it gets models by a brick", func(t *testing.T) { + model := modelsIndex.GetModelsByBrick("not-existing-brick") + assert.Nil(t, model) - brick1Models = modelsIndex.GetModelsByBrick("not-existing-brick") - assert.Nil(t, brick1Models) + model = modelsIndex.GetModelsByBrick("arduino:object_detection") + assert.Len(t, model, 1) + assert.Equal(t, "face-detection", model[0].ID) }) - t.Run("it gets models by multiple bricks", func(t *testing.T) { - brick2Models := modelsIndex.GetModelsByBrick("arduino:non_existing") - assert.Len(t, brick2Models, 0) - assert.Nil(t, brick2Models) - - brick2Models = modelsIndex.GetModelsByBrick("arduino:video_object_detection") - assert.Len(t, brick2Models, 2) - assert.Equal(t, "face-detection", brick2Models[0].ID) - assert.Equal(t, "yolox-object-detection", brick2Models[1].ID) + t.Run("it gets models by bricks", func(t *testing.T) { + models := modelsIndex.GetModelsByBricks([]string{"arduino:non_existing"}) + assert.Len(t, models, 0) + assert.Nil(t, models) - bricks2Models := modelsIndex.GetModelsByBricks([]string{"arduino:object_detection", "arduino:video_object_detection"}) - assert.Len(t, bricks2Models, 2) - assert.Equal(t, "face-detection", bricks2Models[0].ID) - assert.Equal(t, "yolox-object-detection", bricks2Models[1].ID) + models = modelsIndex.GetModelsByBricks([]string{"arduino:video_object_detection"}) + assert.Len(t, models, 2) + assert.Equal(t, "face-detection", models[0].ID) + assert.Equal(t, "yolox-object-detection", models[1].ID) - nonExistentModels := modelsIndex.GetModelsByBrick("nonexistent_brick") - assert.Nil(t, nonExistentModels) + models = modelsIndex.GetModelsByBricks([]string{"arduino:object_detection", "arduino:video_object_detection"}) + assert.Len(t, models, 2) + assert.Equal(t, "face-detection", models[0].ID) + assert.Equal(t, "yolox-object-detection", models[1].ID) }) } From a5bf3f441a83311b04cb3a2bfa47f5b421570e22 Mon Sep 17 00:00:00 2001 From: dido18 Date: Thu, 30 Oct 2025 16:29:12 +0100 Subject: [PATCH 7/7] refactor(tests): rename TestGenerateModelsIndexFromFile to TestModelsIndex for consistency --- internal/orchestrator/modelsindex/modelsindex_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/orchestrator/modelsindex/modelsindex_test.go b/internal/orchestrator/modelsindex/modelsindex_test.go index 0d6141bb..53ffb585 100644 --- a/internal/orchestrator/modelsindex/modelsindex_test.go +++ b/internal/orchestrator/modelsindex/modelsindex_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestGenerateModelsIndexFromFile(t *testing.T) { +func TestModelsIndex(t *testing.T) { modelsIndex, err := GenerateModelsIndexFromFile(paths.New("testdata")) require.NoError(t, err) require.NotNil(t, modelsIndex)