From 3ca171050fc59a95cef493726672ac019d47bd92 Mon Sep 17 00:00:00 2001 From: Jonathan Katz Date: Wed, 18 Nov 2026 16:04:02 -0500 Subject: [PATCH 1/3] Combine Fleet-maintained apps by name instead of slug token --- cmd/maintained-apps/main.go | 12 +- cmd/maintained-apps/main_test.go | 22 +++ frontend/interfaces/software.ts | 2 +- .../FleetMaintainedAppsTable.tests.tsx | 178 ++++-------------- .../FleetMaintainedAppsTable.tsx | 59 ++---- server/datastore/mysql/maintained_apps.go | 71 +++---- .../datastore/mysql/maintained_apps_test.go | 48 +++-- 7 files changed, 147 insertions(+), 245 deletions(-) diff --git a/cmd/maintained-apps/main.go b/cmd/maintained-apps/main.go index 5b98cb30537..abacba18bef 100644 --- a/cmd/maintained-apps/main.go +++ b/cmd/maintained-apps/main.go @@ -9,6 +9,7 @@ import ( "log/slog" "os" "path" + "regexp" "slices" "strings" @@ -157,16 +158,23 @@ func updateAppsListFile(ctx context.Context, outApp *maintained_apps.FMAManifest return ctxerr.Wrap(ctx, err, "unmarshaling output apps list file") } + platform := outApp.Platform() + platformNameSuffix := regexp.MustCompile(` for (macOS|Mac|Windows)$`) var found bool for _, a := range outputAppsFile.Apps { if a.Slug == outApp.Slug { found = true - break + continue + } + + // The Fleet-maintained apps list combines apps by name, so names must be unique per platform. + // The table compares names with utf8mb4_unicode_ci, but EqualFold is close enough for this check. + if a.Platform == platform && strings.EqualFold(platformNameSuffix.ReplaceAllString(a.Name, ""), platformNameSuffix.ReplaceAllString(outApp.Name, "")) { + return ctxerr.New(ctx, fmt.Sprintf("%s uses the name %q, which %s already uses on the same platform", outApp.Slug, outApp.Name, a.Slug)) } } if !found { - platform := outApp.Platform() if platform == "" { return ctxerr.New(ctx, fmt.Sprintf("invalid platform found for slug %s", outApp.Slug)) } diff --git a/cmd/maintained-apps/main_test.go b/cmd/maintained-apps/main_test.go index 856d457ee69..e7c0ede8857 100644 --- a/cmd/maintained-apps/main_test.go +++ b/cmd/maintained-apps/main_test.go @@ -3,8 +3,13 @@ package main import ( "bytes" "encoding/json" + "os" + "path" "strings" "testing" + + maintained_apps "github.com/fleetdm/fleet/v4/ee/maintained-apps" + "github.com/stretchr/testify/require" ) func TestJSONEncoderPreservesHTML(t *testing.T) { @@ -45,3 +50,20 @@ func TestJSONEncoderPreservesHTML(t *testing.T) { t.Logf("Successfully preserved HTML in JSON output: %s", result) } + +func TestUpdateAppsListFileRejectsSameNameOnSamePlatform(t *testing.T) { + ctx := t.Context() + t.Chdir(t.TempDir()) + require.NoError(t, os.MkdirAll(maintained_apps.OutputPath, 0o755)) + + appsList := `{"version": 2, "apps": [{"name": "Docker Desktop", "slug": "docker-desktop/darwin", "platform": "darwin"}]}` + require.NoError(t, os.WriteFile(path.Join(maintained_apps.OutputPath, "apps.json"), []byte(appsList), 0o644)) + + // add a macOS app with the same name, the ingester should return an error + err := updateAppsListFile(ctx, &maintained_apps.FMAManifestApp{Name: "Docker Desktop", Slug: "docker/darwin"}) + require.ErrorContains(t, err, "docker-desktop/darwin already uses on the same platform") + + // add a Windows app with the same name, the ingester should add it + err = updateAppsListFile(ctx, &maintained_apps.FMAManifestApp{Name: "Docker Desktop", Slug: "docker/windows"}) + require.NoError(t, err) +} diff --git a/frontend/interfaces/software.ts b/frontend/interfaces/software.ts index e6b8c49474b..fb905d183e8 100644 --- a/frontend/interfaces/software.ts +++ b/frontend/interfaces/software.ts @@ -1495,7 +1495,7 @@ export interface IFleetMaintainedApp { name: string; version: string; platform: FleetMaintainedAppPlatform; - slug: string; // "/", e.g. "figma/darwin"; the token uniquely identifies an app across its platform entries + slug: string; // "/", e.g. "figma/darwin" software_title_id?: number; // null unless the team already has the software added (as a Fleet-maintained app, App Store (app), or custom package) } diff --git a/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tests.tsx b/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tests.tsx index 0f5150d4b05..dc250e1cb09 100644 --- a/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tests.tsx +++ b/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tests.tsx @@ -1,14 +1,6 @@ -import { - FleetMaintainedAppPlatform, - IFleetMaintainedApp, -} from "interfaces/software"; +import { IFleetMaintainedApp } from "interfaces/software"; -import fmaCatalog from "../../../../../../ee/maintained-apps/outputs/apps.json"; - -import { - combineAppsByPlatform, - WINDOWS_TO_MACOS_SLUGS, -} from "./FleetMaintainedAppsTable"; +import { combineAppsByPlatform } from "./FleetMaintainedAppsTable"; const app = (overrides: Partial): IFleetMaintainedApp => ({ id: 1, @@ -76,29 +68,6 @@ describe("combineAppsByPlatform", () => { expect(combined.displayName).toBe("WeChat"); }); - it("shows the macOS name regardless of order when names differ otherwise", () => { - const macos = app({ - id: 1, - name: "Foo", - slug: "foo/darwin", - platform: "darwin", - }); - const windows = app({ - id: 2, - name: "Foo Desktop", - slug: "foo/windows", - platform: "windows", - }); - - [ - [macos, windows], - [windows, macos], - ].forEach((entries) => { - const [combined] = combineAppsByPlatform(entries); - expect(combined.displayName).toBe("Foo"); - }); - }); - it("keeps the suffix in a single-platform app's name", () => { const [combined] = combineAppsByPlatform([ app({ @@ -112,26 +81,46 @@ describe("combineAppsByPlatform", () => { expect(combined.displayName).toBe("Google Credential Provider for Windows"); }); - it("keeps two distinct apps that share a display name as separate rows", () => { - // MacPaw Gemini and Google Gemini share the name "Gemini" but have - // different slug tokens, so they must not collapse into one row. + it("combines macOS and Windows entries whose names differ only by case into one row", () => { const combined = combineAppsByPlatform([ - app({ id: 1, name: "Gemini", slug: "gemini/darwin", platform: "darwin" }), + app({ + id: 1, + name: "Github Desktop", + slug: "github/darwin", + platform: "darwin", + }), app({ id: 2, - name: "Gemini", - slug: "google-gemini/darwin", + name: "GitHub Desktop", + slug: "github-desktop/windows", + platform: "windows", + }), + ]); + + expect(combined).toHaveLength(1); + expect(combined[0].displayName).toBe("Github Desktop"); + expect(combined[0].windows?.id).toBe(2); + }); + + it("shows Foo and Foo Desktop as separate rows when they share a slug token but not a name", () => { + const combined = combineAppsByPlatform([ + app({ + id: 1, + name: "Foo", + slug: "foo/darwin", platform: "darwin", }), + app({ + id: 2, + name: "Foo Desktop", + slug: "foo/windows", + platform: "windows", + }), ]); expect(combined).toHaveLength(2); - // Each row keeps its own macOS entry (neither Gemini is hidden/overwritten). - expect(combined.map((c) => c.macos?.id).sort()).toEqual([1, 2]); - expect(combined.map((c) => c.macos?.slug).sort()).toEqual([ - "gemini/darwin", - "google-gemini/darwin", - ]); + expect(combined[0].name).toBe("Foo"); + expect(combined[1].name).toBe("Foo Desktop"); }); it("combines Docker Desktop's macOS and Windows entries into one row when their slug tokens differ", () => { @@ -159,103 +148,4 @@ describe("combineAppsByPlatform", () => { expect(combined[0].windows?.slug).toBe("docker/windows"); }); }); - - it("reads apps.json and shows a macOS and a Windows Fleet-maintained app with the same name in one row", () => { - // convert every app in apps.json to the shape the list API returns - const catalogApps = fmaCatalog.apps.map((catalogApp, index) => - app({ - id: index, - name: catalogApp.name, - slug: catalogApp.slug, - platform: catalogApp.platform as FleetMaintainedAppPlatform, - }) - ); - - // build the table rows the same way the UI does, and record each row's slugs as - // " + ", for example "docker-desktop/darwin + docker/windows" - const combinedRowSlugs = new Set( - combineAppsByPlatform(catalogApps).map( - (row) => `${row.macos?.slug} + ${row.windows?.slug}` - ) - ); - - const errors: string[] = []; - - // group the apps by name, each name with one macOS and one Windows app should show as one row - // R and WeChat use a different name on each platform, they share a slug token so they're - // already combined and covered by the cases above - const appsByName: Record = {}; - catalogApps.forEach((catalogApp) => { - appsByName[catalogApp.name] = appsByName[catalogApp.name] ?? []; - appsByName[catalogApp.name].push(catalogApp); - }); - - Object.values(appsByName).forEach((appsWithSameName) => { - // skip names that only one app uses - if (appsWithSameName.length !== 2) { - return; - } - - // skip names that two apps on the same platform use - const macosApp = appsWithSameName.find( - (catalogApp) => catalogApp.platform === "darwin" - ); - const windowsApp = appsWithSameName.find( - (catalogApp) => catalogApp.platform === "windows" - ); - if (!macosApp || !windowsApp) { - return; - } - - // look up the macOS and Windows app pair in the table rows, a missing pair means the UI - // shows them as two separate rows - if (!combinedRowSlugs.has(`${macosApp.slug} + ${windowsApp.slug}`)) { - errors.push( - `The Fleet-maintained apps ${macosApp.slug} and ${windowsApp.slug} use the same name ` + - `'${macosApp.name}', but show as separate rows in the UI because their slugs are ` + - `different. Add ['${windowsApp.slug}', '${macosApp.slug}'] to WINDOWS_TO_MACOS_SLUGS in ` + - `FleetMaintainedAppsTable.tsx, or update this test if this message is incorrect.` - ); - } - }); - - expect(errors).toEqual([]); - }); - - it("reads apps.json and finds both slugs of every pair in WINDOWS_TO_MACOS_SLUGS in it with the same name", () => { - // look up each app's name by its slug, for example "docker/windows" -> "Docker Desktop" - const nameBySlug = new Map( - fmaCatalog.apps.map((catalogApp) => [catalogApp.slug, catalogApp.name]) - ); - - const errors: string[] = []; - - // check every pair in WINDOWS_TO_MACOS_SLUGS, both slugs should be in apps.json with the - // same name - WINDOWS_TO_MACOS_SLUGS.forEach((macosSlug, windowsSlug) => { - const windowsName = nameBySlug.get(windowsSlug); - const macosName = nameBySlug.get(macosSlug); - - // a missing name means the slug isn't in apps.json - if (windowsName === undefined || macosName === undefined) { - errors.push( - `WINDOWS_TO_MACOS_SLUGS in FleetMaintainedAppsTable.tsx combines ${windowsSlug} ` + - `with ${macosSlug}, but apps.json doesn't have both. Remove or update this entry, or ` + - `update this test if this message is incorrect.` - ); - return; - } - - if (windowsName !== macosName) { - errors.push( - `WINDOWS_TO_MACOS_SLUGS in FleetMaintainedAppsTable.tsx combines ${windowsSlug} ` + - `('${windowsName}') with ${macosSlug} ('${macosName}'), but their names are ` + - `different. Remove or update this entry, or update this test if this message is ` + - `incorrect.` - ); - } - }); - - expect(errors).toEqual([]); - }); }); diff --git a/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tsx b/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tsx index 99e3b61986e..58fa7327a3f 100644 --- a/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tsx +++ b/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareFleetMaintained/FleetMaintainedAppsTable/FleetMaintainedAppsTable.tsx @@ -42,75 +42,54 @@ const EmptyFleetAppsTable = () => ( ); /** Converts the FleetMaintainedApp API response, which has separate macOS and - * Windows entries, into a table-friendly format that combines an app's entries - * for different platforms into one row. Apps are keyed by their slug token (the - * prefix before "/"), not by name, so two distinct apps that share a display - * name stay as separate rows. */ + * Windows entries, into a table-friendly format that combines the entries that + * share a name, ignoring a platform suffix like " for macOS", into one row. */ const PLATFORM_NAME_SUFFIX = / for (macOS|Mac|Windows)$/; -// Windows slugs whose slug token differs from the macOS slug of the same app -export const WINDOWS_TO_MACOS_SLUGS = new Map([ - ["docker/windows", "docker-desktop/darwin"], - ["burp-suite-community/windows", "burp-suite/darwin"], - ["chrome-remote-desktop/windows", "chrome-remote-desktop-host/darwin"], - ["github-desktop/windows", "github/darwin"], - ["handbrake/windows", "handbrake-app/darwin"], - ["tableau-desktop/windows", "tableau/darwin"], - ["tailscale/windows", "tailscale-app/darwin"], - ["wireshark/windows", "wireshark-app/darwin"], - ["zen-browser/windows", "zen/darwin"], -]); - export const combineAppsByPlatform = ( fmaList: IFleetMaintainedApp[] ): ICombinedFMA[] => { - const combinedApps: { [appToken: string]: ICombinedFMA } = {}; - const platformNames: { [appToken: string]: Set } = {}; + const combinedApps: { [baseName: string]: ICombinedFMA } = {}; fmaList.forEach((app: IFleetMaintainedApp) => { const { name, platform, ...rest } = app; - const rowSlug = WINDOWS_TO_MACOS_SLUGS.get(app.slug) ?? app.slug; - const appToken = rowSlug.split("/")[0]; + // Compare without case, the way the server groups names + const baseName = name.replace(PLATFORM_NAME_SUFFIX, "").toLowerCase(); - if (!combinedApps[appToken]) { - combinedApps[appToken] = { + if (!combinedApps[baseName]) { + combinedApps[baseName] = { name, displayName: name, macos: null, windows: null, }; - platformNames[appToken] = new Set(); } - platformNames[appToken].add(name); if (platform === "darwin") { // The API orders entries by name in the requested direction, so take the // name from the macOS entry to keep it stable across sort directions. - combinedApps[appToken].name = name; - combinedApps[appToken].displayName = name; - combinedApps[appToken].macos = { + combinedApps[baseName].name = name; + combinedApps[baseName].displayName = name; + combinedApps[baseName].macos = { platform: platform as FleetMaintainedAppPlatform, ...rest, }; } else if (platform === "windows") { - combinedApps[appToken].windows = { + combinedApps[baseName].windows = { platform: platform as FleetMaintainedAppPlatform, ...rest, }; } }); - // Only strip the suffix when the platforms' names differ by it (e.g. "R for - // macOS" and "R for Windows"); a single-platform app's suffix is part of its - // name (e.g. "Google Credential Provider for Windows"). - Object.entries(combinedApps).forEach(([appToken, combinedApp]) => { - const names = platformNames[appToken]; - if (names.size < 2) return; - const baseNames = new Set( - [...names].map((n) => n.replace(PLATFORM_NAME_SUFFIX, "")) - ); - if (baseNames.size === 1) { - [combinedApp.displayName] = baseNames; + // Show the name without the platform suffix only on rows that combine both platforms, a + // single-platform app's suffix is part of its name ("Google Credential Provider for Windows") + Object.values(combinedApps).forEach((combinedApp) => { + if (combinedApp.macos && combinedApp.windows) { + combinedApp.displayName = combinedApp.name.replace( + PLATFORM_NAME_SUFFIX, + "" + ); } }); diff --git a/server/datastore/mysql/maintained_apps.go b/server/datastore/mysql/maintained_apps.go index e76932f692d..11f58726642 100644 --- a/server/datastore/mysql/maintained_apps.go +++ b/server/datastore/mysql/maintained_apps.go @@ -549,16 +549,11 @@ func (ds *Datastore) GetMaintainedAppBySlug(ctx context.Context, slug string, te func (ds *Datastore) ListAvailableFleetMaintainedApps(ctx context.Context, teamID *uint, opt fleet.MaintainedAppListOptions) ([]fleet.MaintainedApp, *fleet.PaginationMetadata, error) { dbReader := ds.reader(ctx) - // We paginate by distinct app token (the slug prefix, e.g. "figma" in - // "figma/darwin"), which identifies an app across its platform entries: the UI - // combines an app's macOS and Windows entries into one row, so an app must not - // be split across a page boundary. Keying on the token rather than the name - // keeps two distinct apps that share a name (e.g. gemini/darwin and - // google-gemini/darwin) as separate rows. The count, by contrast, is the - // number of installable platform entries: each is separately installable (its - // own Add button), so an app shipped on both platforms counts twice. The team - // join tells us whether each app is already added, for the "available only" - // filter. + // Paginate by app name without a platform suffix like " for macOS", and return every platform + // entry for the names on a page, so an app's macOS and Windows entries are never split across + // pages. The count is the number of installable platform entries, so an app shipped on both + // platforms counts twice. The team join tells us whether each app is already added, for the + // "available only" filter. fromClause := `FROM fleet_maintained_apps fma` var fromArgs []any if teamID != nil { @@ -570,23 +565,17 @@ func (ds *Datastore) ListAvailableFleetMaintainedApps(ctx context.Context, teamI where := ` WHERE TRUE` var whereArgs []any if match := opt.MatchQuery; match != "" { - // Match the name the UI shows: when an app's macOS and Windows entries - // differ only by a platform suffix ("R for macOS"/"R for Windows"), the - // row drops it, so search must ignore it too. A single-platform app keeps - // its suffix ("Google Credential Provider for Windows"). + // Merge names that end with the suffix for macOS/Mac/Windows so that they show up + // as the same app in the UI. fromClause += ` LEFT JOIN ( - SELECT names.merged_app_token, names.merged_name - FROM ( - SELECT SUBSTRING_INDEX(slug, '/', 1) AS merged_app_token, REGEXP_REPLACE(name, ' for (macOS|Mac|Windows)$', '') AS merged_name - FROM fleet_maintained_apps - ) names - GROUP BY names.merged_app_token, names.merged_name + SELECT REGEXP_REPLACE(name, ' for (macOS|Mac|Windows)$', '') AS merged_name + FROM fleet_maintained_apps + GROUP BY merged_name HAVING COUNT(*) > 1 - ) merged_names ON merged_names.merged_app_token = SUBSTRING_INDEX(fma.slug, '/', 1) - AND merged_names.merged_name = REGEXP_REPLACE(fma.name, ' for (macOS|Mac|Windows)$', '')` + ) merged_names ON merged_names.merged_name = REGEXP_REPLACE(fma.name, ' for (macOS|Mac|Windows)$', '')` - where += ` AND (CASE WHEN merged_names.merged_app_token IS NOT NULL THEN merged_names.merged_name ELSE fma.name END) LIKE ?` + where += ` AND COALESCE(merged_names.merged_name, fma.name) LIKE ?` whereArgs = append(whereArgs, likePattern(match)) } if opt.Platform == "darwin" || opt.Platform == "windows" { @@ -633,42 +622,40 @@ func (ds *Datastore) ListAvailableFleetMaintainedApps(ctx context.Context, teamI direction = "DESC" } - // Select the page of app tokens, fetching one extra to detect a next page. - // Group by the token and order by the app's name (the token maps to a single - // name), with the token as a deterministic tiebreaker for same-named apps. + // Select the page of app names, fetching one extra to detect a next page. perPage := opt.GetPerPage() - pageTokensStmt := fmt.Sprintf( - `SELECT SUBSTRING_INDEX(fma.slug, '/', 1) AS app_token %s%s GROUP BY app_token ORDER BY MIN(fma.name) %s, app_token %s LIMIT %d OFFSET %d`, - fromClause, where, direction, direction, perPage+1, perPage*opt.Page, + pageNamesStmt := fmt.Sprintf( + `SELECT REGEXP_REPLACE(fma.name, ' for (macOS|Mac|Windows)$', '') AS base_name %s%s GROUP BY base_name ORDER BY base_name %s LIMIT %d OFFSET %d`, + fromClause, where, direction, perPage+1, perPage*opt.Page, ) - pageTokensArgs := append(append([]any{}, fromArgs...), whereArgs...) - var pageTokens []string - if err := sqlx.SelectContext(ctx, dbReader, &pageTokens, pageTokensStmt, pageTokensArgs...); err != nil { - return nil, nil, ctxerr.Wrap(ctx, err, "selecting fleet maintained app page tokens") + pageNamesArgs := append(append([]any{}, fromArgs...), whereArgs...) + var pageNames []string + if err := sqlx.SelectContext(ctx, dbReader, &pageNames, pageNamesStmt, pageNamesArgs...); err != nil { + return nil, nil, ctxerr.Wrap(ctx, err, "selecting fleet maintained app page names") } meta := &fleet.PaginationMetadata{HasPreviousResults: opt.Page > 0, TotalResults: uint(filteredCount)} //nolint:gosec // dismiss G115 - if uint(len(pageTokens)) > perPage { //nolint:gosec // dismiss G115 + if uint(len(pageNames)) > perPage { //nolint:gosec // dismiss G115 meta.HasNextResults = true - pageTokens = pageTokens[:perPage] + pageNames = pageNames[:perPage] } - if len(pageTokens) == 0 { + if len(pageNames) == 0 { // Page is past the last result. return []fleet.MaintainedApp{}, meta, nil } - // Fetch every platform row for the apps on this page so the UI can combine + // Fetch every platform row for the names on this page so the UI can combine // an app's macOS and Windows entries into a single row. selectStmt := `SELECT fma.id, fma.name, fma.platform, fma.slug, ` var rowsArgs []any if teamID != nil { - selectStmt += teamFMATitlesJoin + ` WHERE SUBSTRING_INDEX(fma.slug, '/', 1) IN (?)` - rowsArgs = []any{teamID, teamID, teamID, pageTokens} + selectStmt += teamFMATitlesJoin + ` WHERE REGEXP_REPLACE(fma.name, ' for (macOS|Mac|Windows)$', '') IN (?)` + rowsArgs = []any{teamID, teamID, teamID, pageNames} } else { - selectStmt += `NULL software_title_id FROM fleet_maintained_apps fma WHERE SUBSTRING_INDEX(fma.slug, '/', 1) IN (?)` - rowsArgs = []any{pageTokens} + selectStmt += `NULL software_title_id FROM fleet_maintained_apps fma WHERE REGEXP_REPLACE(fma.name, ' for (macOS|Mac|Windows)$', '') IN (?)` + rowsArgs = []any{pageNames} } - selectStmt += fmt.Sprintf(` ORDER BY fma.name %s, fma.slug ASC`, direction) + selectStmt += fmt.Sprintf(` ORDER BY REGEXP_REPLACE(fma.name, ' for (macOS|Mac|Windows)$', '') %s, fma.name %s, fma.slug ASC`, direction, direction) selectStmt, rowsArgs, err := sqlx.In(selectStmt, rowsArgs...) if err != nil { diff --git a/server/datastore/mysql/maintained_apps_test.go b/server/datastore/mysql/maintained_apps_test.go index bdba1debb4d..e69a97b0ac2 100644 --- a/server/datastore/mysql/maintained_apps_test.go +++ b/server/datastore/mysql/maintained_apps_test.go @@ -746,7 +746,7 @@ func testListAvailableAppsWindows(t *testing.T, ds *Datastore) { } // testListAvailableAppsByNameAndFilters verifies that the list paginates by -// distinct app TOKEN (the slug prefix), so an app's macOS and Windows entries +// distinct app name, so an app's macOS and Windows entries // are combined into one row and never split across a page boundary, while the // count is the number of installable platform entries (each Add button counts // once), and that the platform and available-only filters work server-side. @@ -786,7 +786,7 @@ func testListAvailableAppsByNameAndFilters(t *testing.T, ds *Datastore) { } // Unfiltered: 6 installable platform entries (the count: alpha+delta each ship - // on two platforms) across 4 app tokens, 6 rows returned (the raw per-platform + // on two platforms) across 4 app names, 6 rows returned (the raw per-platform // entries the UI combines into 4 rows). apps, meta, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, listOpts(fleet.ListOptions{})) require.NoError(t, err) @@ -794,7 +794,7 @@ func testListAvailableAppsByNameAndFilters(t *testing.T, ds *Datastore) { require.Len(t, apps, 6) require.False(t, meta.HasNextResults) - // Pagination is by app token: a page of 2 apps that includes a dual-platform + // Pagination is by app name: a page of 2 apps that includes a dual-platform // app returns ALL of that app's rows, so an app is never split across a page // boundary. Page 0 => Alpha (darwin+windows) + Beta (darwin) = 3 rows. apps, meta, err = ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, listOpts(fleet.ListOptions{PerPage: 2})) @@ -861,8 +861,7 @@ func testListAvailableAppsByNameAndFilters(t *testing.T, ds *Datastore) { // testListAvailableAppsSharedName verifies that two distinct apps sharing a // display name (e.g. "Gemini": gemini/darwin and google-gemini/darwin) are -// counted and listed as two separate apps. Keying on the slug token keeps them -// distinct, so the count matches the row count and neither app is hidden. +// both counted and both returned. func testListAvailableAppsSharedName(t *testing.T, ds *Datastore) { ctx := context.Background() @@ -896,22 +895,39 @@ func testListAvailableAppsSharedName(t *testing.T, ds *Datastore) { assertTwoGeminis(fleet.MaintainedAppListOptions{ListOptions: fleet.ListOptions{IncludeMetadata: true}}) assertTwoGeminis(fleet.MaintainedAppListOptions{Platform: "darwin", ListOptions: fleet.ListOptions{IncludeMetadata: true}}) - // Paginating one app at a time yields each Gemini on its own page, never - // splitting or dropping one. + // list one app name per page, the first page should hold both Geminis because they share a name + assertTwoGeminis(fleet.MaintainedAppListOptions{ListOptions: fleet.ListOptions{PerPage: 1, IncludeMetadata: true}}) + + slugs := func(apps []fleet.MaintainedApp) []string { + out := make([]string, 0, len(apps)) + for _, app := range apps { + out = append(out, app.Slug) + } + return out + } + + // Docker Desktop and Zen Browser use a different slug token on each platform. + mkApp("Docker Desktop", "docker-desktop/darwin", "darwin", "com.electron.dockerdesktop") + mkApp("Docker Desktop", "docker/windows", "windows", "Docker Desktop") + mkApp("Zen Browser", "zen/darwin", "darwin", "app.zen-browser.zen") + mkApp("Zen Browser", "zen-browser/windows", "windows", "Zen Browser") + + // list one app name per page, the first page should hold both Docker Desktop entries page0, meta0, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{ListOptions: fleet.ListOptions{PerPage: 1, IncludeMetadata: true}}) require.NoError(t, err) - require.EqualValues(t, 2, meta0.TotalResults) - require.Len(t, page0, 1) require.True(t, meta0.HasNextResults) + require.ElementsMatch(t, []string{"docker-desktop/darwin", "docker/windows"}, slugs(page0)) + + // list the third page, after Docker Desktop and Gemini, it should hold both Zen Browser entries + page2, meta2, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{ListOptions: fleet.ListOptions{PerPage: 1, Page: 2, IncludeMetadata: true}}) + require.NoError(t, err) + require.False(t, meta2.HasNextResults) + require.ElementsMatch(t, []string{"zen/darwin", "zen-browser/windows"}, slugs(page2)) - page1, meta1, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{ListOptions: fleet.ListOptions{PerPage: 1, Page: 1, IncludeMetadata: true}}) + // list with the Windows platform filter, the page should still hold both Docker Desktop entries + windowsPage, _, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{Platform: "windows", ListOptions: fleet.ListOptions{PerPage: 1, IncludeMetadata: true}}) require.NoError(t, err) - require.EqualValues(t, 2, meta1.TotalResults) - require.Len(t, page1, 1) - require.False(t, meta1.HasNextResults) - require.True(t, meta1.HasPreviousResults) - // The two pages cover the two distinct apps. - require.NotEqual(t, page0[0].Slug, page1[0].Slug) + require.ElementsMatch(t, []string{"docker-desktop/darwin", "docker/windows"}, slugs(windowsPage)) } func testListAvailableAppsSearchIgnoresPlatformSuffix(t *testing.T, ds *Datastore) { From ea022375b40af85c94c015a878fd6ab4dfcebacd Mon Sep 17 00:00:00 2001 From: Jonathan Katz Date: Wed, 18 Nov 2026 17:09:04 -0500 Subject: [PATCH 2/3] Fix modernize lint in maintained apps test --- server/datastore/mysql/maintained_apps_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/datastore/mysql/maintained_apps_test.go b/server/datastore/mysql/maintained_apps_test.go index e69a97b0ac2..dc3905b833c 100644 --- a/server/datastore/mysql/maintained_apps_test.go +++ b/server/datastore/mysql/maintained_apps_test.go @@ -896,7 +896,7 @@ func testListAvailableAppsSharedName(t *testing.T, ds *Datastore) { assertTwoGeminis(fleet.MaintainedAppListOptions{Platform: "darwin", ListOptions: fleet.ListOptions{IncludeMetadata: true}}) // list one app name per page, the first page should hold both Geminis because they share a name - assertTwoGeminis(fleet.MaintainedAppListOptions{ListOptions: fleet.ListOptions{PerPage: 1, IncludeMetadata: true}}) + assertTwoGeminis(fleet.MaintainedAppListOptions{PerPage: 1, IncludeMetadata: true}) slugs := func(apps []fleet.MaintainedApp) []string { out := make([]string, 0, len(apps)) @@ -919,13 +919,13 @@ func testListAvailableAppsSharedName(t *testing.T, ds *Datastore) { require.ElementsMatch(t, []string{"docker-desktop/darwin", "docker/windows"}, slugs(page0)) // list the third page, after Docker Desktop and Gemini, it should hold both Zen Browser entries - page2, meta2, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{ListOptions: fleet.ListOptions{PerPage: 1, Page: 2, IncludeMetadata: true}}) + page2, meta2, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{PerPage: 1, Page: 2, IncludeMetadata: true}) require.NoError(t, err) require.False(t, meta2.HasNextResults) require.ElementsMatch(t, []string{"zen/darwin", "zen-browser/windows"}, slugs(page2)) // list with the Windows platform filter, the page should still hold both Docker Desktop entries - windowsPage, _, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{Platform: "windows", ListOptions: fleet.ListOptions{PerPage: 1, IncludeMetadata: true}}) + windowsPage, _, err := ds.ListAvailableFleetMaintainedApps(ctx, &team.ID, fleet.MaintainedAppListOptions{Platform: "windows", PerPage: 1, IncludeMetadata: true}) require.NoError(t, err) require.ElementsMatch(t, []string{"docker-desktop/darwin", "docker/windows"}, slugs(windowsPage)) } From 398124fe4c3bd174b773fbd5b0a52699a9da1431 Mon Sep 17 00:00:00 2001 From: Jonathan Katz Date: Thu, 19 Nov 2026 09:00:23 -0500 Subject: [PATCH 3/3] Only reject a duplicate FMA name when adding a new slug --- cmd/maintained-apps/main.go | 6 +++++- cmd/maintained-apps/main_test.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/maintained-apps/main.go b/cmd/maintained-apps/main.go index abacba18bef..9da03da0c0f 100644 --- a/cmd/maintained-apps/main.go +++ b/cmd/maintained-apps/main.go @@ -161,6 +161,7 @@ func updateAppsListFile(ctx context.Context, outApp *maintained_apps.FMAManifest platform := outApp.Platform() platformNameSuffix := regexp.MustCompile(` for (macOS|Mac|Windows)$`) var found bool + var existingSlugWithSameName string for _, a := range outputAppsFile.Apps { if a.Slug == outApp.Slug { found = true @@ -170,7 +171,7 @@ func updateAppsListFile(ctx context.Context, outApp *maintained_apps.FMAManifest // The Fleet-maintained apps list combines apps by name, so names must be unique per platform. // The table compares names with utf8mb4_unicode_ci, but EqualFold is close enough for this check. if a.Platform == platform && strings.EqualFold(platformNameSuffix.ReplaceAllString(a.Name, ""), platformNameSuffix.ReplaceAllString(outApp.Name, "")) { - return ctxerr.New(ctx, fmt.Sprintf("%s uses the name %q, which %s already uses on the same platform", outApp.Slug, outApp.Name, a.Slug)) + existingSlugWithSameName = a.Slug } } @@ -178,6 +179,9 @@ func updateAppsListFile(ctx context.Context, outApp *maintained_apps.FMAManifest if platform == "" { return ctxerr.New(ctx, fmt.Sprintf("invalid platform found for slug %s", outApp.Slug)) } + if existingSlugWithSameName != "" { + return ctxerr.New(ctx, fmt.Sprintf("%s uses the name %q, which %s already uses on the same platform", outApp.Slug, outApp.Name, existingSlugWithSameName)) + } outputAppsFile.Apps = append(outputAppsFile.Apps, maintained_apps.FMAListFileApp{ Name: outApp.Name, diff --git a/cmd/maintained-apps/main_test.go b/cmd/maintained-apps/main_test.go index e7c0ede8857..63665825e8c 100644 --- a/cmd/maintained-apps/main_test.go +++ b/cmd/maintained-apps/main_test.go @@ -56,7 +56,7 @@ func TestUpdateAppsListFileRejectsSameNameOnSamePlatform(t *testing.T) { t.Chdir(t.TempDir()) require.NoError(t, os.MkdirAll(maintained_apps.OutputPath, 0o755)) - appsList := `{"version": 2, "apps": [{"name": "Docker Desktop", "slug": "docker-desktop/darwin", "platform": "darwin"}]}` + appsList := `{"version": 2, "apps": [{"name": "Docker Desktop", "slug": "docker-desktop/darwin", "platform": "darwin"}, {"name": "Zen Browser", "slug": "zen/darwin", "platform": "darwin"}]}` require.NoError(t, os.WriteFile(path.Join(maintained_apps.OutputPath, "apps.json"), []byte(appsList), 0o644)) // add a macOS app with the same name, the ingester should return an error @@ -66,4 +66,9 @@ func TestUpdateAppsListFileRejectsSameNameOnSamePlatform(t *testing.T) { // add a Windows app with the same name, the ingester should add it err = updateAppsListFile(ctx, &maintained_apps.FMAManifestApp{Name: "Docker Desktop", Slug: "docker/windows"}) require.NoError(t, err) + + // refresh an existing macOS app whose incoming name matches another app, the ingester should + // not return an error because the name of an existing app isn't updated + err = updateAppsListFile(ctx, &maintained_apps.FMAManifestApp{Name: "Docker Desktop", Slug: "zen/darwin"}) + require.NoError(t, err) }