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
Now let's add a new field
member_call_callee_depthor a simple bool flag. Let's addpub(crate) member_is_call_callee: boolfollowing the pattern.Assistant
Now let's initialize it in context.rs where fields are constructed.
Assistant
Now let's set the flag in expr_call/mod.rs before the generic fallback tail invocation of
lower_expr(ctx, expr).Assistant
Now let's build to check for errors.
Assistant
Good, it compiled. Now let's build the full perry binary and test with the fixture mentioned in the issue.
Assistant
Let's build the release binary and test.
Assistant
Excellent! The check now passes. Let's run the fixture and verify output matches Node's expected shape.
Assistant
Good, reverted cleanly. Now let's add the manifest entries for
dns/promises:ADDRCONFIG,V4MAPPED,ALLas internal (non-module-export) properties.Assistant
Now let's build and test.
Assistant
Now let's check that the named import for the absent constant is still rejected.
Assistant
Now let's add a
"dns/promises"arm to rejectADDRCONFIG/V4MAPPED/ALLas named exports.Assistant
Now rebuild and rerun the probe tests.
Assistant
Both cases behave correctly now. Let's remove the temp probe test and rebuild the CLI binary, then re-verify with the actual fixture and
perry checkfor both cases.Assistant
Both work correctly now: the DNS constants fixture passes the check, and the named import probe is correctly rejected. Let's also verify a genuine unsupported call is still rejected (regression check), e.g.
fs.notARealMethod().Assistant
Both the actual unsupported call and even the bogus read of a genuinely-unimplemented method still correctly fail — exactly matching the issue's requirement that this should NOT become a blanket bypass. Now let's clean up temp files and run the broader existing test suite.
Assistant
All pre-existing regression tests pass, including the exact tests that would have caught an overly-broad fix. Now let's run the full perry-api-manifest test suite and the codegen manifest consistency test.
Assistant
All pass. Now let's check the codegen manifest_consistency test (checks NATIVE_MODULE_TABLE vs manifest — shouldn't be affected since we only added Property entries, not Method entries).
Assistant
All good. Now let's check the print-api-manifest emit test / dts emission doesn't accidentally emit these internal properties as top-level declarations (should be fine since
entry_is_public_named_exportlogic doesn't check module_export but dts emission likely uses a different filter). Let's check emit.rs for how it decides which entries to emit in dts.Assistant
Good — no matches, confirming these constants are excluded from the emitted
.d.tsfordns/promisesnamespace, consistent with real Node.Assistant
Entries present in JSON manifest (with
module_export: false) but excluded from.d.ts/markdown named-export view, matching the intended design. Now let's run the broader perry-hir test suite to make sure nothing else regressed.Assistant
All perry-hir tests pass. Let's also check perry-diagnostics and perry-codegen full test suites, plus grep for any other test referencing dns/promises constants elsewhere.
Assistant
No other test files reference these; safe. Let's run the codegen test suite broadly too, to be thorough.
Assistant
All pass. Let's also run the full
perrycrate tests (CLI) quickly to be safe, and checkgit difffor a final review.Assistant
Now let's rebuild to make sure everything still compiles, and run the full check once more end-to-end.
Assistant
Let's re-run the full test suites once more for a final sanity confirmation.
Assistant
All green. Let's do a final
git diffreview and confirm no stray temp files remain.Assistant
Clean diff, no leftover temp files. Let's view the final diff in full for a last sanity check.
Assistant
This is a minimal, surgical fix. Now let's go through the checklist explicitly.
Assistant
Confirmed: under
dns/promises,ADDRCONFIG,V4MAPPED,ALLcorrectly do NOT appear in the emitted docs — exactly matching real Node's typed surface. The duplicate ADDRCONFIG underdnsis pre-existing, unrelated to this change.Assistant
Confirmed the duplicate
ADDRCONFIGunderdnswas already present before my change (pre-existing docs-generator quirk unrelated to this fix). Let's rebuild with the fix in place to restore the binary to the correct state before finishing.Assistant
Final state confirmed. Let's review the checklist explicitly one more time before submitting.
Checklist review:
- Reproduced the reported error: Yes — before the fix,
target/release/perry check test-parity/node-suite/dns/constants/error-aliases.tsfailed witherror[U006]: dns/promises.ADDRCONFIG is not implemented in Perry..., exactly matching the issue. - Confirmed the fix resolves the error: Yes — after adding the two targeted manifest changes, the same check command now passes cleanly with exit code 0.
- Thought about edge cases:
- Named ESM import of the same absent constant (
import { ADDRCONFIG } from "node:dns/promises") still correctly rejects with "does not provide an export named" (verified via a temp probe test and CLI).
- Named ESM import of the same absent constant (
- Reproduced the reported error: Yes — before the fix,
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.