Skip to content

fix(514): keep dotted alias imports and non-JS alias imports on their module - #2975

Merged
DeusData merged 6 commits into
DeusData:mainfrom
lev-os:fix/514-alias-dotted-basename
Nov 18, 2026
Merged

DeusData merged 6 commits into
DeusData:mainfrom
lev-os:fix/514-alias-dotted-basename

Conversation

@chidev

@chidev chidev commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Written with Claude Code (an AI agent) on behalf of @chidev, who reviewed it and is accountable for it.

What does this PR do?

This is the split you asked for in the review of #2900: the dotted-basename commit together with item 5 of that review, on current main (a3e9c91). Part of #514. It does not close the issue.

  • Commit 1 is @antespi's fix(514): preserve dotted filename, unchanged, with his sign-off.
  • Commit 2 fixes item 5. It puts path_alias.c and tests/test_path_alias.c back to main's state and makes the decision in the alias branch of cbm_pipeline_resolve_module (alias_module_qn in pass_pkgmap.c). The net diff against main is 3 files, 366 lines added, 6 removed.
  • Commit 3 repairs a fault in commit 2 that a review found after I opened this PR: a ? in a folder name (~/dir?name/file) was cut as a bundler query and reached src/dir.ts. Only a ? in the file name starts a query now.
  • Commit 4 repairs a second fault a review found: the shared alias resolver removes a spelled .ts, and the new code then read the next dotted part as another extension. ~/tokens.css.ts reached tokens.css and ~/worker.task.mjs.ts reached worker.task.mjs when both files exist. What is left after the resolver removed a spelled extension is now the whole file stem.

A qualified name cannot tell styles.css from styles/css.ts, because filename dots and path separators both become dots. So the file path decides, in this order:

  1. An explicit JS/TS or JSON extension names its module.
  2. A module at exactly the imported path wins (~/styles.css, also beside styles.css.ts or styles/css.ts).
  3. Else a dotted-name module at that path plus a module extension wins (~/theme.css reaches theme.css.ts; ~/cats/cat.service reaches cat.service.ts).
  4. Else the extension drops, as on main.

A bundler ?query and a #fragment on the file name are cut before the extension is read. The shared alias resolver is unchanged, so doc links keep the file identity they have on main.

Evidence

Machine: Apple M3 Ultra, macOS 26.2, no sanitizer (SANITIZE=). My runs used a separate BUILD_DIR and a private HOME; the commands below are the same without those two settings.

Run Command Result
New tests, main's pass_pkgmap.c scripts/test.sh SANITIZE= --suites edge_imports 86 passed, 2 failed
All suites below, this branch (commit 4) scripts/test.sh SANITIZE= --suites path_alias,edge_imports,doc_mentions_ts,fqn 200 passed
The 3 alias tests, commit 2's pass_pkgmap.c CBM_TEST_ONLY=edge_imports:ei_typescript_alias_import_keeps_question_mark_folder,... build/c/test-runner edge_imports 2 passed, 1 failed: src/user.ts -> src/dir.ts, expected src/dir?name/file.ts
Repro, commit 2 make -f Makefile.cbm SANITIZE= build/c/test-repro-runner && CBM_REPRO_ONLY=repro_issue514 build/c/test-repro-runner 1 passed, 1 failed (see limits)

The two tests that fail with main's production code:

  • ei_typescript_dotted_alias_import_targets_source_module (tests/test_edge_imports.c:663).
  • ei_typescript_alias_import_non_js_file_targets_its_module, on three of its 17 edges: src/app.ts -> src/cats/cat.service.ts, src/panel.ts -> src/theme.css.ts, src/cat-user.ts -> src/cat.service.ts.

The other 14 edges of the second test pass on main. They are the guard for item 5: ~/styles/globals.css, ~/styles.css?url, styles.css beside styles/css.ts, tokens.css beside tokens.css.ts (plain and ?url), a #fragment import with a same-name decoy function in another folder, and .mjs .cjs .mts .cts .json files. Each expects the exact target file and the Module label. The third new test, ei_typescript_alias_import_keeps_question_mark_folder, passes on main and guards commit 3; it is not built on Windows, where a file name cannot hold ?.

