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
I'll start by exploring the repository structure and understanding the issue.
Assistant
I'll start by exploring the repository structure.
Assistant
Let me look at the relevant file mentioned in the issue and the test fixture.
Assistant
I need to make single tool calls. Let me look at the relevant file mentioned in the issue.
Assistant
The file is large. Let me search for the relevant section handling
NativeModuleRefandmodule_has_symbol.Assistant
Let me look at the section around lines 1722-1850 to understand the logic.
Assistant
Now I understand the gate. Let me look at how calls on native module refs are lowered, since the issue wants call gaps to still be caught while allowing property reads.
Assistant
Let me look at the expr_call module structure and find where calls on native module refs are handled.
Assistant
Let me look at the call-time gate in
native_module.rs.Assistant
Let me understand the call-lowering path and whether
lower_memberis invoked for call callees.Assistant
Let me look further to see how the call handles a MemberExpr callee. Let me look at the part where it matches
ast::Callee::Expr(callee_expr)with a MemberExpr.Assistant
Let me see the very end of the call dispatch to understand what happens when no arm matches.
Assistant
Let me check whether the handled-module call arms (fs, path, crypto, etc.) have their own unimplemented gates.
Assistant
Let me look at
module_static.rsto see how it handles unrecognized fs/path methods.Assistant
Let me search for where fs and path dispatch arms are in module_static.rs and what they do with unrecognized methods. Let me look for how they handle unknown method names - do they fall through (return Err(args)) or raise an error?
Assistant
Let me look at the structure of module_static.rs more carefully after the fs arm to understand the fall-through.
Assistant
Let me look at the very end of module_static.rs to see the fall-through.
Assistant
Let me check if there's a pre-built binary and reproduce the issue.
Assistant
Let me look at the LoweringContext struct to understand existing flags.
Assistant
Let me find where these flags are initialized in
new.Assistant
Let me verify named import validation exists separately (at import time), to ensure my change won't break that.
Assistant
Named import validation is separate. Let me check the manifest definitions for dns/promises to confirm ADDRCONFIG/V4MAPPED/ALL are absent while NODATA/CANCELLED are present.
Assistant
Let me see the dns/promises properties section.
Assistant
Let me check
module_has_public_named_exportandmodule_has_symbolto understand how dns constants resolve.Assistant
Let me check whether dns/promises has property constants in the manifest anywhere (the issue says NODATA/CANCELLED are present for dns/promises).
Assistant
There's a second dns/promises properties section at line 3742. Let me see its context.
Assistant
Now I have a clear picture. The manifest is correct (dns/promises has NODATA/CANCELLED but not ADDRCONFIG/V4MAPPED/ALL). The fix is in the lower_member gate. Let me check callers of
lower_member_innerand howlower_memberis structured.Assistant
The manifest is correct. The fix is purely in the lower_member gate. Let me build first to reproduce the issue, then make changes. Let me check the build setup.
Assistant
Let me check if there's a specific toolchain expected (rust-toolchain.toml).
Assistant
No toolchain file. Let me make the code changes now. First, add the field to LoweringContext.
Assistant
Now initialize it in context.rs:
Assistant
Now modify
lower_memberto consume the flag and pass it tolower_member_inner. Let me view the exact lines:Assistant
Now update the
lower_member_innersignature to acceptis_call_callee:Assistant
Now let me update the gate to use
is_call_callee. Let me view the exact gate lines now (they shifted).Assistant
Now let me modify the gate condition to only bail for calls, with an explanatory comment.
Assistant
Now let me set the flag in lower_call's tail around the callee lowering.
Assistant
Now let me check for existing tests/fixtures that might expect the unimplemented-API error on bare property reads (which would now compile instead). Let me search the test suite.
Assistant
Let me look for how the unimplemented-API gate is tested (rust tests referencing #463 or the gate).
Assistant
This is important — there are existing tests that expect bare reads of bogus members to be rejected (
crypto_unknown_method_is_rejected,supported_module_with_unknown_member_is_rejected,every_supported_module_rejects_bogus_member). The issue explicitly wants bare reads to now compile toundefined. These tests encode the old behavior. Let me verify the call-form test still passes with my change by checking the handled-module (crypto/os/fs) call path falls through to the tail.Assistant
Let me check the os arm falls through too.
Assistant
Let me check how
new module.Member()is handled in expr_new, since my change to lower_member could affect constructor calls on absent native module members.Assistant
Let me check existing tests for
newon native module members to understand expected behavior.Assistant
Let me look at the lower_new structure to understand native module constructor dispatch.
Assistant
I'll also arm the flag in
lower_new's callee lowering to preserve rejection ofnew <absent native member>()(constructor invocations are still "API calls"). Let me view the exact code.Assistant
Now let me build to verify the changes compile. Let me run a check on the affected crates first.
Assistant
perry-hir compiles. Now let me run the relevant HIR unit tests to confirm the call-form test still passes and observe which read-form tests now reflect the new behavior.
Assistant
The 3 read-form tests now fail (they encode the old "reads error" behavior the issue explicitly changes), while the call-form test
every_supported_module_rejects_bogus_calland all positive/named-import tests pass. Let me confirm the call-form regression test passes.Assistant
The call-form regression test passes. The 3 read-form tests fail because they encode the old "reads error" behavior that the issue explicitly changes to "reads return undefined". Per the issue's scope ("Similar absent-property reads on strict native module namespaces should follow normal JS property semantics when the code is only reading the value"), this broad change is correct.
Now let me build the release binary to verify the primary acceptance criterion.
Assistant
Now let me verify the primary acceptance criterion — the DNS fixture check passes without the escape hatch.
Assistant
The check passes. Now let me verify the runtime output matches Node's shape.
Assistant
The
check(primary acceptance) passes. Therunfails due to an environment LLVM/clang issue (clang 14 doesn't support opaqueptrtype), unrelated to my change. Let me check available backends.Assistant
The
check(primary acceptance) passes. Therunis blocked by an environment clang issue (clang 14 vs opaque-pointer IR), unrelated to my fix. Since my change produces the identical HIR (PropertyGet) as the known-goodPERRY_ALLOW_UNIMPLEMENTED=1path the issue already validated, the runtime output will match. Let me try to get a working clang to fully verify runtime output.Assistant
Let me try to install a newer clang to verify runtime output.
Assistant
Only clang-14 is available (bookworm), which is incompatible with Perry's opaque-pointer LLVM IR — a pre-existing environment limitation. Let me check how the test-parity fixtures are run/expected, to see if there's an alternate runtime verification path.
Assistant
Let me look at how the parity runner validates fixture output (snapshots/expected output).
Assistant
The parity runner uses
perry run(blocked by clang). But named-import validation and call-catching happen at HIR lowering (checktime), which works. Let me verify those distinctions with temp probes.Assistant
Named import of an absent export is rejected (matching Node). Now let me verify the read-vs-call distinction at the binary level.
Assistant
Let me see the full output — that error line doesn't match my file.
Assistant
A first-run telemetry prompt is blocking. Let me disable it via env var.
Assistant
perry checkis scanning the directory (2 files). Let me isolate each probe in its own directory and disable telemetry.Assistant
Absent reads compile. Now verify the call-form is still rejected:
Assistant
The distinction works perfectly: absent reads compile, absent calls are rejected. Let me verify
newon an absent native member is still rejected (since I armed the flag in lower_new).Assistant
All distinctions work. The runtime output for reads is guaranteed identical to the issue's confirmed
PERRY_ALLOW_UNIMPLEMENTED=1path (samePropertyGetHIR). Let me try to confirm the runtime output by working around the clang opaque-pointer issue. Let me check Perry's clang flag handling.Assistant
The IR uses opaque-pointer
ptrsyntax (LLVM 15+) but clang-14 needs the flag. Let me check if Perry reads an env var for extra clang args.Assistant
I can use
PERRY_LLVM_CLANGto point to a wrapper that adds the opaque-pointer flag for clang-14, avoiding a rebuild.Assistant
Let me check clang-14's opaque pointer flag name.
Assistant
clang-14 (LLVM 14) has no opaque-pointer support at all; Perry's IR needs LLVM 15+. So the LLVM runtime is unrunnable in this environment (unrelated to my fix). The runtime output is guaranteed identical to the issue's confirmed
PERRY_ALLOW_UNIMPLEMENTED=1path since the HIR is the samePropertyGet.Let me run the broader perry-hir test suite to find all tests affected by the behavior change.
Assistant
Only the 3 read-form tests fail (they encode the old behavior the issue explicitly changes). All other perry-hir tests pass. Let me check whether any other crates' tests expect the read-form error (which would now compile).
Assistant
These are structural manifest checks (unaffected by my change). Let me verify they still pass.
Assistant
Let me check the
util_types_loweringtest that referenced the gate.Assistant
The
util.types.notReal()test uses the CALL form (still caught) and passes. Only the 3 read-form tests break. Let me check the top-leveltests/andtest-files/for any fixtures expecting read-form check failures.Assistant
The only breakages are the 3 read-form tests that encode the old behavior the issue explicitly changes. Per the issue's scope, all absent-property reads on strict native module namespaces must follow JS semantics (undefined), so these tests need updating — which I'm instructed not to do, and the eval system won't count them.
Let me review my complete diff.
Assistant
The diff is clean and minimal. Let me verify the repo has no stray files and run a final confirmation of the key acceptance checks.
Assistant
Only the 5 intended source files are modified — no stray/untracked files.
Let me do a final verification of the complete acceptance criteria set, then submit.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.