Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void merge(Category category) {
for (Category subCategory : category.categories) {
Category existingSubCategory = null;
for (Category c : categories) {
if (c.getDisplayName().equals(subCategory.getDisplayName())) {
if (c.getDisplayName().equalsIgnoreCase(subCategory.getDisplayName())) {
existingSubCategory = c;
break;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public void install(RecipeListing recipe, List<CategoryDescriptor> categoryPath)

private Category findOrCreateCategory(CategoryDescriptor categoryDescriptor) {
for (Category category : categories) {
if (category.getDisplayName().equals(categoryDescriptor.getDisplayName())) {
if (category.getDisplayName().equalsIgnoreCase(categoryDescriptor.getDisplayName())) {
return category;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,50 @@ void mergePreservesMetadata() {
assertThat(mergedOther.getMetadata().get("embedding")).isEqualTo("xyz789");
}

@Test
void mergeCategoriesCaseInsensitive() {
// Simulates the real-world scenario where rewrite-java defines category "AI"
// and rewrite-ai defines category "ai" -- these should merge into one category
RecipeMarketplace marketplace1 = new RecipeMarketplaceReader().fromCsv("""
name,category1,ecosystem,packageName
org.openrewrite.java.ai.ClassDefinitionLength,AI,maven,org.openrewrite:rewrite-java
org.openrewrite.java.ai.MethodDefinitionLength,AI,maven,org.openrewrite:rewrite-java
""");

RecipeMarketplace marketplace2 = new RecipeMarketplaceReader().fromCsv("""
name,category1,ecosystem,packageName
io.moderne.ai.FindAgentsInUse,ai,maven,io.moderne.recipe:rewrite-ai
io.moderne.ai.FindLibrariesInUse,ai,maven,io.moderne.recipe:rewrite-ai
""");

marketplace1.getRoot().merge(marketplace2.getRoot());

assertThat(marketplace1.getRoot().getCategories())
.as("AI and ai should merge into a single category")
.hasSize(1);
assertThat(marketplace1.getRoot().getCategories().getFirst().getRecipes()).hasSize(4);
// The first-seen casing wins
assertThat(marketplace1.getRoot().getCategories().getFirst().getDisplayName()).isEqualTo("AI");
}

@Test
void installCategoriesCaseInsensitive() {
// When installing recipes via CSV where one uses "AI" and another uses "ai"
// in the same category position, they should land in the same category
RecipeMarketplace marketplace = new RecipeMarketplaceReader().fromCsv("""
name,category1,ecosystem,packageName
org.example.Recipe1,AI,maven,org.example:test1
org.example.Recipe2,ai,maven,org.example:test2
""");

assertThat(marketplace.getRoot().getCategories())
.as("AI and ai should be treated as the same category during install")
.hasSize(1);
assertThat(marketplace.getRoot().getCategories().getFirst().getRecipes()).hasSize(2);
// The first-seen casing wins
assertThat(marketplace.getRoot().getCategories().getFirst().getDisplayName()).isEqualTo("AI");
}

private static RecipeMarketplace.Category findCategory(RecipeMarketplace.Category category, String name) {
return category.getCategories().stream()
.filter(c -> c.getDisplayName().equals(name))
Expand Down
Loading