Skip to content

fix(wrapper): let a member named like a wrapper property win, and refuse then by name - #580

Merged
Shinrai merged 28 commits into
nextfrom
fix/nested-name-namespace
Oct 12, 2026
Merged

Shinrai merged 28 commits into
nextfrom
fix/nested-name-namespace

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

📦 Dependencies

No dependency updates

🔧 Other Changes

👥 Contributors

@cldmv-bot cldmv-bot Bot added the ! fix → next v4 flow: fix contributor PR targeting the next integration branch label Oct 8, 2026
@Shinrai

Shinrai commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Resolves #571 — closed when this ships to the default branch.

@cldmv-bot cldmv-bot Bot added area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure type: documentation Relates to docs, README updates, guides, or inline code comments labels Oct 8, 2026
Shinrai
Shinrai previously approved these changes Oct 8, 2026

Copilot AI 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.

🟡 Changes recommended

Member metadata becomes stale after removal or reload, and reserved-folder validation misses names that sanitize to framework keys.

2 open findings
What changed in this PR

Fixes #571 by allowing API members to shadow wrapper properties while rejecting unusable then names.

Changes:

  • Tracks folder member names and resolves wrapper-property collisions.
  • Rejects reserved/thenable paths with localized errors.
  • Adds documentation, declarations, fixtures, and tests.
File Description
src/​lib/​handlers/​unified-wrapper.mjs Implements member shadowing and member reads.
src/​lib/​handlers/​api-manager.mjs Handles shadowed names in API paths.
src/​lib/​builders/​modes-processor.mjs Supplies folder member names.
src/​lib/​processors/​loader.mjs Validates folder and then names.
types/​src/​lib/​handlers/​unified-wrapper.d.mts Declares new APIs and options.
types/​src/​lib/​handlers/​unified-wrapper.d.mts.map Updates declaration map.
types/​src/​lib/​handlers/​api-manager.d.mts.map Updates declaration map.
types/​src/​lib/​builders/​modes-processor.d.mts.map Updates declaration map.
types/​src/​lib/​processors/​loader.d.mts.map Updates declaration map.
tests/​vitests/​suites/​unified-wrapper/​wrapper-answered-member-names.test.vitest.mjs Tests collisions and rejection.
tests/​vitests/​setup/​vitest-helper.mjs Registers fixtures.
tools/​dev/​inspect-api-structure.mjs Hardens lazy-function inspection.
tools/​ci/​i18n-latin-tokens-accepted.json Allows new terminology.
src/​lib/​i18n/​languages/​en-us.json Adds English messages.
src/​lib/​i18n/​languages/​en-gb.json Adds British English messages.
src/​lib/​i18n/​languages/​de-de.json Adds German messages.
src/​lib/​i18n/​languages/​es-es.json Adds Spanish messages.
src/​lib/​i18n/​languages/​es-mx.json Adds Mexican Spanish messages.
src/​lib/​i18n/​languages/​fr-fr.json Adds French messages.
src/​lib/​i18n/​languages/​hi-in.json Adds Hindi messages.
src/​lib/​i18n/​languages/​ja-jp.json Adds Japanese messages.
src/​lib/​i18n/​languages/​ko-kr.json Adds Korean messages.
src/​lib/​i18n/​languages/​pt-br.json Adds Portuguese messages.
src/​lib/​i18n/​languages/​ru-ru.json Adds Russian messages.
src/​lib/​i18n/​languages/​zh-cn.json Adds Chinese messages.
docs/​MODULE-STRUCTURE.md Documents naming behavior.
docs/​API-RULES.md Clarifies wrapper-property rules.
api_tests/​api_test_wrapper_prop_members/​session/​prototype/​get.mjs Adds prototype fixture.
api_tests/​api_test_wrapper_prop_members/​session/​name/​set.mjs Adds name folder fixture.
api_tests/​api_test_wrapper_prop_members/​session/​length/​get.mjs Adds length fixture.
api_tests/​api_test_wrapper_prop_members/​session/​info.mjs Adds sibling fixture.
api_tests/​api_test_wrapper_prop_members/​profile/​bio.mjs Adds mount-target fixture.
api_tests/​api_test_wrapper_prop_members/​label.mjs Adds primitive-name fixture.
api_tests/​api_test_wrapper_prop_members/​account/​name.mjs Adds name file fixture.
api_tests/​api_test_wrapper_prop_members_mount/​set.mjs Adds mounted-module fixture.
api_tests/​api_test_reject_then_folder/​session/​then/​set.mjs Adds rejected folder fixture.
api_tests/​api_test_reject_then_folder/​ok.mjs Adds valid sibling fixture.
api_tests/​api_test_reject_then_file/​session/​then.mjs Adds rejected file fixture.
api_tests/​api_test_reject_then_file/​ok.mjs Adds valid sibling fixture.
api_tests/​api_test_reject_reserved_folder/​session/​_impl/​set.mjs Adds reserved-folder fixture.
api_tests/​api_test_reject_reserved_folder/​ok.mjs Adds valid sibling fixture.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread src/lib/handlers/unified-wrapper.mjs Resolved
Comment thread src/lib/processors/loader.mjs Resolved

