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 exploring the repository structure to understand the codebase.
Assistant
The output got truncated. Let me find the specific code that handles namespace
PropertyGeton aNativeModuleRef(module)and rejects whenmodule_has_symbol(module, prop)is None.Assistant
Let me look at the test fixture mentioned in the issue.
Assistant
Let me look at how the namespace object is constructed at runtime.
Assistant
Now let's see how
lookup_native_moduleworks and the imports transform:Assistant
Now let me look at how native modules are registered, especially for namespace imports.
Assistant
Now let me look at how named imports get registered:
Assistant
Now let me look at the imports transform to see how named imports are handled:
Assistant
Now let me look at the module_decl code that handles the named imports validation:
Assistant
Now let me look at the
lower_callto understand how member accesses are used in calls:Assistant
This is the unimplemented-API gate for method calls. Now let me also look at the dns specific native module code to see how DNS promises is handled:
Assistant
Now let's look at how the
dnsPromisesis constructed and accessed at runtime:Assistant
Now let me look at the runtime to see how the namespace object is built and how property gets work:
Assistant
Now let me look at how property gets on native module namespaces work:
Assistant
The runtime already returns
JSValue::undefined()as a fallback. Let me look atget_native_module_constantand the test fixture:Assistant
Let me look at the issue and confirm my understanding. Let me also reproduce the bug first:
Assistant
Let me check the build status:
Assistant
Let me check the rust-toolchain file:
Assistant
Now let me reproduce the error. First I need to understand the structure better:
Assistant
Let me check the existing tests for unimplemented API:
Assistant
Now let me look at the existing test for unimplemented_api_check:
Assistant
Let me look at how
lower_callhandles the property access gate:Assistant
Let me now look at the part where the gate runs in expr_call:
Assistant
Now I understand the structure. Let me trace through the issue and the proposed fix:
Assistant
Now let me also look at how dns/promises is handled for calls in expr_call:
Assistant
Now let me first build the project to verify the current state:
Assistant
Good, the build works. Now let me reproduce the error:
Assistant
I've reproduced the bug. Now let me look at the gate more carefully and plan the fix:
Assistant
Let me look at how
lower_callhandles different callee expressions:Assistant
Let me look at what happens before
lower_expron the callee inlower_call_inner:Assistant
Let me look at the call path more carefully:
Assistant
Let me check how imports are parsed and tracked:
Assistant
Hmm, namespace_import_locals is only populated for non-native imports. For native imports, it's not.
Let me check if there's a different way to know if a local is a namespace. Let me look atimports.rs:
Assistant
Let me check how
namespace_import_localsis currently set:Assistant
Let me check how
namespace_import_localsis used in static_and_instance.rs:Assistant
Let me look at the imports structure:
Assistant
Let me check if
LoweringContexthas access to module imports:Assistant
Let me look at the
lower_module_fullto understand the structure:Assistant
Let me look at the
LoweringContextstructure:Assistant
Let me check the imported_array_methods context:
Assistant
Let me now plan and implement the fix. First, let me understand the existing context structure:
Assistant
Let me now start implementing the fix. First, let me look at the full lowering_context structure:
Assistant
Now let me make the fix. First, I'll add a new field to track native namespace imports:
Assistant
Now let me look at the imports structure to find the best way to detect namespace imports:
Assistant
Let me now implement the fix. I'll start by modifying the
LoweringContextto track native namespace imports:Assistant
Now let me add a new field for tracking native namespace imports:
Assistant
Let me make the changes. First, I'll add a field to track native namespace imports:
Assistant
Let me first understand the gate logic in
expr_member.rsbetter and make the fix:Assistant
Now let me make the actual fix. I'll add a
native_namespace_import_localsfield to track native namespace imports:Assistant
Now let me initialize the field in
context.rs:Assistant
Now let me populate the set for native namespace imports in
module_decl.rs:Assistant
Now let me modify the gate in
expr_member.rs:Assistant
Now let me build to make sure the changes compile:
Assistant
Let me check my edit:
Assistant
I see the issue - my edit didn't close the
if letblock correctly. Let me look at the structure:Assistant
Let me look at the area around the issue more carefully:
Assistant
I need to add a closing brace for the outer
if letblock. Let me fix this:Assistant
I made a mess of the edit. Let me fix the file:
Assistant
I have a duplicate
match &member.prop {. Let me remove the duplicate:Assistant
The file got messed up. Let me restore it and start over more carefully:
Assistant
Good. Now let me make the expr_member.rs change more carefully. Let me look at the exact lines around the gate first:
Assistant
Now let me use the
replacecommand to make a precise edit:Assistant
Now let me build to verify:
Assistant
Good, it builds. Let me test the fix:
Assistant
The check passes. Now let me verify the runtime behavior matches Node:
Assistant
There's a clang compatibility issue. Let me check the LLVM config:
Assistant
Let me look for a newer clang version:
Assistant
Let me run the existing test suite to verify the behavior:
Assistant
Let me look for where the call gate is for handled modules:
Assistant
Let me look at the call flow more carefully:
Assistant
Let me look at the full structure of
try_native_module_methods:Assistant
Let me add a separate gate for handled modules in
try_native_module_methods. First let me view the relevant area:Assistant
Let me add a gate check for handled modules after the existing
if !is_handled_moduleblock:Assistant
The edit didn't quite work. Let me revert and try again:
Assistant
Now let me look at the structure again carefully:
Assistant
Now let me add a precise gate check for handled modules:
Assistant
Now let me build and run the tests:
Assistant
Let me check
try_path_subnamespace:Assistant
Let me see what's happening with
path/posix. Let me write a small test to verify:Assistant
Let me check the path/posix entries:
Assistant
Let me check
path_submodule_name:Assistant
Let me check
dispatch_path_subnamespace:Assistant
I found the bug! Let me look at the current code:
Assistant
Let me fix the path submodule dispatch to only return when matched:
Assistant
Now let me build and test:
Assistant
The issue is
argsis moved. Let me fix:Assistant
The args parameter is not mutable. Let me check the function signature.
Assistant
I need to make
argsmutable. Let me check the existing function:Assistant
Let me change the approach - instead of mutating args, I'll just check the dispatch result before calling:
Assistant
Let me make args mutable in the function signature:
Assistant
The edit duplicated the line. Let me fix:
Assistant
Both remaining failures are testing the old behavior (expecting reads of bogus members to error). Per the issue, reads should return undefined.
Let me test that the call form still errors:
Assistant
Both calls still error as expected. Let me also test the namespace read case:
Assistant
The check is checking 3 files (which I think are the temp files). Let me check the actual test by looking at the test/eval more carefully. Actually, the error shows the bogus call errors are surfaced. Let me also check the namespace read test passes.
Assistant
The check is checking 3 files. Let me check what other files are being checked:
Assistant
Hmm, it's checking 3 files. The 3rd file must be something else. Let me see what's happening:
Assistant
The namespace read test passes. Now let me also test the actual fixture from the issue:
Assistant
Let me test more edge cases:
Assistant
Named imports still error. Let me test default imports of bogus properties:
Assistant
Default imports still error. Let me clean up the test files:
Assistant
Now let me run the full test suite to see how many tests pass:
Assistant
Let me run more tests to ensure I haven't broken anything else:
Assistant
Now let me look at the test_parity to understand the dns tests:
Assistant
Let me run a broader set of tests to ensure I haven't broken anything:
Assistant
All lib tests pass. Let me also run the api-manifest tests:
Assistant
Let me also run more tests:
Assistant
All tests pass except the 2 in
unimplemented_api_check.rsthat test the OLD behavior. Let me look at the failing tests once more to confirm they need updating:Assistant
Let me verify the test
supported_module_with_unknown_member_is_rejectedstill passes:Assistant
That test passes. Let me also run the full unimplemented test suite to confirm:
Assistant
Both failures are exactly the tests for the OLD behavior the issue is changing. The call gate test (
every_supported_module_rejects_bogus_call) now passes.Let me verify my fix doesn't break valid use cases by running additional checks:
Assistant
Valid use cases still work. Let me also test with defaultimport + method call:
Assistant
Hmm, axios.get passes. Let me check if
axios.getis in the manifest:Assistant
Now let me also test default import of bogus member:
Assistant
Default imports of bogus properties still error. Let me also verify the runtime by looking at the HIR output of the fixture:
Assistant
The check passes with the release binary. Let me also check the runtime behavior more carefully:
Assistant
Let me check the HIR output to verify my fix:
Assistant
Let me also verify the runtime returns undefined for missing properties:
Assistant
Let me check how
typeofis handled to ensure it works correctly:Assistant
Let me also run all of the test suite to check for unintended consequences:
Assistant
Let me also run more tests:
Assistant
All perry-codegen tests pass. Let me also run the parser and transform tests:
Assistant
Let me also check the tests for the related dns functionality:
Assistant
Let me verify my changes to module_decl.rs:
Assistant
Let me do a final verification by checking the fixture and all critical cases:
Assistant
All checks pass. Let me clean up:
Assistant
Let me also check that the existing tests for node_named_export_hygiene still pass (which tests named imports):
Assistant
The 2 failures are testing the OLD behavior that the issue is changing. Per the instructions, I should ignore these as they're testing behavior that legitimately changed.
Let me also verify all changes are well-documented and the test for the regression test (call gate) still works:
Assistant
Let me look at the final summary of changes:
Assistant
Let me now also write a small temporary script to do a comprehensive end-to-end test of my fix:
Assistant
The script timed out because each
perry checkis slow. Let me run them individually:Assistant
All checks pass. Let me also do a final sanity check by running the perry-hir lib tests once more:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.