Repository navigation
Commit a6e8bb7
authored
✨ Validate a supplied document without executing it (#654)
* ✨ Validate a supplied document without executing it (#653)
Add `validateDocument()`: one core operation that reads a supplied root and
the Markdown source closure ordinary component selection discovers, and
answers with deterministic version-1 data — one closed code per diagnostic,
the normalized schema issues execution already produces, and one record per
authored invocation saying whether it is valid, invalid, or not decidable
without running the document.
Traversal follows source rather than execution reachability: the selected
root projection first, then definitions in FIFO discovery order, each source
identity read once, so a cycle terminates and is not a failure. An invocation
inside authored control flow is checked like any other, and no branch is
evaluated to decide whether it would run.
The rules come from execution rather than a second catalog. The body
output/return contract moves to `body-structure.ts`, and the static parts of
every structural construct move to `structural-rules.ts`; expansion renders
the same facts as the printed errors it always produced. Frontmatter and
definition parsing report the phase a failure belongs to, so nothing
classifies an error by reading its message. The declaration-only registry
inspection built is now shared.
Observation performs no document effect: no expression is evaluated, no
component invoked, no repository module imported, no identity factory called,
no provider installed, no journal opened, and nothing the document authored is
written.
* 🐛 Give one source identity one scan, and a structural fact its own record (#653)
Two version-1 contracts were wrong.
The root did not enter the source cache, so a root living where a component
name resolves was scanned twice: a retained root at `components/Foo.md`
containing `<Foo />` returned the invocation names `["Foo", "Foo"]` and read
the file again. The root now registers under its own path, so a selection
finding it terminates the walk the way any other cycle does and reads nothing.
A structural fact a parent discovered about a descendant went to the parent
alone. A misplaced `<Else>` found through its `<If>` named `If`, and the
`<Else>` it was about stayed valid. Such a finding now names and is positioned
at the element it identifies, reaches that element's record, and still leaves
the `<If>` whose structure is malformed invalid. Preorder guarantees the parent
is visited first, so the child picks it up rather than losing it.
An `<If>` with an unknown prop also returned early, hiding the missing
condition and a malformed `<Else>` beside it. Every independent static check
now runs. Expansion's first-refusal behavior is unchanged: it stops at the
first violation over the same shared facts, and validation reads all of them.
Each regression was confirmed discriminating by reverting its fix.
* 🐛 Keep a targeted root's projection out of the definition a component selected (#653)
One path is bytes; what is parsed from them depends on who asked. Caching the
root under its path conflated the two, so a targeted root's projection stood in
for the full Markdown definition an ordinary component selection asks for — and
a `<Foo />` in the selected section returned `valid` while the sections the root
never selected held a definite `body-shape-invalid` failure.
Reading and parsing are now separate. A path is read once, whatever views the
walk needs; the full-definition view is registered per path. An untargeted
root's body is the whole file, so it registers as that view and a name resolving
there finds it already scanned — the self-cycle deduplication is unchanged. A
targeted root registers no view: a component selecting that path parses the full
definition from the bytes already read and enters the FIFO queue in discovery
order like any other source.
Both halves of the regression were confirmed discriminating: substituting the
projection again, and bypassing the content cache so the second view re-reads.
* 📝 Name the delivery PR in the construct inventory (#653)
* 🚑 Sort with what the Node lib provides (#653)
`Array.prototype.toSorted` is ES2023 and `tsconfig.node.json` targets ES2022,
so every `test-node` shard failed at its typecheck before running a test.
Deno's own lib is newer, which is why `deno check` and the whole local suite
were green.
Both call sites already build a fresh array, so sorting in place mutates
nothing anyone else holds. That reinstates an oxlint `no-array-sort` warning —
the shape the rest of the repository is in, and a warning rather than the
error this was.
Verified with the check CI runs: `tsc --project tsconfig.node.json --noEmit`,
plus the validation suite under all three runtimes.
* ♻️ Finish the extraction, and say what a source view is (#653)
Validation still reimplemented four authored decisions expansion owns: an
ordinary component's `as` form and binding name, the requirement that a
component declaring `returns` is invoked with `as`, and the `<Answers>` and
`<Answer>` prop, delegate, body-shape, template-form and required-value rules.
Sharing the sentences was not sharing the decisions.
New `invocation-rules.ts` owns the ordinary-component rules, and the `<Answers>`
and `<Answer>` rules in `structural-rules.ts` split into the phases their
callers ask in. Extraction is phase-appropriate rather than phase-bound: whether
`as` was written as an expression is answered from the scanned element, while
what a binding name may be is answered from whatever value each caller has —
expansion passes the prop it resolved, validation passes the literal the author
wrote. Expansion refuses at the first of them, in the phase it always did, with
byte-identical prose; validation aggregates every independent one.
The regressions run each document twice — once through `execute()`, once
through `validateDocument()` — and require one sentence from both. Each was
confirmed discriminating by giving expansion back a private copy of the rule.
The source/view contract is also corrected everywhere it was stated. Bytes are
read once per path; each semantic view of them is parsed and scanned once. An
untargeted root is that path's full-definition view as well. A targeted root's
projection and a component-selected full definition are two distinct views of
one path. The claim that a source identity is parsed or scanned once is gone
from architecture.md, the spec, the public comments and the tests.
---------
Co-authored-by: Taras Mankovski <[email protected]>1 parent 6625319 commit a6e8bb7
14 files changed
Lines changed: 4350 additions & 799 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3429 | 3429 | | |
3430 | 3430 | | |
3431 | 3431 | | |
| 3432 | + | |
| 3433 | + | |
| 3434 | + | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
| 3438 | + | |
| 3439 | + | |
| 3440 | + | |
| 3441 | + | |
| 3442 | + | |
| 3443 | + | |
| 3444 | + | |
| 3445 | + | |
| 3446 | + | |
| 3447 | + | |
| 3448 | + | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
| 3478 | + | |
| 3479 | + | |
| 3480 | + | |
| 3481 | + | |
| 3482 | + | |
| 3483 | + | |
| 3484 | + | |
| 3485 | + | |
| 3486 | + | |
| 3487 | + | |
| 3488 | + | |
| 3489 | + | |
| 3490 | + | |
| 3491 | + | |
| 3492 | + | |
| 3493 | + | |
| 3494 | + | |
| 3495 | + | |
| 3496 | + | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
| 3511 | + | |
| 3512 | + | |
| 3513 | + | |
| 3514 | + | |
| 3515 | + | |
| 3516 | + | |
3432 | 3517 | | |
3433 | 3518 | | |
3434 | 3519 | | |
3435 | 3520 | | |
3436 | 3521 | | |
3437 | 3522 | | |
3438 | 3523 | | |
| 3524 | + | |
3439 | 3525 | | |
3440 | 3526 | | |
3441 | 3527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
216 | 229 | | |
217 | 230 | | |
218 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
| |||
151 | 161 | | |
152 | 162 | | |
153 | 163 | | |
154 | | - | |
155 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
156 | 172 | | |
157 | 173 | | |
158 | | - | |
159 | | - | |
160 | | - | |
| 174 | + | |
| 175 | + | |
161 | 176 | | |
162 | 177 | | |
163 | 178 | | |
164 | 179 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 180 | + | |
171 | 181 | | |
172 | 182 | | |
173 | 183 | | |
| |||
218 | 228 | | |
219 | 229 | | |
220 | 230 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
232 | | - | |
| 237 | + | |
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
| |||
241 | 246 | | |
242 | 247 | | |
243 | 248 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
255 | 252 | | |
256 | 253 | | |
257 | 254 | | |
| |||
311 | 308 | | |
312 | 309 | | |
313 | 310 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
322 | 314 | | |
323 | 315 | | |
324 | 316 | | |
325 | | - | |
| 317 | + | |
326 | 318 | | |
327 | 319 | | |
328 | 320 | | |
| |||
351 | 343 | | |
352 | 344 | | |
353 | 345 | | |
354 | | - | |
| 346 | + | |
355 | 347 | | |
356 | 348 | | |
357 | 349 | | |
| |||
519 | 511 | | |
520 | 512 | | |
521 | 513 | | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
538 | 522 | | |
539 | 523 | | |
540 | 524 | | |
541 | 525 | | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | 526 | | |
546 | 527 | | |
547 | 528 | | |
| |||
564 | 545 | | |
565 | 546 | | |
566 | 547 | | |
567 | | - | |
568 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
569 | 551 | | |
570 | 552 | | |
571 | 553 | | |
| |||
575 | 557 | | |
576 | 558 | | |
577 | 559 | | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
578 | 565 | | |
579 | 566 | | |
580 | 567 | | |
| |||
641 | 628 | | |
642 | 629 | | |
643 | 630 | | |
644 | | - | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
645 | 635 | | |
646 | 636 | | |
647 | 637 | | |
648 | 638 | | |
649 | | - | |
| 639 | + | |
650 | 640 | | |
651 | 641 | | |
652 | 642 | | |
653 | 643 | | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
| 644 | + | |
| 645 | + | |
667 | 646 | | |
0 commit comments