Copilot AI 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.

🔵 Needs a closer look

Lazy reloads lose member-name metadata, and named then exports remain silently unreachable.

0 open findings

2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Named then exports remain silently unreachable

src/​lib/​processors/​loader.mjs:517

This rejects then only when it comes from a scanned file/folder name. A module can still declare a named then export because extractExports() only rejects framework-reserved keys; after composition, the wrapper get trap unconditionally returns undefined for then, so that export is silently unreachable despite the new documentation saying then cannot be any member name. Reject the export key as well and add eager/lazy coverage.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@Shinrai

Shinrai commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Copilot review 5458921724, "Previously missed: Named then exports remain silently unreachable" (src/lib/processors/loader.mjs:517): addressed in 07437148.

The export was not merely unreachable: a module exporting then hung slothlet() indefinitely in eager and lazy mode, ESM and CommonJS alike (already the case on next). Its namespace is thenable, so awaiting it calls the module's then.

  • then is now a reserved export name. A CommonJS module exporting it is refused with MODULE_RESERVED_EXPORT in #loadCJSIsolated, before the namespace is awaited, and extractExports refuses it alongside the framework-reserved keys. Tests cover a CJS fixture across the matrix plus extractExports directly.
  • An ES module exporting then cannot be refused by name, because import() calls its then before any export is visible. Importing through a wrapper module would avoid that, but it would move every module load outside the runner's module graph (vitest/coverage, instance import hooks, customImport, browser CSP), so it is not done. docs/MODULE-STRUCTURE.md documents the limitation.

Copilot AI 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.

🔵 Needs a closer look

Lazy reloads lose member metadata, and same-named nested directories are incorrectly omitted.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Lazy folder drops same-named subdirectories

src/​lib/​builders/​modes-processor.mjs:247

#folderMemberNames also drops a same-named subdirectory, but only a same-named file is flattened into the folder. During lazy materialization, a same-named subdirectory is explicitly treated as a legitimate nested namespace (see the populateDirectly guard around lines 1893–1900). For a structure such as name/name/get.mjs, the outer lazy wrapper therefore omits its real name member and answers its own "name" string instead, so the child cannot be reached before some other access materializes the parent. Filter self-named files only; retain every directory name.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@Shinrai

Shinrai commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Copilot review 5459561968, "Previously missed: Lazy folder drops same-named subdirectories" (src/lib/builders/modes-processor.mjs:247): not changed in this PR.

The cited structure (name/name/get.mjs) does not reach x.name.name in lazy mode for a reason unrelated to name. On next, lazy mode flattens any folder whose only entry is a same-named folder (x/foo/foo/get.mjs composes x.foo.get lazily, x.foo.foo.get eagerly). That eager/lazy divergence is pre-existing and is filed as #581, with the fix on its own branch. Modelling it in the member-name list here would only duplicate the composition rules.

