Commit fd03b22
committed
feat(python): FR5a — thread source through parser + validation + MetaData.source
Wires the FR5a foundation (commit c163bae) into the loader pipeline so every
parser-constructed metadata node carries its origin and every error raised
during parse / per-node validation produces an ADR-0009-shaped envelope.
* `meta/meta_data.py` — new `source` property + `set_source` setter
(freeze-guarded). Defaults to `CodeSource.DEFAULT` for programmatic /
test construction, mirroring the C# `MetaData.Source` contract.
* `errors.py` — `MetaError` gains an `envelope: ErrorSource | None` field
alongside the legacy `source` / `path` strings (conformance still inspects
`code` only; the envelope is additive).
* `parser.py` — threads a `JsonPathBuilder` through the recursion. Pushes
the wrapper key at root, the `children` key + `[i]` index + child wrapper
on each descent, and the `@key` for reserved-attr errors. Every node
created in `_build` calls `set_source(JsonSource(files=(src,), json_path=…))`;
every error raised mid-parse passes the same envelope via the new
`_current_envelope` helper. Falls back to `CodeSource.DEFAULT` when the
source id is missing — matches the C# `ParseState.CurrentSource` fallback
so the FR5a length-1 invariant on `JsonSource.files` can't be violated.
* `loader/validation_passes.py` — 29 `MetaError(...)` sites updated to pass
`envelope=<node>.source` where a node is in scope. `_validate_entity_field_ref`
and `_validate_via_path` gained a required `origin_node` parameter so
`@from` / `@of` / `@via` failures attach to the origin node, not just a
text label.
* `loader/meta_data_loader.py` — top-level OSError / JSON-decode / YAML
parse-error sites build a `JsonSource(files=(src.id,), json_path="$")`
envelope (with `CodeSource` fallback when the source has no real id).
* `source/error_source.py` — `CodeSource.DEFAULT` declared as a class-level
`ClassVar["CodeSource"]` so mypy sees the singleton statically.
* `source/semantic_diff.py` — lazy MetaData import to break the
meta_data ↔ source module cycle; `bool(...)` cast on the return path for
strict-mypy compatibility.
The canonical JSON serializer already only emits recognized structural keys,
so `source` is naturally omitted from `canonical_serialize` output — verified
by the new `test_canonical_serializer_omits_source_from_output` test.
Tests: +7 new in `tests/source/test_source_on_node.py` (programmatic default;
freeze guard; parser populates JsonSource on every node with correct
bracket-vs-dot JSONPath segmentation; canonical serializer omits `source`;
parse-error envelope carries the right files+jsonPath; MetaData subclass
inheritance). Conformance baseline unchanged (94/94). Full Python suite:
466 baseline + 28 new FR5a = 494/494 green.1 parent c163bae commit fd03b22
8 files changed
Lines changed: 344 additions & 33 deletions
File tree
- server/python
- src/metaobjects
- loader
- meta
- source
- tests/source
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
51 | 62 | | |
52 | 63 | | |
53 | 64 | | |
54 | 65 | | |
55 | 66 | | |
56 | 67 | | |
57 | 68 | | |
| 69 | + | |
58 | 70 | | |
59 | 71 | | |
60 | 72 | | |
61 | 73 | | |
62 | 74 | | |
| 75 | + | |
63 | 76 | | |
64 | 77 | | |
65 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
142 | 151 | | |
143 | 152 | | |
144 | 153 | | |
145 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
146 | 157 | | |
147 | 158 | | |
148 | 159 | | |
149 | 160 | | |
150 | 161 | | |
151 | 162 | | |
152 | 163 | | |
153 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
154 | 167 | | |
155 | 168 | | |
156 | 169 | | |
157 | 170 | | |
158 | 171 | | |
159 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
160 | 176 | | |
161 | 177 | | |
Lines changed: 37 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| |||
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
| 222 | + | |
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
| |||
231 | 233 | | |
232 | 234 | | |
233 | 235 | | |
| 236 | + | |
234 | 237 | | |
235 | 238 | | |
236 | 239 | | |
| |||
277 | 280 | | |
278 | 281 | | |
279 | 282 | | |
| 283 | + | |
280 | 284 | | |
281 | 285 | | |
282 | 286 | | |
| |||
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
| 296 | + | |
292 | 297 | | |
293 | 298 | | |
294 | 299 | | |
| |||
299 | 304 | | |
300 | 305 | | |
301 | 306 | | |
| 307 | + | |
302 | 308 | | |
303 | 309 | | |
304 | 310 | | |
| |||
337 | 343 | | |
338 | 344 | | |
339 | 345 | | |
| 346 | + | |
340 | 347 | | |
341 | 348 | | |
342 | 349 | | |
| |||
415 | 422 | | |
416 | 423 | | |
417 | 424 | | |
| 425 | + | |
418 | 426 | | |
419 | 427 | | |
420 | 428 | | |
| |||
434 | 442 | | |
435 | 443 | | |
436 | 444 | | |
| 445 | + | |
437 | 446 | | |
438 | 447 | | |
439 | 448 | | |
| |||
480 | 489 | | |
481 | 490 | | |
482 | 491 | | |
| 492 | + | |
483 | 493 | | |
484 | 494 | | |
485 | 495 | | |
486 | 496 | | |
487 | 497 | | |
488 | | - | |
| 498 | + | |
| 499 | + | |
489 | 500 | | |
490 | 501 | | |
491 | 502 | | |
492 | 503 | | |
493 | 504 | | |
494 | 505 | | |
495 | 506 | | |
| 507 | + | |
496 | 508 | | |
497 | 509 | | |
498 | 510 | | |
| |||
503 | 515 | | |
504 | 516 | | |
505 | 517 | | |
| 518 | + | |
506 | 519 | | |
507 | 520 | | |
508 | 521 | | |
| |||
513 | 526 | | |
514 | 527 | | |
515 | 528 | | |
| 529 | + | |
516 | 530 | | |
517 | 531 | | |
518 | 532 | | |
| |||
524 | 538 | | |
525 | 539 | | |
526 | 540 | | |
| 541 | + | |
527 | 542 | | |
528 | 543 | | |
529 | 544 | | |
530 | 545 | | |
| 546 | + | |
531 | 547 | | |
532 | 548 | | |
533 | 549 | | |
534 | 550 | | |
535 | 551 | | |
536 | 552 | | |
537 | 553 | | |
| 554 | + | |
538 | 555 | | |
539 | 556 | | |
540 | 557 | | |
| |||
547 | 564 | | |
548 | 565 | | |
549 | 566 | | |
| 567 | + | |
550 | 568 | | |
551 | 569 | | |
552 | 570 | | |
| |||
561 | 579 | | |
562 | 580 | | |
563 | 581 | | |
| 582 | + | |
564 | 583 | | |
565 | 584 | | |
566 | 585 | | |
| |||
573 | 592 | | |
574 | 593 | | |
575 | 594 | | |
| 595 | + | |
576 | 596 | | |
577 | 597 | | |
578 | 598 | | |
| |||
584 | 604 | | |
585 | 605 | | |
586 | 606 | | |
| 607 | + | |
587 | 608 | | |
588 | 609 | | |
589 | 610 | | |
| |||
619 | 640 | | |
620 | 641 | | |
621 | 642 | | |
| 643 | + | |
622 | 644 | | |
623 | 645 | | |
624 | 646 | | |
625 | 647 | | |
626 | | - | |
| 648 | + | |
627 | 649 | | |
628 | 650 | | |
629 | 651 | | |
630 | | - | |
| 652 | + | |
631 | 653 | | |
632 | 654 | | |
633 | 655 | | |
| |||
636 | 658 | | |
637 | 659 | | |
638 | 660 | | |
| 661 | + | |
639 | 662 | | |
640 | 663 | | |
641 | 664 | | |
642 | 665 | | |
643 | | - | |
| 666 | + | |
644 | 667 | | |
645 | 668 | | |
646 | 669 | | |
647 | 670 | | |
648 | 671 | | |
649 | 672 | | |
650 | 673 | | |
| 674 | + | |
651 | 675 | | |
652 | 676 | | |
653 | 677 | | |
654 | | - | |
| 678 | + | |
655 | 679 | | |
656 | 680 | | |
657 | 681 | | |
| |||
691 | 715 | | |
692 | 716 | | |
693 | 717 | | |
| 718 | + | |
694 | 719 | | |
695 | 720 | | |
696 | 721 | | |
| |||
699 | 724 | | |
700 | 725 | | |
701 | 726 | | |
| 727 | + | |
702 | 728 | | |
703 | 729 | | |
704 | 730 | | |
| |||
736 | 762 | | |
737 | 763 | | |
738 | 764 | | |
| 765 | + | |
739 | 766 | | |
740 | 767 | | |
741 | 768 | | |
| |||
812 | 839 | | |
813 | 840 | | |
814 | 841 | | |
| 842 | + | |
815 | 843 | | |
816 | 844 | | |
817 | 845 | | |
| |||
821 | 849 | | |
822 | 850 | | |
823 | 851 | | |
| 852 | + | |
824 | 853 | | |
825 | 854 | | |
826 | 855 | | |
| |||
853 | 882 | | |
854 | 883 | | |
855 | 884 | | |
| 885 | + | |
856 | 886 | | |
857 | 887 | | |
858 | 888 | | |
| |||
868 | 898 | | |
869 | 899 | | |
870 | 900 | | |
| 901 | + | |
871 | 902 | | |
872 | 903 | | |
873 | 904 | | |
| |||
885 | 916 | | |
886 | 917 | | |
887 | 918 | | |
| 919 | + | |
888 | 920 | | |
889 | 921 | | |
890 | 922 | | |
| |||
0 commit comments