Skip to content

Update RealmPaths#inRealm to handle both formats#4628

Merged
backspace merged 7 commits intomainfrom
@cardstack/base-realm-membership-cs-10982
May 7, 2026
Merged

Update RealmPaths#inRealm to handle both formats#4628
backspace merged 7 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.

inRealm resolves both sides to the same form comparisons work.

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      1 suites   1h 59m 26s ⏱️
2 634 tests 2 619 ✅ 15 💤 0 ❌
2 653 runs  2 638 ✅ 15 💤 0 ❌

Results for commit 9f7be00.

Realm Server Test Results

    1 files      1 suites   17m 55s ⏱️
1 262 tests 1 262 ✅ 0 💤 0 ❌
1 340 runs  1 340 ✅ 0 💤 0 ❌

Results for commit 9f7be00.

@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>
@backspace backspace requested a review from a team May 5, 2026 16:33
Comment thread packages/host/app/services/realm.ts Outdated
Comment thread packages/host/app/services/realm.ts Outdated
backspace added 4 commits May 5, 2026 18:31
Per review: use the existing branded types in the helper signature
so intent is documented through the type system. Callers cast their
unbranded strings via `ri()` / `rri()` for now; tightening the source
types of `availableRealmURLs`, `Workspace.args.realmURL`, and
`CardDef.id` is tracked separately.
Per review: extend `inRealm` to accept `RealmResourceIdentifier | URL`
and normalize both sides to URL form internally when the same-form
`startsWith` fails. The recurring `inRealm(rri(<URL>.href))` and
`inRealm(rri(cardIdToURL(...).href))` idioms collapse to passing the
URL or branded RRI directly.

This also makes `RealmService.contains` redundant — drop it; callers
construct `new RealmPaths(realm).inRealm(resource)` directly (and can
hoist the `RealmPaths` out of inner loops).

Sweeps 17 call sites across runtime-common, host, and realm-server.
…-membership-cs-10982

# Conflicts:
#	packages/runtime-common/realm-index-query-engine.ts
@backspace backspace changed the title Add RealmService.contains for cross-form membership checks Update RealmPaths#inRealm to handle RRIs May 7, 2026
@backspace backspace changed the title Update RealmPaths#inRealm to handle RRIs Update RealmPaths#inRealm to handle both formats May 7, 2026
@backspace backspace merged commit 4820d18 into main May 7, 2026
72 of 74 checks passed
lukemelia added a commit that referenced this pull request May 7, 2026
…fter-4628

runtime-common: prettier --fix follow-up to #4628
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.

3 participants