refactor: clarify service boundaries and unify project tooling

This commit is contained in:
Meghdad committed 2026-10-16 18:46:23 +03:30
1 parent 1ca321e312
commit fda3ea9799
31 files changed
+832 -539

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env python3
"""Check public source paths, local Markdown links, and metadata references.
Reads Git-visible files only; ignored private configuration and outputs are never
opened. This is a hygiene check, not a substitute for reviewing secrets or a
release archive. Run from any directory within the checkout.
"""
import json
from pathlib import Path
import re
import subprocess
from urllib.parse import unquote, urlsplit
def main():
root = Path(subprocess.check_output(
["git", "rev-parse", "--show-toplevel"], text=True).strip())
names = subprocess.check_output(
["git", "ls-files", "--cached", "--others", "--exclude-standard", "-z"],
cwd=root).decode().split("\0")
errors = []
for name in sorted(set(names) - {""}):
path = root / name
if path.is_symlink():
errors.append(f"{name}: symlinks are not supported in public source checks")
continue
if not path.is_file(): # Deletions and renames not yet staged.
continue
parts = Path(name).parts
base = path.name
private = (
any(part in {"dist", "outputs", ".idea", "__pycache__", "certificates"}
for part in parts)
or (base.startswith(".env") and name != ".env.example")
or (base.startswith(".smb.") and name != ".smb.example.json")
or base in {"smb.json", "config.sh", "supervisor.private.sh"}
or path.suffix in {".key", ".pem", ".pcap", ".backup", ".log", ".pid"}
)
if private:
errors.append(f"{name}: private/generated material in public source set")
continue
if path.suffix != ".md":
continue
# Inline Markdown links; skip web links, anchors, and fenced examples.
content = re.sub(r"```.*?```", "", path.read_text(), flags=re.S)
for match in re.finditer(r"\]\((<[^>]+>|[^\s)]+)\)", content):
target = match[1].strip("<>")
url = urlsplit(target)
if url.scheme or url.netloc or not url.path:
continue
destination = (path.parent / unquote(url.path)).resolve()
if not destination.is_relative_to(root) or not destination.exists():
errors.append(f"{name}: broken local link {target}")
if errors:
raise SystemExit("\n".join(errors))
metadata = json.loads((root / "project.json").read_text())
for service in metadata["services"].values():
for key in ("entrypoint", "configuration", "documentation"):
if key in service and not (root / service[key]).exists():
errors.append(f"project.json: missing {key} {service[key]}")
if errors:
raise SystemExit("\n".join(errors))
print("Public source paths, local documentation links and service metadata valid")
if __name__ == "__main__":
main()
+56
View File
@@ -0,0 +1,56 @@
"""Exercise the repository checker against disposable Git working trees."""
import json
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
CHECKER = Path(__file__).resolve().parents[1] / "check_repository.py"
class RepositoryChecks(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory(prefix="routershelf-source-check-")
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
subprocess.run(["git", "init", "--quiet", str(self.root)], check=True)
(self.root / ".gitignore").write_text(".env\noutputs/\n")
(self.root / "README.md").write_text("[Guide](guide.md)\n")
(self.root / "guide.md").write_text("Public guide\n")
(self.root / "project.json").write_text(json.dumps({
"services": {"web": {"entrypoint": "README.md",
"configuration": "guide.md"}}}))
def check(self):
return subprocess.run([sys.executable, "-B", str(CHECKER)],
cwd=self.root, capture_output=True, text=True)
def test_ignored_private_data_is_excluded(self):
(self.root / ".env").write_text("do not read or expose this private value")
(self.root / "outputs").mkdir()
(self.root / "outputs" / "private.md").write_text("[Broken](absent)")
result = self.check()
self.assertEqual(result.returncode, 0, result.stderr)
self.assertNotIn("private value", result.stdout + result.stderr)
def test_broken_links_and_private_source_are_rejected(self):
(self.root / "README.md").write_text("[Missing](absent.md)\n")
(self.root / "account.key").write_text("must never appear in diagnostics")
result = self.check()
self.assertNotEqual(result.returncode, 0)
self.assertIn("broken local link absent.md", result.stderr)
self.assertIn("account.key: private/generated", result.stderr)
self.assertNotIn("must never appear", result.stdout + result.stderr)
def test_symlink_cannot_open_ignored_private_data(self):
(self.root / ".env").write_text("private-data-sentinel")
(self.root / "leak.md").symlink_to(".env")
result = self.check()
self.assertNotEqual(result.returncode, 0)
self.assertIn("leak.md: symlinks", result.stderr)
self.assertNotIn("private-data-sentinel", result.stdout + result.stderr)
if __name__ == "__main__":
unittest.main()