ReviewOS

home-lang/home

Port Bun mock.module dynamic, spy, and live-binding matrix

#125
Closed chris opened this 9 days ago ·
9 days ago

Scope

Port the byte-identical js/bun/test/mock/mock-module.test.ts corpus and its three TypeScript fixtures. The file contains nine active tests plus one upstream todo.

This is the broader follow-on to #122 and #124, covering:

  • async mock factories
  • mock.restore and spyOn namespace restoration
  • nonexistent package and relative module mocks
  • file URL mock resolution
  • require/import/require.resolve agreement
  • repeated local module replacement with live imported bindings and re-exports
  • repeated package replacement through an existing dynamic namespace
  • builtin aliasing between fs/promises and node:fs/promises

Baseline

Home currently rewrites the whole file to one native todo:

  • 0 pass
  • 0 fail
  • 0 unsupported
  • 1 native todo

Acceptance

  • Keep the corpus file and fixtures byte-identical to Bun.
  • Run all nine active upstream tests as real tests.
  • Preserve the single upstream todo without introducing Home-native todos.
  • Implement stable live namespaces, lazy async factory handling, module overlay semantics, spy restoration, canonical builtin mock keys, and consistent require/import mock lookup.
  • Add a permanent unchanged-corpus regression.
  • Pass the exact file and full home_test gate.
  • Commit and push as Chris Breuer with no coauthors.
  • Link completion to #66.
9 days ago

Implemented and pushed in b15c3f7.

The byte-identical mock-module.test.ts corpus and all three fixtures now run through the Home bridge. The implementation adds:

  • canonical mock keys for fs/promises and node:fs/promises
  • lazy async factory normalization and caching
  • descriptor-preserving mock overlays on original namespaces
  • stable live dynamic namespaces across repeated replacements
  • shared mock lookup for import, dynamic import, require, and require.resolve
  • relative file URL normalization
  • mock.restore spy restoration
  • live local imports, re-export aliases, and originating re-export cell propagation

Validation:

  • exact mock-module.test.ts: 9 pass, 0 fail, 0 unsupported, 1 upstream todo
  • prior mock/6874: A 1/1 and B 1/1
  • prior mock/6879: 2/2
  • permanent unchanged-corpus regression asserts the 9-pass/1-upstream-todo shape
  • all four corpus files are byte-identical to Bun
  • formatting and diff checks pass
  • full home_test gate passes with no failures

The commit is authored and committed as Chris Breuer with no coauthors. This follows #122 and #124 and advances #66.

Sign in to comment on this issue.