Skip to content

Add RealmService.contains for cross-form membership checks#4628

Open
backspace wants to merge 3 commits intomainfrom
@cardstack/base-realm-membership-cs-10982
Open

Add RealmService.contains for cross-form membership checks#4628
backspace wants to merge 3 commits intomainfrom
@cardstack/base-realm-membership-cs-10982

Conversation

@backspace
Copy link
Copy Markdown
Contributor

@backspace backspace commented May 1, 2026

This was split off #4539, although it’s so small it could have been included!

Substring-prefix checks like card.id.startsWith(realm) only work when both sides are in the same form (URL vs registered prefix). After RRI migration, IDs may be prefix-form while realm URLs are URL-form (or vice versa), silently breaking those checks.

contains resolves both sides to URL form via cardIdToURL before delegating to RealmPaths.inRealm, so cross-form comparisons work as long as the prefix is registered.

Sweeps the two known callers in search.ts and workspace.gts.

Substring-prefix checks like `card.id.startsWith(realm)` only work
when both sides are in the same form (URL vs registered prefix).
After RRI migration, IDs may be prefix-form while realm URLs are
URL-form (or vice versa), silently breaking those checks.

`contains` resolves both sides to URL form via `cardIdToURL` before
delegating to `RealmPaths.inRealm`, so cross-form comparisons work
as long as the prefix is registered.

Sweeps the two known callers in `search.ts` and `workspace.gts`.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Preview deployments

Host Test Results

    1 files  ±  0      1 suites  ±0   2h 0m 14s ⏱️ + 13m 18s
2 562 tests +145  2 547 ✅ +150  15 💤 +1  0 ❌ ±0 
2 581 runs  +146  2 566 ✅ +157  15 💤 +1  0 ❌  - 6 

Results for commit 558a060. ± Comparison against earlier commit 9a39a4a.

Realm Server Test Results

    1 files  ±  0      1 suites  ±0   17m 16s ⏱️ + 8m 27s
1 212 tests +211  1 212 ✅ +211  0 💤 ±0  0 ❌ ±0 
1 284 runs  +241  1 284 ✅ +241  0 💤 ±0  0 ❌ ±0 

Results for commit 558a060. ± Comparison against earlier commit 9a39a4a.

@backspace backspace marked this pull request as ready for review May 1, 2026 23:17
@habdelra habdelra requested a review from Copilot May 4, 2026 15:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a reliable realm-membership helper on the Host-side RealmService to avoid incorrect startsWith() realm checks when identifiers may be in mixed forms (URL-form vs registered-prefix form) after the RRI migration.

Changes:

  • Added RealmService.contains(realm, resource) that normalizes both inputs to URL-form via cardIdToURL() and then uses RealmPaths.inRealm().
  • Updated SearchResource.instancesByRealm to use realm.contains() instead of card.id.startsWith(realm).
  • Updated workspace deletion “active workspace” detection to use realm.contains() for open card IDs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/host/app/services/realm.ts Adds RealmService.contains() for cross-form realm membership checks (URL/prefix).
packages/host/app/resources/search.ts Switches realm grouping logic to use realm.contains() instead of string prefix checks.
packages/host/app/components/operator-mode/workspace-chooser/workspace.gts Uses realm.contains() when checking if any open card belongs to the workspace realm.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/host/app/services/realm.ts Outdated
backspace and others added 2 commits May 4, 2026 09:09
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants