diff --git a/server/app/config.py b/server/app/config.py index 17c3da2..64b38b6 100644 --- a/server/app/config.py +++ b/server/app/config.py @@ -37,6 +37,9 @@ ) self.storage_backend = backend self.database_url = database_url or os.environ.get("GNEXUS_BOOK_DATABASE_URL") + self.file_backend_frozen = os.environ.get( + "GNEXUS_BOOK_FILE_BACKEND_FROZEN", "false" + ).lower() in {"1", "true", "yes", "on"} self.auth_client_id = os.environ.get("GNEXUS_BOOK_AUTH_CLIENT_ID") self.auth_client_secret = os.environ.get("GNEXUS_BOOK_AUTH_CLIENT_SECRET") diff --git a/server/app/git_adapter.py b/server/app/git_adapter.py index 3e4f323..559d5e7 100644 --- a/server/app/git_adapter.py +++ b/server/app/git_adapter.py @@ -59,6 +59,11 @@ "Write path is not available in database mode yet; use the file backend " "until Phase 2 of the PostgreSQL migration" ) + if self.settings.file_backend_frozen: + raise GitAdapterError( + "The file backend is frozen after the PostgreSQL cutover; " + "use database changesets instead" + ) validation = validate_repository(self.settings) if validation["status"] != "ok": raise GitAdapterError("Repository validation failed; commit blocked") diff --git a/server/app/pending_changes.py b/server/app/pending_changes.py index 690f0de..32bd24d 100644 --- a/server/app/pending_changes.py +++ b/server/app/pending_changes.py @@ -122,6 +122,7 @@ raise PendingChangeError("Only doc and inventory-item changes can be applied in the current MVP") def delete(self, change_id: str) -> dict[str, Any]: + self._require_file_backend() path = self._path_for_id(change_id) if not path.exists(): raise PendingChangeError("Pending change not found") @@ -261,6 +262,11 @@ "Write path is not available in database mode yet; use the " "database changeset repository" ) + if self.settings.file_backend_frozen: + raise PendingChangeError( + "The file backend is frozen after the PostgreSQL cutover; " + "use database changesets instead" + ) def _new_id(self) -> str: return datetime.now(UTC).strftime("%Y%m%d%H%M%S") + "-" + uuid4().hex[:8] diff --git a/server/tests/test_pending_changes.py b/server/tests/test_pending_changes.py index 4fc98ed..2bf0243 100644 --- a/server/tests/test_pending_changes.py +++ b/server/tests/test_pending_changes.py @@ -1,7 +1,23 @@ +import pytest + from app.config import Settings from app.pending_changes import PendingChangeError, PendingChangeRepository, ProposedChangeRequest +def test_frozen_file_backend_blocks_writes(tmp_path, monkeypatch) -> None: + monkeypatch.setenv("GNEXUS_BOOK_FILE_BACKEND_FROZEN", "true") + repo = PendingChangeRepository(Settings(tmp_path)) + request = ProposedChangeRequest( + kind="inventory-item", + target="virtual-machines/gnauth", + summary="Update gnauth VM metadata", + payload={"runs_services": ["gnexus-auth"]}, + ) + + with pytest.raises(PendingChangeError, match="frozen"): + repo.create(request) + + def test_creates_and_reads_pending_change(tmp_path) -> None: repo = PendingChangeRepository(Settings(tmp_path)) request = ProposedChangeRequest(