test(resolution): assert canonical import-target ids in jsconfig tests (follow-up to #2169)

#2169 canonicalizes cross-file edge targets to the root-relative file-node
id (the same id the target file gets as a node) instead of the old
absolute-path form. The #2153 baseUrl tests asserted the absolute form;
update them to the canonical id via a _cid() helper. Resolution behavior
is unchanged — only the expected id form.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
safishamsi
2026-07-25 23:16:52 +01:00
co-authored by Claude Opus 4.8
parent a8da0d3821
commit 52e1ed4050
+18 -10
View File
@@ -41,7 +41,15 @@ def _rails_tree(tmp_path: Path, config_name: str, importer_body: str,
def _widget(tmp_path: Path, base_url: str = "app/javascript") -> str:
return _make_id(str(tmp_path / base_url / "mods" / "Widget.js"))
# The resolved import target is canonicalized to the root-relative file-node
# id (the same id Widget.js gets as a node), not the absolute-path form
# (#2169 canonicalizes cross-file edge targets).
return _cid(tmp_path, tmp_path / base_url / "mods" / "Widget.js")
def _cid(tmp_path: Path, abs_path: Path) -> str:
"""Canonical root-relative file-node id of a cross-file import target (#2169)."""
return _make_id(str(Path(abs_path).relative_to(tmp_path).with_suffix("")))
def test_jsconfig_baseurl_static_import_resolves(tmp_path):
@@ -98,8 +106,8 @@ def test_declared_paths_alias_still_wins_over_baseurl(tmp_path):
"import W from '@mods/Widget.js';\nexport default W;\n")
r = extract([f], cache_root=tmp_path)
targets = _targets(r)
assert _make_id(str(real)) in targets
assert _make_id(str(tmp_path / "app/javascript" / "@mods" / "Widget.js")) not in targets
assert _cid(tmp_path, real) in targets
assert _cid(tmp_path, tmp_path / "app/javascript" / "@mods" / "Widget.js") not in targets
def test_declared_directory_prefix_alias_still_wins(tmp_path):
@@ -117,7 +125,7 @@ def test_declared_directory_prefix_alias_still_wins(tmp_path):
f = _write(tmp_path / "app/javascript" / "packs" / "p.js",
"import u from '@lib/util.js';\nexport default u;\n")
r = extract([f], cache_root=tmp_path)
assert _make_id(str(real)) in _targets(r)
assert _cid(tmp_path, real) in _targets(r)
def test_tsconfig_paths_alias_unchanged(tmp_path):
@@ -132,7 +140,7 @@ def test_tsconfig_paths_alias_unchanged(tmp_path):
f = _write(tmp_path / "src" / "app" / "main.ts",
"import { a } from '@services/api';\nexport default a;\n")
r = extract([f], cache_root=tmp_path)
assert _make_id(str(svc)) in _targets(r)
assert _cid(tmp_path, svc) in _targets(r)
def test_external_package_not_fabricated_under_baseurl(tmp_path):
@@ -143,7 +151,7 @@ def test_external_package_not_fabricated_under_baseurl(tmp_path):
f = _write(tmp_path / "app/javascript" / "packs" / "p.js",
"import React from 'react';\nexport default React;\n")
r = extract([f], cache_root=tmp_path)
assert _make_id(str(tmp_path / "app/javascript" / "react")) not in _targets(r)
assert _cid(tmp_path, tmp_path / "app/javascript" / "react") not in _targets(r)
def test_relative_import_unaffected_by_baseurl(tmp_path):
@@ -154,7 +162,7 @@ def test_relative_import_unaffected_by_baseurl(tmp_path):
f = _write(tmp_path / "app/javascript" / "packs" / "main.js",
"import L from './Local.js';\nexport default L;\n")
r = extract([f], cache_root=tmp_path)
assert _make_id(str(local)) in _targets(r)
assert _cid(tmp_path, local) in _targets(r)
def test_no_baseurl_declared_changes_nothing(tmp_path):
@@ -165,7 +173,7 @@ def test_no_baseurl_declared_changes_nothing(tmp_path):
f = _write(tmp_path / "packs" / "d.js",
"import W from 'mods/Widget.js';\nexport default W;\n")
r = extract([f], cache_root=tmp_path)
assert _make_id(str(tmp_path / "mods" / "Widget.js")) not in _targets(r)
assert _cid(tmp_path, tmp_path / "mods" / "Widget.js") not in _targets(r)
def test_tsconfig_wins_when_both_configs_present(tmp_path):
@@ -181,5 +189,5 @@ def test_tsconfig_wins_when_both_configs_present(tmp_path):
"import W from 'mods/W.js';\nexport default W;\n")
r = extract([f], cache_root=tmp_path)
targets = _targets(r)
assert _make_id(str(ts_hit)) in targets
assert _make_id(str(tmp_path / "js_root" / "mods" / "W.js")) not in targets
assert _cid(tmp_path, ts_hit) in targets
assert _cid(tmp_path, tmp_path / "js_root" / "mods" / "W.js") not in targets