Skip to content

fix(browser): eager-mode api.remove now deletes the mount + fires impl:removed - #126

Merged
Shinrai merged 10 commits into
nextfrom
fix/browser-mode-node-imports
May 31, 2026
Merged

Shinrai merged 10 commits into
nextfrom
fix/browser-mode-node-imports

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

🔧 Other Changes

👥 Contributors

Shinrai added 3 commits May 30, 2026 10:36
…ntext crash (#123)

Browser mode (v3.9.0) couldn't load: top-level static node:* imports across ~14 modules broke ESM parse in a browser, and once past that the first self/context access in live mode crashed dereferencing a null AsyncLocalStorage.

- platform.mjs: single source of truth for node-vs-browser host differences (isNode + lazily-imported builtins/shims + host-polymorphic loadJson). The affected modules use plain static imports from it; no node:* specifier enters the browser graph.
- Fix the live-mode crash: AsyncContextManager.tryGetContext() guards a null ALS so the runtime dispatcher's probe is browser-safe.
- Browser i18n: navigator-based detection, async setLanguageAsync, locale files exported at @cldmv/slothlet/i18n/language/*.
- engines.node >= 22 (Node 20 EOL; keeps the JSON import attribute warning-free).
- Tests: real-Chromium Playwright smoke (self/hooks/permissions/metadata/i18n/events/api.add), static loadability test, KNOWN_LOCALES drift guard, setLanguageAsync coverage.

Full Node suite green (11085/0); coverage 99.93/99.92/100/100.
Harden browser mode (shipped under-tested in v3.9.0) so context, permissions,
self, hooks (error/suppressErrors), metadata, lifecycle events, and api
mutations run in `npm run coverage`, not only the Chromium smoke. Adds a
runtime-probe fixture (context/self/caller via the live runtime) and a
browser-only v8-ignore policy note in platform.mjs.

These suites surface pre-existing eager+browser findings (api.remove and
impl:removed no-op on eager mounts; full-instance reload config guard) which
are tracked for follow-up fixes; the mutations suite's mode labels and the
two remove assertions are corrected alongside the ownership fix.
…l:removed

In eager+browser mode, api.add re-runs the eager build, and
UnifiedWrapper.___createChildWrapper derived the child moduleID from the shared
leaf functions' existing metadata. For a base leaf re-mounted at a new path that
metadata is base_slothlet, so ownership stacked the new module over base and
api.remove rolled the leaves back to base instead of deleting them — the mount
stayed readable and impl:removed never fired (lazy and node modes were
unaffected). Prefer the parent/build owner (one buildAPI builds exactly one
module's subtree).

Tests + coverage:
- browser-mutations: drop the green-pinned "FINDING" and its config-destructuring
  bug (it passed the {name,config} wrapper to browserCfg, so every standalone case
  ran eager); assert remove() clears the property across the full matrix.
- browser-events: expand impl:removed from lazy-only to the full matrix.
- Close 3 pre-existing coverage gaps to 100% statements + branches:
  eventemitter-context untrack guard (justified ignore matching its siblings),
  module-discovery dot-dir skip (add the missing .hidden-dir fixture so the
  existing test exercises line 349), typescript cache-write non-EEXIST rethrow
  (fault-injection test).
- run-all-vitest: per-file heap override for metadata-edge-cases (already solo;
  ~1.2GB peak intermittently OOM-flaked under coverage instrumentation).

Full node suite green (313 files, 0 failures); coverage 100%.
@cldmv-bot cldmv-bot Bot added area: core type: dependencies Relates to dependency updates, version bumps, or package management labels May 30, 2026
@Shinrai
Shinrai requested a review from Copilot May 30, 2026 22:27
…ed config (#91)

transformConfig's browser guard rejected a null resolveModuleSpecifier, but the
config normalization stores `?? null` for "no override". reload() re-feeds the
already-normalized config into load() -> transformConfig, so a browser instance
created without a resolveModuleSpecifier (stored as null) threw
INVALID_CONFIG_BROWSER_RESOLVE_SPECIFIER_INVALID on reload. Treat null like
undefined (both mean "use the default resolver"), matching the versionDispatcher
guard at config.mjs:428 -- transformConfig is now idempotent.

browser-mutations: replace the characterization test that pinned the throw with
full-matrix assertions that reload() re-composes the api (fresh instanceID and
keepInstanceID:true), and flip the fileoverview note.

This comment was marked as resolved.

Shinrai added 2 commits May 30, 2026 16:07
…uage consistent

PR review follow-ups:
- shutdown() ran the TS transform-cache cleanup unconditionally; `fsp` is null in a
  browser (helpers/platform), so it could TypeError in a real browser/Electron renderer.
  Guard with `isNode` to match the reload-time cleanup (slothlet.mjs:788).
- setLanguageAsync() reset translations to the bundled English defaults but only updated
  currentLanguage after the await resolved, so getLanguage() reported the stale prior
  locale while the (async, in a browser) load was pending. Set currentLanguage to "en-us"
  up front so it stays consistent with the active translations; success overwrites it.
  The browser setLanguage() branch inherits this via `void setLanguageAsync`.
The #123 consolidation added src/lib/helpers/platform.mjs and i18n setLanguageAsync but
never regenerated the checked-in declarations, so `@cldmv/slothlet/helpers/platform` had no
types/src/lib/helpers/platform.d.mts and translations.d.mts was absent. Regenerate via
`npm run build:types`; resyncs the declarations the consolidation touched. Validated with
`npm run test:types` (51 exports).

This comment was marked as resolved.

…redundant runtime axis

Browser forces the live context manager (no AsyncLocalStorage, #123), so the
browser suites' full async/live matrix was redundant: a runtime:"async" config
is silently coerced to live, re-running live configs under a misleading name.

- Add getBrowserMatrixConfigs() (live-only, mode×hooks, "_LIVE" token dropped);
  switch all 11 browser suites; drop the now-moot runtime keys in
  browser-mutations' targeted configs.
- Assert the async->live coercion explicitly, once (browser-context), instead of
  smearing a fictional "async browser" runtime across the whole matrix.
- Fix browser-context "concurrent context.run() stay isolated": it asserted an
  ALS-only invariant the live manager cannot provide (a single global
  currentInstanceID is overwritten across an await by a sibling run()). Now
  asserts live's real guarantee - sequential run() isolation with base restored
  between calls. Interleaved concurrency stays covered by the Node async (ALS)
  runtime in context/per-request-context.
- Document the boundary: LiveContextManager JSDoc + docs/CONTEXT-PROPAGATION.md;
  regenerate the context-live type declaration.

No production behavior change (context-live.mjs is JSDoc-only). Full coverage
gate: 100% statements/branches/functions/lines, 0 failures.
@cldmv-bot cldmv-bot Bot added the type: documentation Relates to docs, README updates, guides, or inline code comments label May 31, 2026
@Shinrai
Shinrai requested a review from Copilot May 31, 2026 02:51
@Shinrai Shinrai self-assigned this May 31, 2026

This comment was marked as resolved.

Shinrai added 3 commits May 30, 2026 20:16
…g); refresh README What's New

v3.9.0 shipped browser mode (#119/#116) but never got a changelog or a README
update; v3.9.1 (this PR) had neither yet. Back-fill both and bring the README
"What's New" section current.

- docs/changelog/v3/v3.9.0.md — browser/worker mode introduction: manifest-based
  api loading (no fs), generateManifest() build-time helper, platform vs env
  split, dir->base migration, suppressFixes (C03), security/CodeQL fixes.
- docs/changelog/v3/v3.9.1.md — browser-mode hardening: #123 live-binding
  self/context crash (node:* gating consolidated into a platform helper), #91
  full-instance reload(), eager api.remove mount deletion + impl:removed, browser
  shutdown crash, i18n currentLanguage consistency; new setLanguageAsync(); Node
  minimum raised to 22 (import attributes for bundled i18n — noted, shipped as a
  patch by decision); CodeQL cleanup (#122); browser test suites + matrix sweep.
- README: Latest -> v3.9.1; Recent Releases -> v3.9.0, v3.8.0, v3.7.0, v3.6.0
  (4-entry cap per readme-whats-new rules; v3.5.1/v3.5.0 drop off).
The resolved node:* builtins in helpers/platform are `let x = null` reassigned
inside the isNode block, so tsc inferred the declared type as `null` — a TS
consumer importing e.g. `fs` saw a non-callable `null`. Annotate them `any` via
source JSDoc and regenerate declarations. Not `typeof import("node:*")`: that
would force @types/node onto every consumer (including browser) and fails the
no-extra-types export validation. (PR review)
…d import

The #123 loadability scan silently continued on an Acorn parse failure, so a
reachable module the parser can't read would be dropped from the graph walk —
hiding a potential top-level node:* import. It now collects parse failures and
asserts none, skipping only `.json` data leaves (browser-safe, not JS, can't
carry node:* imports). Also removes an unused `relative` import from the
Playwright smoke test. (PR review)
@Shinrai
Shinrai merged commit 53c7fb2 into next May 31, 2026
19 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/browser-mode-node-imports branch May 31, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: dependencies Relates to dependency updates, version bumps, or package management 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.

BUG: @cldmv/slothlet 3.9.0 — platform: "browser" cannot actually be loaded by a browser

2 participants