"""Unit tests for OpenSourceMalware heuristics integration."""

import unittest
from metapackage import MetaPackage
from analysis import heuristics


class TestOpenSourceMalwareHeuristics(unittest.TestCase):
    """Test cases for OpenSourceMalware heuristics integration."""

    def setUp(self):
        """Set up test fixtures."""
        self.mp = MetaPackage("test-package", "npm")
        self.mp.exists = True

    def test_heuristics_auto_fail_malicious(self):
        """Test that heuristics auto-fail malicious packages."""
        self.mp.osm_malicious = True
        self.mp.osm_reason = "Cryptocurrency miner"
        self.mp.score = 0.8  # High score initially

        heuristics.run_heuristics([self.mp])

        # Score should be overridden to 0.0
        self.assertEqual(self.mp.score, 0.0)

    def test_heuristics_allow_clean(self):
        """Test that heuristics allow clean packages."""
        self.mp.osm_malicious = False
        self.mp.osm_checked = True
        self.mp.score = 0.8

        heuristics.run_heuristics([self.mp])

        # Score should remain unchanged
        self.assertEqual(self.mp.score, 0.8)


if __name__ == "__main__":
    unittest.main()
