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 member-lowering logic, related native-module checks, and existing tests/fixtures. Then I’ll reproduce the reported failure before making a narrowly scoped distinction between value reads and call usage.
- Assistant
The file is large and ripgrep is unavailable, so I’ll use
grepto locate the exact native namespace branch and call-lowering guard. I’ll also confirm whether the cited fixture exists and whether a usable Perry binary is already built. - Assistant
The reported fixture is present. I’ll now read the full namespace-property branch and native-call branch, plus nearby unit/integration test conventions, to determine whether the correct fix is to lower absent reads directly to
Undefinedwhile leaving call validation untouched. - Assistant
There is already a focused
unimplemented_api_checktest suite covering named imports and unsupported methods. I’ll inspect it and the import validator, then run the relevant existing test and reproduce the fixture using the project’s build/test commands. - Assistant
The current tests encode the old policy for bare reads (
crypto.foobar,axios.foo), but direct unsupported calls have an independent gate inexpr_call/native_module.rs. The issue explicitly changes read semantics, so those old read assertions are expected to become obsolete while the call gate remains valid. Before editing, I’ll run a targeted HIR test and invoke the CLI through Cargo to capture the reported DNS failure. - Assistant
The repository has no selected Rust toolchain in this environment, so reproduction could not run yet. I’ll inspect available toolchains and project CI configuration, then select/install the expected stable toolchain without changing repository files.
- Assistant
No Rust toolchain is installed. I’ll install stable via rustup and then rerun the baseline checks.
- Assistant
The toolchain downloaded successfully, but this container’s rustup shim reports a nonstandard home-path error after setting the default. I’ll inspect paths and invoke the installed toolchain binaries directly if needed.
- Assistant
HOMEis empty, while rustup installed under/root; settingHOME=/rootper command should resolve it. I’ll rerun the baseline targeted test and DNS check with accurate exit-code capture. - Assistant
The old read-rejection test passes, confirming the gate is active. The workspace has multiple binaries, so I’ll rerun the CLI baseline with
--bin perry. - Assistant
A blanket removal would also weaken strict checks for third-party native packages such as
axios, which is outside this Node-specific issue. I’ll inspect the manifest’s distinction between supported symbols and Node public exports. If it can identify a genuine absent Node export, I can allow only those misses while preserving rejection for unsupported-but-real APIs and external modules. - Assistant
The manifest’s “public named export” view is not a complete independent Node export catalog; it is derived from implemented entries, so it cannot distinguish an unsupported real export from an absent export when
module_has_symbolisNone. The reliable semantic distinction available here is operation context: namespace reads must use JavaScript property-miss behavior, while direct calls retain their separate strict gate and named imports retain module validation. I’ll make the member gate skip Node core namespaces only, preserving strict third-party native package reads. - Assistant
The source change is intentionally one condition and is already formatted structurally; rustfmt is merely absent. I’ll verify
dns/promisesis recognized as Node core, inspect whether the existing suite already has a direct bogus-call assertion, and run focused tests for: DNS namespace read acceptance, missing named import rejection, unsupported direct call rejection, and external package read rejection. I can use temporary files outside the repository for CLI probes. - Assistant
The DNS check now passes, and the external
axios.fooread remains rejected. The named-import probe correctly fails, but the CLI recursively checked both files placed in/tmp, masking the unsupported-call probe; I’ll isolate probes in separate directories. I’ll also run the existing comprehensive bogus-call regression and execute the DNS fixture to verify runtime values. - Assistant
This exposed an important edge case: several specially dispatched built-ins (
fs,crypto,path, etc.) relied on the member-read gate even for call expressions, because their call lowering falls back throughlower_member; skipping all Node reads therefore accidentally allows those unsupported calls. I’ll inspect call lowering and context flags to add an explicit “currently lowering a call callee” signal, so only pure reads bypass the gate while every call path remains strict. - Assistant
A global “inside any call” flag would incorrectly classify namespace reads occurring in arguments. Instead, the robust approach is to perform the unsupported module-method check once at the start of call lowering by inspecting the call’s AST callee (
namespace.ident(...)) before dispatch. This catches all special and generic module paths without affecting argument reads. I’ll inspect the early call sequence and native module lookup API to insert this narrowly. - Assistant
I’ll add a small pre-dispatch validator for statically named calls on native namespace identifiers, including TypeScript/parenthesis wrappers. It will mirror the existing U006 message and escape hatch, run before arguments are lowered, and only reject absent manifest symbols. Then the member branch can safely permit Node property reads.
- Assistant
The pre-dispatch call validator is in place. I’ll correct the member comment to reference call lowering generally, then run the comprehensive call sweep, the DNS check, named-import and call probes, and the external read test. Afterward I’ll investigate the runtime fixture’s earlier codegen failure from its full log rather than only the linker tail.
- Assistant
All static acceptance distinctions now behave correctly: DNS reads pass, missing named import fails, bogus
fscall fails, and external native reads remain strict. I’ll rerun the DNS fixture with the rebuilt release binary and inspect all codegen diagnostics to determine whether runtime verification is possible in this container. - Assistant
Runtime compilation is blocked by the environment’s Clang 14, which cannot parse the opaque-pointer LLVM IR emitted by current Perry. I’ll check for a newer installed Clang and use
PERRY_LLVM_CLANGif available; otherwise static check plus the issue’s documented bypass-runtime evidence is the feasible verification. - Assistant
The implementation compiles and
git diff --checkis clean. I’ll update the old member-gate documentation so it no longer claims all native namespace reads fail, then run compilation and focused named-export/API-manifest tests. I’ll also review the final diff for unintended changes. - Assistant
Focused compilation, named-import validation, call-gate sweep, external strict-read test, and all manifest tests pass. I’ll perform a final diff review and rerun the exact DNS acceptance check plus direct-call probe with explicit statuses, then submit if clean.
- Assistant
The final probes pass with expected statuses. One edge case worth checking before submission is CommonJS aliasing (
const fs = require("fs"); fs.notARealMethod()), because the new validator relies on namespace lookup. I’ll inspect that lookup and probe the CommonJS shape to ensure unsupported calls remain caught beyond ESM imports. - Assistant
The CommonJS probe fails, but I’ll inspect its exact diagnostic to confirm it is the intended unsupported-API gate rather than an unrelated
requirerestriction.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.