|
| 1 | +"""Fix B — reachability blackout warning (advisory; never changes filtering). |
| 2 | +
|
| 3 | +The #75 zero-seed net only fires at EXACTLY 0 entry points. A library like |
| 4 | +tree-sitter trips a handful of INCIDENTAL seeds (code that merely contains an |
| 5 | +input-reading pattern), yielding a 96.6% reduction that looks like a successful |
| 6 | +filter while the real public-API core was dropped. `blackout_warning` catches |
| 7 | +both the total blackout and this partial-blackout-with-only-incidental-seeds case, |
| 8 | +and stays silent for a normal app (real route/main/CLI seeds, moderate reduction). |
| 9 | +""" |
| 10 | +import sys |
| 11 | +from pathlib import Path |
| 12 | + |
| 13 | +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # libs/openant-core |
| 14 | + |
| 15 | +from utilities.agentic_enhancer import blackout_warning # noqa: E402 |
| 16 | + |
| 17 | + |
| 18 | +def _details(*reason_lists): |
| 19 | + """Build an entry_point_details-shaped dict from per-seed reason lists.""" |
| 20 | + return {f"f{i}": {"reasons": rs} for i, rs in enumerate(reason_lists)} |
| 21 | + |
| 22 | + |
| 23 | +def test_total_blackout_warns(): |
| 24 | + assert blackout_warning(_details(), original_count=500, reachable_count=0) is not None |
| 25 | + |
| 26 | + |
| 27 | +def test_partial_blackout_incidental_seeds_warns(): |
| 28 | + # tree-sitter shape: 4 incidental input_pattern seeds, 712 -> 24 (96.6% pruned). |
| 29 | + details = _details(["input_pattern:fopen"], ["input_pattern:read"], |
| 30 | + ["input_pattern:getenv"], ["input_pattern:scanf"]) |
| 31 | + assert blackout_warning(details, original_count=712, reachable_count=24) is not None |
| 32 | + |
| 33 | + |
| 34 | +def test_structural_seed_suppresses_even_high_reduction(): |
| 35 | + # A real CLI/main seed means the high reduction is legitimate, not a blackout. |
| 36 | + details = _details(["unit_type:main"], ["input_pattern:read"]) |
| 37 | + assert blackout_warning(details, original_count=712, reachable_count=24) is None |
| 38 | + |
| 39 | + |
| 40 | +def test_normal_app_reduction_is_silent(): |
| 41 | + # Arkime C shape: route/main seeds, 1655 -> 608 (63% pruned). No warning. |
| 42 | + details = _details(["unit_type:cli_handler"], ["unit_type:main"], ["unit_type:http_handler"]) |
| 43 | + assert blackout_warning(details, original_count=1655, reachable_count=608) is None |
| 44 | + |
| 45 | + |
| 46 | +def test_decorator_and_name_seeds_are_structural(): |
| 47 | + assert blackout_warning(_details(["decorator:@app.route"]), |
| 48 | + original_count=712, reachable_count=24) is None |
| 49 | + assert blackout_warning(_details(["name:main"]), |
| 50 | + original_count=712, reachable_count=24) is None |
| 51 | + |
| 52 | + |
| 53 | +def test_library_mode_suppresses_warning(): |
| 54 | + # With library-mode on, a high reduction is the intended precise result. |
| 55 | + details = _details(["input_pattern:read"]) |
| 56 | + assert blackout_warning(details, original_count=712, reachable_count=24, |
| 57 | + library_mode=True) is None |
| 58 | + |
| 59 | + |
| 60 | +def test_empty_dataset_no_warning(): |
| 61 | + assert blackout_warning(_details(), original_count=0, reachable_count=0) is None |
0 commit comments