fix(schema): recognize cross-realm arrays with Array.isArray - #1646
fix(schema): recognize cross-realm arrays with Array.isArray#1646edenbuilds wants to merge 3 commits into
Conversation
ProtoNode and objectKindOf used instanceof Array, which rejects arrays from other windows/vm contexts. Use Array.isArray (and the compiled equivalent) so number[] accepts foreign-realm arrays (fixes arktypeio#1597).
There was a problem hiding this comment.
Important
The fix itself is correct, but the newly-added test fails as written, so the suite is red. attest(T(foreign)).equals([1, 2, 3]) at array.test.ts:294 throws Objects did not have the same constructor because attest's equals rejects mismatched constructors, and a cross-realm array's constructor differs from a local [1, 2, 3] literal.
Reviewed changes
proto.ts—ProtoNodenow routes theArrayproto throughArray.isArrayin bothtraverseAllowsandcompiledCondition, so arrays from other realms validate.objectKinds.ts—objectKindOfearly-returns"Array"for anyArray.isArrayvalue, keeping kind/error descriptions accurate across realms.array.test.ts— adds avm-realm cross-realm array test.
I verified the runtime behavior directly: with the fix, type("number[]").allows returns true for a vm-realm [1, 2, 3] (and reverting proto.ts to instanceof Array breaks it), so the fix is sound. The only problem is the test's final assertion, which fails regardless of the fix and must be corrected before this can merge.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
attest().equals treats foreign-realm arrays as unequal to literals because their constructors differ. Assert identity + element values.
Unblocks arktype CI prChecks (prettier --check on proto.ts).
|
@pullfrog addressed: the test no longer uses `attest(...).equals` against a foreign-realm array (constructor identity fails). It asserts identity + element values instead. CI `core` / `prChecks` / compatibility are green on the latest head. |
There was a problem hiding this comment.
✅ No new issues found.
Confirmed the fix: array.test.ts no longer calls attest(...).equals against the foreign-realm array (whose constructor differs, which attest treats as unequal). It now asserts realm-safe facts — Array.isArray(foreign) is true, T.allows(foreign) is true, T(foreign) returns the same object (result === foreign) — and compares element values via a local spread [...(result as number[])].
pnpm mocha ark/type/__tests__/arrays/array.test.ts passes accepts arrays from another realm. (The benchTemplate/snapTemplate module-not-found output in that run comes from the ark/attest dev build not being present locally and is unrelated to this PR.) The earlier review blocker is resolved.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Summary
ProtoNodevalidated arrays withinstanceof Array(and the same in the JITcompiledCondition), which fails for arrays from another window/vmrealm.Array.isArrayfor the Array proto; early-return"Array"fromobjectKindOfthe same way so error text stays accurate.Fixes #1597
Test plan
vmforeign[1,2,3]→allowsfalse on main, true with fix;T(foreign)returns[1,2,3]accepts arrays from another realminark/type/__tests__/arrays/array.test.tsproto.ts/objectKinds.tsare stashedMade with Cursor