from pathlib import Path
import sys
import unittest

ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "scripts"))
from scaffold_slice import Spec, plan, validate  # noqa: E402

class ScaffoldSliceTests(unittest.TestCase):
    def test_plan_is_deterministic_and_contains_be_fe_contracts(self):
        spec = Spec("MarketData", "IngestDailyBars", "REQ-DAT-001", "Post", "internal/v1/data/bars", "DataOps", "market-data")
        first = plan(spec)
        second = plan(spec)
        self.assertEqual(first, second)
        paths = {str(path.relative_to(ROOT)) for path in first}
        self.assertIn("src/KArtSell.Modules.MarketData/Features/IngestDailyBars/Endpoint.cs", paths)
        self.assertIn("frontend/src/features/market-data/schema.ts", paths)
        self.assertTrue(all("__" not in content for content in first.values()))

    def test_invalid_or_unsafe_spec_is_rejected(self):
        with self.assertRaises(ValueError):
            validate(Spec("marketData", "Slice", "REQ-X", "Post", "/unsafe", "Unknown", "Bad_Feature"))

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