Skip to content

fix(5223): point tsconfig extends and exact paths at the scanned file - #5341

Open
Deepjyoti-Sarmah wants to merge 4 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5223-tsconfig-targets
Open

Deepjyoti-Sarmah wants to merge 4 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5223-tsconfig-targets

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5223. In a tsconfig, a local extends became a concept stub labelled with its raw text, and an exact compilerOptions.paths alias produced no edge at all. On 0.9.112, with the issue's repro:

a/tsconfig.build.json --extends--> "./tsconfig.json"   [concept, source_file a/tsconfig.build.json]
b/tsconfig.build.json --extends--> "./tsconfig.json"   [concept, source_file b/tsconfig.build.json]
tsconfig.json  paths {"@demo": ["src/index.ts"]}       (no edge)

Both come from extract_json in graphify/extractors/json_config.py. Traced in pdb:

extends   json_config.py:226  ref_nid = _make_id("ref", "./tsconfig.json")   # never resolved against the config's directory
@demo     json_config.py:200  ('@demo', 'array', 'paths')                     # not `extends`, not a string: falls through, nothing emitted

The fix resolves both to the real file and emits only the edge, stamped with target_file. That's how JS imports already do it (#2195), so extract()'s existing repoint pass lands the edge on the target's file node:

 extends "<value>"
-  -> concept stub ref_<value>
+  value starts with ./ ../ or is absolute
+    and <config dir>/<value> exists (or <value>.json, as tsc retries)
+      -> edge to that config, target_file stamped
+  otherwise -> concept stub (unchanged: packages, missing files)

 compilerOptions.paths "<alias>": [targets]
+  alias and target contain no "*"
+    base = own baseUrl, else a baseUrl inherited through local extends,
+           else the declaring config's directory
+    first target that resolves on disk (extension probing as for imports)
+      -> tsconfig.json --references--> that file

Choosing the base directory for paths

I measured four candidates against the new tests, and checked the disputed cases against tsc 5.9.3 (--traceResolution, --showConfig):

candidate tests inherited baseUrl (base/ sets baseUrl: "../lib", child declares "@d": ["x.ts"])
A: own baseUrl, else own directory 14/15 links root x.ts, wrong
B: as A, skip if extends may supply one 15/15 no edge
C: follow local extends for baseUrl (this PR) 15/15 lib/x.ts, same as tsc
D: match stub labels to files at build time not built both stubs above read ./tsconfig.json, so a label alone can't tell a/ from b/

tsc resolved @d to lib/x.ts and "extends": "./tsconfig.base" to tsconfig.base.json. C matches both.

Commits

ff9a7bc0  test(5223): pin tsconfig extends and paths declaration targets
cae87160  test(5223): read edge direction from _src/_tgt and use scanned base configs
29a22ba2  fix(5223): point tsconfig extends and exact paths at the scanned file
115ec250  fix(cache): bump AST cache schema to 49 for tsconfig declaration targets

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: an extends or exact paths target that is a scanned file is that file's node. Anything else keeps today's stub or gets no edge.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Merge Danger

Door: two-way. No schema or API change. Reverting the two fix commits restores 0.9.112 output; the cache bump only forces one re-extraction.

Blast Radius: small.

  • Only tsconfig-style JSON configs change, and only their extends and paths edges.
  • A local extends now joins the parent config's node instead of a private stub, so those configs may move into the same community.
  • _AST_CACHE_SCHEMA 48 -> 49, so every cached file re-extracts once. Without it, a cache filled by 0.9.112 served the old ref_tsconfig_json stub to the fixed extractor (2/2 files from cache).

Limitations

  • Wildcard aliases ("@/*": ["src/*"]) get no edge, as the issue suggests; expanding them needs its own policy.
  • When paths has no own baseUrl and the extends chain leaves the scan (a package such as @tsconfig/...), the base can't be known, so there is no edge.
  • An extends pointing at a JSON file graphify doesn't scan (no config name or key, e.g. {}) has no node to link to and drops out, as before.
  • The result is cached per file. If the target file appears later, the cached stub stays until the citing config changes. Relative JS imports behave the same way.
  • The relation for paths is references, not imports, so it stays out of import-cycle and dependency analytics.

How was this tested?

New tests/test_tsconfig_declaration_targets.py, 15 tests, each building a graph from a small tree:

test_local_extends_points_at_the_real_config        string, array (TS 5), no .json suffix, ../ parent dir, JSONC
test_external_or_missing_extends_keeps_its_stub      @tsconfig/node18/tsconfig.json, ./missing.json
test_exact_paths_alias_references_its_file           issue repro, no baseUrl, baseUrl subdir, first-existing fallback, extensionless
test_wildcard_or_missing_paths_target_gets_no_edge   "@/*", missing target
test_paths_use_baseurl_inherited_through_extends     == {tsconfig.json --references--> lib/x.ts}
tree new tests
0.9.112 340268a7 11 failed, 4 passed (the 4 are the stub/no-edge guards)
115ec250 15 passed

Full suite, both trees run at the same time in the same venv:

tree failed passed
340268a7 77 11514
115ec250 76 11530

No failure is unique to this branch. The one failure unique to 340268a7, test_language_override_lifecycle.py::test_watch_root_config_lifecycle_rebuilds_and_refreshes_event_mapping[replace], is a watch timing test unrelated to JSON extraction.

