[PR #2770] [MERGED] fix(reference): preserve directory intent when resolving source imports #5379

Closed
opened 2026-10-31 01:06:10 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2770
Author: @Shenrui-Ma
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @morluto

Base: main ← Head: fix/reference-directory-imports


📝 Commits (1)

  • d0898da fix(reference): preserve directory intent when resolving source imports

📊 Changes

2 files changed (+129 additions, -7 deletions)

View changed files

📝 src/application/ReferenceSourceImportEntries.ts (+11 -7)
➕ tests/boundary/cli/referenceSourceDirectoryImports.test.ts (+118 -0)

📄 Description

Summary

import-reference-source can leave require("./lib/") unresolved or link require("./lib/.") to a sibling file. This fixes those dependency edges in the reference-source graph.

No separate issue; the observed CLI output is included below.

Problem and expected behavior

Concatenated index paths such as lib//index.js do not match inventory identities. Normalizing ./lib/. also removes its directory intent, allowing a sibling file to match.

Explicit directory requests should use the importer's existing index candidates.

Change and scope

Build index paths with posix.join and preserve directory intent when selecting candidates. Directory requests skip file and TypeScript emitted-filename fallbacks.

Routine correction to the existing source-import workflow; no separate maintainer scope decision is required.

Contract and boundary impact

  • Owner: reference-source candidate generation.
  • CLI: corrected graph relationships; MCP contracts and tool catalog unchanged.
  • Compatibility: ordinary candidate order, exact/Unicode matching, non-directory TypeScript substitutions, and root confinement unchanged.
  • Evidence: source bytes and entry digests are unchanged; corrected relationships can change the graph digest.
  • Authority and cleanup: existing source-tree reads and cleanup.
  • Metadata, packaging, and installation: unchanged.

Expected effects:

  • Read existing files or captured data.

Evidence and regression coverage

Ran the compiled CLI against a synthetic source tree. Node independently resolved and executed the CommonJS fixture modules. Excerpts from the resulting graph:

Request Before After
require("./lib/") lib/, unresolved lib/index.js, internal
require("./lib/.") lib.ts, internal lib/index.js, internal
require(".") or require("./") . or ./, unresolved index.js, internal
Nested require("..") or require("../") . or ./, unresolved index.js, internal

The regression also covers file and index ordering, TypeScript substitutions, missing directories, and root confinement. It fails on the unmodified base and passes with this patch.

  • Observed results and remaining limitations are distinguished.
  • Entry identity and source provenance are preserved.
  • Missing and out-of-root targets remain unresolved.

Validation performed

  • npm run test:focused -- tests/boundary/cli/referenceSourceDirectoryImports.test.ts — passed.
  • npm run check — passed with warnings.
  • The earlier full local run had 12 failing cases, each reproduced on its unmodified base. After updating the base, the focused tests and static checks were rerun.

Compatibility, safety, and release

Verified on macOS arm64. Native Windows import remains unsupported; native Linux/Windows and full external-provider verification were not run. No migration or new dependency. Full Node resolution and source-to-bundle matching are outside this change.

Before merge

  • Focused, in-scope fix with a conventional title.
  • No separate issue; regression and output included.
  • Changed behavior and failure paths covered.
  • No schema, documentation, or metadata updates needed.
  • Diff checked for secrets, unrelated changes, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2770 **Author:** [@Shenrui-Ma](https://github.com/Shenrui-Ma) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/reference-directory-imports` --- ### 📝 Commits (1) - [`d0898da`](https://github.com/morluto/rea/commit/d0898da11fea8277cebcce6edefe761be4ff8aad) fix(reference): preserve directory intent when resolving source imports ### 📊 Changes **2 files changed** (+129 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/application/ReferenceSourceImportEntries.ts` (+11 -7) ➕ `tests/boundary/cli/referenceSourceDirectoryImports.test.ts` (+118 -0) </details> ### 📄 Description ## Summary `import-reference-source` can leave `require("./lib/")` unresolved or link `require("./lib/.")` to a sibling file. This fixes those dependency edges in the reference-source graph. No separate issue; the observed CLI output is included below. ## Problem and expected behavior Concatenated index paths such as `lib//index.js` do not match inventory identities. Normalizing `./lib/.` also removes its directory intent, allowing a sibling file to match. Explicit directory requests should use the importer's existing index candidates. ## Change and scope Build index paths with `posix.join` and preserve directory intent when selecting candidates. Directory requests skip file and TypeScript emitted-filename fallbacks. Routine correction to the existing source-import workflow; no separate maintainer scope decision is required. ## Contract and boundary impact - Owner: reference-source candidate generation. - CLI: corrected graph relationships; MCP contracts and tool catalog unchanged. - Compatibility: ordinary candidate order, exact/Unicode matching, non-directory TypeScript substitutions, and root confinement unchanged. - Evidence: source bytes and entry digests are unchanged; corrected relationships can change the graph digest. - Authority and cleanup: existing source-tree reads and cleanup. - Metadata, packaging, and installation: unchanged. Expected effects: - [x] Read existing files or captured data. ## Evidence and regression coverage Ran the compiled CLI against a synthetic source tree. Node independently resolved and executed the CommonJS fixture modules. Excerpts from the resulting graph: | Request | Before | After | | --- | --- | --- | | `require("./lib/")` | `lib/`, unresolved | `lib/index.js`, internal | | `require("./lib/.")` | `lib.ts`, internal | `lib/index.js`, internal | | `require(".")` or `require("./")` | `.` or `./`, unresolved | `index.js`, internal | | Nested `require("..")` or `require("../")` | `.` or `./`, unresolved | `index.js`, internal | The regression also covers file and index ordering, TypeScript substitutions, missing directories, and root confinement. It fails on the unmodified base and passes with this patch. - [x] Observed results and remaining limitations are distinguished. - [x] Entry identity and source provenance are preserved. - [x] Missing and out-of-root targets remain unresolved. ## Validation performed - `npm run test:focused -- tests/boundary/cli/referenceSourceDirectoryImports.test.ts` — passed. - `npm run check` — passed with warnings. - The earlier full local run had 12 failing cases, each reproduced on its unmodified base. After updating the base, the focused tests and static checks were rerun. ## Compatibility, safety, and release Verified on macOS arm64. Native Windows import remains unsupported; native Linux/Windows and full external-provider verification were not run. No migration or new dependency. Full Node resolution and source-to-bundle matching are outside this change. ## Before merge - [x] Focused, in-scope fix with a conventional title. - [x] No separate issue; regression and output included. - [x] Changed behavior and failure paths covered. - [x] No schema, documentation, or metadata updates needed. - [x] Diff checked for secrets, unrelated changes, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:06:10 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5379
No description provided.