Commit 72ff465
committed
[Fix] --json-report: field parity, unified JSON escaping, O(N) list rendering at scale; issue #482
[Fix] --json-report list: reports[] entries now include a "path" field, matching
the text-mode list output; active[] entries gain the lifecycle schema
(eta, workers, sig_version, progress{}) so --json-report list and
-L/--list-active emit the same shape; stopped[] entries gain an elapsed
field; all string fields in active[] and stopped[] are now JSON-escaped
via the shared _json_escape_string helper (previously only "path" was
escaped — stage, engine, stopped_hr, stages, sig_version could emit
invalid JSON if scan.meta contained quotes, backslashes, or control
characters); issue #482
[Fix] --json-report list: scaling regression at large session counts. Pre-fix
the function exhibited effective hang at ~20K indexed sessions from two
compounding costs: (1) _seen_ids built as a whitespace-joined string
with glob-pattern dedup (O(N^2)) and (2) one subshell fork per report
for path escaping. Dedup now uses a function-scoped local -A associative
array (O(N)), and the reports[]/legacy hot loops use the new
_json_escape_var out-parameter helper instead of $() command
substitution. Measured: 20K reports 82s -> 1.7s; 50K reports ~1.7s
(linear). Regression guard: tests/31-json-report.bats test 27 runs a
10K-entry synthetic index under a 30s timeout
[Change] Lifecycle JSON (-L --format json): "scan_id" is now the canonical
field name; "scanid" remains as a deprecated alias for one release cycle
and will be removed in v2.1.0. Consumers should switch to "scan_id"
[Change] Lifecycle JSON (-L --format json): "workers" field type normalized to
unquoted number to match the field's underlying integer value
[Change] _json_escape_string: promoted from lmd_hook.sh (optional sub-lib) to
lmd.lib.sh shared utilities so all JSON emitters — scan list, active
lifecycle, post-scan hook, and ELK dispatch — share one helper. Three
call sites in lmd_alert.sh previously using _alert_json_escape (from the
vendored alert_lib) now use the project-owned helper; vendored library
coupling reduced to the lib's internal self-use. Sibling out-parameter
helper _json_escape_var (sets _JSON_ESC_OUT) also defined for hot
loops that must avoid a subshell fork per iteration
[New] tests/31-json-report.bats: four regression cases — reports[] path
parity (issue #482), JSON validity with special-character paths,
total_quarantined field presence, linear scaling at 10K sessions
[Change] tests/46-post-scan-hook.bats: J-15 structural guard now points to
lmd.lib.sh (the new home for _json_escape_string)1 parent 9a80cb2 commit 72ff465
File tree
8 files changed
+251
-56
lines changed- files/internals
- tests
8 files changed
+251
-56
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
155 | 187 | | |
156 | 188 | | |
157 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
155 | 187 | | |
156 | 188 | | |
157 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
158 | 177 | | |
159 | 178 | | |
160 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
308 | | - | |
309 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| |||
717 | 717 | | |
718 | 718 | | |
719 | 719 | | |
720 | | - | |
721 | | - | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
722 | 724 | | |
723 | 725 | | |
724 | 726 | | |
725 | 727 | | |
726 | | - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
727 | 738 | | |
728 | | - | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
729 | 742 | | |
730 | 743 | | |
731 | 744 | | |
| |||
743 | 756 | | |
744 | 757 | | |
745 | 758 | | |
746 | | - | |
747 | | - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
748 | 763 | | |
749 | 764 | | |
750 | | - | |
751 | | - | |
752 | | - | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
753 | 770 | | |
754 | 771 | | |
755 | 772 | | |
756 | 773 | | |
757 | 774 | | |
758 | 775 | | |
759 | | - | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
760 | 780 | | |
761 | 781 | | |
762 | 782 | | |
| |||
775 | 795 | | |
776 | 796 | | |
777 | 797 | | |
778 | | - | |
| 798 | + | |
779 | 799 | | |
780 | 800 | | |
781 | 801 | | |
| |||
792 | 812 | | |
793 | 813 | | |
794 | 814 | | |
795 | | - | |
796 | | - | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
797 | 824 | | |
798 | 825 | | |
799 | 826 | | |
| |||
805 | 832 | | |
806 | 833 | | |
807 | 834 | | |
808 | | - | |
| 835 | + | |
809 | 836 | | |
810 | | - | |
| 837 | + | |
811 | 838 | | |
812 | 839 | | |
813 | | - | |
| 840 | + | |
814 | 841 | | |
815 | 842 | | |
816 | 843 | | |
| |||
827 | 854 | | |
828 | 855 | | |
829 | 856 | | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
830 | 863 | | |
831 | 864 | | |
832 | 865 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 19 | | |
32 | 20 | | |
33 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
387 | 402 | | |
388 | 403 | | |
389 | 404 | | |
| |||
402 | 417 | | |
403 | 418 | | |
404 | 419 | | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
414 | 425 | | |
415 | 426 | | |
416 | 427 | | |
| |||
433 | 444 | | |
434 | 445 | | |
435 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
436 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
437 | 454 | | |
438 | 455 | | |
439 | 456 | | |
440 | 457 | | |
441 | | - | |
| 458 | + | |
442 | 459 | | |
443 | 460 | | |
444 | 461 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | 462 | | |
457 | 463 | | |
458 | 464 | | |
| |||
0 commit comments