fix(fs): restore fs/promises parity (#6785) - #6820
Conversation
📝 WalkthroughWalkthroughThe compiler now installs the Changesfs.promises parity
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant EntryModule
participant collect_modules
participant CompilationContext
EntryModule->>collect_modules: provide lowered imports and class bodies
collect_modules->>CompilationContext: enable uses_regex for fs/promises glob
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
crates/perry-codegen/tests/native_proof_regressions.rs (1)
2076-2093: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftPrefer a PR-visible test location for this regression.
This file is under
crates/perry-codegen/tests, an integration suite that does not run on every PR. Move the assertion into cargo-test-visible unit coverage, or explicitly wire this target into the PR test matrix.As per coding guidelines, integration suites under
crates/*/tests/*.rsdo not run on every PR; prefer acceptance coverage in cargo-test-visible unit tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/perry-codegen/tests/native_proof_regressions.rs` around lines 2076 - 2093, Move the regression test fs_parent_promises_property_installs_submodule_dispatch from the crates/perry-codegen/tests integration suite into cargo-test-visible unit coverage, preserving both IR assertions for fs.promises submodule installation and native-module property resolution; alternatively, explicitly add this integration target to the PR test matrix.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/perry-codegen/tests/native_proof_regressions.rs`:
- Around line 2085-2091: Update the assertions in the fs.promises regression
test to compare the positions of the `js_node_submod_install_fs_promises` and
`js_native_module_property_by_name` calls in the generated IR. Assert that the
installation call occurs before property resolution, while preserving the
existing presence checks and diagnostic messages.
In `@crates/perry/src/commands/compile/collect_modules/feature_detect.rs`:
- Around line 131-136: Update the feature-detection logic surrounding the HIR
debug check to identify glob references using structured HIR or module metadata
that confirms the source is node:fs/promises, rather than matching the bare
name: "glob" token. Ensure unrelated external imports such as ./util do not
enable the optional regex engine, while genuine node:fs/promises glob imports
continue to do so.
- Around line 131-136: Update the HIR serialization used by the regex scan in
the feature-detection logic to include hir_module.classes alongside init and
functions. Ensure class bodies, including instance and static methods, are
represented before checking for the exact `name: "glob"` marker so
ctx.uses_regex is set for node:fs/promises.glob usage.
---
Nitpick comments:
In `@crates/perry-codegen/tests/native_proof_regressions.rs`:
- Around line 2076-2093: Move the regression test
fs_parent_promises_property_installs_submodule_dispatch from the
crates/perry-codegen/tests integration suite into cargo-test-visible unit
coverage, preserving both IR assertions for fs.promises submodule installation
and native-module property resolution; alternatively, explicitly add this
integration target to the PR test matrix.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 22795d41-14be-4a82-a90c-c541aff873e4
📒 Files selected for processing (5)
changelog.d/6785-fs-promises-parity.mdcrates/perry-codegen/src/expr/property_get.rscrates/perry-codegen/tests/native_proof_regressions.rscrates/perry/src/commands/compile/collect_modules/feature_detect.rscrates/perry/src/commands/compile/collect_modules/tests.rs
4dc0308 to
f653e2c
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/perry/src/commands/compile/collect_modules/tests.rs (1)
140-182: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a regression that actually depends on scanning class bodies.
This assertion stays true if
hir_module.classesis removed from the scan becauseimports_fs_promises_globdetects the import independently. Add a separate class-only HIR trigger—such as a namespacefs.promises.globproperty read inScanner.scan—so the test fails if class traversal regresses.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/perry/src/commands/compile/collect_modules/tests.rs` around lines 140 - 182, Add a class-only HIR trigger to fs_promises_named_glob_in_class_enables_regex_engine by referencing a namespace-style fs.promises.glob property inside Scanner.scan, ensuring the assertion depends on class-body traversal rather than only imports_fs_promises_glob. Keep the existing aliased import and regex assertion intact, and ensure the added expression is the sole trigger that would fail if hir_module.classes scanning is removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/perry/src/commands/compile/collect_modules/tests.rs`:
- Around line 140-182: Add a class-only HIR trigger to
fs_promises_named_glob_in_class_enables_regex_engine by referencing a
namespace-style fs.promises.glob property inside Scanner.scan, ensuring the
assertion depends on class-body traversal rather than only
imports_fs_promises_glob. Keep the existing aliased import and regex assertion
intact, and ensure the added expression is the sole trigger that would fail if
hir_module.classes scanning is removed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9faf39fd-3eca-43f8-b2e8-bc2307c8f9b9
📒 Files selected for processing (5)
changelog.d/6785-fs-promises-parity.mdcrates/perry-codegen/src/expr/property_get.rscrates/perry-codegen/src/expr/property_get/tests.rscrates/perry/src/commands/compile/collect_modules/feature_detect.rscrates/perry/src/commands/compile/collect_modules/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- changelog.d/6785-fs-promises-parity.md
- crates/perry-codegen/src/expr/property_get.rs
Closes #6785.
What changed
ExternFuncRef { name: "glob" }HIR shape produced by namednode:fs/promisesimports, so auto-optimized builds retainperry-runtime/regex-engine.js_node_submod_install_fs_promises()before materializing the parentfs.promisesproperty. This populates callable namespace fields for destructuring/indirect calls while preserving dead stripping for programs that only use synchronousnode:fs.Baseline evidence
The issue's abbreviated report hid the actual deltas:
glob/async-iterator: the iterator shape was present, but every valid glob yielded no matches andnulloptions were not validated because the regex-backed implementation was compiled out.imports/parent-promises-property:fs.promiseswas an object, butopen,readFile,writeFile,mkdir, andrmall read asundefined; callingopenthen rejected withTypeError: value is not a function.Validation
cargo fmt --all -- --checkcargo test -p perry-codegen --test native_proof_regressions fs_parent_promises_property_installs_submodule_dispatch -- --exactCARGO_PROFILE_DEV_DEBUG=0 CARGO_INCREMENTAL=0 cargo check -p perry --bin perryperry-runtimefeature set (dyn-eval,full,regex-engine,stdlib), confirming the runtime glob path selected by this detector. The shared volume filled while LLVM emitted the final static archives, so the complete executable comparison is left to CI.Summary by CodeRabbit
Bug Fixes
node:fs/promises.globin auto-optimized builds.fs.promisesmethods are available when accessed through the parentfs.promisesnamespace.node:fs/promises.globusage, including imports within class methods, so the required glob engine is enabled reliably.Tests
globimports.fs.promisesproperty resolution.