Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/host/tests/live-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export async function loadRealmTests(application) {
import('@cardstack/host/config/environment'),
]);

// Mutate the shared config module object directly (not just the copy
// handed to loaderInstance's shim below) so every app instance created
// later by individual tests' setupApplicationTest — which import
// '@cardstack/host/config/environment' as a normal static import, not
// through this loader — also sees the real catalog realm address.
hostConfigEnvironment.default.resolvedCatalogRealmURL = realmURL;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Override config before loading helper modules

When liveTest runs a realm test that uses the host helper/mock-matrix modules, those modules have already been imported by the Promise.all immediately above this assignment. Several of them snapshot ENV.resolvedCatalogRealmURL at module evaluation (for example mock-matrix/_client.ts builds publicRealmURLs, and helpers re-export catalogRealmURL from host/lib/utils), so setting the shared config here is too late: those helpers still behave as if the catalog realm is absent even though app instances see the new value. Import the config module and set it before importing the helpers, or make the helper reads lazy, so live catalog tests get consistent config.

Useful? React with 👍 / 👎.


const loaderInstance = application.buildInstance({
rootElement: '#ember-testing-loader',
});
Expand Down
4 changes: 4 additions & 0 deletions packages/host/tests/unit/plan-install-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const baseRealmURL = new URL('https://cardstack.com/base/');
const foreignRealmURL = new URL('https://localhost:4201/user1/personal-realm/');

const virtualNetwork = new VirtualNetwork();
// The install planner canonicalizes module refs through the virtual
// network's realm mappings, so register the base realm prefix the same way
// the host's network service does at construction.
virtualNetwork.addRealmMapping('@cardstack/base/', baseRealmURL.href);

module('Unit | Catalog | Install Plan Builder', function () {
test('when listing name is not provided, just provides uuid (in this case uuid="xyz")', function (assert) {
Expand Down
27 changes: 21 additions & 6 deletions packages/runtime-common/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { CardDef } from '@cardstack/base/card-api';
import { RealmPaths, join } from './paths.ts';
import type { ResolvedCodeRef } from './code-ref.ts';
import { resolveAdoptedCodeRef } from './code-ref.ts';
import { realmURL } from './constants.ts';
import { baseRealmRRI, realmURL } from './constants.ts';
import { logger } from './log.ts';
import type { LocalPath } from './paths.ts';
import { rri } from './realm-identifiers.ts';
Expand All @@ -23,7 +23,22 @@ export interface Listing extends CardDef {
skills: any[];
}

const baseRealmPath = new RealmPaths(new URL('https://cardstack.com/base/'));
// A codeRef.module for a base-realm class may reach the planner as the
// literal symbolic `https://cardstack.com/base/` URL or as the base realm's
// real backing URL (e.g. `https://localhost:4201/base/skill`), so
// canonicalize once to RRI form and compare against the `@cardstack/base/`
// prefix. This requires the base realm's URL and realm mappings to be
// registered on the VirtualNetwork the caller hands us — every production
// VirtualNetwork registers them at construction (see the host's network
// service), and tests must do the same. The durable end-state is for refs
// to already be canonical before they reach this layer, at which point the
// unresolveURL call collapses to a no-op prefix check.
function isInBaseRealm(
module: RealmResourceIdentifier,
virtualNetwork: VirtualNetwork,
): boolean {
return virtualNetwork.unresolveURL(module).startsWith(baseRealmRRI);
Comment thread
richardhjtan marked this conversation as resolved.
}

// sourceCodeRef -- (installs module) --> targetCodeRef
// sourceCodeRef: code ref of the code from the source realm
Expand Down Expand Up @@ -222,7 +237,7 @@ function resolveTargetCodeRef(
resolver: ListingPathResolver,
virtualNetwork: VirtualNetwork,
): ResolvedCodeRef {
if (baseRealmPath.inRealm(codeRef.module)) {
if (isInBaseRealm(codeRef.module, virtualNetwork)) {
return codeRef;
} else {
let moduleURL = virtualNetwork.toURL(codeRef.module);
Expand All @@ -249,7 +264,7 @@ export function planModuleInstall(
};
});
let modulesCopy = codeRefs.flatMap((sourceCodeRef: ResolvedCodeRef) => {
if (baseRealmPath.inRealm(sourceCodeRef.module)) {
if (isInBaseRealm(sourceCodeRef.module, virtualNetwork)) {
return [];
}
let targetCodeRef = resolveTargetCodeRef(
Expand All @@ -276,10 +291,10 @@ export function planInstanceInstall(
for (let instance of instances) {
let sourceCodeRef = resolveAdoptedCodeRef(instance, virtualNetwork);
let lid = resolver.local(virtualNetwork.toURL(instance.id).href);
if (baseRealmPath.inRealm(rri(instance.id))) {
if (isInBaseRealm(rri(instance.id), virtualNetwork)) {
throw new Error('Cannot install instance from base realm');
}
if (!baseRealmPath.inRealm(sourceCodeRef.module)) {
if (!isInBaseRealm(sourceCodeRef.module, virtualNetwork)) {
let targetCodeRef = resolveTargetCodeRef(
sourceCodeRef,
resolver,
Expand Down
Loading