Commit Graph

73685 Commits

Author SHA1 Message Date
Fredrik Adelöw 1399e136d7 Merge pull request #34073 from backstage/renovate/actions-cache-digest
chore(deps): update actions/cache digest to 27d5ce7
2026-05-13 13:18:37 +02:00
Fredrik Adelöw 9ed2f68261 Merge pull request #34163 from backstage/dependabot/npm_and_yarn/fast-uri-3.1.2
chore(deps): Bump fast-uri from 3.0.1 to 3.1.2
2026-05-13 13:15:07 +02:00
Fredrik Adelöw b6e1ecf158 Merge pull request #34166 from backstage/renovate/actions-upload-artifact-7.x
chore(deps): update actions/upload-artifact action to v7.0.1
2026-05-13 13:14:32 +02:00
Fredrik Adelöw 985fa2d8c8 Merge pull request #34212 from backstage/freben/fix-catalog-entity-page-test-flake
fix(catalog): increase test timeout and fix waitFor antipattern
2026-05-13 12:33:06 +02:00
Fredrik Adelöw 6fd90ee0a7 fix: address review feedback
- Await both tabs before asserting order in tab ordering tests
- Use findByText for icon assertions in context menu tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
2026-05-13 12:00:48 +02:00
Fredrik Adelöw 4eb547fa12 fix: move jest.setTimeout below imports
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
2026-05-13 11:48:17 +02:00
Fredrik Adelöw e481250793 fix(catalog): increase test timeout and replace waitFor antipattern in entity page tests
The entity page tests render the full extension tester + entity layout
component tree, which involves multiple React.lazy boundaries,
useAsyncRetry for entity fetching, and Material-UI CSS-in-JS processing
in jsdom. This makes each test inherently slow (~300-600ms) due to
jsdom's CSS engine processing MUI stylesheets during React render
cycles. Under CI load, the default 5s Jest timeout can be exceeded.