Known limits

  • cat.service.ts and cat/service.ts still share one qualified name. This PR does not change how module names are built; the test pins which file an alias import reaches when both exist.
  • ~/a.b with only a/b.ts on disk: .b is not an indexed extension, so the name stays whole and reaches a/b.ts, because the two share one qualified name. Main drops .b.
  • ~/theme.css.ts written in full beside a theme.css file now reaches theme.css.ts (commit 4; test ei_typescript_alias_import_spelled_ext_on_dotted_name, which fails on commit 3's code with src/a.ts -> src/tokens.css and src/b.ts -> src/worker.task.mjs). Main reaches theme.css there. Not covered: a doubled extension such as ~/a.ts.ts.
  • In tests/repro/repro_issue514.c, the new test repro_issue514_ctor_param_property_alias_import_callers passes. The older repro_issue514_data_flow_surfaces_arg_expr fails at line 171 in my local run. The response is project not found or not indexed, which points at my private HOME setup and not at this change. I did not run it on a3e9c91 without this change, so CI is the check for it. This PR does not touch that test.
  • I did not run the full test leg or lint-ci locally. clang-format 20.1.8 reports no difference on src/pipeline/pass_pkgmap.c.

Checklist

  • Every commit is signed off (git commit -s); scripts/check-dco.sh origin/main..HEAD passes for both commits
  • Tests pass locally (make -f Makefile.cbm test): only the suites in the table were run
  • Lint passes (make -f Makefile.cbm lint-ci): not run locally
  • New behavior is covered by a test (reproduce-first for bug fixes)

antespi and others added 2 commits November 13, 2026 08:37
Signed-off-by: Antonio Espinosa <antespi@gmail.com>
A path-alias import of a dotted TypeScript file (~/cats/cat.service)
must keep the dotted name, but an alias import of a non-JS file
(~/styles/globals.css, ~/styles.css?url) must still drop its extension,
as it does on main. Keeping every extension sent the CSS imports away
from their module nodes.

The alias branch of cbm_pipeline_resolve_module now decides from the
file path, because filename dots and path separators both become dots
in a qualified name:

- an explicit JS/TS or JSON extension names its module;
- a module at exactly the imported path wins (styles.css, also beside
  styles.css.ts or styles/css.ts);
- else a dotted-name module at that path plus a module extension wins
  (theme.css.ts imported as ~/theme.css);
- else the extension drops, as on main.

A bundler ?query and a #fragment are cut before the extension is read.
The shared alias resolver in path_alias.c is back to main's behaviour,
so doc links keep the file identity they had.

Refs DeusData#514

Signed-off-by: chidev <chicagowebdev@gmail.com>
@chidev
chidev requested a review from DeusData as a code owner November 13, 2026 17:20
@github-actions

Copy link
Copy Markdown

Thanks for opening this — it has been seen, and it is queued.

This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence.

Current review status: working through a backlog. 0.9.1-rc.1 is out, so the release freeze that held reviews is over — but it left a large queue of open pull requests behind it, and we are reading through them oldest-first. The background is in discussion #1144.

What that means for this PR, concretely:

  • It will not be closed for inactivity. No stale bot touches pull requests here.
  • It may still sit a while before a human reads it. That is on us, not on you.
  • Older PRs are read first, so a recent one is not being skipped — it is behind a queue.

Things that will genuinely speed it up whenever review does happen:

  • Keep it rebased on main — the tree is moving quickly right now, and a conflicting branch cannot be reviewed as the diff you intended.
  • Get CI green, or say which failures you believe are pre-existing.
  • Keep the change to one claim. Bundled features and refactors get split before they get merged, which costs you a round trip.
  • Every commit needs a sign-off (git commit -s) — CI enforces DCO.

If this fixes a bug, a reproduction we can run is worth more than a description of the symptom.

Thanks for contributing, and sorry in advance for the wait.

An alias import of ~/dir?name/file was cut at the question mark and
reached src/dir.ts. Only a question mark in the file name starts a
bundler query. The dotted-alias test now also checks the Module label.

Refs DeusData#514

Signed-off-by: chidev <chicagowebdev@gmail.com>
…port

The alias resolver removes a spelled module extension. The module-name
helper then read the next dotted part as another extension, so
~/tokens.css.ts reached tokens.css and ~/worker.task.mjs.ts reached
worker.task.mjs when both files exist. What is left after the resolver
removed a spelled extension is now the whole file stem.

Refs DeusData#514

Signed-off-by: chidev <chicagowebdev@gmail.com>
DeusData added a commit to htarnacki/codebase-memory-mcp that referenced this pull request Nov 17, 2026
subprocess_tree_rss_measures_contained_descendants compared two
independently spawned process trees, one idle and one whose descendant
touched 128 MiB, and required the loaded total to be at least 96 MiB
above the idle total. Two separate trees need not start from the same
footprint. On the hosted Windows CLANG64 leg they did not: the loaded
tree measured only 78 MiB above the idle one (167 MiB vs 245 MiB), and
the test failed on two unrelated PRs within two days (DeusData#2965 on
889170c, DeusData#2975 run 43499140720). The diagnosis that the two separate
trees are the cause comes from DeusData#2965.

The test now samples ONE tree twice, and every wait in the handshake is
a blocking pipe read instead of a poll of a ready file:

- The test creates two pipes, "up" (tree to test) and "down" (test to
  tree): FIFOs in its private temporary directory on POSIX, named pipes
  named after that directory's unique leaf on Windows. The
  __cbm_rss_tree_root role connects both as its first action and starts
  one __cbm_rss_tree_hold descendant that inherits the connected ends
  (fork on POSIX, an explicit two-handle inherit list on Windows); the
  root then drops its own copies.
- The descendant writes 'I'; the test takes the idle sample and writes
  'L'; the descendant touches every page of a 192 MiB load and writes
  'R'; the test takes the loaded sample and closes its ends, which
  releases the descendant to free the load and exit.
- A descendant that dies closes its ends, so the waiting read returns
  end-of-file instead of blocking. No handshake step has a sleep, a poll
  interval or a deadline.

The floor stays at 96 MiB and is now half the load: the root does not
grow between the two samples, so a probe that counts only the root
misses the floor by 96 MiB, and a probe that counts the descendant
clears it with 96 MiB to spare. The two member-fault tests use the same
handshake and keep their assertions. Production code is unchanged.

Evidence:
- macOS arm64, ASan: subprocess suite 60 passed, 2 skipped (the
  Windows-only Job Object probes); the rewritten test passed 20 of 20
  consecutive runs, idle 43 MiB and loaded 259 MiB in every run.
- Binding: with the macOS probe temporarily limited to the root process,
  the test fails at the floor assertion (idle 33 MiB, loaded 33 MiB);
  restoring the probe returns the suite to green.
- Linux arm64 container, gcc ASan: subprocess suite 60 passed,
  2 skipped; the rewritten test passed 20 of 20 consecutive runs, idle
  462 MiB and loaded 654 MiB in every run.
- Windows: both changed files compile with -fsyntax-only -Wall -Wextra
  -Werror under llvm-mingw for x86_64 and aarch64.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>

@DeusData DeusData left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you @chidev, this is exactly the split we asked for, and it is a pleasure to review. Keeping @antespi's original preserve dotted filename commit with his authorship and sign-off, and building the item 5 fix on top of it, is the right way to carry his work forward. Thanks again to @antespi as well: the dotted-basename idea goes back to his work in #2402 and #2900, and nest users get the benefit of it here.

The way you solved item 5 is better than the simple fix we suggested. A qualified name cannot tell styles.css from styles/css.ts, so letting the file path decide (explicit module extension first, then a module at exactly the imported path, then a dotted module at that path plus a module extension, else main's behaviour) is the right call. The tests are strong. Each edge checks the exact target file and the Module label, there are decoys for the name-guess fallback (css, service, tokens, frag), and the ?url, #fragment, .mjs/.cjs/.mts/.cts/.json and tokens.css beside tokens.css.ts cases are all pinned. It was also good to see you catch and fix two faults in your own commit 2 (the ? in a folder name, and the spelled .ts read twice), each with its own test, and to list the known limits plainly in the description.

What we checked on our side, on the head commit 57205dc:

  • Scope: only the dotted alias fix and item 5. The net diff touches pass_pkgmap.c and two test files; path_alias.c and test_path_alias.c end up unchanged against main, and nothing from the barrel work is included.
  • RED/GREEN: with main's pass_pkgmap.c and your tests, edge_imports fails 3 tests for the right reasons (cat.service and theme.css miss their modules, one of them lands on the decoy css function and one on the src/cat folder, and ~/tokens.css.ts reaches tokens.css). With your code they pass. The ? folder test passes on main too, as your description says; it guards commit 3. For the record, the "86 passed, 2 failed" in the description predates commit 4: with all four commits' tests it is 87 passed, 3 failed on main's code.
  • Suites (ASan/UBSan build): edge_imports, pipeline, parallel, ts_lsp, path_alias, complexity, fqn and doc_mentions_ts, 1115 passed, none failed. In the repro suite, your new repro_issue514_ctor_param_property_alias_import_callers passes. The older repro_issue514_data_flow_surfaces_arg_expr fails here too, at line 171 with "project not found or not indexed", so your private HOME setup was not the cause. The repro harness restores CBM_CACHE_DIR after indexing, which is the same thing your new rh514_trace_inbound helper works around. This PR does not touch that test, and we will look at it separately.
  • Real repositories, main's code against yours, with both the parallel and the sequential resolver:
    • nestjs/nest: 25 IMPORTS edges gained, 1 lost, all 26 judged by hand. The gains are spec and sample files that import dotted modules through tsconfig paths (unknown-dependencies.exception, shared.utils, cli-colors.util, route-paramtypes.enum, load-package.util, ...) and now reach the right module. The one lost edge was wrong on main: StandardSchemaSerializerInterceptor was bound to an unrelated LateHeadersController.interceptor method by name, and now reaches standard-schema-serializer.interceptor.ts. Six CALLS that were name guesses (unique_name, suffix_match) now resolve through the import map to the same functions, and one new super.createIOServer call reaches IoAdapter.createIOServer. No TESTS edge changes.
    • trpc/trpc: no IMPORTS, CALLS or TESTS change at all. In particular import '~/styles/globals.css' reaches the same CSS module as on main, so the item 5 regression from #2900 is gone.
    • The sequential and parallel resolvers give the same change on both repositories, repeated runs are identical, and a Go repository (caddy) indexes byte-identically with and without this change.
  • A small probe repository with tsconfig paths: @/app.module, ~/user.model, ~/types/global.d and ~/types/global.d.ts, and default and namespace imports of ~/cats/cat.service now reach their modules (main had no edge for any of them). ~/lib, ~/lib/index, ~/lib/index.ts (the /index case from our first #2900 review), .json, .css, .scss and ?react imports reach the same targets as on main.
  • The new lookups run in the IMPORTS phase after every Module node exists, in both pipelines, so the result does not depend on file order. They are constant work per import, and the complexity guard stays green.
  • clang-format and cppcheck are clean on pass_pkgmap.c, and the memory-core linter passes. The branch merges cleanly with current main; main's recent changes to path_alias.c and pass_pkgmap.c do not interact with this one, so there is no need to merge main in.

We have nothing more to ask for here. One small note: main has moved on since, so we used GitHub's update-branch to merge current main into your branch (4a8ae8d); your commits are unchanged, please pull before pushing again. Once CI is green on that head we will merge it.

Thanks again to both of you. This closes a real gap for NestJS and monorepo users, and the barrel part in #2900 can now move on separately.

@DeusData

Copy link
Copy Markdown
Owner

One more merge of current main into this branch (f267c48), via GitHub's update-branch: main just merged #2360, which also touches src/pipeline/pass_pkgmap.c and tests/test_edge_imports.c, so CI needs a fresh run on top of it. Your commits are unchanged; please pull before pushing again. We will merge once it is green. Thank you!

@DeusData
DeusData merged commit 08a7a58 into DeusData:main Nov 18, 2026
26 checks passed
@DeusData

Copy link
Copy Markdown
Owner

Merged in 08a7a58. Thank you, @chidev, for turning this into exactly the split we asked for and for the careful tests, and thank you again to @antespi, whose dotted-basename work from #2402 and #2900 is the first commit here. NestJS-style dotted modules (*.service, *.exception, *.util) and non-JS alias imports now reach their modules through tsconfig paths. The barrel part in #2900 can move on separately.

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.

3 participants