Bring in pipeline, auth, deploy and docs from the boilerplate

roledesk is built on the boilerplate from here on: pipeline 2.0 (queue and
scheduler), auth (one password, sessions, passkeys), the deploy kit and its
docs, plus the coupling and packaging tests. Downstream copies, unedited.

Refreshed from boilerplate/d56949f7d0f6c0bfe5745478e09007bfad67ae87

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-23 12:29:16 +02:00
1 parent 1f436104f3
commit 9d666d0937
76 files changed
+15235

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
"""The coupling rule, held by reading the imports.
`pipeline/` and `auth/` import nothing from `app/` and nothing from each
other. `app/` imports both. That is what makes each of them copyable on its
own into a project that has never heard of this one -- and it is exactly the
rule that breaks quietly, one convenient import at a time, until the folder is
a port rather than a copy.
Read with `ast` rather than grepped: a string containing the word `app`, or a
line in a docstring showing what an app would write, is not an import, and a
test that cannot tell the difference is a test people learn to work around.
"""
from __future__ import annotations
import ast
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
#: The module folders and what each may not reach for. Listed rather than
#: derived so that adding a fourth folder is a decision, not an accident.
FORBIDDEN = {
"pipeline": ("app", "auth"),
"auth": ("app", "pipeline"),
}
def imported_modules(source: str) -> set[str]:
"""Every top-level package name this file imports."""
found: set[str] = set()
tree = ast.parse(source)
for node in ast.walk(tree):
if isinstance(node, ast.Import):
found.update(alias.name.split(".")[0] for alias in node.names)
elif isinstance(node, ast.ImportFrom):
# A relative import stays inside the folder by construction.
if node.level == 0 and node.module:
found.add(node.module.split(".")[0])
return found
def python_files(folder: str) -> list[Path]:
root = ROOT / folder
if not root.is_dir():
return []
return sorted(p for p in root.rglob("*.py") if "__pycache__" not in p.parts)
CASES = [(folder, path) for folder in FORBIDDEN for path in python_files(folder)]
@pytest.mark.parametrize(
("folder", "path"), CASES,
ids=[str(path.relative_to(ROOT)).replace("\\", "/") for _, path in CASES])
def test_a_module_folder_imports_nothing_above_it(folder: str, path: Path):
imported = imported_modules(path.read_text(encoding="utf-8"))
for name in FORBIDDEN[folder]:
assert name not in imported, (
f"{path.relative_to(ROOT)} imports {name!r}. "
f"{folder}/ has to survive being copied on its own.")
@pytest.mark.parametrize("folder", sorted(FORBIDDEN))
def test_the_folder_is_actually_there(folder: str):
"""A parametrised test over an empty list passes by saying nothing.
So the rule is only proved for what exists, and this is what makes "it
exists" a thing the suite checks rather than a thing somebody assumes --
the day a folder is moved or renamed, the coupling test would otherwise go
quiet instead of red.
"""
assert python_files(folder), f"no {folder}/ to check"
+75
View File
@@ -0,0 +1,75 @@
"""What has to be true about the repository itself, not about the code in it.
Three facts that are invisible until they cost a deployment: a PowerShell
script that will not parse, a folder that is not in the wheel, and a container
missing a package the app imports.
"""
from __future__ import annotations
import tomllib
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
SCRIPTS = sorted((ROOT / "deploy").rglob("*.ps1"))
@pytest.mark.parametrize("script", SCRIPTS, ids=lambda p: p.name)
def test_powershell_scripts_are_ascii(script: Path):
"""Windows PowerShell 5.1 reads a BOM-less file as Windows-1252.
So an em dash becomes three characters, the last of which is a closing
quote: the string ends in the middle of itself and the script fails to
parse before it runs a line. It happened on a comment nobody thought was
code. Write `--`, `->`, `...`.
"""
raw = script.read_bytes()
bad = [(i, b) for i, b in enumerate(raw) if b > 0x7F]
assert not bad, (
f"{script.relative_to(ROOT)} has non-ASCII bytes at offsets "
f"{[i for i, _ in bad[:5]]} -- PowerShell 5.1 will mis-read them"
)
def test_there_are_scripts_to_check():
"""A parametrised test over an empty list passes by saying nothing."""
assert SCRIPTS, "no .ps1 found under deploy/ -- did the copy go wrong?"
def test_pyproject_packages_the_module_folders():
data = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
include = data["tool"]["setuptools"]["packages"]["find"]["include"]
for pattern in ("app*", "pipeline*", "auth*"):
assert pattern in include, f"{pattern} is missing: an install would leave it out"
def test_no_test_folder_travels_into_the_image():
"""`COPY auth auth` copies `auth/tests` with it unless the ignore file says
otherwise, and a module folder added later brings its own.
Nothing breaks when they arrive, which is why nobody notices: the image is
just carrying a test suite, its fixtures and whatever they import, in a
container on a server. One line per folder, next to the recipe.
"""
ignored = {line.strip() for line
in (ROOT / "deploy" / "Dockerfile.dockerignore")
.read_text(encoding="utf-8").splitlines()}
for folder in sorted(p.parent for p in ROOT.glob("*/tests")):
name = f"{folder.name}/tests"
assert name in ignored, f"{name} is not in Dockerfile.dockerignore"
def test_the_dockerfile_copies_the_module_folders():
"""`COPY app app` alone builds an image whose app cannot import its queue.
The failure is at startup, in a container, on a server -- which is the
worst of the three places to find out.
"""
dockerfile = (ROOT / "deploy" / "Dockerfile").read_text(encoding="utf-8")
lines = [line.strip() for line in dockerfile.splitlines()]
for folder in ("pipeline", "auth"):
copies = [line for line in lines if line == f"COPY {folder} {folder}"]
assert len(copies) == 2, (
f"expected `COPY {folder} {folder}` in both stages, found {len(copies)}")