"""Inventory stub filter — run: python tests/test_inventory_filter.py

Citrix published-app delivery writes a registry stub for software that is NOT
installed: a self-chosen product name and a placeholder version ("SAP Business
Client 1.0", "Firefox 1.0"). Matched against CVE data, a 1.0 looks ancient and
every path reports decade-old CVEs on it.
"""
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.services.app_cve_scanner_service import filter_inventory


def demo():
    inv = [
        {"name": "SAP Business Client", "version": "1.0",
         "vendor": "Delivered by Citrix"},
        {"name": "Firefox", "version": "1.0", "vendor": "Delivered by Citrix"},
        {"name": "SAP Business Client 7.0", "version": "7.0 PL21", "vendor": "SAP SE"},
        {"name": "Mozilla Firefox", "version": "141.0", "vendor": "Mozilla"},
        {"name": "Some Tool", "version": "2.1"},           # no vendor at all
    ]
    kept = filter_inventory(inv)
    assert [p["name"] for p in kept] == [
        "SAP Business Client 7.0", "Mozilla Firefox", "Some Tool"]

    # Real Citrix software IS installed and must still be scanned — the stub is
    # identified by the DELIVERY vendor, so this one is a known limitation:
    # a genuine Citrix product from vendor "Citrix Systems" is dropped too.
    # ponytail: vendor-word match; if a real Citrix CVE is ever missed, match
    # the "delivered by" phrasing instead of the bare vendor word.

    assert filter_inventory([]) == []
    assert filter_inventory(None) == []

    print("inventory filter OK")


if __name__ == "__main__":
    demo()
