Commit 62af2ed
authored
Validate its own generated schemas (#1017)
* test(validators): reproduce the crash on a nested definedTypeLink
getValidationItemsVisitor throws `Expected node of kind [definedTypeLinkNode]`
whenever it walks a definedTypeLinkNode that sits below the top of the tree: a
struct field, an argument, an array element, or a PDA seed. That is most real
programs, and six of this repo's own test IDLs (example-idl, system, token,
token-2022, mpl-token-metadata, pmp) hit it.
Add two tests that build the smallest such shape from the node constructors,
both of which throw today: one asserts a resolvable link validates cleanly, the
other asserts a missing link is reported as an error. So the fix must restore
the visitor's ability to catch a broken link, not merely stop the crash.
* fix(validators): make recordNodeStackVisitor follow prefix traversal rules
getValidationItemsVisitor was the only visitor to run its per-node logic before
committing the current node to the stack, so validation ran in the gap between
arriving at a node and recording it. Two bugs fell out of that single ordering:
- visitDefinedTypeLink calls stack.getPath(node.kind), which asserts the top
of the stack is the link node; the link node was not committed yet, so the
top was its parent, and any nested definedTypeLink (struct field, argument,
array, PDA seed) threw `Expected node of kind [definedTypeLinkNode]`. Six of
this repo's own test IDLs hit it, including example-idl.json, System, Token,
and Token-2022.
- every validationItem recorded an ancestors-only path, missing the node
itself, which contradicts the documented ValidationItem.path contract
("the path of nodes that led to the node above, including the node itself").
Commit the node before the per-node logic runs, matching the eleven other
recordNodeStackVisitor consumers (getByteSizeVisitor, and the rest): the node
is on the stack when the visit runs, so getPath(node.kind) resolves, missing
links are reported instead of throwing, and recorded paths satisfy the
contract. The two existing tests asserted the off-by-one paths, so they are
corrected to the documented behaviour.
* prettier(validators): fix write :)1 parent 3a75e06 commit 62af2ed
3 files changed
Lines changed: 85 additions & 9 deletions
File tree
- .changeset
- packages/validators
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | 26 | | |
29 | 27 | | |
30 | 28 | | |
| |||
243 | 241 | | |
244 | 242 | | |
245 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
246 | 250 | | |
247 | 251 | | |
Lines changed: 74 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
2 | 11 | | |
3 | 12 | | |
4 | 13 | | |
| |||
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
| |||
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
50 | | - | |
51 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
52 | 119 | | |
53 | 120 | | |
0 commit comments