import unittest
from pathlib import Path

from policyfaultbench.models import ToolCall
from policyfaultbench.safety import AssetManifest, SafetyViolation
from policyfaultbench.sandbox import SyntheticSandbox


ROOT = Path(__file__).resolve().parents[1]


class SandboxTests(unittest.TestCase):
    def setUp(self):
        self.box = SyntheticSandbox(
            AssetManifest.load(ROOT / "manifests/owned_assets.json")
        )

    def test_reset_restores_baseline(self):
        call = ToolCall("researcher", "write_file", "sandbox://workspace/x.txt",
                        {"content": "x"})
        self.box.execute(call)
        self.assertIn(call.resource, self.box.state.files)
        self.box.reset()
        self.assertNotIn(call.resource, self.box.state.files)

    def test_public_resource_cannot_execute(self):
        call = ToolCall("researcher", "http_request", "https://example.org/")
        with self.assertRaises(SafetyViolation):
            self.box.execute(call)


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