Update RealmPaths#inRealm to handle both formats#4628
Merged
Conversation
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`.
Contributor
Contributor
There was a problem hiding this comment.
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 viacardIdToURL()and then usesRealmPaths.inRealm(). - Updated
SearchResource.instancesByRealmto userealm.contains()instead ofcard.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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…-membership-cs-10982
lukemelia
approved these changes
May 5, 2026
…-membership-cs-10982
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
1 task
lukemelia
added a commit
that referenced
this pull request
May 7, 2026
…fter-4628 runtime-common: prettier --fix follow-up to #4628
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.inRealmresolves both sides to the same form comparisons work.