-
Notifications
You must be signed in to change notification settings - Fork 12
Match type filters through re-export spellings via canonical code refs #5800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lukemelia
merged 2 commits into
main
from
cs-12168-type-filtered-search-expands-the-adoption-chain-for-card
Aug 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
115 changes: 115 additions & 0 deletions
115
packages/host/tests/unit/query-canonicalization-test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { module, test } from 'qunit'; | ||
|
|
||
| import { | ||
| canonicalizeFilterRefs, | ||
| rri, | ||
| type ResolvedCodeRef, | ||
| type Filter, | ||
| } from '@cardstack/runtime-common'; | ||
|
|
||
| const CANONICAL_FILE_DEF: ResolvedCodeRef = { | ||
| module: rri('https://cardstack.com/base/card-api'), | ||
| name: 'FileDef', | ||
| }; | ||
| const REEXPORT_FILE_DEF: ResolvedCodeRef = { | ||
| module: rri('https://cardstack.com/base/file-api'), | ||
| name: 'FileDef', | ||
| }; | ||
| const PERSON: ResolvedCodeRef = { | ||
| module: rri('http://example.com/person'), | ||
| name: 'Person', | ||
| }; | ||
|
|
||
| // Resolves the file-api re-export spelling to the canonical card-api ref, | ||
| // echoes already-canonical refs, and fails everything else. | ||
| async function resolve( | ||
| ref: ResolvedCodeRef, | ||
| ): Promise<ResolvedCodeRef | undefined> { | ||
| if ( | ||
| ref.module === REEXPORT_FILE_DEF.module && | ||
| ref.name === REEXPORT_FILE_DEF.name | ||
| ) { | ||
| return CANONICAL_FILE_DEF; | ||
| } | ||
| if ( | ||
| (ref.module === CANONICAL_FILE_DEF.module && | ||
| ref.name === CANONICAL_FILE_DEF.name) || | ||
| (ref.module === PERSON.module && ref.name === PERSON.name) | ||
| ) { | ||
| return ref; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| module('Unit | query-canonicalization', function () { | ||
| test('rewrites a top-level `type` ref to its canonical form', async function (assert) { | ||
| let { filter, incomplete } = await canonicalizeFilterRefs( | ||
| { type: REEXPORT_FILE_DEF }, | ||
| resolve, | ||
| ); | ||
| assert.deepEqual(filter, { type: CANONICAL_FILE_DEF }); | ||
| assert.false(incomplete); | ||
| }); | ||
|
|
||
| test('rewrites `on` refs nested through any/every/not', async function (assert) { | ||
| let input: Filter = { | ||
| any: [ | ||
| { on: PERSON, eq: { name: 'x' } }, | ||
| { | ||
| every: [ | ||
| { not: { on: REEXPORT_FILE_DEF, eq: { name: 'y' } } }, | ||
| { type: REEXPORT_FILE_DEF }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
| let { filter, incomplete } = await canonicalizeFilterRefs(input, resolve); | ||
| assert.deepEqual(filter, { | ||
| any: [ | ||
| { on: PERSON, eq: { name: 'x' } }, | ||
| { | ||
| every: [ | ||
| { not: { on: CANONICAL_FILE_DEF, eq: { name: 'y' } } }, | ||
| { type: CANONICAL_FILE_DEF }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| assert.false(incomplete); | ||
| // the input filter is not mutated | ||
| assert.deepEqual( | ||
| (input.any![1] as { every: Filter[] }).every[1], | ||
| { type: REEXPORT_FILE_DEF }, | ||
| 'input tree is left untouched', | ||
| ); | ||
| }); | ||
|
|
||
| test('an unresolvable ref stays as-given and marks the result incomplete', async function (assert) { | ||
| let bogus: ResolvedCodeRef = { | ||
| module: rri('http://example.com/nope'), | ||
| name: 'Nope', | ||
| }; | ||
| let { filter, incomplete } = await canonicalizeFilterRefs( | ||
| { every: [{ type: bogus }, { on: PERSON, eq: { name: 'x' } }] }, | ||
| resolve, | ||
| ); | ||
| assert.deepEqual(filter, { | ||
| every: [{ type: bogus }, { on: PERSON, eq: { name: 'x' } }], | ||
| }); | ||
| assert.true(incomplete); | ||
| }); | ||
|
|
||
| test('duplicate refs resolve once', async function (assert) { | ||
| let calls = 0; | ||
| await canonicalizeFilterRefs( | ||
| { | ||
| any: [{ type: REEXPORT_FILE_DEF }, { type: REEXPORT_FILE_DEF }], | ||
| }, | ||
| async (ref) => { | ||
| calls++; | ||
| return resolve(ref); | ||
| }, | ||
| ); | ||
| assert.strictEqual(calls, 1); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.