ISSUE DESCRIPTION Node API checker: namespace reads of absent builtin exports should…
- User
ISSUE DESCRIPTION
Node API checker: namespace reads of absent builtin exports should return undefined
Summary
Perry's strict built-in API gate currently rejects some namespace property reads that Node treats as ordinary JavaScript property misses returning
undefined.This surfaced in the curated DNS constants fixture on current
origin/main@22824ba90abf:node:dns/promisesintentionally does not exportADDRCONFIG,V4MAPPED, orALL, but reading those properties from the namespace object is valid in Node and returnsundefined. Perry rejects the property read at check/lower time before the runtime can produce the matching value.This is separate from named ESM import validation. Node rejects
import { ADDRCONFIG } from "node:dns/promises", and Perry should continue not claiming that named export. The compatibility gap is namespace/property-read semantics.Local evidence
Current main:
22824ba90abf Expose globalThis.EventTarget (#3628)Node v25.9.0 behavior for the namespace object:
$ node -e 'import("node:dns/promises").then(m=>{for (const k of ["ADDRCONFIG","V4MAPPED","ALL","NODATA","CANCELLED"]){console.log(k, Object.prototype.hasOwnProperty.call(m,k), k in m, typeof m[k], m[k]);}})' ADDRCONFIG false false undefined undefined V4MAPPED false false undefined undefined ALL false false undefined undefined NODATA true true string ENODATA CANCELLED true true string ECANCELLEDNode rejects the corresponding named import, which is correct and should remain true:
$ node --input-type=module -e 'import { ADDRCONFIG } from "node:dns/promises"; console.log(ADDRCONFIG)' SyntaxError: The requested module 'node:dns/promises' does not provide an export named 'ADDRCONFIG'Perry currently rejects the namespace property read in the curated fixture:
$ target/release/perry check test-parity/node-suite/dns/constants/error-aliases.ts error[U006]: `dns/promises.ADDRCONFIG` is not implemented in Perry — see `perry --print-api-manifest` for the supported surface, or set `PERRY_ALLOW_UNIMPLEMENTED=1` to ignore. (#463) --> test-parity/node-suite/dns/constants/error-aliases.ts:9:48The manifest matches Node for named exports:
dns/promisesincludes DNS error aliases likeNODATAandCANCELLED, but does not includeADDRCONFIG,V4MAPPED, orALL.With the gate bypassed, Perry's runtime output matches Node for this fixture, including the absent namespace properties:
Assistant
Let me start by understanding the repository structure and the issue. The issue is about Node API checker: namespace reads of absent builtin exports should return
undefinedinstead of producing an error.Let me explore the repository structure first, then look at the specific file mentioned:
crates/perry-hir/src/lower/expr_member.rs.Let me also reproduce the error first.
Assistant
Let me look at the specific file mentioned in the issue and the test fixture.
Assistant
Let me do one command at a time.
Assistant
Let me look at the specific section where the namespace property read gate is implemented. Let me search for relevant patterns
Assistant
Let me look at the section around line 1741 where the critical code is:
Assistant
Now let me look at the test fixture:
Assistant
Let me reproduce the error first. Let me build and run the check:
Assistant
Let me look at how
lookup_native_moduleworks and understand the distinction between namespace and named imports betterAssistant
Let me look at the
lookup_native_modulefunction.Assistant
Let me check how method calls are handled — is there a separate gate in `lower_call
Assistant
Let me check the API manifest to understand what's registered
Assistant
Let me see more of the dns entries, especially constants
Assistant
Let me look at how method calls to native modules are lowered and where their
Assistant
Let me see the context around line 1300-1350 in native_module.rs
Assistant
Let me see the full
obj_is_named_importcheck with surrounding context for all the matchAssistant
Let me search for where
NativeModuleRefis createdAssistant
Let me search differently.
Assistant
Let me first try to build perry to reproduce the error.
Assistant
Let me check the available toolchain
Assistant
Let me check if there's a pre-built binary already
Assistant
Let me check if rustup is available
Assistant
Let me install the Rust toolchain
Assistant
Now let's build perry and reproduce the error
Assistant
Now let me reproduce the error with the check command
Assistant
Let me try with the flag to skip the prompt
Assistant
I've reproduced the error. Let me also verify that bypassing the gate works
Assistant
Good - I've confirmed the error. Now let me implement the fix. The issue is in the gate at line 1813 of
expr_member.rs. I need to also skip the gate when the object is a namespace import (not just a named import). Let me look at the exact code and make the editAssistant
Let me edit the file directly. First, let me see the exact lines I need to change
Assistant
Now I need to add a check for namespace imports. I'll add a
obj_is_namespace_importvariable parallel toobj_is_named_import.Assistant
I need to use the heredoc syntax for multi-line edits. Let me try again
Assistant
Let me try a different approach. I'll use the replace command to add the namespace import check, and then separately modify the condition
Assistant
Let me use sed to make the changes precisely. First, let me get the exact line numbers
Assistant
Let me escape the special
Assistant
Let me use Python to make the edit precisely since the file is complex
Assistant
Let me verify the edit looks correct
Assistant
The edit looks correct. Now let me build and
Assistant
Build succeeded. Now let me test the fix
Assistant
The check passes! Now let me verify that named imports for absent exports are still rejected. Let me create a quick
Assistant
Named imports still rejected properly. Now let me verify that unsupported method calls still
Assistant
Let me use a separate directory for the
Assistant
Hmm, the method call passed. Let me check if
fsis in theAssistant
Let me check how the call path handles namespace-import method calls
Assistant
Let me search for how the call path handles
NativeModuleRefinAssistant
Let me search for how the call path handles namespace import method calls
Assistant
Let me look at the lower_call entry point
Assistant
Let me look at how
lower_call_innerhandles theAssistant
Let me continue reading the lower_call flow
Assistant
Let me look at
try_native_module_methodsfor the gateAssistant
Let me test with a more specific module that has manifest
Assistant
Let me test with
fs- it's in the handled list so it might behave differently. Let me check what actuallyAssistant
Let me use a fresh directory with a single file
Assistant
Let me check if the original code catches
fs.notARealMethod()by reverting temporarilyAssistant
Let me stash my changes, test the original code, then
Assistant
Now test the old behavior
Assistant
Let me understand the issue better. When my fix skips the member gate for namespace imports,
fs.notARealMethod()passes through. But the call path only catches this for non-handled modules. Let me look at which modules are handledAssistant
Let me test what happens with the original code (without my change) when we use the escape hatch for the fs method test
Assistant
Let me understand the handled module dispatch better. Let me look at what happens after
is_handled_modulefor handledAssistant
Let me look at
try_module_static_methodsto see how it handles unknown fsAssistant
Let me find the function more
Assistant
Let me look at how
try_module_static_methodshandles unknownAssistant
Let me see how the call path ends when no handler picks up the
Assistant
Let me see the final fallback at the end of the
Assistant
Let me test what happens with the original code when the gate is bypassed for fs.notARealMethod
Assistant
Let me take a different approach. Instead of skipping the gate, I should make the gate return
undefinedfor namespace imports. Let me first restore my changes and think about the right fix.Assistant
Let me test what happens when we actually try to compile
fs.notARealMethod()with the escape hatch (which simulates my change forfsAssistant
Let me try the compile command
Assistant
Let me look at the complete fallback in lower_call to see where the final call is emitted
Assistant
Let me check what the codegen does with unknown methods on NativeModuleRef
Assistant
Let me look at the property_get codegen for NativeModuleRef
Assistant
Let me verify my current change and test both scenarios. Let me rebuild
Assistant
Let me test both scenarios
Assistant
Let me change my approach. Instead of skipping the gate entirely, I'll modify it to return
Expr::Undefinedfor namespace imports with absent properties. This way property reads work correctly, and method calls will result in the callee beingundefinedwhich won't silently call absent methods.First, let me check how the call path handles
Expr::Undefinedas a calleeAssistant
Let me look at how fs methods are dispatched in the call path
Assistant
Let me look at the full context around line 153
Assistant
I need a more nuanced approach. The current approach skips the gate entirely for namespace imports, which allows
fs.notARealMethod()to pass. I need to also add the gate for handled modules in the call path.Let me update my approach: keep the namespace import skip in
lower_member_inner, but also add the unimplemented gate for handled modules intry_native_module_methods.Let me first revert my changes and take a cleaner
Assistant
Let me check if the manifest includes
fs.readFileSyncAssistant
Now let me implement the proper fix. I'll make two changes:
- In
lower_member_inner: skip the error gate for namespace imports - In
try_native_module_methods: apply the gate for all modules, not just non-handled ones
- In
Assistant
Now edit
try_native_module_methodsto apply the gate for allAssistant
Let me look at the exact text in native_module.rs around the handled modules
Assistant
Let me use a simpler approach with sed to restructure the code
Assistant
Let me use a more careful Python approach
Assistant
Now let me build and test both scenarios
Assistant
Now let me test
Assistant
Both cases work correctly. Let me verify more scenarios
Assistant
Let me clean up and test valid method calls in isolation
Assistant
Let me test more edge cases
Assistant
Let me check files one at a time since the checker picks up sibling
Assistant
All tests pass. Let me now run the existing test suite to make sure nothing is broken
Assistant
Let me look at the failing tests to understand what they test
Assistant
Let me check the
path/posixandpath/win32modules in the manifestAssistant
Let me investigate why
path/posixbogus call doesn'tAssistant
Let me check the NATIVE_MODULES list
Assistant
Let me verify the edit in native_module.rs was
Assistant
Let me re-examine the test output more carefully
Assistant
Let me check how
path/posiximports are handledAssistant
Let me look at module_decl to see how path submodules are
Assistant
Let me check the special handling for path submodules in native_module
Assistant
Let me search where
path_submodule_nameis usedAssistant
Let me look at line 1258 and surrounding
Assistant
I found the issue! For
path/posixandpath/win32, the code has a special early return for path submodules that happens BEFORE the unimplemented gate. I need to move the gate before the path submodule dispatch.Let me fix this
Assistant
Let me write a Python script file instead to avoid escaping issues
Assistant
Let me verify the edit and build
Assistant
Let me see the rest of the modified code
Assistant
Now let me build and test
Assistant
Let me run the tests
Assistant
All three cases work. Now let me run the unit tests
Assistant
The call-form tests pass. The member-read tests need to be updated to reflect the new behavior. Let me update them
Assistant
Let me check the sweep test and update
Assistant
Let me view lines 264-320 of the test file to update
Assistant
Let me replace the sweep test
Assistant
Let me use Python for this edit
Assistant
Now let me run the tests
Assistant
All 12 tests pass! Let me clean up temporary files and do a final end-to-end verification.
Assistant
All end-to-end tests pass! Let me run a broader set of tests to check
Assistant
All tests pass. Let me also check for other tests that might be impacted by my changes
Assistant
Let me review the final diff
Assistant
Let me do a quick final sanity check
Assistant
Let me do one final summary check of all changes and confirm everything is clean
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.