@Shinrai
Shinrai force-pushed the fix/nested-name-namespace branch from 0743714 to 383a216 Compare October 8, 2026 21:44
@Shinrai
Shinrai requested a balanced review from Copilot October 9, 2026 03:46

Copilot AI 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.

🟡 Changes recommended

Lazy reload metadata and additional fixed function-property collisions still leave supported members unreachable.

2 open findings

🧠 Review effort: Balanced

Comment thread src/lib/builders/modes-processor.mjs Resolved
Comment thread src/lib/handlers/unified-wrapper.mjs Resolved

Copilot AI 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.

🔵 Needs a closer look

Lazy reloads lose member-name metadata, and some synthetic or default-object then exports remain accepted but unreachable.

0 open findings

2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate then exports across synthetic and default paths

src/​lib/​processors/​loader.mjs:1145

This check does not cover every export shape that becomes API members. Synthetic leaves bypass extractExports entirely (modes-processor.mjs:480–482), so api.add("svc", { exports: { then() {} } }) is accepted, while the wrapper's unconditional then trap makes that export unreachable. Likewise, export default { then() {} } presents only default in this loop, then the default object's own then is adopted as a child. Validate composed export/member names in the shared regular/synthetic processing path (while retaining the early CJS guard that prevents assimilation hangs).

🧠 Review effort: Balanced

@Shinrai

Shinrai commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Previously-missed finding from the c25f5eff review (loader.mjs:1145, then exports on synthetic and default paths): fixed in d8d1fb88. The wrapper now refuses a then member (MODULE_RESERVED_EXPORT) where it adopts its impl's members, the one point every member goes through. That covers a default object's or default function's own then, a key of an exported object, and an api.add() inline exports entry, none of which reach extractExports. The CommonJS load-time guard is unchanged. Covered by the new api_test_reject_then_default fixture (default object, root file, refused at load in both modes) and a synthetic-exports test over the named / default / nested shapes.

Copilot AI 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.

🔵 Needs a closer look

Lazy reloads discard fresh member metadata, and deep API paths can still traverse the wrong wrapper through waiting proxies.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Chained lazy child traversal resolves to the wrong wrapper

src/​lib/​handlers/​api-manager.mjs:1311

This pre-walk does not actually descend through an ordinary unmaterialized lazy child. Reading that child returns a waiting proxy, and resolveWrapper(waitingProxy) maps back to the ancestor wrapper that created it; therefore a following special segment such as name materializes/checks the ancestor, not the child. For an existing outer.inner/ lazy folder with no name member, api.add("outer.inner.name.deep", …) still reaches ensureParentPath with inner unloaded, reads its wrapper-owned "inner" name, and rejects the path as non-traversable. Resolve/await chained waiting proxies to their concrete child before testing the next wrapper-answered segment.

🧠 Review effort: Balanced

@Shinrai
Shinrai force-pushed the fix/nested-name-namespace branch from 9dcf6a6 to ba3d04c Compare October 11, 2026 23:28
@Shinrai
Shinrai requested a balanced review from Copilot October 11, 2026 23:29

Copilot AI 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.

🟡 Changes recommended

The CJS thenable guard can still hang, and an in-flight dispatcher mount can survive teardown.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread src/lib/processors/loader.mjs Resolved
Comment thread src/lib/handlers/version-manager.mjs Resolved
… shutdown; refuse a CommonJS Proxy's read `then`

- A path's dispatcher mounts run in order, and each writes only while
  its dispatcher is still the path's. A write already under way when
  unregister or shutdown lands is taken back out unless a newer
  dispatcher was registered for the path since.
- The CommonJS export guard refuses an own `then` whose read is a
  function, as the namespace copy reads it, not only one described as
  callable: a module.exports Proxy may describe data while its get trap
  answers a function.