ruff check graphify/extractors/json_config.py tests/test_tsconfig_declaration_targets.py -> All checks passed

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (No fragment change.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages. (No trailer in the commit messages.)

…onfigs

build_from_json returns an undirected graph, so g.edges() can list an edge
either way round; build keeps the written direction in _src/_tgt. A base
config holding only {} has no config name or key and is skipped by
_is_config_json, so it has no node to point at. The inherited-baseUrl case
now requires the lib/x.ts edge tsc 5.9.3 resolves.
A relative extends (or one that resolves after appending .json, as tsc
does) now emits an edge stamped with target_file, so extract()'s repoint
pass lands it on the real config's node instead of a concept stub labelled
with the raw text. Package and missing extends keep their stub.

An exact compilerOptions.paths alias now references the first target that
exists, resolved against baseUrl (the config's own, else one inherited
through local extends) or the declaring config's directory. Wildcard
aliases, and configs whose baseUrl could come from a package, get no edge.
A cache filled by 0.9.112 served the old ref_tsconfig_json stub to the
fixed extractor (2/2 from cache); with 49 both files re-extract.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify code review View in Graphify

Review completed · 115ec25010ac

Warning

Merge confidence: 3/5 · Review before merging · 🟠 High impact
1 P2 bug checked against the code

The JSON config extractor now links local tsconfig extends values and exact paths aliases to files in the scan.

Full summary

The JSON config extractor now links local tsconfig extends values and exact paths aliases to files in the scan. Cache schema 49 invalidates prior cached extractions.

Bugs (1)

P2 · Check all parents in extends when resolving baseUrl in _paths_base: choosing only the last parent can resolve exact paths aliases against the child directory instead of an earlier parent's inherited baseUrl. Inspect source

Detailed review · checked against the code

Mappings miss baseUrl inherited from earlier parent configs

When a config extends multiple local configs, paths mappings can point to the wrong files if only an earlier parent sets baseUrl.

Expected: Resolve the alias target against the inherited baseUrl declared by the earlier parent.
Actually: Resolve the target against the child config directory, potentially omitting the reference or linking the wrong scanned file.

When paths has an exact alias, extract_json calls _paths_base and resolves the target against its returned directory. For an extends array, _paths_base selects only the last string parent. If that parent has no baseUrl or further extends, it returns the child config directory without checking earlier parents. The alias loader independently confirms arrays are processed in order and parent aliases are merged, so an earlier parent’s inherited settings can remain in effect. This can make the extractor miss the target file or emit a reference to the wrong file.

  • Independent source review: Checked the alias loader’s array handling and the extract_json path-resolution caller. The loader processes parents in order; no guard in the inspected _paths_base route checks earlier parents after selecting the last one.

  • Also reported as: Aliases use the wrong base when a later parent omits baseUrl

Code graph and static checks · 3752 functions depend on this change

Impact & health

Impact — 3752 functions depend on the 123 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1284 callers, 78 callees
  • worse: extract_json() — 33 callers, 8 callees
  • new: _edges() — 5 callers, 3 callees
  • worse: walk_object() — 1 callers, 11 callees

Formal checks — 3752 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Gate & verification

✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 2211 function(s) in the blast radius were not formally verified this run

Test selection

60 of 594 test file(s) selected (10%) via static blast radius.

  • tests/test_binary_media_words.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_long_paths.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cache_windows_case_4925.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_code_only_scope_4923.py — impact
  • tests/test_cpp_template_members.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_grammar_cache_key.py — impact
  • tests/test_hook_content_freshness.py — impact
  • tests/test_ignore_file_encoding.py — impact
  • tests/test_incremental_mtime_collision.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_java_nested_type_identity.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_json_schema_config.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_language_overrides.py — impact
  • tests/test_linked_worktree_reconcile.py — impact
  • tests/test_llm_ambiguous_fragments.py — impact
  • tests/test_llm_backends.py — impact
  • tests/test_manifest_ingest.py — impact
  • tests/test_msbuild_dir_evidence.py — impact
  • tests/test_objc_field_table_remap.py — impact
  • tests/test_out_dir_evidence.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_pipeline.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_injected_factory_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_rust_self_member_calls.py — impact
  • tests/test_rust_use_trees.py — impact
  • tests/test_semantic_cache_basename_recovery.py — impact
  • tests/test_semantic_cache_out_root.py — impact
  • tests/test_skill_persisted_scan_options.py — impact
  • tests/test_skill_semantic_all_cached.py — impact
  • tests/test_skillgen.py — impact
  • tests/test_slice_checkpoint_completeness.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_stat_index_husk.py — impact
  • tests/test_stat_index_multi_root.py — impact
  • tests/test_stat_index_portability.py — impact
  • … and 10 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Every flagged function

  • extract() in graphify/extract.py:11742 · 1284 callers, 78 callees: fans out to 78 callees (efferent coupling); 1284 callers depend on it (afferent coupling)
  • extract_json() in graphify/extractors/json_config.py:141 · 33 callers, 8 callees: fans out to 8 callees (efferent coupling); 33 callers depend on it (afferent coupling)
  • _edges() in tests/test_tsconfig_declaration_targets.py:7 · 5 callers, 3 callees: high coupling complexity (Ca·Ce = 15)
  • walk_object() in graphify/extractors/json_config.py:231 · 1 callers, 11 callees: fans out to 11 callees (efferent coupling)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve local tsconfig extends and paths declarations to scanned file nodes

1 participant