Skip to content

fix: compose the same api in eager and lazy mode, and make the structure check compare them - #585

Merged
Shinrai merged 83 commits into
nextfrom
fix/structures-test-eager
Oct 13, 2026
Merged

Shinrai merged 83 commits into
nextfrom
fix/structures-test-eager

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Oct 9, 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 ! fix → next v4 flow: fix contributor PR targeting the next integration branch area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure labels Oct 9, 2026
@Shinrai

Shinrai commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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

@Shinrai

Shinrai commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Resolves #583, #584, #586 — closed when this ships to the default branch.

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

Object cloning remains lossy and Case 1 conflicts do not honor configured collision precedence.

1 open finding
What changed in this PR

Aligns eager and lazy API composition for same-named files/folders and callable collisions.

Changes:

  • Corrects callable detection and lazy-wrapper enumeration.
  • Reworks same-name collision and flattening behavior.
  • Adds parity checks and regression fixtures.
File Description
types/​src/​lib/​handlers/​unified-wrapper.d.mts.map Updates declaration mappings.
types/​src/​lib/​handlers/​unified-wrapper.d.mts Declares isCallableValue.
types/​src/​lib/​builders/​modes-processor.d.mts.map Updates declaration mappings.
types/​src/​lib/​builders/​api-assignment.d.mts.map Updates declaration mappings.
tools/​dev/​inspect-api-structure.mjs Improves callable inspection and hook configuration.
tests/​vitests/​suites/​smart-flattening/​smart-flattening-same-name.test.vitest.mjs Tests same-name composition shapes.
tests/​vitests/​suites/​smart-flattening/​smart-flattening-merge-replace-callable.test.vitest.mjs Tests callable collision modes.
tests/​vitests/​suites/​api-structures/​all-api-structures.test.vitest.mjs Compares eager and lazy structures correctly.
src/​slothlet.mjs Validates shutdown-hook callability.
src/​lib/​handlers/​unified-wrapper.mjs Fixes descriptors and adds callable detection.
src/​lib/​builders/​modes-processor.mjs Revises flattening and collision composition.
src/​lib/​builders/​api-assignment.mjs Handles lazy callable collisions.
src/​lib/​builders/​api_builder.mjs Validates lifecycle-hook callability.
api_tests/​smart_flatten/​api_smart_flatten_same_name_i/​s/​s.mjs Adds single-export fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_h/​s/​s.mjs Adds object-export fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_h/​s/​helper.mjs Adds sibling fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_g/​s/​s.mjs Adds named-function fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_g/​s/​helper.mjs Adds sibling fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_f/​s/​s/​worker.mjs Adds nested-folder fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_e/​s/​s.mjs Adds default-function fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_e/​s/​helper.mjs Adds sibling fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_d/​s/​s.mjs Adds multi-export fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_d/​s/​helper.mjs Adds sibling fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_c/​s/​s/​worker.mjs Adds nested namespace fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_c/​s/​other.mjs Adds unrelated sibling fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_b/​s/​s/​worker.mjs Adds nested default-export fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_b/​s/​s.mjs Adds callable same-name fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_a/​s/​s/​worker.mjs Adds nested named-export fixture.
api_tests/​smart_flatten/​api_smart_flatten_same_name_a/​s/​s.mjs Adds named-only fixture.
api_tests/​smart_flatten/​api_smart_flatten_merge_replace_callable/​utils.mjs Adds second root callable.
api_tests/​smart_flatten/​api_smart_flatten_merge_replace_callable/​services/​services.mjs Adds inner callable collision.
api_tests/​smart_flatten/​api_smart_flatten_merge_replace_callable/​services.mjs Adds root callable collision.
api_tests/​smart_flatten/​api_smart_flatten_callable_file_plain_folder/​utils.mjs Adds second root callable.
api_tests/​smart_flatten/​api_smart_flatten_callable_file_plain_folder/​services/​other.mjs Adds plain-folder members.
api_tests/​smart_flatten/​api_smart_flatten_callable_file_plain_folder/​services.mjs Adds callable-file members.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/lib/builders/modes-processor.mjs Resolved
@Shinrai

Shinrai commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Resolves #583, #584, #586, #587 — closed when this ships to the default branch.

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

Several addapi and self-named conflicts still disregard configured warn, error, replace, or merge-replace behavior.

2 open findings
1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Compare complete API structure in eager/lazy parity test

tests/​vitests/​suites/​api-structures/​all-api-structures.test.vitest.mjs:132

This now launches the two actual modes, but the assertion still does not compare the printed API Structure tree: extractApiStructure retains only root function metadata and callable paths. An eager result can therefore omit or misplace a primitive/plain namespace key and still pass. Parse and normalize the structure section (or have the tool emit a machine-readable shape) and compare it as part of this parity check.

