Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
This commit is contained in:
1 parent
9dd425f765
commit
d5d21b7841
302 files changed
+20037
-3492
No files matched your search
@@ -9,6 +9,7 @@ Uses only the Python standard library.
|
||||
from __future__ import annotations
|
||||
|
||||
import difflib
|
||||
import fcntl
|
||||
import fnmatch
|
||||
import glob
|
||||
import hashlib
|
||||
@@ -336,6 +337,26 @@ class PagesWikiCLI:
|
||||
if not self.database_path.is_file():
|
||||
raise CLIError(f"SQLite database not found: {self.database_path}")
|
||||
|
||||
# Coordinate with offline DR snapshots/promotions. Do this before any
|
||||
# schema repair or content write. A standby never permits this CLI.
|
||||
self._instance_lock = None
|
||||
try:
|
||||
lock_path = self.database_path.parent / ".pageswiki-instance.lock"
|
||||
self._instance_lock = lock_path.open("rb") if lock_path.exists() else lock_path.open("a+b")
|
||||
fcntl.flock(self._instance_lock.fileno(), fcntl.LOCK_SH | fcntl.LOCK_NB)
|
||||
for root in {self.data_dir, self.database_path.parent, self.documents.parent}:
|
||||
config_path = root / "dr-node.json"
|
||||
if config_path.exists():
|
||||
config = json.loads(config_path.read_text())
|
||||
if not isinstance(config, dict) or config.get("version") != 1 or config.get("role") != "primary":
|
||||
raise CLIError("DR standby or invalid configuration: data CLI is disabled")
|
||||
if root != self.database_path.parent or self.documents != root / "documents":
|
||||
raise CLIError("DR requires DB and documents in the same instance data directory")
|
||||
except (OSError, ValueError, CLIError) as exc:
|
||||
if self._instance_lock is not None:
|
||||
self._instance_lock.close()
|
||||
raise CLIError(f"DR maintenance guard: {exc}") from exc
|
||||
|
||||
self.db = sqlite3.connect(
|
||||
self.database_path,
|
||||
timeout=30,
|
||||
@@ -351,6 +372,8 @@ class PagesWikiCLI:
|
||||
|
||||
def close(self) -> None:
|
||||
self.db.close()
|
||||
if self._instance_lock is not None:
|
||||
self._instance_lock.close()
|
||||
|
||||
def _check_schema(self) -> None:
|
||||
required = {"objects", "paths", "revisions"}
|
||||
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compatibility launcher for the unreleased prototype. Prefer pages-cli/pages."""
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
print('Renamed to pages (pages-cli). Use pages configure, then pages login. See pages-cli/README.md.', file=sys.stderr)
|
||||
runpy.run_path(str(Path(__file__).resolve().parent.parent / 'pages-cli' / 'pages'), run_name='__main__')
|
||||
@@ -0,0 +1,34 @@
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from pageswiki_cli_test import pageswiki_cli
|
||||
|
||||
|
||||
class DRGuardTest(unittest.TestCase):
|
||||
def test_standby_rejected_before_database_open(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
(root / "pages.db").write_bytes(b"not a database; must not be opened")
|
||||
(root / "dr-node.json").write_text(json.dumps({"version": 1, "role": "standby"}))
|
||||
with patch.dict(os.environ, {"PAGESWIKI_DATA_DIR": directory, "PAGESWIKI_DB": str(root / "pages.db"), "PAGESWIKI_DOCUMENTS_DIR": str(root / "documents")}):
|
||||
with self.assertRaisesRegex(pageswiki_cli.CLIError, "standby"):
|
||||
pageswiki_cli.PagesWikiCLI()
|
||||
|
||||
def test_offline_maintenance_lock_blocks_cli(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
(root / "pages.db").write_bytes(b"not a database")
|
||||
with (root / ".pageswiki-instance.lock").open("wb") as lock:
|
||||
fcntl.flock(lock.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
with patch.dict(os.environ, {"PAGESWIKI_DATA_DIR": directory, "PAGESWIKI_DB": str(root / "pages.db")}):
|
||||
with self.assertRaisesRegex(pageswiki_cli.CLIError, "maintenance guard"):
|
||||
pageswiki_cli.PagesWikiCLI()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user