-
Notifications
You must be signed in to change notification settings - Fork 12
fix: ingest-card copies Spec + instances from shared/published source realms #5276
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
Open
jurgenwerk
wants to merge
3
commits into
main
Choose a base branch
from
cs-11652-ingest-card-per-realm-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ import { | |
| type ProfileManager, | ||
| } from '../../lib/profile-manager.ts'; | ||
| import type { RealmAuthenticator } from '../../lib/realm-authenticator.ts'; | ||
| import { search } from '../search.ts'; | ||
|
|
||
| const CARD_JSON = 'application/vnd.card+json'; | ||
| const MODULE_EXTENSIONS = ['.gts', '.gjs', '.ts', '.js']; | ||
|
|
@@ -104,17 +103,14 @@ export function resolveSameRealmFile( | |
| class RealmCardIngester extends RealmSyncBase { | ||
| hasError = false; | ||
| copiedFiles: string[] = []; | ||
| private profileManager: ProfileManager; | ||
| private cardUrl: string; | ||
| private sourceCache = new Map<string, string | null>(); | ||
|
|
||
| constructor( | ||
| options: SyncOptions & { cardUrl: string }, | ||
| authenticator: RealmAuthenticator, | ||
| profileManager: ProfileManager, | ||
| ) { | ||
| super(options, authenticator); | ||
| this.profileManager = profileManager; | ||
| this.cardUrl = options.cardUrl; | ||
| } | ||
|
|
||
|
|
@@ -342,15 +338,36 @@ class RealmCardIngester extends RealmSyncBase { | |
| private async searchCards( | ||
| query: Record<string, unknown>, | ||
| ): Promise<CardResource[]> { | ||
| let result = await search([this.realmRoot], query, { | ||
| profileManager: this.profileManager, | ||
| }); | ||
| if (!result.ok) { | ||
| // Query the SOURCE realm's own `_search` directly rather than the | ||
| // profile-scoped `_federated-search`. A shared/published source realm | ||
| // (e.g. the catalog) isn't in the active profile's federated set, so | ||
| // federated search returns nothing for it — which is why instances and | ||
| // Specs went uncopied (the module crawl survives because it uses direct | ||
| // file fetches). The realm's own `_search` sees its full index. | ||
| let res = await this.authenticator.authedRealmFetch( | ||
| `${this.realmRoot}_search`, | ||
| { | ||
| method: 'QUERY', | ||
| headers: { | ||
| Accept: CARD_JSON, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify(query), | ||
| }, | ||
| ); | ||
| if (!res.ok) { | ||
| this.hasError = true; | ||
| console.warn(` search failed: ${result.error ?? 'unknown'}`); | ||
| // Include statusText + a body snippet so auth errors, malformed queries, | ||
| // etc. are diagnosable from the CLI output, not just a bare status code. | ||
| let body = await res.text().catch(() => ''); | ||
| console.warn( | ||
| ` search failed: HTTP ${res.status} ${res.statusText}`.trimEnd() + | ||
| (body ? ` — ${body.slice(0, 300)}` : ''), | ||
| ); | ||
| return []; | ||
| } | ||
|
Comment on lines
+358
to
368
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Written by Claude on Matic's behalf.) Fixed in 814f807. The |
||
| return (result.data ?? []) as CardResource[]; | ||
| let json = (await res.json()) as SearchResponse; | ||
| return selectSearchResults(json); | ||
| } | ||
|
|
||
| private cardIdToInstanceRel(id: string | undefined): string | null { | ||
|
|
@@ -418,6 +435,23 @@ interface CardResource { | |
| attributes?: { specType?: string; ref?: unknown; [k: string]: unknown }; | ||
| } | ||
|
|
||
| interface SearchResponse { | ||
| data?: CardResource[]; | ||
| included?: CardResource[]; | ||
| } | ||
|
|
||
| /** | ||
| * Pick the matched cards out of a realm `_search` response. A normal realm | ||
| * returns matches in `data`; a published realm (e.g. the catalog) returns them | ||
| * in `included` with an empty `data`. Prefer `data`, fall back to `included` — | ||
| * never merge, so a normal realm's `included` (linked deps of the matches) is | ||
| * not mistaken for matches. Exported for unit testing. | ||
| */ | ||
| export function selectSearchResults(json: SearchResponse): CardResource[] { | ||
| let data = json.data ?? []; | ||
| return data.length > 0 ? data : (json.included ?? []); | ||
| } | ||
|
|
||
| function tryParseCardDoc( | ||
| source: string, | ||
| ): { data?: { meta?: { adoptsFrom?: { module?: string } } } } | null { | ||
|
|
@@ -490,7 +524,6 @@ export async function ingestCard( | |
| cardUrl, | ||
| }, | ||
| authenticator, | ||
| pm, | ||
| ); | ||
| console.log( | ||
| `Ingesting ${cardUrl}\n from realm ${realmRoot}\n into ${localDir}`, | ||
|
|
||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the direct
_searchfetch rejects (for example during token refresh/network failure) or the response body cannot be parsed as JSON, the exception now escapessearchCards()and abortssync()beforedownloadAll(), so even the module graph already discovered is not copied. The previous federatedsearch()converted these failures intook: false, and the surrounding code still treats search as optional viahasErrorandreturn []; this direct path should catch fetch/parse failures and use the same warning/empty-result path.Useful? React with 👍 / 👎.