🧠 Review effort: Balanced

Comment thread src/lib/builders/modes-processor.mjs Resolved
Comment thread src/lib/processors/flatten.mjs Resolved
@Shinrai

Shinrai commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Previously-missed finding from the 665c0f1b review (all-api-structures.test.vitest.mjs:132, parity test ignores the structure tree): fixed in d8c6b712. inspect-api-structure now prints a mode-neutral API Shape of the loaded api (every key, node kind, callable arity, primitive value; a lazy node is always a function-typed proxy, so the printed tree itself cannot be compared), and the test deep-compares it. Per-load random ids are compared by type only, and a fixture that refuses to load must fail with the same error code in both modes. Before, the error went to stderr and two empty outputs compared equal.

The full comparison found one real divergence, filed as #588 and fixed in a085a4e2: lazy materialize.materialized stayed false and wait() never resolved after a file/folder collision, a reload, or a root shutdown/ folder, because the materialization counter was moved by wrappers that were never counted (or never reachable). All 576 parity cases pass.

Resolves #583, #584, #586, #587, #588 — closed when this ships to the default branch.

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

Object-spread cloning breaks non-plain defaults, and the new public Flatten method is absent from consumer declarations.

3 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread src/lib/builders/modes-processor.mjs Resolved
Comment thread src/lib/processors/flatten.mjs Resolved
Comment thread src/lib/processors/flatten.mjs Resolved
@cldmv-bot cldmv-bot Bot added the type: documentation Relates to docs, README updates, guides, or inline code comments label Oct 9, 2026
@Shinrai

Shinrai commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Resolves #583, #584, #586, #587, #588, #589, #590 — closed when this ships to the default branch.

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

Unresolved correctness issues remain in default cloning, collision handling, ownership provenance, and materialization completion tracking.

2 open findings
3 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Use one consistent own-property conflict check across composition paths

src/​lib/​processors/​flatten.mjs:269

The shared resolver does not actually make every path consistent because its callers use three different conflict predicates: propertyIsEnumerable, key in default, and hasOwnProperty. For example, a non-enumerable own member is overwritten under merge in the addapi/flatten branches, while an inherited class method is treated as a conflict only in the hybrid branches. This contradicts this method’s “same-named own member” contract and makes the result depend on the composition path. Centralize an own-property check (hasOwnProperty) for all call sites before applying the mode.

🧠 Review effort: Balanced

Comment thread src/lib/handlers/unified-wrapper.mjs Resolved
Comment thread src/lib/processors/flatten.mjs Resolved
@Shinrai

Shinrai commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Previously-missed finding from the 83a1b489 review (flatten.mjs:269, three different conflict checks): fixed in 1e61458e. Probing each shape showed real defects, not just inconsistency:

  • A default with a non-enumerable, read-only own member plus a same-named named export failed the load ("Cannot assign to read only property"): propertyIsEnumerable missed the member, then the copy's property was assigned.
  • A class instance's prototype methods never counted, so a named add replaced the instance's add under merge.
  • On the function-default path implToWrap[key] !== undefined counted Function.prototype's call/bind.

Every path now asks Flatten#defaultHasMember: an own property (enumerable or not) or one a prototype the module defines provides; Object.prototype, Function.prototype and Array.prototype are not the default's members. A named export that wins over a read-only member replaces it (Flatten#assignNamedExport) instead of throwing. The probe also exposed a lazy-only divergence: a class-instance default of a folder's same-named file lost its prototype methods when the folder had a sibling (the materializer rebuilt it as a plain object); it is now composed as the instance, members in eager's order. New fixture api_smart_flatten_default_member_conflict, suite smart-flattening-default-member-conflict (48 tests, all 8 configs). Docs: MODULE-STRUCTURE.md and C19 in API-RULES-CONDITIONS.md.

Resolves #583, #584, #586, #587, #588, #589, #590, #594 — closed when this ships to the default branch.

@Shinrai

Shinrai commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Previously-missed items from review 5495524928 (against 8f69631):

  1. inspect-api-structure.mjs:403: the compared shape was cut at the display depth, so eager/lazy differences below it compared equal. Fixed in eabc2b38: every lazy node is loaded at any depth first, and the shape is built with no depth limit. maxDepth now applies only to the printed structure and callable list. Test: "compares the whole shape, below the display depth too" (fixture api_test_special_numbers/nested.mjs). The all-api-structures parity suite still passes with the full-depth comparison (736 + 8).
  2. inspect-api-structure.mjs:566: the callable-paths walk skipped every _-prefixed key. Fixed in eabc2b38: only shutdown is skipped, because framework keys are not on the node's surface. Test: "lists an underscore-prefixed function among the callable paths" (api.nested._hidden()).
  3. composition.mjs:33: the module overview still described the array copy as slice(). Fixed in 2c3a8487: it now describes the copy as keeping elements, holes, other own members and descriptors.

Both tests fail before the fix and pass after.

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

Composition layers currently apply incorrect defaults for omitted property descriptor attributes.

1 open finding

🧠 Review effort: Balanced

Comment thread src/lib/helpers/composition.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

The extensive core composition and lazy-state changes require final human validation, and one documentation inconsistency remains.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity Update stale strategy table for layering and array-copy semantics

tests/​vitests/​suites/​helpers/​composition.test.vitest.mjs:26

The strategy table no longer matches the implementation it documents: plain functions are layered when addsMembers is true, and arrays are copied with all own descriptors rather than via slice. Keeping this table stale makes the helper’s intended identity and descriptor semantics misleading.

🧠 Review effort: Balanced

@Shinrai

Shinrai commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Previously-missed item from review 5496136197 (against 2fa9117):

  • composition.test.vitest.mjs:26: the strategy table was out of date. Fixed in da43792d: a plain function gets a callable layer when named exports are added; an array is copied with its elements, holes, other members and descriptors; a composition layer is copied as a fresh layer over the same value.

Also in this push, 9c748287: tests/validate-typestubs.mjs now stages its consumer (core link + carved @cldmv/slothlet-types) in its own temporary project with its own package.json, and type-checks with --preserveSymlinks. It no longer writes into the project's node_modules. When that folder is shared with another checkout, an interrupted run used to leave the staged copy there, and it was picked up by every other checkout, which broke the "absent" case. An existing @cldmv/slothlet link was also reused as-is, even when it pointed at another tree. If the absent case fails, the message now names any copy installed above the project.

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

Composition layers still mishandle unsafe __proto__ exports, prototype mutation, and stateful Array subclasses.

1 open finding
Previously missed (2)

In code that hasn't changed since last review

Medium severity Refuse unsupported setPrototypeOf mutations

src/​lib/​helpers/​composition.mjs:351

The layer forwards getPrototypeOf but has no setPrototypeOf trap. Consequently Reflect.setPrototypeOf(layer, replacement) succeeds by changing only the shell, while Object.getPrototypeOf(layer) still reports the underlying value's prototype; callers receive success for a mutation that is not observable. Refuse prototype changes, as this layer already refuses preventExtensions, because forwarding the mutation would modify the module export.

Medium severity Layer array subclasses instead of cloning private state

src/​lib/​helpers/​composition.mjs:412

This copies every array by descriptors and then restores its prototype, but that cannot reproduce private fields held by an Array subclass. A default or named export such as class Items extends Array { #tag = "x"; tag() { return this.#tag; } } becomes an Items-looking copy whose tag() throws, just like the class-instance cloning problem this helper avoids. Treat non-plain arrays as stateful instances and layer them instead of copying them.

🧠 Review effort: Balanced

Comment thread src/lib/helpers/reserved-keys.mjs Resolved
@Shinrai

Shinrai commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Previously-missed items from review 5496431181 (against 9c74828):

  1. composition.mjs:351: a layer had no setPrototypeOf trap, so Reflect.setPrototypeOf(layer, other) succeeded but changed only the shell. Fixed in 24d581a2: a change is refused, and setting the prototype it already reports succeeds, as on an object. Test: "refuses changing a layer's prototype…" in helpers/composition.
  2. composition.mjs:412: an Array subclass instance was copied by descriptors, which lost its private fields (tag() threw). Fixed in 24d581a2: it is treated as a class instance, kept as itself and layered when members are added. Only plain arrays are copied. Test: "keeps an Array subclass instance itself…".

Both tests fail before the fix and pass after. The default-shape matrix stays at 168/168.

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

The broad, tightly coupled changes to proxy invariants, collision semantics, ownership, and lazy lifecycle accounting warrant final human validation.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@Shinrai
Shinrai merged commit 316ad56 into next Oct 13, 2026
30 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/structures-test-eager branch October 13, 2026 02:32
Shinrai added a commit that referenced this pull request Nov 16, 2026
A lazy node is built on a function target before what it holds is known,
since a folder may turn out callable, and a Proxy's form is fixed when it
is made. Once it loaded a namespace object it stayed a function:
typeof api.deep was "function" where eager reads "object",
Function.prototype.toString accepted it, and calling it threw
INVALID_CONFIG_NOT_A_FUNCTION instead of the engine's TypeError.

A loaded node holding no function is now rebuilt on eager's object
target, as an array or a primitive already was (#585), and put in its
parent in place of the lazy proxy. A reference taken before the load
keeps the lazy proxy, which forwards to the loaded node.

Fixes #811
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