@@ -2,6 +2,10 @@ |
| 2 | 2 | |
| 3 | 3 | from __future__ import annotations |
| 4 | 4 | |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 5 | 9 | from dlm_lsp.doc_state import DocumentState, StateStore |
| 6 | 10 | |
| 7 | 11 | _MINIMAL_DLM = """\ |
@@ -41,6 +45,29 @@ class TestDocumentState: |
| 41 | 45 | assert state.ensure_parsed() is None |
| 42 | 46 | assert state.parse_error is None |
| 43 | 47 | |
| 48 | + def test_ensure_store_creates_store_on_first_call( |
| 49 | + self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path |
| 50 | + ) -> None: |
| 51 | + monkeypatch.setenv("DLM_HOME", str(tmp_path)) |
| 52 | + state = DocumentState(uri="file:///a.dlm", text=_MINIMAL_DLM) |
| 53 | + created = state.ensure_store() |
| 54 | + assert created is True |
| 55 | + manifest = tmp_path / "store" / "01KPQ9M3000000000000000000" / "manifest.json" |
| 56 | + assert manifest.exists() |
| 57 | + |
| 58 | + def test_ensure_store_skips_if_already_exists( |
| 59 | + self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path |
| 60 | + ) -> None: |
| 61 | + monkeypatch.setenv("DLM_HOME", str(tmp_path)) |
| 62 | + state = DocumentState(uri="file:///a.dlm", text=_MINIMAL_DLM) |
| 63 | + state.ensure_store() |
| 64 | + created_again = state.ensure_store() |
| 65 | + assert created_again is False |
| 66 | + |
| 67 | + def test_ensure_store_returns_false_on_bad_doc(self) -> None: |
| 68 | + state = DocumentState(uri="file:///a.dlm", text="not a dlm file") |
| 69 | + assert state.ensure_store() is False |
| 70 | + |
| 44 | 71 | def test_ensure_base_model_spec_resolves_registry_key(self) -> None: |
| 45 | 72 | state = DocumentState(uri="file:///a.dlm", text=_MINIMAL_DLM) |
| 46 | 73 | spec = state.ensure_base_model_spec() |