294 lines
20 KiB
Python
294 lines
20 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""catalog_gates.py — THE entry point for this repo's gates. Run from the repo root:
|
|
|
|
python3 scripts/catalog_gates.py # every AVAILABLE app, all three gates
|
|
python3 scripts/catalog_gates.py papra wishlist # only these app dirs (the normal case)
|
|
python3 scripts/catalog_gates.py --all # include hidden/abandoned apps too
|
|
python3 scripts/catalog_gates.py --fast # static gates only — no network, no
|
|
# containers; this is what .githooks/pre-push runs
|
|
python3 scripts/catalog_gates.py --fast --range=<A>..<B> # the hook passes the push range
|
|
# through to the gate that diffs commits
|
|
|
|
Gates, in order (all must pass; **non-zero exit on any failure**):
|
|
|
|
1. image-pins static, instant, whole repo — no :latest / untagged / floating alias
|
|
2. image-resolvable network — every pinned tag still EXISTS upstream
|
|
3. volume-persistence RUNTIME — the folder a template preserves is the folder the app writes to
|
|
5. catalog-since static, needs GIT HISTORY — an image: move bumps that app's catalog_since (R-452)
|
|
7. probe-matches-compose static, instant, whole repo — the .felhom.yml health probe dials the
|
|
port/path the app's own compose healthcheck dials (R-618). Runs in the
|
|
hook: a wrong probe stops a WORKING app at the end of a successful update.
|
|
8. test-record static, instant, whole repo — every update_ladder is well-formed, continuous,
|
|
and its newest step IS the compose's images (runs in CI too)
|
|
9. test-record-move git history + the registry for MOVED refs only — an image move adds a PROVEN
|
|
ladder entry whose digests the registry still serves (hook; skipped on CI)
|
|
10. onboarding static, instant, whole repo — a NEW template directory carries a complete onboarding
|
|
record (NEW-APP-CHECKLIST.md; the 53 apps published before 2026-10-01 are exempt by name)
|
|
11. mem-limit-sum static, instant, whole repo — `.felhom.yml` resources.mem_limit equals the sum of every
|
|
service's deploy.resources.limits.memory, and every service has one (R-758)
|
|
12. data-key static, instant, whole repo — every data-encrypting key carries data_key: true (name rule
|
|
or REGISTRY), and no flag is unexplained (R-127)
|
|
13. unclean-boot-images static, instant, whole repo — an after_unclean_boot block lists the image its service
|
|
runs (R-1007): an Immich bump without a re-proven repair is refused, not silently skipped
|
|
14. guide-version static, instant, ADVISORY — a user guide's checked_version is not the image tag the app
|
|
runs: a WARN naming both versions, and exit 0 always (it never fails a push)
|
|
16. redis-persistence static, instant, whole repo — no template's Redis/Valkey service runs append-only (R-1096)
|
|
17. privileges static, instant, whole repo — no template or ladder step asks for a container right the box's
|
|
allow-list does not give (R-971); the box (controller >= 0.328.0) refuses on its own
|
|
18. security-scan the SHARED scanner (felhom.eu/scripts/security_scan_gate.py) — gitleaks on the pushed commits,
|
|
WARN-FIRST: it lists, it never refuses (R-986); no Go module here, so no govulncheck
|
|
15. gate-decoys the decoy suite (test_gate_decoys.py) — each gate above still convicts its decoys
|
|
(R-1115). ~3 minutes, needs PyYAML: the full run only, never --fast
|
|
4. engine-major static, needs GIT HISTORY — no database engine pin crosses a MAJOR version
|
|
(operator ruling 2026-09-13; expires when Slice 4 / R-448 ships). Runs in the
|
|
pre-push hook, which has the full clone; on a SHALLOW clone (CI fetches at
|
|
--depth 1 — the R-452 gap) it is SKIPPED and the skip is printed, because a
|
|
gate that reddens every CI push gets bypassed within a week.
|
|
|
|
WHY THIS FILE EXISTS (operator ruling, 2026-08-02 — R-161).
|
|
|
|
The volume-persistence gate was built because papra's backup completed, verified, and contained an
|
|
empty directory. The obvious enforcement points were both rejected, each for a measured reason:
|
|
|
|
- **Controller-side, at template load: rejected because it would PASS on the defect it exists to
|
|
catch.** A check at load time can only read the file, and papra's compose is well-formed — a
|
|
static audit of all 53 templates reports the catalog clean, papra included. The property is only
|
|
decidable at runtime (see `check-volume-persistence.py`'s header).
|
|
- **CI: rejected for now** — neither repo has any CI to build on, and there are no users yet.
|
|
|
|
What was chosen instead is the shape that demonstrably works in this project. Of every gate written
|
|
here, **the only ones that ever get run are the ones with a single entry point named in a CLAUDE.md**:
|
|
`felhom.eu/scripts/site_gates.py` is run; R-29's three orphaned gates are named nowhere and have
|
|
stopped nothing. So this copies that shape rather than adding a fourth gate nobody invokes. It is
|
|
mandated in `CLAUDE.md` the way `site_gates.py` is.
|
|
|
|
**R-161 stays OPEN at reduced scope:** this is convention, run by a person. Real automatic
|
|
enforcement is owed when a second person touches templates.
|
|
|
|
EXIT CODES. Each gate returns 0 clean / 1 convicted / 2 inconclusive (3 = the harness refused to run, R-605). This runner exits **non-zero if
|
|
any gate is non-zero**, and reports 2 distinctly as INCONCLUSIVE — an undetermined result is never a
|
|
pass (an app that wrote nothing has not been shown correct; a throttled registry has not shown an
|
|
image alive), but it is also not a conviction, and the operator reading the summary needs to know
|
|
which they have.
|
|
|
|
SCOPE. With app names, every gate that accepts scoping is scoped to them — that is the normal
|
|
after-a-template-change run and it is fast. With no names the runtime gate deploys **every** template,
|
|
which takes minutes per app and **belongs on a scratch host, never a customer box** (see CLAUDE.md).
|
|
"""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
SCRIPTS = os.path.join(ROOT, "scripts")
|
|
|
|
# (label, filename, accepts_app_scope, fast, takes_range)
|
|
#
|
|
# `takes_range` = the gate diffs two commits and is handed `--range=<A>..<B>` when the runner was
|
|
# given one (the pre-push hook computes it from the refs git feeds it). Without a range the gate
|
|
# defaults to origin/main..HEAD. It cannot run on a shallow clone — see the skip in main().
|
|
#
|
|
# `fast` = touches NO network and NO container runtime, so it is safe to run on every push.
|
|
# image-resolvable talks to registries and volume-persistence deploys containers for minutes per
|
|
# app — neither belongs in a hook. A push that pulls images and starts containers gets bypassed
|
|
# within a week, and the bypass becomes the habit; both stay deliberate periodic runs (start of a
|
|
# catalog campaign, before a publish train that vouches the catalog, whenever a template's
|
|
# volumes: block or image tag changes) — on a scratch host, never a customer box.
|
|
GATES = [
|
|
("image-pins", "check-image-pins.py", False, True, False),
|
|
("image-resolvable", "check-image-resolvable.py", True, False, False),
|
|
("volume-persistence", "check-volume-persistence.py", True, False, False),
|
|
("engine-major", "check-engine-major.py", False, True, True),
|
|
# R-452 (2026-09-13): an image: move must bump that app's catalog_since. Same shape as
|
|
# engine-major — git history, fast, skipped out loud on a shallow clone.
|
|
("catalog-since", "check-catalog-since.py", False, True, True),
|
|
# R-560 (2026-09-20): the Hungarian copy is frozen byte for byte and the English `i18n:` block
|
|
# is structurally sound and actually English. Static, instant, no git history. It accepts app
|
|
# scope for the LANGUAGE checks only — the Hungarian freeze always runs on all 53, because a
|
|
# scoped push that quietly edits a neighbour's copy is precisely what a freeze is for.
|
|
("copy-i18n", "check-copy-i18n.py", True, True, False),
|
|
# R-618 (2026-09-22): the `.felhom.yml` probe must dial the port — and, where the probe can
|
|
# actually fail on it, the path — that the SAME service's compose healthcheck dials on
|
|
# loopback. Static, instant, no git history, no network. It is `--fast` deliberately: the
|
|
# defect it catches does not merely mis-colour a badge, it makes a SUCCESSFUL update stop a
|
|
# working app (the `verifying` phase waits on this probe), so it must bite at push time.
|
|
("probe-matches-compose", "check-probe-matches-compose.py", True, True, False),
|
|
# R-715 (2026-09-29): a setup gate's `setup_done_probe:` must carry its measured before/after answers directly
|
|
# above it. A guessed probe that never flips keeps an app closed to all but the household AND blocks their press.
|
|
("probe-measured", "check-probe-measured.py", True, True, False),
|
|
# 2026-09-23 (`09` §3 decision 13, §6.4 part 4): THE TEST RECORD. The static half needs no
|
|
# history and no network, so it bites in CI too: a ladder must be well-formed and its newest step
|
|
# must BE the compose's images. The move half needs history (skipped out loud on CI's shallow
|
|
# clone, like engine-major) and asks the registry ONLY for refs that moved in the range: an image
|
|
# move must add a PROVEN entry whose digests the registry still serves.
|
|
("test-record", "check-test-record.py", True, True, False),
|
|
("test-record-move", "check-test-record-move.py", False, True, True),
|
|
# 2026-10-01 (operator request): a NEW template directory carries a complete onboarding record —
|
|
# onboarding/<app>.md answering every NEW-APP-CHECKLIST.md id, none open, every `done` naming evidence that
|
|
# exists. Static, files only, so it is --fast and bites in the hook AND in CI. The 53 apps published before
|
|
# the checklist are exempt by name inside the script.
|
|
("onboarding", "check-onboarding.py", False, True, False),
|
|
# 2026-10-02 (`09` §3 decisions 63/64): a family-gated template's exceptions are literal prefixes, it declares
|
|
# min_controller >= 0.287.0, and the newest baked golden knows the gate. Static, files only.
|
|
("family-gate", "check-family-gate.py", False, True, False),
|
|
# R-758 (2026-10-05): `.felhom.yml` resources.mem_limit is the SUM of the compose limits (REUSE.md §2). Eight
|
|
# templates were under it — the deploy screen and the box's overcommit warning read less than the app may take.
|
|
# Static, stdlib only (no PyYAML on CI), so --fast: the hook and CI.
|
|
("mem-limit-sum", "check-mem-limit-sum.py", True, True, False),
|
|
# R-1106 (2026-10-16 night): a database service's password variable must be a `type: secret` deploy field, so the
|
|
# backup carries it and a restore can put the password back with the data (controller v0.324.0). Static, stdlib.
|
|
("db-credentials", "check-db-credentials.py", True, True, False),
|
|
# R-127 leg (a) (2026-10-05): every data-encrypting key carries `data_key: true` (by its NAME, or by a registry
|
|
# entry with its reason) and every flag is accounted for — the restore's fail-closed gate reads only that flag.
|
|
("data-key", "check-data-key.py", True, True, False),
|
|
# R-1007 (2026-10-14, decision 236): an `after_unclean_boot:` block's `images:` must list the image its service
|
|
# runs in the compose (and in each steps/ file that carries the block). The repair uses the app's internals, so the
|
|
# controller SKIPS it on an unproven image and nobody is told — this refuses the image bump that would do that.
|
|
("unclean-boot-images", "check-unclean-boot-images.py", True, True, False),
|
|
# 2026-10-15 (app guides night): ADVISORY — a guide's `checked_version` differs from the image the app runs, so
|
|
# the guide may describe a changed screen. It prints a WARN naming both versions and ALWAYS exits 0: an image move
|
|
# is judged by its test record, and a stale-prose warning must never hold back an update.
|
|
("guide-version", "check-guide-version.py", True, True, False),
|
|
# 2026-10-16 (controller 0.320.0): `app_info.login_kind` is one of first_visit | email | none. An enum, not copy;
|
|
# a typo would read as first_visit on the box. Static, stdlib only, so --fast: the hook and CI.
|
|
("login-kind", "check-login-kind.py", False, True, False),
|
|
# R-1097 (2026-10-16): a household-data path an image keeps in its own anonymous VOLUME (RomM's /romm/assets) is
|
|
# mounted by the template, or no app backup takes it. Measured registry; static, stdlib only: the hook and CI.
|
|
("image-volumes", "check-image-volumes.py", False, True, False),
|
|
# R-1096 (2026-10-17): no catalog Redis runs append-only — a damaged AOF keeps Redis (and its app) down until a
|
|
# person repairs it; snapshots are written by temp-file-and-rename. Static, stdlib only: the hook and CI.
|
|
("redis-persistence", "check-redis-persistence.py", False, True, False),
|
|
# R-971 (2026-10-17, operator decision D2 = A): no template or ladder step asks for a container right the BOX's
|
|
# allow-list does not give (privileged, cap_add, devices, host namespaces, the Docker socket, binds outside the
|
|
# data roots, ...). The box (controller >= 0.328.0) is the authority and refuses on its own; this is the early
|
|
# warning, so a bad template fails here instead of on every box. Static, stdlib only: the hook and CI.
|
|
("privileges", "check-privileges.py", False, True, False),
|
|
# R-986 (2026-10-19): the shared dependency and secret scanner, WARN-FIRST (exit 0 whatever it finds). It reads no
|
|
# network here (no Go module, so no govulncheck); gitleaks on the pushed commits, ~1 s. CI fetches the pinned gitleaks
|
|
# (FELHOM_SCAN_FETCH=1 in gates.yml).
|
|
# R-1019 (2026-10-20): a download client's download folder (bound at /downloads or /watch) is declared `excluded`,
|
|
# so no tier copies it — optional mirrored every download to the second drive, unlisted sent it off-site.
|
|
("download-binds", "check-download-binds.py", False, True, False),
|
|
("security-scan", "check-security-scan.py", False, True, False),
|
|
# R-1115 (2026-10-17): the gates' OWN decoy suite — every gate above is red-proved against its decoys here. It
|
|
# was not in this table, so a case that stopped convicting (a template edit removed its premise) failed for a
|
|
# night with nobody looking. Static (a local clone, a stub docker), but ~3 minutes and it needs PyYAML, so NOT
|
|
# --fast: the full run only, like the two slow gates.
|
|
("gate-decoys", "test_gate_decoys.py", False, False, False),
|
|
]
|
|
|
|
# 3 (R-605): the gate's HARNESS refused to run — its canary failed or it had nothing to judge — so NO app was
|
|
# evaluated. It used to share 2's label, and the 2026-09-17 chaos night could not tell afterwards which had happened.
|
|
VERDICT = {0: "OK", 1: "FAILED", 2: "INCONCLUSIVE", 3: "DID-NOT-RUN"}
|
|
|
|
|
|
def run_gate(label, script, args):
|
|
path = os.path.join(SCRIPTS, script)
|
|
if not os.path.exists(path):
|
|
print("FAIL: %s — %s is missing from scripts/" % (label, script))
|
|
return 1
|
|
print("\n" + "=" * 78)
|
|
print("== gate: %s (%s%s)" % (label, script, (" " + " ".join(args)) if args else ""))
|
|
print("=" * 78, flush=True)
|
|
# stream the gate's own output rather than capturing it — its diagnostics are the point,
|
|
# and a runner that swallows them makes a conviction unreadable.
|
|
return subprocess.call([sys.executable, path] + args, cwd=ROOT)
|
|
|
|
|
|
def is_shallow():
|
|
p = subprocess.run(["git", "rev-parse", "--is-shallow-repository"], cwd=ROOT,
|
|
capture_output=True, text=True)
|
|
return p.returncode == 0 and p.stdout.strip() == "true"
|
|
|
|
|
|
def main(argv):
|
|
include_hidden = "--all" in argv
|
|
fast = "--fast" in argv
|
|
rng = ""
|
|
for a in argv:
|
|
if a.startswith("--range="):
|
|
rng = a[len("--range="):]
|
|
apps = [a for a in argv if not a.startswith("-")]
|
|
unknown = [a for a in argv if a.startswith("-") and a not in ("--all", "--fast")
|
|
and not a.startswith("--range=")]
|
|
if unknown:
|
|
print("unknown option(s): %s" % " ".join(unknown))
|
|
print(__doc__.strip().splitlines()[0])
|
|
return 2
|
|
|
|
scope_note = ("apps: " + ", ".join(apps)) if apps else (
|
|
"static gate only" if fast else
|
|
"ALL apps (runtime gate deploys every template — scratch host only)")
|
|
print("catalog_gates — %s%s%s" % (scope_note, " [--fast]" if fast else "",
|
|
" [--all: incl. hidden/abandoned]" if include_hidden else ""))
|
|
|
|
selected = [g for g in GATES if g[3] or not fast]
|
|
skipped = [g[0] for g in GATES if not (g[3] or not fast)]
|
|
# engine-major needs a parent commit. The CI runner fetches at --depth 1 (the R-452 gap), so on
|
|
# a shallow clone it is skipped OUT LOUD rather than convicting every push it cannot judge — the
|
|
# pre-push hook, which has the full clone, is where it bites. A silent skip would be the R-421
|
|
# shape (a gate named in the table that never runs), so the skip is announced and pinned by
|
|
# test_catalog_gates.py.
|
|
shallow = is_shallow()
|
|
if shallow:
|
|
needs_history = [g[0] for g in selected if g[4]]
|
|
selected = [g for g in selected if not g[4]]
|
|
if needs_history:
|
|
print(" SHALLOW CLONE — SKIPPED: %s — it diffs an image: line against the parent commit\n"
|
|
" and this clone has none (the CI runner fetches at --depth 1; R-452). It is\n"
|
|
" enforced by .githooks/pre-push, which runs on the full clone. NOT a pass — a\n"
|
|
" cross-major engine move is caught at push time, not here." % ", ".join(needs_history))
|
|
if skipped:
|
|
print(" --fast SKIPPED: %s — they need network and a container runtime and take minutes\n"
|
|
" per app (gate-decoys: ~3 minutes on its own), so they are NEVER in a hook. They\n"
|
|
" remain deliberate periodic runs: start\n"
|
|
" of a catalog campaign, before a publish train, or when a template's volumes:/image\n"
|
|
" changes. Run them with no --fast, on a scratch host." % ", ".join(skipped))
|
|
|
|
results = []
|
|
for label, script, scoped, _f, takes_range in selected:
|
|
args = []
|
|
if include_hidden:
|
|
args.append("--all")
|
|
if scoped and apps:
|
|
args += apps
|
|
if takes_range and rng:
|
|
args.append("--range=" + rng)
|
|
results.append((label, run_gate(label, script, args)))
|
|
|
|
return summarise(results)
|
|
|
|
|
|
def summarise(results):
|
|
"""Print the summary for [(label, rc)] and return the runner's exit: 0 all OK, 1 any conviction, else 2. A gate
|
|
whose harness refused (3) is named apart from one that ran and could not decide (2) — R-605, pinned by
|
|
test_catalog_gates.py."""
|
|
print("\n" + "=" * 78)
|
|
print("== summary")
|
|
print("=" * 78)
|
|
worst = 0
|
|
for label, rc in results:
|
|
print(" %-20s %-13s (exit %d)" % (label, VERDICT.get(rc, "ERROR"), rc))
|
|
# 1 (a conviction) outranks 2 (undetermined) in what it tells the operator to do
|
|
if rc != 0:
|
|
worst = 1 if rc == 1 or worst == 1 else 2
|
|
if worst == 0:
|
|
print("\nall catalog gates OK")
|
|
return 0
|
|
convicted = [l for l, rc in results if rc == 1]
|
|
refused = [l for l, rc in results if rc == 3]
|
|
undecided = [l for l, rc in results if rc not in (0, 1, 3)]
|
|
if convicted:
|
|
print("\nCONVICTED: %s" % ", ".join(convicted))
|
|
if undecided:
|
|
print("UNDETERMINED (it ran; some results could not be decided — never a pass): %s" % ", ".join(undecided))
|
|
if refused:
|
|
print("DID NOT RUN (the harness refused — its canary failed or it had nothing to judge; NO app was "
|
|
"evaluated — never a pass): %s" % ", ".join(refused))
|
|
return worst
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|