Skip to content
Open
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
3 changes: 3 additions & 0 deletions packages/catalog-realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"@cardstack/boxel-ui": "workspace:*",
"@cardstack/local-types": "workspace:*",
"@cardstack/runtime-common": "workspace:*",
"@ember/test-helpers": "catalog:",
"@types/lodash": "catalog:",
"@types/qunit": "catalog:",
"@universal-ember/test-support": "catalog:",
"@types/uuid": "catalog:",
"chess.js": "catalog:",
"concurrently": "catalog:",
Expand Down
2 changes: 2 additions & 0 deletions packages/catalog-realm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"experimentalDecorators": true,
"paths": {
"https://cardstack.com/base/*": ["../base/*"],
"@cardstack/host/tests/*": ["../host/tests/*"],
"@cardstack/boxel-host/commands/*": ["../host/app/commands/*"]
},
"types": ["@cardstack/local-types"]
},
"include": ["**/*.ts", "**/*.gts"],
"glint": {
"environment": ["ember-loose", "ember-template-imports"]
}
Expand Down
3 changes: 3 additions & 0 deletions packages/experiments-realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"@cardstack/boxel-ui": "workspace:*",
"@cardstack/local-types": "workspace:*",
"@cardstack/runtime-common": "workspace:*",
"@ember/test-helpers": "catalog:",
"@types/qunit": "catalog:",
"@universal-ember/test-support": "catalog:",
"@cardstack/view-transitions": "catalog:",
"@types/lodash": "catalog:",
"ember-animated": "catalog:",
Expand Down
110 changes: 110 additions & 0 deletions packages/experiments-realm/sample-command-card.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {
CardDef,
field,
contains,
Component,
} from 'https://cardstack.com/base/card-api';
import StringField from 'https://cardstack.com/base/string';

export class SampleCommandCard extends CardDef {
static displayName = 'Sample Command Card';
@field title = contains(StringField);

static isolated = class Isolated extends Component<typeof SampleCommandCard> {
<template>
<h1><@fields.title /></h1>
<button type='button'>Create Card</button>
</template>
};
}

// ── Tests (imports resolved via loader.shimModule in live-test.js) ────────────
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import GlimmerComponent from '@glimmer/component';
import { module, test } from 'qunit';

import { getService } from '@universal-ember/test-support';
import { baseRealm, type Store } from '@cardstack/runtime-common';
import {
setupIntegrationTestRealm,
setupLocalIndexing,
setupOnSave,
setupCardLogs,
testRealmURL,
setupRealmCacheTeardown,
withCachedRealmSetup,
type TestContextWithSave,
} from '@cardstack/host/tests/helpers';
import { TestRealmAdapter } from '@cardstack/host/tests/helpers/adapter';
import { setupMockMatrix } from '@cardstack/host/tests/helpers/mock-matrix';
import { setupRenderingTest } from '@cardstack/host/tests/helpers/setup';

class CreateCardButton extends GlimmerComponent {
@service declare store: Store;

createCard = async () => {
await this.store.add(
new SampleCommandCard({ title: 'Hello from live-test' }),
);
};

<template>
<button type='button' {{on 'click' this.createCard}}>Create Card</button>
</template>
}

module('Experiments | SampleCommandCard', function (hooks) {
setupRenderingTest(hooks);
setupLocalIndexing(hooks);
setupOnSave(hooks);
setupRealmCacheTeardown(hooks);
setupCardLogs(hooks, async () =>
(getService('loader-service') as any).loader.import(
`${baseRealm.url}card-api`,
),
);

let mockMatrixUtils = setupMockMatrix(hooks, {
loggedInAs: '@testuser:localhost',
activeRealms: [testRealmURL],
autostart: true,
});

let testRealmAdapter: TestRealmAdapter;

hooks.beforeEach(async function () {
({ adapter: testRealmAdapter } = await withCachedRealmSetup(async () =>
setupIntegrationTestRealm({
mockMatrixUtils,
contents: {
'sample-command-card.gts': { SampleCommandCard },
'.realm.json': '{ "name": "Sample Realm" }',
},
}),
));
});

test('clicking Create Card writes a new card to the realm', async function (this: TestContextWithSave, assert) {
assert.expect(3);

let savedUrl: URL | undefined;
this.onSave((url, doc) => {
savedUrl = url;
assert.strictEqual(
(doc as any).data.attributes.title,
'Hello from live-test',
'saved doc has correct title',
);
});

await render(<template><CreateCardButton /></template>);
await click('button');

assert.ok(savedUrl, 'card was saved to realm');
let relativePath = `${savedUrl!.href.substring(testRealmURL.length)}.json`;
let file = await testRealmAdapter.openFile(relativePath);
assert.ok(file, 'card JSON file exists in the realm adapter');
});
});
Comment on lines +20 to +110
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im perfroming a full reindex on experiments to be certain this doesn't break the indexer. Which is the key issue

Copy link
Contributor Author

@tintinthong tintinthong Mar 18, 2026

Choose a reason for hiding this comment

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

Seems to have succesfully indexed the file independent of the host

Copy link
Contributor

@habdelra habdelra Mar 18, 2026

Choose a reason for hiding this comment

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

this is a really important comment: specifically, due to the static nature you have defined the modules tests are run as a result of just loading this card. I don't think we ever want that. that means indexing is actually running tests (other things will end up running tests--like the user just interacting with this card will always end up running tests as a result of using this card). we should never have the module() or test() functions in module scope. A better shape might be:

export function runTests() {
  module('my test module', function (hooks) {
    test('test 1', function (assert) {});
   test('test 2', function (assert) {});
  });
}

and then tests are only executed when runTests() is called, not as a side effect of just loading the module.

Copy link
Contributor

Choose a reason for hiding this comment

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

i feel so strongly about this, that we should probably include a lint and/or skills for this as well, because users or AI might author cards in this way. this would be a very bad performance hit to our indexing system if this gets into a card.

2 changes: 2 additions & 0 deletions packages/experiments-realm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
"experimentalDecorators": true,
"paths": {
"https://cardstack.com/base/*": ["../base/*"],
"@cardstack/host/tests/*": ["../host/tests/*"],
"@cardstack/catalog/commands/*": ["../catalog-realm/commands/*"],
"@cardstack/catalog/*": ["../catalog-realm/catalog-app/*"]
},
"types": ["@cardstack/local-types"]
},
"include": ["**/*.ts", "**/*.gts"],
"glint": {
"environment": ["ember-loose", "ember-template-imports"]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@cardstack/view-transitions": "catalog:",
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^3.3.1",
"@ember/test-helpers": "catalog:",
"@ember/test-waiters": "catalog:",
"@embroider/compat": "^3.5.5",
"@embroider/core": "^3.4.15",
Expand Down
33 changes: 27 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading