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 first inspect the repository status and the relevant lowering code/tests, then reproduce the reported check failure before changing behavior. The likely fix is to defer strict validation for a bare native-module property read while preserving validation when that member expression is used as a call target and preserving named-import validation through its separate path.
- Assistant
The file is large and
ripgrepis unavailable, so I’ll usegrepto locate the exact native-module branch and call lowering logic. I also need to identify the repository’s test organization and whether the reported fixture is present at this checkout. - Assistant
The reported fixture exists. I’ll now inspect the complete strict-gate branch, the native call checker, and existing regression tests. This will show whether simply returning
Undefinedfor a missing read is correct at HIR/runtime level and whether call syntax is independently rejected before or after member lowering. - Assistant
The member gate currently conflates reads and calls, but the native-call path already contains its own manifest check for generic module calls. I’ll inspect the surrounding call dispatcher and full test file to ensure special modules (
fs,path, etc.) also retain strict rejection, since those may bypass the generic branch. Then I’ll reproduce with the available CLI/build artifacts. - Assistant
Existing tests explicitly assert unknown reads are rejected; those encode the old semantics and will become stale under this issue, while a separate exhaustive test asserts unknown calls are rejected. Per the environment rule, I will not modify tests. Before editing, I’ll run the exact fixture through the debug CLI to reproduce U006, then implement read semantics and run both the fixture and the existing call-form sweep.
- Assistant
The reproduction command is blocked by environment configuration rather than the project: Rustup has installed toolchains but no default selected. I’ll inspect the pinned toolchain and installed versions, set
RUSTUP_TOOLCHAINper-command (without changing repository files), and rerun. - Assistant
No Rust toolchain is installed. I’ll install the stable toolchain via Rustup so the reported behavior and regression suite can be verified. This is an environment-only dependency installation and will not alter tracked project files.
- Assistant
The install completed all components and set stable despite Rustup’s final self-path warning. I’ll verify
cargoand rerun the exact reproduction; compilation may take some time on the first build. - Assistant
The right read result is the normal
PropertyGet, not a hardcodedUndefined: present exports must still resolve dynamically, and the runtime already returnsundefinedfor absent properties (as confirmed by the issue’s bypass evidence). I’ll remove only the member-read refusal block and document that strict API validation belongs to import/call lowering. Then the exhaustive call sweep will reveal any special-module call paths that depended on this read-time check. - Assistant
The edit is structurally simple; formatting failed only because the minimal Rust profile omitted
rustfmt. I’ll install it, format, then run: (1) the DNS check, (2) named-export hygiene, and (3) the exhaustive bogus-call regression. I’ll first list exact call-sweep test names to target them accurately. - Assistant
I’ll run the acceptance check first, then the named-import and strict-call tests. The old read-rejection tests are expected to fail because their assertion is exactly the behavior this issue intentionally changes; the call sweep is the important non-regression distinction.
- Assistant
The acceptance check and named-import test pass, while the exhaustive call sweep found exactly seven special-dispatch modules that had relied on the removed read gate (
crypto,os,child_process,fs, and path variants). I’ll move/add a call-specific manifest check at the start of native-module member-call dispatch, before special handlers, using the same U006 message, hint, escape hatch, and tree-shaking deferral behavior. This preserves all call diagnostics without reintroducing read validation. - Assistant
I found a single choke point before all native-module special cases. I’ll add the missing-symbol call gate there only for namespace bindings (
lookup_native_module(..., None)) plus globalprocess; named imported values remain excluded because calling a property on an imported class/value is not a namespace call. The existing later generic gate can remain as a defensive check for its path, though known missing calls will now be caught uniformly before special dispatch. - Assistant
The call-only gate is now in place. I’ll rerun the exhaustive sweep with output captured to avoid warning noise, then directly probe the issue’s representative
fs.notARealMethod()CLI error as an end-to-end confirmation. - Assistant
The strict-call distinction now passes for every supported module and end-to-end
fs.notARealMethod()still emits U006. I’ll verify the exact absent DNS named import is rejected, then run the curated fixture to confirm runtime output for absent and present properties. The runtime command may require native linker/LLVM dependencies; if available, I’ll compare the key lines explicitly. - Assistant
The exact named import is correctly rejected. Runtime compilation reached codegen but failed because the environment’s Clang 14 cannot parse opaque-pointer LLVM IR, unrelated to the change. I’ll check for a newer installed compiler or apt candidate and use
PERRY_LLVM_CLANGto complete runtime verification without modifying the repository. - Assistant
No newer Clang is installed or visible in the stale package cache. I’ll refresh apt metadata and install Clang 16 (the first Debian release with opaque pointers enabled by default), then rerun only the runtime fixture with that compiler.
- Assistant
Clang 16 is available. I’ll rerun the fixture and assert the exact key output lines for all three absent promise constants and the present named aliases.
- Assistant
Although the diagnostic recommends
PERRY_LLVM_CLANG, this checkout did not honor it and still invoked theclangexecutable by name. I’ll inspect compiler selection to find the actual override behavior; if it is hardcoded, I can prepend a temporary directory containing aclangsymlink to Clang 16 inPATH, again without repository changes. - Assistant
The override exists in code, so I’ll inspect whether it requires an absolute path or whether an object-cache selection captured the prior compiler. Then I’ll use the full
/usr/bin/clang-16path and disable/clear only temporary object cache if needed. - Assistant
The override deliberately requires the path to exist as written, so a bare
clang-16falls back toclang; the diagnostic did not explain that nuance. I’ll rerun with/usr/bin/clang-16. - Assistant
Runtime output now exactly matches the acceptance criteria: all three absent
dns/promisesproperties areundefined, present aliases are strings, and named aliases retain expected values. I’ll inspect the exhaustive sweep’s import shape and repository status, remove any generated executable, then run the full named-export hygiene suite pluscargo check -p perry-hir. I’ll also review the final diff for accidental changes. - Assistant
All five named-export hygiene tests and
cargo check -p perry-hirpass; the working tree contains only the two intended source changes. One maintenance concern remains: the later generic call branch still has comments claiming the member-read gate exists. I’ll locate and update stale source comments (without changing behavior), then inspect the complete diff. - Assistant
Two stale comments remain. The generic two-deep branch should refer to the new early call gate; the three-deep class/static branch likely has its own call-specific validation, so I’ll inspect that context before editing both comments accurately.
- Assistant
The three-deep gate is still necessary because its direct receiver is
mod.X, not the namespace identifier, so it bypasses the new two-deep choke point. I’ll revise comments to describe call-shape routing rather than the removed read gate, then format and perform a final diff check. - Assistant
cargo fmttouched more lines than expected inmodule_class_static.rs, likely reflowing pre-existing formatting around the comment. Since that file needs only a comment correction and minimizing the patch is preferable, I’ll inspect its diff and revert any unrelated formatting. - Assistant
The diff is clean and the third file contains only an accurate comment update. To match the acceptance command literally rather than relying only on debug/test builds, I’ll build the release CLI and run
target/release/perry checkon the DNS fixture, capturing warnings and reporting only the final results.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.