import json
import unittest
from pathlib import Path


PROJECT_ROOT = Path(__file__).resolve().parents[1]
MANIFEST_PATH = PROJECT_ROOT / "data" / "drivers" / "nvidia-gpu.json"
NVIDIA_IMAGE = "quay.io/stillhq/stillos-workstation-nvidia"


class NvidiaDriverTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.manifest = json.loads(MANIFEST_PATH.read_text(encoding="utf-8"))
        cls.check_script = "\n".join(cls.manifest["check_script"])
        cls.install_script = "\n".join(cls.manifest["install_script"])
        cls.success_script = "\n".join(cls.manifest["success_script"])

    def test_switches_to_nvidia_workstation_image(self):
        self.assertIn("io.stillhq.SamService.add_dict_to_queue", self.install_script)
        self.assertIn("nvidia-driver", self.install_script)
        self.assertIn("'system', 'nvidia'", self.install_script)
        self.assertNotIn("bootc switch", self.install_script)
        self.assertNotIn("rpm-ostree install", self.install_script)

    def test_skips_and_verifies_using_bootc_image_status(self):
        self.assertIn(NVIDIA_IMAGE, self.check_script)
        self.assertIn("bootc status --json", self.check_script)
        self.assertIn("get_queue_actions_dict", self.success_script)


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