common: Fix relative references to @cardstack/*#4242
Draft
Conversation
When the reference is already an absolute http(s):// URL, resolve it directly without passing the (potentially prefix-form) relativeTo base to new URL, since the WHATWG URL spec validates the base even when the first arg is absolute. When relativeTo is a prefix-form string (e.g. @cardstack/skills/Skill/foo), resolve it through prefix mappings before using as a base URL for relative references like ./foo.md. Includes unit tests for resolveCardReference covering both fixes and existing behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a card-endpoints test that verifies linksTo relationships resolve correctly when a card's ID is in prefix form (e.g. @test/realm/Pet/foo). This exercises the processRelationships -> resolveCardReference code path that previously failed because prefix-form IDs are not valid URL bases. Also exports unregisterCardReferencePrefix for test cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…stack-reference-cs-10500 # Conflicts: # packages/realm-server/tests/card-reference-resolver-test.ts
The e2e test required the prefix mapping to be active during indexing, but setupPermissionedRealmCached indexes before beforeEach hooks run. Coverage is provided by card-reference-resolver-test.ts which has both resolveCardReference unit tests and relativizeDocument integration tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests relativizeDocument with prefix-form resource IDs and realistic relationship patterns: - Relative URL (./my-skill.md) relative to prefix-form card ID - Absolute URL (https://cardstack.com/base/Theme/...) with prefix-form card ID These mirror the actual bugs where @cardstack/skills/Skill/... cards had relationships that failed to resolve because prefix-form strings are not valid URL bases. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
definition-lookup.ts:canonicalURL was not calling unresolveCardReference, so module lookups used full URLs while the indexer (dependency-url.ts) stored module entries in prefix form. This caused FilterRefersTo- NonexistentTypeError when indexing new modules with a prefix mapping active. Added e2e card-endpoints test that registers a prefix mapping, writes card definitions and instances, then fetches a card with a linksTo relationship to verify the full indexing→serving pipeline works with prefix-form IDs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 task
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is akin to #4241 but in a deeper place. It’s meant to address errors like this, where relative references with
@cardstack/catalogaren’t working: