import json
from pathlib import Path
import tempfile
import unittest
from train_suite34 import verify_completed, collect


class CompletionManifestTests(unittest.TestCase):
    def test_uncommitted_staging_directory_is_not_a_completed_cell(self):
        with tempfile.TemporaryDirectory() as td:
            output = Path(td)
            staging = output/"cells/incomplete_interrupted"
            staging.mkdir(parents=True)
            (staging/"complete.json").write_text("{}")
            result = collect(output, "same")
            self.assertTrue(result["metrics"].empty)

    def test_missing_artifact_manifest_cannot_mark_cell_complete(self):
        with tempfile.TemporaryDirectory() as td:
            path = Path(td)
            (path/"complete.json").write_text(json.dumps(dict(run_signature="same", artifacts={})))
            with self.assertRaisesRegex(ValueError, "artifact|manifest"):
                verify_completed(path, "same")