- Add jest.setTimeout(30_000) to prevent CI timeouts
- Replace waitFor(expect(getByRole(...))) antipattern with
  await expect(findByRole(...)).resolves pattern throughout

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
2026-05-13 11:39:35 +02:00
backstage-goalie[bot] f52cbd9a89 Merge pull request #34208 from backstage/renovate/estree-1.x-lockfile
chore(deps): update dependency @types/estree to v1.0.9
2026-05-13 07:17:19 +00:00
renovate[bot] 50879e3e8e chore(deps): update dependency @types/estree to v1.0.9
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-13 06:03:44 +00:00
backstage-goalie[bot] b8183f2f98 Merge pull request #34207 from backstage/renovate/stoplight-spectral-runtime-1.x-lockfile
chore(deps): update dependency @stoplight/spectral-runtime to v1.1.5
2026-05-13 05:57:54 +00:00
renovate[bot] 9b12ba8b41 chore(deps): update dependency @stoplight/spectral-runtime to v1.1.5
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-13 04:44:39 +00:00
backstage-goalie[bot] 9e10997c4c Merge pull request #34206 from backstage/renovate/stoplight-spectral-rulesets-1.x-lockfile
chore(deps): update dependency @stoplight/spectral-rulesets to v1.22.1
2026-05-13 04:39:32 +00:00
dependabot[bot] 75e0a10c3b chore(deps): Bump fast-uri from 3.0.1 to 3.1.2
Bumps [fast-uri](https://github.com/fastify/fast-uri) from 3.0.1 to 3.1.2.
- [Release notes](https://github.com/fastify/fast-uri/releases)
- [Commits](https://github.com/fastify/fast-uri/compare/v3.0.1...v3.1.2)

---
updated-dependencies:
- dependency-name: fast-uri
  dependency-version: 3.1.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-13 03:26:11 +00:00
renovate[bot] 2fb5ae4c69 chore(deps): update dependency @stoplight/spectral-rulesets to v1.22.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-13 03:25:41 +00:00
backstage-goalie[bot] d0df1b372a Merge pull request #34205 from backstage/renovate/stoplight-spectral-functions-1.x-lockfile
chore(deps): update dependency @stoplight/spectral-functions to v1.10.2
2026-05-13 03:20:47 +00:00
renovate[bot] 876cabf31d chore(deps): update dependency @stoplight/spectral-functions to v1.10.2
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-13 02:09:29 +00:00
backstage-goalie[bot] 2974681fa8 Merge pull request #34204 from backstage/renovate/stoplight-spectral-formatters-1.x-lockfile
chore(deps): update dependency @stoplight/spectral-formatters to v1.5.1
2026-05-13 02:02:41 +00:00
renovate[bot] 6cb7d2b12e chore(deps): update dependency @stoplight/spectral-formatters to v1.5.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-13 01:19:50 +00:00
backstage-goalie[bot] ea223011c8 Merge pull request #34192 from backstage/renovate/slack-web-api-7.x-lockfile
chore(deps): update dependency @slack/web-api to v7.15.2
2026-05-13 01:15:20 +00:00
Fredrik Adelöw fcdf63f54b Merge pull request #34201 from backstage/freben/harden-bot-changeset-workflows
ci: add explicit permissions to pull_request_target workflows
2026-05-12 23:38:59 +02:00
Fredrik Adelöw f5709382c9 Merge pull request #34140 from backstage/changeset-release/master
Version Packages (next)
2026-05-12 21:52:16 +02:00
github-actions[bot] 42a2f56e61 Version Packages (next) 2026-05-12 18:28:01 +00:00
Fredrik Adelöw add5d1ace7 catalog-backend: drive paginated entity ordering from search-by-key (#34162)
* draft: restructure entities() ordering to drive from search-by-key

When a sort field is specified, build the query so the search table
filtered by that key is the driving relation, instead of left-joining
search onto final_entities and sorting after. The planner can then walk
the (key, value, entity_id) index in already-sorted order and short
circuit on LIMIT.

Measured against a production replica, the catalog UI's default
"first page of components ordered by metadata.name" query goes from
~940 ms to ~8 ms. See PR description for the full numbers.

Known caveats this draft does not yet address:
- Entities lacking the order field are excluded; the previous shape
  put them at the end with NULLS LAST. A UNION ALL pattern can
  preserve the old semantics.
- Multi-field order falls back to the OLD shape (only the first field
  is taken when present today; subsequent fields acted as
  tie-breakers). Restoring tie-breakers needs additional joins or a
  CTE.
- queryEntities (/entities/by-query) is left untouched; the same
  optimization applies but the CTE/cursor structure makes the rewrite
  more involved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>

* two-phase entities() ordering: fast path + NULLs-last fallback

When an order field is specified, run a fast path first that drives
from the search-by-key index (excluding entities without the field).
If that path doesn't produce enough rows to cover offset+limit+1, run
a fallback that picks up the no-field entities in entity_id order.
This preserves NULLs-LAST semantics while keeping the fast plan for
the common case where every entity has the order field.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>

* fix: multi-field order fallback + MySQL quoting in entities()

Fall back to the original LEFT JOIN shape when multiple order fields
are specified, since tie-breaking on secondary fields inherently
requires materialization. The fast INNER-JOIN-driven path is used only
for single-field order (the typical UI case).

Fix the phase 2 NOT EXISTS clause to use knex's ?? identifier escaping
instead of hardcoded double-quotes, which broke on MySQL.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>

* catalog-backend: fix phase 2 ordering and update changeset

Fix two issues raised in review:

- Phase 2 (entities lacking the sort field) now always sorts by
  entity_id ASC regardless of the primary sort direction, matching the
  original NULLS-LAST behaviour where the NULL group was always
  entity_id ASC.

- Update changeset to describe the actual two-phase behaviour (NULLS
  LAST preserved) instead of the stale description that said entities
  without the field are excluded.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

* catalog-backend: apply offset when limit is undefined in runOrderedEntitiesQuery

Previously the fast-path returned the full combined array when no limit
was specified, silently ignoring any pagination offset. The old
implementation always pushed offset to SQL independently of limit.
Restore parity by slicing the combined array by the offset even when
limit is absent.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

* catalog-backend: add pagination and phase-boundary tests for entities() ordering

Add two new test cases that cover the parts of runOrderedEntitiesQuery not
exercised before:

- "paginates correctly through single-field ordering": exercises limit, offset,
  and hasNextPage through the fast path (Phase 1 only) across all DB engines.

- "paginates across the Phase 1 / Phase 2 boundary": exercises the case where
  the requested page straddles entities that have the sort field (Phase 1) and
  those that do not (Phase 2), and verifies that Phase 2 entities are always
  ordered ASC by entity_id regardless of the primary sort direction.

Also fixes a double-space caught by prettier in DefaultEntitiesCatalog.ts.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

* catalog-backend: treat null sort-field value the same as a missing sort field

buildEntitySearch stores value=NULL for entity fields that are explicitly
null or exceed MAX_VALUE_LENGTH. Previously, Phase 1 included those rows via
the INNER JOIN (key matches, value IS NULL), causing them to sort ahead of
entities that have no row for the key at all — changing semantics vs the old
LEFT JOIN shape where both cases landed in the same NULLS-LAST bucket.

Fix Phase 1 to require order_0.value IS NOT NULL, and fix Phase 2's NOT EXISTS
to check for no non-null value (value IS NOT NULL) so that both null-valued
and missing-key entities are collected in Phase 2 and ordered together by
entity_id ASC.

Adds a regression test covering an entity with spec.b=null alongside one with
no spec.b, asserting both appear after sorted entities regardless of direction.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-12 20:20:14 +02:00
Fredrik Adelöw 17c0551651 ci: add explicit permissions to pull_request_target workflows
Add least-privilege permissions blocks to three workflows that use
pull_request_target without explicit permission scoping:

- sync_renovate-changesets: contents:write + pull-requests:write
- sync_dependabot-changesets: contents:write + pull-requests:write
- sync_pull-requests-trigger: all none (only uploads artifacts)

These workflows run in the base repo context and have access to secrets.
Explicit permissions ensure the GITHUB_TOKEN is scoped to only what each
workflow needs, reducing blast radius if a guard is ever bypassed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
2026-05-12 19:59:05 +02:00
Fredrik Adelöw ab690eea30 Merge pull request #34190 from backstage/freben/facets-count-optimization
fix(catalog-backend): simplify facets COUNT(DISTINCT) to COUNT(*)
2026-05-12 15:32:08 +02:00
Fredrik Adelöw bbd16c6f39 Merge pull request #34175 from backstage/freben/query-entities-inner-join
catalog-backend: drive queryEntities ordering from search-by-key
2026-05-12 15:28:50 +02:00
Fredrik Adelöw b61936fc62 fix(catalog-backend): add orderBy to facets query and clean up tests
Add ORDER BY to guarantee stable result ordering across all database
backends (MySQL does not sort without it). Also consolidate double
catalog.facets() calls in tests into a single call with both content
and length assertions on the same result.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-12 15:18:10 +02:00
Fredrik Adelöw c2de113030 draft(catalog-backend): drive queryEntities ordering from search-by-key
Replace the LEFT OUTER JOIN + DISTINCT in the queryEntities CTE with
an INNER JOIN that drives from the search table for the sort field's
key. Entities lacking the sort field are excluded from both the result
and the count, aligning totalItems with navigable entities.

Removes DISTINCT (prerequisite: search table dedup migration).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
2026-05-12 14:35:36 +02:00
Fredrik Adelöw af1c16db10 fix(catalog-backend): make facets predicate tests order-independent
GROUP BY result ordering is non-deterministic across database engines.
The switch from COUNT(DISTINCT entity_id) to COUNT(*) changes MySQL's
aggregation plan, which surfaces a different row order. Use
arrayContaining + length check instead of exact array equality.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
2026-05-12 14:29:01 +02:00
Fredrik Adelöw 387ea7dd75 fix(catalog-backend): simplify facets COUNT(DISTINCT) to COUNT(*)
The UNIQUE constraint on (entity_id, key, value) from the search
indices migration guarantees each entity appears at most once per
(key, original_value) group, making DISTINCT unnecessary. Removing
it lets the database use a simpler aggregation plan.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
2026-05-12 14:29:01 +02:00
Fredrik Adelöw 3be2ee90b6 Merge pull request #34177 from backstage/freben/search-indices-migration
feat(catalog-backend): search table dedup, covering indices, and UNIQUE constraint
2026-05-12 14:19:53 +02:00
Ben Lambert cde3643387 fix(catalog-backend): add missing description to unregister-entity MCP action parameter (#34196)
Signed-off-by: benjdlambert <ben@blam.sh>
2026-05-12 13:34:27 +02:00
Ben Lambert d09c21cb84 feat(scaffolder): config-driven template groups and swappable TemplateCard (#34147)
* feat(scaffolder): config-driven template groups and swappable TemplateCard

Signed-off-by: benjdlambert <ben@blam.sh>

* refactor(scaffolder): keep createGroupsWithOther internal

Signed-off-by: benjdlambert <ben@blam.sh>

* docs(scaffolder): fix sub-page extension ID in changeset

Signed-off-by: benjdlambert <ben@blam.sh>

* address PR review feedback

Signed-off-by: benjdlambert <ben@blam.sh>

* split TemplateCard swappable contract from legacy props

Signed-off-by: benjdlambert <ben@blam.sh>

* address review feedback: dedupe tags, defensive groups copy, doc clarifications

Signed-off-by: benjdlambert <ben@blam.sh>

* regenerate api reports

Signed-off-by: benjdlambert <ben@blam.sh>

* align docs and changeset with actual default group titles

Signed-off-by: benjdlambert <ben@blam.sh>

* regen api reports after rebase

Signed-off-by: benjdlambert <ben@blam.sh>

---------

Signed-off-by: benjdlambert <ben@blam.sh>
2026-05-12 12:29:44 +02:00
renovate[bot] 9ff4098ea2 chore(deps): update dependency @slack/web-api to v7.15.2
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-12 10:27:36 +00:00
renovate[bot] b4d844d304 chore(deps): update actions/upload-artifact action to v7.0.1
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-12 10:26:25 +00:00
renovate[bot] 9b22d8dbf1 chore(deps): update actions/cache digest to 27d5ce7
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-12 10:25:52 +00:00
Fredrik Adelöw 92dfe61e79 Merge pull request #34087 from backstage/otel/tracing-service
feat: `TracingService` to match `MetricService`
2026-05-12 12:15:30 +02:00
Erik Hughes d726bcd842 feat(ui): add DatePicker component (#34184)
* feat(ui): add DatePicker component

Add a single-date picker built on React Aria's DatePicker, mirroring the
existing DateRangePicker implementation. Includes the date field with
segmented input, calendar popover, BUI design tokens, bg consumer
pattern, and full keyboard/screen reader accessibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Erik Hughes <erikh@spotify.com>

* fix(ui): address DatePicker PR feedback

- Remove unused dataAttributes spread from DatePickerGroup
- Mark DatePickerGroupDefinition and DatePickerCalendarDefinition as
  public so CSS class name changes appear in API reports
- Add Affected components line to changeset

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Erik Hughes <erikh@spotify.com>

* fix(ui): restore dataAttributes spread in DatePickerGroup

The bg: 'consumer' config on DatePickerGroupDefinition emits
data-on-bg attributes via useDefinition. Without spreading
dataAttributes onto <Group>, the CSS [data-on-bg] selectors
never match and background auto-increment doesn't work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Erik Hughes <erikh@spotify.com>

---------

Signed-off-by: Erik Hughes <erikh@spotify.com>
Co-authored-by: Erik Hughes <erikh@spotify.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-12 10:46:46 +02:00
Ben Lambert dbeb7aab3e feat(scaffolder): add BUI theme for scaffolder forms (#33053)
* feat(scaffolder): add BUI theme for scaffolder forms

Add a Backstage UI (BUI) form theme as an alternative to the Material
UI theme. Toggled via formProps.theme or enableBackstageUi page config.

Includes BUI widgets, templates, field extension variants, and a ported
React Aria Autocomplete component.

Signed-off-by: benjdlambert <ben@blam.sh>

* refactor(scaffolder): use BUI Combobox and CheckboxGroup for form widgets

Signed-off-by: benjdlambert <ben@blam.sh>

* chore(scaffolder): enable BUI form flag and add kitchen sink demo template

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(scaffolder): use outlined input style for BUI form widgets

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(scaffolder): address BUI form PR feedback

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(scaffolder): format CSS and regen API reports

Signed-off-by: benjdlambert <ben@blam.sh>

---------

Signed-off-by: benjdlambert <ben@blam.sh>
2026-05-12 10:35:21 +02:00
Ben Lambert 728629cf64 fix(catalog): show not-found instead of falling back to first route on unknown entity sub-paths (#34081)
* fix(catalog): show not-found instead of falling back to first route on unknown entity sub-paths

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(catalog): address PR review feedback

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(core-compat-api): update entity page conversion test for new not-found behavior

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(catalog): use NotFoundErrorPage and drop redundant route sort

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(catalog): split slash trimming into two replacements for clarity

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(catalog): comment normalizeRoutePath regex and memoize routes

Signed-off-by: benjdlambert <ben@blam.sh>

* fix(catalog): preserve explicit trailing wildcards in route paths

Signed-off-by: benjdlambert <ben@blam.sh>

---------

Signed-off-by: benjdlambert <ben@blam.sh>
2026-05-12 09:57:28 +02:00
Fredrik Adelöw 0305dc2c1e fix(catalog-backend): use shared NULL_SENTINEL constant in dedup keys
Move NULL_SENTINEL to util.ts and import it in buildEntitySearch and
syncSearchRows instead of hardcoding '\x01'. Keeps the dedup keys
consistent with filterSentinelValues and the SQL COALESCE(…, chr(1))
logic, avoiding drift if the sentinel ever changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
2026-05-12 09:19:23 +02:00
Fredrik Adelöw 50b5cbd226 catalog-backend: remove redundant direct-duplicate-insert test
The 'silently rejects a direct duplicate insert' test inserted a row
via raw Knex onConflict().ignore(), which has no corresponding
production code path (syncSearchRows uses ON CONFLICT DO UPDATE, not
DO NOTHING). The idempotency behaviour it was intended to verify is
already covered by 'leaves unchanged rows untouched'.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 20:20:09 +02:00
Fredrik Adelöw cdf38bd8db catalog-backend: fix syncSearchRows test to use real call path
Replace the raw Knex onConflict().merge() insert in the
'overwrites original_value on conflict' test with a direct UPDATE to
corrupt the stored original_value, followed by a second syncSearchRows
call. This tests the actual application code path (ON CONFLICT DO UPDATE
inside syncSearchRows) rather than embedding the conflict logic in the
test itself.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 20:05:47 +02:00
Fredrik Adelöw befdb6b31e catalog-backend: add migration test for search_indices_and_dedup
Tests two scenarios across all supported databases:

  Preconditions NOT met (dedup runs): inserts five rows with two
  duplicate (entity_id, key, value) pairs (one with null value),
  runs the migration, and verifies that duplicates are removed, null
  values are handled correctly, and the unique constraint is enforced
  post-migration. The down migration is verified to drop the constraint
  so duplicates can be inserted again.

  Preconditions met (PostgreSQL only, dedup skipped): pre-creates the
  unique index to simulate a user who ran the manual SQL before
  deploying, re-runs the migration, and verifies the row count is
  unchanged — confirming the fast path fires correctly.

  Non-PostgreSQL databases skip the fast-path test with an early return
  since the pg_index check is PostgreSQL-specific.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 18:50:49 +02:00
Fredrik Adelöw 9fa8b118c2 catalog-backend: fix syncSearchRows test to expect first-wins semantics
Update the 'keeps one row when original_value casing differs' test to
expect original_value: 'V' (first occurrence) instead of 'v' (last
occurrence), matching the first-wins dedup semantics that were aligned
with buildEntitySearch in a prior commit.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 18:42:24 +02:00
Fredrik Adelöw 62c67c752b catalog-backend: create covering index before dedup for vanilla installs
The index-only GROUP BY scan in Phase 1 of the dedup requires
search_key_value_entity_idx (key, value, entity_id) to exist.
Previously it was created after dedup, meaning fresh installs that
had never manually run preparatory SQL would fall back to a full
sequential scan.

Move the ensurePgIndex call for search_key_value_entity_idx to before
the dedup step so the fast path is guaranteed for all users, not just
those who created the index manually in advance.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 18:41:01 +02:00
Fredrik Adelöw fbae43b4d0 catalog-backend: use index-only GROUP BY + LATERAL for dedup
Replace the window-function full-table scan with a two-phase approach
that leverages search_key_value_entity_idx (key, value, entity_id):

  Phase 1: GROUP BY entity_id, key, value with HAVING COUNT(*) > 1
           resolves as a pure index-only scan (Heap Fetches: 0).
           Stores only the duplicate groups in a temp table (~8s for
           a 14M-row table with 700k dupes).

  Phase 2: CROSS JOIN LATERAL back into search using the same covering
           index (Nested Loop + Index Scan). row_number() runs per-group
           over the 2-3 matching rows, so there is no global external
           sort. A single DELETE removes all extras in one statement
           (~16s).

NULL values get a separate UNION ALL arm so the index equality
condition stays usable (value = NULL is always false in SQL).

Benchmarked on a 14.4M-row production-like staging master with
700k injected duplicates, post-VACUUM:
  Old (seq scan + external merge sort): ~101s
  New (index-only + index scan):         ~25s  (~4× faster)

Clean second run (no dupes, fast path skips dedup): <50ms.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 18:27:11 +02:00
Fredrik Adelöw c7706249ba fix(catalog-backend): use explicit null sentinel in dedup keys and add buildEntitySearch dedup tests
Use `=== null ? '\x01' : value` instead of `?? ''` in both buildEntitySearch
and syncSearchRows dedup maps, so that null and empty-string values are
treated as distinct keys. In theory an entity could produce both value=null
and value='' for the same key (e.g. spec.foo: [null, '']), and the old
encoding would silently drop one of the two distinct rows.

Also adds two focused unit tests to buildEntitySearch.test.ts: one covering
deduplication of duplicate array values (e.g. tags: ['java', 'java', 'Java']),
and one confirming that null and empty-string are kept as separate rows.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 17:07:49 +02:00
Fredrik Adelöw 36514a23d6 fix(catalog-backend): use two-phase dedup in search migration to avoid full-table re-scans
The original single-pass CTE window-function DELETE re-scanned every row
on each invocation — including the idempotent "nothing to do" case which
took over 4 minutes on a 14 M-row table, and timed out the DB proxy on
the dirty case (~217 s for 722 k duplicates).

Replace it with two improvements:

1. Fast path: if the UNIQUE index already exists and is valid, skip dedup
   entirely. A valid unique index is a proof-of-no-duplicates. This makes
   migration startup essentially free for installations that prepare the
   index manually beforehand (as documented in the migration comment).

2. Two-phase dedup when dedup is needed: Phase 1 does one full-table scan
   to collect all duplicate ctids into a temp table (~60 s on 14 M rows).
   Phase 2 drains that temp table in 10 k-row batches via cheap ctid
   lookups with no further full-table scans (~5 s for 722 k rows). Total
   ~65 s dirty vs >217 s+ before, and ~35 ms clean vs 4+ minutes before.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 16:52:44 +02:00
Fredrik Adelöw cbac98d9e7 Merge pull request #34182 from backstage/cursor/14538ae4
pin jest to ~30.2.0 to avoid Node 24.9+ requirement
2026-05-11 15:46:16 +02:00