Copilot AI 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.

🟡 Changes recommended

Dispatcher failures and teardown races can leave one API tree partially mounted or remove a newer dispatcher.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread src/lib/handlers/version-manager.mjs Resolved
Comment thread src/lib/handlers/version-manager.mjs Resolved
…ched, and order teardown with the path's mounts

- A mount that fails on boundApi after writing api now removes what it
  wrote before rejecting, so rollback never sees a half-mounted
  dispatcher.
- teardownDispatcher's removal joins the path's chain: it runs after
  any mount in flight, and the path's next mount waits for it, so a
  removal that pauses cannot delete a dispatcher registered after it.

Copilot AI 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.

🔵 Needs a closer look

Version tags can still inject the reserved composite-key separator into effective API paths.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

…eparator

The separator checks covered only the logical path and the moduleID, so
a versioned add could mount at a path whose tag carried the separator,
which remove() and leaves() split on.
@Shinrai

Shinrai commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Review 5485616543… follow-up: the latest review on 7e0331ff listed 0 findings, but its summary noted that version tags can still inject the reserved composite-key separator into effective API paths.

Fixed in 0dc798fa. Reproduced: api.slothlet.api.add("auth", dir, {}, { version: "v__slothlet_sep__x" }) mounted, with or without an explicit moduleID, because the separator checks covered only the logical path and the moduleID. remove() / leaves() split their argument on the separator, so that mount path could be split to another module's id. A tag holding the separator is now refused with INVALID_CONFIG_API_PATH_INVALID (API_PATH_REASON_RESERVED_SEPARATOR, segment index 0), and the api is left unchanged. Test: versioning-conflict "refuses a version tag holding the reserved moduleID separator", with and without a moduleID, all 8 configs; both failed before.

Copilot AI 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.

🔵 Needs a closer look

It changes foundational proxy and dispatcher invariants, and dotted version-tag dispatch still lacks an end-to-end regression test.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Add end-to-end test for dotted version tag dispatch

src/​lib/​handlers/​api-manager.mjs:1921

The new atomic mount handling for dotted version tags is not exercised end-to-end. The existing 2.0.0 test only checks versioning.list("auth"); it never invokes api.auth, so a regression that mounts or resolves the value through split segments would still pass. Please add a test that registers a dotted tag and calls the logical dispatcher.

🧠 Review effort: Balanced

@Shinrai

Shinrai commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Review on 0dc798fa, previously missed item "Add end-to-end test for dotted version tag dispatch" (src/lib/handlers/api-manager.mjs:1921): added in a24a5d78. versioning-default-auto "mounts a dotted version tag as one segment and dispatches the logical path to it" registers 1.0.0 and 2.0.0 and checks that:

  • api["1.0.0"].auth.login() / api["2.0.0"].auth.login() reach v1 / v2;
  • api["2"] is undefined (the tag is not split);
  • the logical api.auth.login() dispatches to the default 2.0.0.

All 8 configs pass. No source change was needed: the current code already mounts the tag as one segment.

Copilot AI 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.

🔵 Needs a closer look

It changes core Proxy invariants, lazy materialization, and concurrent dispatcher lifecycle behavior across many execution modes.

0 open findings

🧠 Review effort: Balanced

@Shinrai
Shinrai merged commit 908ac21 into next Oct 12, 2026
29 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/nested-name-namespace branch October 12, 2026 01:43
Shinrai added a commit that referenced this pull request Oct 12, 2026
… module fails both modes

The inspector's materialize step only touched nodes whose function name
contained "lazy", so a lazy api was compared before its modules loaded.
A fixture refusing a module at load (#580's MODULE_THENABLE_EXPORT
fixtures) then failed eager and looked loaded in lazy. Every lazy node is
now awaited, recursively, and a refusal surfaces as the api's load error,
which the structure test compares across modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch type: documentation Relates to docs, README updates, guides, or inline code comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants