Repository navigation
feat: colon-safe moduleID resolution and scoped api.remove(moduleID, apiPath) - #306
Conversation
…reload `:` is slothlet's internal composite "moduleID:apiPath" separator. A user (or internal) moduleID that itself contained a colon — e.g. a `vine:abc` namespaced convention — mounted and resolved fine and add() returned the exact id, but the id could not be removed or reloaded by that id: removeApiComponent split the argument on `:` and looked up only the first segment, and child wrappers of a multi-child mount were attributed to the truncated base, so remove() left the subtree behind. The mount was silently unmanageable. - removeApiComponent now resolves an exact registered moduleID verbatim before falling back to the split-based "<base>_<hash>" / composite heuristic, and the no-ownership branch no longer truncates the id on ":". - Base-id recovery no longer splits the composite: tagSystemMetadata stores the raw owning-module id as baseModuleID alongside the composite moduleID, and the two unified-wrapper recovery sites (impl:changed event, child attribution) read it verbatim. This also corrects internal `versionDispatcher:<path>` base ids, which were previously truncated to `versionDispatcher`. The composite stays the per-path user-metadata key; only the fragile colon-split recovery is removed. Adds colon-moduleID round-trip coverage (remove, leaves, reload, reload-then-remove, synthetic, multi-colon, hyphen control). Fixes #303
There was a problem hiding this comment.
Pull request overview
Fixes runtime add/remove/reload behavior when a user-supplied moduleID contains : (which also serves as Slothlet’s internal "moduleID:apiPath" composite separator), ensuring the module ID round-trips verbatim through lifecycle and ownership operations.
Changes:
- Adds a new regression test suite covering
remove(),leaves(), andreload()with colon-containing moduleIDs. - Stores the raw owning module ID separately as
baseModuleIDin system metadata and uses it in wrapper lifecycle/child attribution paths. - Updates
removeApiComponent()to prefer verbatim moduleID matching before applying any “base” heuristics.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/vitests/suites/api-manager/api-manager-colon-module-id.test.vitest.mjs | Adds regression coverage for colon-containing moduleID round-tripping across add/leaves/remove/reload. |
| src/lib/handlers/unified-wrapper.mjs | Switches lifecycle/module attribution to use baseModuleID (colon-safe) rather than splitting composite IDs. |
| src/lib/handlers/metadata.mjs | Persists baseModuleID alongside composite moduleID to allow verbatim module ownership recovery. |
| src/lib/handlers/api-manager.mjs | Adjusts moduleID resolution in removeApiComponent() to avoid truncating colon-containing IDs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Address Copilot review on #306. The verbatim-first match resolves an exact registered id, but the fallback still did `pathOrModuleId.split(":")[0]`, which truncated on ':': `remove("vine:abc")` with only a "vine" module registered matched "vine" and wrongly removed it (returned true, tore down the wrong mount). Match the auto-generated "<id>_<hash>" form of the WHOLE id instead of a ':'-truncated prefix, so a colon-containing id never collides with a shorter base. Adds a regression test asserting remove("vine:abc") leaves a registered "vine" mount untouched (and the real id still removes it).
remove(id) removes every path a module owns and remove(apiPath) removes that path's whole subtree regardless of which module owns each node, so neither can surgically remove a single module's node at a shared path — e.g. two modules mounted under the same namespace, or one moduleID reused across mounts. Add an optional second argument: remove(moduleID, apiPath) resolves the first argument strictly as a moduleID, verifies it owns apiPath, and removes only that node — sibling modules sharing the mount and the module's other mounts are left intact. Returns whether anything was removed; the single-argument forms are unchanged. Routes through the existing single-node removal path.
|
Auto-normalized PR title: rewrote PR title to match the highest-priority commit type (
If this isn't what you want, edit the title — the normalizer won't re-fire as long as the title stays conventional. |
…ng on ':'
The previous fallback dropped colon handling entirely to stop remove("vine:abc")
from truncating to a registered "vine". But a leaf's __metadata.moduleID is the
internal composite "<moduleID>:<apiPath-with-slashes>", and remove(meta.moduleID)
is a supported call — dropping the split broke removing a module by that
composite (metadata-collision-modes).
Restore composite resolution safely: match a registered module whose id is the
':'-delimited prefix ONLY when it actually owns the apiPath encoded in the
suffix. That ownership check distinguishes a real composite (base owns the path)
from a bare user id that merely contains ':' (a "vine:abc" whose "abc" no "vine"
owns still resolves to nothing, not to "vine"). Verbatim and "<id>_<hash>"
matches still run first.
…h composite Replace ':' as slothlet's internal composite separator with a reserved token (MODULE_ID_SEPARATOR = "__slothlet_sep__"). A ':' is common in real module ids — a `vine:abc` namespacing convention, the internal `versionDispatcher:<path>` id — so using it as the splitter made those ids un-round-trippable and forced fragile disambiguation. With a reserved token no module id may contain, the composite is always unambiguous to split and ':' (and every other character) is free. - metadata.mjs builds the composite with MODULE_ID_SEPARATOR (exported). - add() refuses a moduleID containing the separator (MODULE_ID_RESERVED_SEPARATOR, all 12 locales) — the only token a module id may not contain. - removeApiComponent recovers the base by splitting on the separator: a plain id (which cannot contain it) is preserved intact, a composite strips to its base. Drops the earlier ':'-specific verbatim/ownership-verified workarounds. - Update the metadata format tests (system-metadata, user-metadata) that pinned the old `prefix:apiPath` shape to the new separator; they now assert structure via the imported constant. __metadata.moduleID reads e.g. "modm__slothlet_sep__m/leaf". Fixes #303
…rator) Address Copilot review on #306. The doc block still described a Promise<void> return and an underscore-based moduleID heuristic. Document the boolean return, the options argument (scopedApiPath / recordHistory), and that the argument is resolved by splitting on the reserved composite separator — matching the current behavior.
…d separator Address Copilot review on #306. add() rejected a user-supplied moduleID containing MODULE_ID_SEPARATOR, but a default moduleID is derived from the apiPath (buildDefaultModuleId), so mounting at an apiPath whose segment carries the separator produced an auto-generated id containing it — breaking the "no moduleID contains the separator" invariant that remove()/metadata splitting rely on. Check the effective moduleID (user-supplied or auto-generated) once it is finalized and refuse it with MODULE_ID_RESERVED_SEPARATOR. Adds a regression test for the no-moduleID (apiPath-carries-separator) case.
A module's id survives a reload — the "add" op records options.moduleID and
addApiComponent reuses it on re-add (user-supplied and auto-generated
<path>_<hash> ids alike; the "replay_<hash>" param the replay passed was dead,
addApiComponent has no top-level moduleID param). So a scoped removal CAN be
replayed by id, contrary to the earlier assumption.
Record scoped removals as {type:"remove", apiPath, scopedModuleID} (honoring
recordHistory), and replay them via the two-argument
removeApiComponent(scopedModuleID, {scopedApiPath}) so only that module's nodes
go — not the whole path. Verified end-to-end: after a reload, remove(modA,"shop")
keeps modA's subtree gone while modB's survives (no over-delete). Also drop the
dead replay_<hash> param and correct the replay comment. Adds a reload-
persistence test.
…estore revert
Synthetic (in-memory) adds — an inline function, an export map, or a
`{ exports, ...options }` object — now record their original inline value as the
replay folderPath instead of the internal `synthetic:<path>` sentinel, which a
full-instance reload() would otherwise resolve as a filesystem path and fail on.
A synthetic add (and a scoped removal of one) now survives reload(), keeping its
moduleID so it stays removable afterward. restoreApiPath re-adds via the same
recorded folderPath, so ownership rollback of a synthetic mount is consistent too.
Also cover the scoped-removal restore branch that had no test: a shadowed-node
case drives the revert-to-previous-owner path, and the dead else fallback now
uses `/* v8 ignore else */` with an honest unreachability comment (a node whose
removePath returns "restore" always has a concrete current value, so the else
never runs) instead of a `never exercised in tests` justification.
…with honest, reachability-based ones The removeApiComponent apiPath+moduleID restore path was hidden behind a whole-block `/* v8 ignore */` labelled "never triggered in tests", but its restore branch IS reachable and already covered by the stacked-remove-by-apiPath tests — the ignore was burying tested code. Expose it and ignore only the genuinely-dead parts precisely: `/* v8 ignore else */` on the always-true action and value checks, and a scoped ignore on the none/return-false tail that cannot run (in that branch moduleID is always the path's current owner, so removePath yields "delete" or "restore", never "none"). The apiPath-only restore block and restoreApiPath are genuinely unreachable, but were justified with "tests never trigger" wording. Restate the real reasons: the apiPath-only branch runs only when the ownership handler is absent, which forces action "none"; and restoreApiPath's four call sites are all in unreachable branches (each restore fallback, which never fires because a restored node always resolves to a concrete value, and the reload zero-affected-caches path, guarded by an INVALID_API_PATH throw and the always-present base "." module). Consolidate restoreApiPath's scattered per-line ignores into one honest whole-body ignore. No behaviour change; full coverage remains 100% (the exposed restore path is covered).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 23 changed files in this pull request and generated no new comments.
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
src/lib/i18n/languages/pt-br.json:67
- Sentence starts with a lowercase article; capitalize it for correct Portuguese grammar.
"HINT_MODULE_ID_RESERVED_SEPARATOR": "o slothlet une internamente o ID e o caminho de API de um módulo com este token; um ID de módulo que o contenha corromperia essa chave. Escolha outro ID.",
src/lib/handlers/api-manager.mjs:1508
MODULE_ID_SEPARATORis treated as a reserved delimiter for resolvingremove()arguments (moduleID vs composite metadata). HowevernormalizeApiPath()currently allows the separator token inside anapiPathwhen the caller supplies an explicitmoduleID. That makesremoveApiComponent(pathOrModuleId)ambiguous: callingremove("seg__slothlet_sep__ment")can be mis-resolved as moduleID"seg"(viasplit(MODULE_ID_SEPARATOR)[0]) and remove the wrong module.
Please reject apiPaths containing MODULE_ID_SEPARATOR at add-time (regardless of whether options.moduleID is supplied), and add a regression test that api.add(<apiPath with separator>, ..., { moduleID: "..." }) rejects with an appropriate validation error.
const { apiPath: normalizedPath, parts } = this.normalizeApiPath(apiPath);
…ly the moduleID (#306 review) A user-supplied clean moduleID let a separator-bearing apiPath slip past the moduleID-only guards, so `add("x__slothlet_sep__y", fn, { moduleID: "clean" })` was accepted and a later `remove("seg__slothlet_sep__y")` split the argument on the reserved separator and removed the wrong module ("seg"). Reject an apiPath containing MODULE_ID_SEPARATOR at add-time: when an explicit moduleID is supplied the offending token is the path itself, so it surfaces as INVALID_CONFIG_API_PATH_INVALID with a new API_PATH_REASON_RESERVED_SEPARATOR reason (added to all 12 locales) rather than the moduleID-framed error, which the auto-generated-id guard still covers for the no-moduleID case. Regression test added. Also fix the pt-br HINT_MODULE_ID_RESERVED_SEPARATOR, which uniquely began with a lowercase article ("o slothlet"); drop it so the hint starts with the brand token like the other 11 locales (the fleet convention), rather than capitalizing it.
|
Addressed the two suppressed findings from the latest review (#pullrequestreview-5020148506) in
|
|
Resolves #303 — closed when this ships to the default branch. |
… reload A scoped remove(moduleID, apiPath) that empties the module intermittently failed to persist across a reload under lazy mode: the removed subtree reappeared on next access. Root cause is a materialization race in the reload replay. When the replayed add re-mounts a directory under lazy, only the eagerly-known paths register (e.g. shop, shop.a, shop.a.interop and the leaf branches); a lazy submodule's own leaves (shop.a.interop.interopCjs.*) are not yet registered. The scoped remove computes its target list from the module's owned paths, then walks it — and tearing down the lazy shop.a.interop node materializes it, which registers those previously- unregistered descendants AFTER the target list was fixed. On a reload replay those late registrations leak back and resurrect the subtree. Fix: when a scoped removal empties the module (it owns nothing outside the scoped path), block it from further registration BEFORE the walk via a new ownership.markUnregistered(), so register() rejects the late materialization-driven registrations. Gated to full removals only: a partial removal keeps sibling paths outside the scoped node that must still be able to materialize, so it is not blocked. Reverts of shared nodes use the previous owner's id and are unaffected. Cleared on the next reload (ownership.clear()), matching the moduleID-only remove's async-race guard. Verified: the remove-scoped suite is 0/16 across repeated runs (was ~1/12), and a 300-iteration in-process reload loop is clean across 8 runs (~2400 iterations) where it previously failed within 3-17 iterations every run. Eager was never affected. Full coverage remains 100%.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 24 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
src/lib/handlers/api-manager.mjs:1519
- This apiPath reserved-separator guard is also currently gated on
typeof restOptions.moduleID === "string". Since moduleID is later coerced to a string anyway, a non-string truthy moduleID (e.g. a number) will skip this validation and allow an apiPath containing the reserved separator token, which can break remove()/leaves() resolution. Gate on the presence of moduleID rather than its pre-coercion type.
if (typeof restOptions.moduleID === "string" && normalizedPath.includes(MODULE_ID_SEPARATOR)) {
const segIndex = parts.findIndex((p) => p.includes(MODULE_ID_SEPARATOR));
throw new this.SlothletError("INVALID_CONFIG_API_PATH_INVALID", {
apiPath: normalizedPath,
segment: parts[segIndex],
…non-string moduleID (#306 review) Both add-time reserved-separator guards were gated on `typeof restOptions.moduleID === "string"`. add() coerces moduleID with String(...) later, so a non-string truthy moduleID (e.g. a number) skipped the guards — a separator-bearing apiPath would then slip through and reintroduce the wrong-module removal on remove(). Coerce to string and gate on presence instead: the moduleID guard checks String(moduleID).includes(separator) (and reports the coerced value), and the apiPath guard fires whenever a moduleID is supplied regardless of its type. Regression test added.
|
Addressed the suppressed finding from |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 24 changed files in this pull request and generated 1 comment.
Suppressed comments (3)
Previously missed (3) — in code that hasn't changed since the last review.
src/lib/handlers/api-manager.mjs:2514
- In the scoped remove(moduleID, apiPath) branch, a scoped removal that fully empties a module marks it unregistered, but it does not clear the module’s endpoint from ownership.moduleEndpoints. Since OwnershipManager.removePath() deletes moduleToPath entries when the last path is removed (but does not delete moduleEndpoints), this leaves stale endpoint entries behind until the next ownership.clear() (reload), causing unnecessary memory growth and stale endpoint data.
const isFullRemoval = [...ownedPaths].every((p) => p === normalizedScoped || p.startsWith(scopedPrefix));
if (isFullRemoval) {
ownership?.markUnregistered?.(scopedModuleIDKey);
}
tests/vitests/suites/api-manager/api-manager-synthetic-reload.test.vitest.mjs:9
- The header timestamp epoch in parentheses does not match the ISO datetime shown (1756022400 corresponds to 2025-08-24T00:00:00-08:00, not 2026-08-24T00:00:00-08:00). This makes the file metadata internally inconsistent.
* @Date: 2026-08-24T00:00:00-08:00 (1756022400)
tests/vitests/suites/api-manager/api-manager-remove-scoped.test.vitest.mjs:9
- The header timestamp epoch in parentheses does not match the ISO datetime shown (1756022400 corresponds to 2025-08-24T00:00:00-08:00, not 2026-08-24T00:00:00-08:00). This makes the file metadata internally inconsistent.
* @Date: 2026-08-24T00:00:00-08:00 (1756022400)
…t test header epochs (#306 review) A scoped remove(moduleID, apiPath) that empties a module marked it unregistered but left its ownership.moduleEndpoints entry behind — removePath() deletes the emptied moduleToPath set but not the endpoint, and the moduleID-only unregister() does delete it, so the scoped full-removal leaked a stale endpoint until the next reload. markUnregistered() now also deletes the endpoint (it is only called when a module is fully gone). Regression test added. Also fix the parenthesized epoch in three test-file headers: 1756022400 is 2025-08-24, not the 2026-08-24 ISO shown. (A repo-wide epoch/ISO drift exists across ~49 files; a checker/corrector is requested upstream in CLDMV/fix-headers#31 and will be swept separately.)
|
Addressed the 3 suppressed findings from
|
On slothlet <3.15.0, a base api.slothlet.api.reload() on the GROW side silently dropped synthetic (bare-function) add() mounts from its replay - a host reloading itself for reasons unrelated to the vine would lose every mounted stub with no error and no link.close() ever firing. Fixed upstream in CLDMV/slothlet#306. This required no vine code change; the test exists so a regression upstream is caught here rather than shipping quietly.
🚀 What's Changed
💥 Breaking Changes
No breaking changes
✨ Features
🐛 Bug Fixes
📦 Dependencies
No dependency updates
🔧 Other Changes
👥 Contributors