Skip to content

common: Fix relative references to @cardstack/*#4242

Draft
backspace wants to merge 8 commits intomainfrom
common/relative-@cardstack-reference-cs-10500
Draft

common: Fix relative references to @cardstack/*#4242
backspace wants to merge 8 commits intomainfrom
common/relative-@cardstack-reference-cs-10500

Conversation

@backspace
Copy link
Contributor

@backspace backspace commented Mar 24, 2026

This is akin to #4241 but in a deeper place. It’s meant to address errors like this, where relative references with @cardstack/catalog aren’t working:

image

backspace and others added 4 commits March 24, 2026 10:56
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
@github-actions
Copy link

github-actions bot commented Mar 24, 2026

Host Test Results

    1 files  ±0      1 suites  ±0   2h 7m 48s ⏱️ -35s
2 030 tests ±0  2 015 ✅ ±0  15 💤 ±0  0 ❌ ±0 
2 045 runs  ±0  2 030 ✅ ±0  15 💤 ±0  0 ❌ ±0 

Results for commit f652245. ± Comparison against base commit 7ce5f7b.

♻️ This comment has been updated with latest results.

backspace and others added 4 commits March 24, 2026 12:53
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant