diff --git a/commands/listing-install.ts b/commands/listing-install.ts index 1deea2d8..bdbf5bee 100644 --- a/commands/listing-install.ts +++ b/commands/listing-install.ts @@ -67,6 +67,7 @@ export function buildInstanceOperation( delete (doc as any).data.id; delete (doc as any).included; let cardResource = (doc as any).data as LooseCardResource; + cardResource.meta.adoptsFrom = copyInstanceMeta.targetCodeRef; let href = join(realmIdentifier, copyInstanceMeta.lid) + '.json'; return { op: 'add', href, data: cardResource }; } diff --git a/tests/helpers/test-fixtures.ts b/tests/helpers/test-fixtures.ts index 54fcd17b..3fb86dcb 100644 --- a/tests/helpers/test-fixtures.ts +++ b/tests/helpers/test-fixtures.ts @@ -543,10 +543,10 @@ export function makeMockCatalogContents( self: pirateSkillId, }, }, - }, - 'categories.0': { - links: { - self: writingCategoryId, + 'categories.0': { + links: { + self: writingCategoryId, + }, }, }, meta: { diff --git a/tests/live/catalog-app/listing-install.test.gts b/tests/live/catalog-app/listing-install.test.gts index 89f82a82..7add9fc8 100644 --- a/tests/live/catalog-app/listing-install.test.gts +++ b/tests/live/catalog-app/listing-install.test.gts @@ -1,6 +1,8 @@ import { getService } from '@universal-ember/test-support'; import { module, test } from 'qunit'; +import { identifyCard, isResolvedCodeRef } from '@cardstack/runtime-common'; + import ListingInstallCommand from '../../../commands/listing-install'; import type { CardDef } from 'https://cardstack.com/base/card-api'; @@ -38,7 +40,7 @@ const authorListingId = `${mockCatalogURL}Listing/author`; const blogPostListingId = `${mockCatalogURL}Listing/blog-post`; export function runTests() { - module.skip( + module( 'Acceptance | Catalog | catalog app - listing install', function (hooks) { setupApplicationTest(hooks); @@ -107,7 +109,7 @@ export function runTests() { test('card listing', async function (assert) { const listingName = 'author'; - await executeCommand( + let result = await executeCommand( ListingInstallCommand, authorListingId, testDestinationRealmURL, @@ -128,6 +130,28 @@ export function runTests() { let examplePath = `${outerFolder}${listingName}/Author/example.json`; await openDir(assert, examplePath); await verifyFileInFileTree(assert, examplePath); + + // Author/example.json's own adoptsFrom is an absolute URL into + // the catalog realm (see makeMockCatalogContents), so this + // catches the install pipeline leaving the copied instance + // pointed at the source realm instead of rewriting it into the + // newly installed module. + let store = getService('store'); + let installedCard = (await store.get( + result.exampleCardId as string, + )) as CardDef; + let installedRef = identifyCard(installedCard.constructor); + if (!installedRef || !isResolvedCodeRef(installedRef)) { + throw new Error('expected a resolved code ref'); + } + assert.ok( + installedRef.module.startsWith(testDestinationRealmURL), + `installed card module "${installedRef.module}" resolves into the destination realm`, + ); + assert.false( + installedRef.module.startsWith(mockCatalogURL), + `installed card module "${installedRef.module}" should not still point at the catalog realm`, + ); }); test('listing installs relationships of examples and its modules', async function (assert) {