diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf3c2e..570bd93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## 2026-10-15 (night) — the user guide: the copy gate reads it, and a guide-version warning (app guides, Part 0) + +- `scripts/check-copy-i18n.py`: `app_info.guide` is COPY — every section title, intro and step and every FAQ question and + answer is counted, frozen and translated like the rest, addressed by index (the controller matches the guide by index, + `10-localisation.md` §7). The English overlay may carry `guide`; it may NOT carry `checked_version` (the render gate — + a translator does not vouch for a version). Refused: a section with no title or an empty `steps`, an FAQ entry + missing `q` or `a`, an unquoted `checked_version`, an English guide with no Hungarian one, an English list of a + different length (sections, FAQ, or one section's steps), and a download source named in any guide string in either + language (a deny-list of the obvious names, folded and matched as words; the human rule is wider than the list). +- `scripts/check-guide-version.py` (gate `guide-version`, `--fast`, standard library only): ADVISORY — a WARN naming the + app and both versions when the guide's `checked_version` is not the tag the app's own service runs; exit 0 always. + It also lists the hidden guides (empty `checked_version`). +- `scripts/test_gate_decoys.py`: 19 cases on a self-contained decoy app (13 copy-gate, 6 guide-version), each rule + red-proved by switching it off (felhom.eu `documentation/audits/app-guides-2026-10-15/part0-redproofs.txt`). + `test_catalog_gates.py`: 16 gates. +- No template changed; no guide yet. + ## 2026-10-15 (evening) — Prowlarr's copy: the box links it whichever app comes first (R-1058) - `templates/prowlarr`: first_steps (HU/EN) and the compose header drop the „Bekötés most" sentence — controller 0.314.0 diff --git a/scripts/catalog_gates.py b/scripts/catalog_gates.py index 8c5ad0f..90241c1 100644 --- a/scripts/catalog_gates.py +++ b/scripts/catalog_gates.py @@ -31,6 +31,8 @@ Gates, in order (all must pass; **non-zero exit on any failure**): 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) 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 @@ -134,6 +136,10 @@ GATES = [ # 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), ] # 3 (R-605): the gate's HARNESS refused to run — its canary failed or it had nothing to judge — so NO app was diff --git a/scripts/check-copy-i18n.py b/scripts/check-copy-i18n.py index 9cc78a4..8f8eb04 100644 --- a/scripts/check-copy-i18n.py +++ b/scripts/check-copy-i18n.py @@ -157,6 +157,22 @@ def copy_strings(meta): for k in ("use_cases", "first_steps", "prerequisites"): for i, v in enumerate(ai.get(k) or []): add("app_info.%s[%d]" % (k, i), v) + # The user guide (controller >= 0.315.0, 10-localisation.md §7). Addressed BY INDEX — the only copy + # that is: a section's title is the thing being translated, so it has no key. `checked_version` is + # NOT copy (the render gate; a translator does not vouch for a version) and is never collected. + g = ai.get("guide") if isinstance(ai.get("guide"), dict) else {} + for i, se in enumerate(g.get("sections") or []): + if not isinstance(se, dict): + continue + add("app_info.guide.sections[%d].title" % i, se.get("title")) + add("app_info.guide.sections[%d].intro" % i, se.get("intro")) + for j, st in enumerate(se.get("steps") or []): + add("app_info.guide.sections[%d].steps[%d]" % (i, j), st) + for i, qa in enumerate(g.get("faq") or []): + if not isinstance(qa, dict): + continue + add("app_info.guide.faq[%d].q" % i, qa.get("q")) + add("app_info.guide.faq[%d].a" % i, qa.get("a")) for i, f in enumerate(meta.get("deploy_fields") or []): key = f.get("env_var") or "#%d" % i for fld in ("label", "description", "placeholder"): @@ -222,8 +238,11 @@ def overlay_strings(ov, hu_meta): errs.append("app_info must be a mapping") else: for k in ai: - if k not in ("tagline", "default_creds", "add_people", "use_cases", "first_steps", "prerequisites"): + if k not in ("tagline", "default_creds", "add_people", "use_cases", "first_steps", "prerequisites", + "guide"): errs.append("unknown key app_info.%s — `docs_url` and the rest are not copy" % k) + if ai.get("guide") is not None: + guide_overlay(ai.get("guide"), (hu_meta.get("app_info") or {}).get("guide"), scalar, errs) scalar("app_info.tagline", ai.get("tagline"), "app_info.tagline") scalar("app_info.default_creds", ai.get("default_creds"), "app_info.default_creds") scalar("app_info.add_people", ai.get("add_people"), "app_info.add_people") @@ -348,6 +367,149 @@ def overlay_strings(ov, hu_meta): return out, errs +# ── The user guide (controller >= 0.315.0) ─────────────────────────────────────────────────────── +# +# Sections and FAQ entries are matched BY INDEX on the box (metadata_i18n.go AppGuideOverlay), so the +# English must carry the SAME number of each, and each section the same number of steps (`steps` +# replaces whole). A longer English list is dropped past the Hungarian count on the box with one WARN; +# a shorter one shows Hungarian in an English page. Both are refused here, where they cost nothing. +# `checked_version` is the render gate and NOT copy: an overlay that carries it is refused — the box +# ignores it there, and a translator who believes they vouched for a version did not. + +GUIDE_SECTION_KEYS = ("title", "intro", "steps") +GUIDE_FAQ_KEYS = ("q", "a") + +# The media guides never name a download source (15-media-library.md §6: „Indexers stay the household's +# choice"). The list is the OBVIOUS names, folded and matched as words; the human rule is wider than it. +SOURCE_DENYLIST = [ + "the pirate bay", "piratebay", "thepiratebay", "1337x", "rarbg", "yts", "yify", "eztv", "nyaa", + "torrentgalaxy", "limetorrents", "kickass", "kickasstorrents", "rutracker", "rutor", "ncore", "bithumen", + "iptorrents", "torrentleech", "torrentday", "filelist", "magnetdl", "torlock", "zooqle", "solidtorrents", + "bitsearch", "torrentz2", "nzbgeek", "nzbplanet", "drunkenslug", "nzbfinder", "dognzb", "nzb.su", + "ninjacentral", "nzbcat", "newshosting", "eweka", "easynews", "usenetserver", "frugalusenet", +] + + +def guide_shape(app, meta, fails): + """The Hungarian guide's own shape. An empty `steps`, a section with no title, an FAQ entry with no + answer: each renders as an empty heading or a question nobody answers.""" + ai = meta.get("app_info") or {} + g = ai.get("guide") + if g is None: + return + where = "%s: app_info.guide" % app + if not isinstance(g, dict): + fails.append("%s must be a mapping" % where) + return + for k in g: + if k not in ("checked_version", "sections", "faq"): + fails.append("%s.%s — unknown key (the controller reads checked_version, sections, faq)" % (where, k)) + cv = g.get("checked_version") + if cv is not None and not isinstance(cv, str): + fails.append("%s.checked_version must be a QUOTED string (an image tag), got %s — YAML reads 1.10 as 1.1" + % (where, type(cv).__name__)) + secs, faq = g.get("sections"), g.get("faq") + if secs is not None and not isinstance(secs, list): + fails.append("%s.sections must be a list" % where) + secs = [] + if faq is not None and not isinstance(faq, list): + fails.append("%s.faq must be a list" % where) + faq = [] + if not (secs or faq): + fails.append("%s has neither sections nor faq — the box would render nothing under a heading" % where) + for i, se in enumerate(secs or []): + sw = "%s.sections[%d]" % (where, i) + if not isinstance(se, dict): + fails.append("%s is not a mapping" % sw) + continue + for k in se: + if k not in GUIDE_SECTION_KEYS: + fails.append("%s.%s — unknown key" % (sw, k)) + if not (isinstance(se.get("title"), str) and se.get("title").strip()): + fails.append("%s.title is missing or empty" % sw) + steps = se.get("steps") + if not isinstance(steps, list) or not steps: + fails.append("%s.steps is missing or empty" % sw) + continue + for j, st in enumerate(steps): + if not (isinstance(st, str) and st.strip()): + fails.append("%s.steps[%d] is not a non-empty string" % (sw, j)) + for i, qa in enumerate(faq or []): + fw = "%s.faq[%d]" % (where, i) + if not isinstance(qa, dict): + fails.append("%s is not a mapping" % fw) + continue + for k in qa: + if k not in GUIDE_FAQ_KEYS: + fails.append("%s.%s — unknown key" % (fw, k)) + for k in GUIDE_FAQ_KEYS: + if not (isinstance(qa.get(k), str) and qa.get(k).strip()): + fails.append("%s.%s is missing or empty" % (fw, k)) + + +def guide_overlay(g, hu_g, scalar, errs): + """One language's `app_info.guide` overlay: same counts as the Hungarian, matched by index.""" + if not isinstance(g, dict): + errs.append("app_info.guide must be a mapping") + return + if not isinstance(hu_g, dict): + errs.append("app_info.guide is translated but the Hungarian has no guide — it would be INERT") + return + for k in g: + if k == "checked_version": + errs.append("app_info.guide.checked_version in the English block — it is the render gate, not copy; " + "a translator does not vouch for a version (10-localisation.md §7)") + elif k not in ("sections", "faq"): + errs.append("unknown key app_info.guide.%s — only sections and faq are translated" % k) + for lk, keys in (("sections", GUIDE_SECTION_KEYS), ("faq", GUIDE_FAQ_KEYS)): + lst = g.get(lk) + if lst is None: + continue + if not isinstance(lst, list): + errs.append("app_info.guide.%s must be a list" % lk) + continue + hu_lst = hu_g.get(lk) if isinstance(hu_g.get(lk), list) else [] + if len(lst) != len(hu_lst): + errs.append("app_info.guide.%s has %d entries, Hungarian has %d — entries are matched BY INDEX, so " + "the counts and the running order must match" % (lk, len(lst), len(hu_lst))) + for i, e in enumerate(lst): + p = "app_info.guide.%s[%d]" % (lk, i) + if not isinstance(e, dict): + errs.append("%s is not a mapping" % p) + continue + for k in e: + if k not in keys: + errs.append("unknown key %s.%s" % (p, k)) + for k in keys: + if k == "steps": + continue + scalar("%s.%s" % (p, k), e.get(k), "%s.%s" % (p, k)) + if lk == "sections" and e.get("steps") is not None: + st = e.get("steps") + if not isinstance(st, list): + errs.append("%s.steps must be a list" % p) + continue + for j, v in enumerate(st): + scalar("%s.steps[%d]" % (p, j), v, "%s.steps[%d]" % (p, j)) + hu_e = hu_lst[i] if i < len(hu_lst) and isinstance(hu_lst[i], dict) else {} + hu_n = len(hu_e.get("steps") or []) + if len(st) != hu_n: + errs.append("%s.steps has %d entries, Hungarian has %d — steps are replaced WHOLE" + % (p, len(st), hu_n)) + + +def guide_sources(app, strings, fails): + """No download source named in a guide, in either language (Scenario E).""" + for path, val in sorted(strings.items()): + if ".guide." not in path: + continue + f = fold(val) + for name in SOURCE_DENYLIST: + if re.search(r"(?= 0.315.0 renders a guide only when it is set — `02-controller-module-map.md`, „The catalog's +user guide"). When the app's image moves, the guide may describe a screen that changed. This gate says so, +naming the app and both versions. + +IT NEVER FAILS A PUSH (exit 0 always). An image move is decided by its test record (`check-test-record*.py`); +a guide that may be stale is a reason to re-read it, not a reason to hold back a security fix. Refusing here +would make every Renovate-style bump wait on prose, and a gate that blocks the wrong thing gets bypassed. + +Which tag is „the app's": the compose service named like the template directory (or whose container_name +is), else — when no service is — every service's tag. A sidecar sharing the checked tag by coincidence +is the cost of that fallback; it is stated rather than hidden. + +STANDARD LIBRARY ONLY: the CI runner has python3 and git and nothing else (the copy gate's first six pushes +turned CI red by importing yaml). The two values are read by indentation from files whose shape the other +gates already hold: `checked_version:` at four spaces under ` guide:` under top-level `app_info:` — so the +English block (six spaces and deeper) and a comment are never read as the fact. +""" +import io +import os +import re +import sys + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +def strip_comment(line): + # A `#` starts a comment only outside quotes; the values read here never contain one. + out, q = [], None + for c in line: + if q: + if c == q: + q = None + elif c in "'\"": + q = c + elif c == "#": + break + out.append(c) + return "".join(out).rstrip() + + +def unquote(v): + v = v.strip() + if len(v) >= 2 and v[0] == v[-1] and v[0] in "'\"": + return v[1:-1] + return v + + +def checked_version(felhom_yml): + """(present, value) — present is False when the template carries no guide block at all.""" + state = None # None → in app_info → in guide + present, value = False, None + for raw in io.open(felhom_yml, encoding="utf-8").read().split("\n"): + line = strip_comment(raw) + if not line.strip(): + continue + ind = len(line) - len(line.lstrip(" ")) + if ind == 0: + state = "app_info" if line.strip() == "app_info:" else None + continue + if state == "app_info" and ind == 2: + state = "guide" if line.strip() == "guide:" else "app_info" + if state == "guide": + present = True + continue + if state == "guide": + if ind <= 2: + state = "app_info" + continue + m = re.match(r"^ checked_version:\s*(.*)$", line) + if m: + value = unquote(m.group(1)) + return present, value + + +def image_tags(compose, slug): + """{service: tag} for every image: line, and the services that are „the app" by name.""" + tags, cname, svc, in_services = {}, {}, None, False + for raw in io.open(compose, encoding="utf-8").read().split("\n"): + line = strip_comment(raw) + if not line.strip(): + continue + ind = len(line) - len(line.lstrip(" ")) + if ind == 0: + in_services = line.strip() == "services:" + svc = None + continue + if not in_services: + continue + if ind == 2 and line.strip().endswith(":"): + svc = line.strip()[:-1] + continue + if svc and ind == 4: + m = re.match(r"^\s+image:\s*(\S+)", line) + if m: + ref = unquote(m.group(1)).split("@")[0] + last = ref.rsplit("/", 1)[-1] + tags[svc] = last.split(":", 1)[1] if ":" in last else "" + m = re.match(r"^\s+container_name:\s*(\S+)", line) + if m: + cname[svc] = unquote(m.group(1)) + main = [s for s in tags if s == slug or cname.get(s) == slug] + return tags, main + + +def main(argv): + global ROOT + if "--root" in argv: + ROOT = os.path.abspath(argv[argv.index("--root") + 1]) + skip = {argv.index("--root") + 1} if "--root" in argv else set() + scope = [a for i, a in enumerate(argv) if i >= 1 and not a.startswith("-") and i not in skip] + tdir = os.path.join(ROOT, "templates") + apps = sorted(d for d in os.listdir(tdir) if os.path.exists(os.path.join(tdir, d, ".felhom.yml"))) + if scope: + apps = [a for a in apps if a in scope] + shown, hidden, stale, none = [], [], [], 0 + for app in apps: + present, cv = checked_version(os.path.join(tdir, app, ".felhom.yml")) + if not present: + none += 1 + continue + if not cv: + hidden.append(app) + continue + compose = os.path.join(tdir, app, "docker-compose.yml") + if not os.path.exists(compose): + print("WARN %s: guide checked against %s, but the template has no docker-compose.yml to compare" % (app, cv)) + stale.append(app) + continue + tags, main_svcs = image_tags(compose, app) + cands = [tags[s] for s in main_svcs] or list(tags.values()) + if cv in cands: + shown.append(app) + continue + stale.append(app) + now = ", ".join("%s=%s" % (s, tags[s]) for s in (main_svcs or sorted(tags))) + print("WARN %s: the guide was checked against %s, the image is now %s — re-check the guide's labels " + "and set checked_version again (the box still shows it)" % (app, cv, now or "(no image line)")) + print("guide-version: %d app(s) · %d guide(s) current · %d may be STALE · %d hidden (checked_version empty) · " + "%d without a guide" % (len(apps), len(shown), len(stale), len(hidden), none)) + if hidden: + print("guide-version: hidden — %s" % ", ".join(hidden)) + print("guide-version: advisory — never fails a push") + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/scripts/test_catalog_gates.py b/scripts/test_catalog_gates.py index 52f540f..108b38b 100644 --- a/scripts/test_catalog_gates.py +++ b/scripts/test_catalog_gates.py @@ -67,7 +67,9 @@ class CatalogGatesFastTest(unittest.TestCase): # 13 since 2026-10-05: mem-limit-sum (R-758), fast and history-free, so it runs in CI too. # 14 since the same night: data-key (R-127 leg a). # 15 since 2026-10-14: unclean-boot-images (R-1007) — fast, no history, so the hook AND CI. - self.assertEqual(len(mod.GATES), 15) + # 16 since 2026-10-15: guide-version — advisory (exit 0 always), fast, no history: the hook AND CI. + self.assertEqual(len(mod.GATES), 16) + self.assertIn("guide-version", [g[0] for g in mod.GATES if g[3] and not g[4]]) self.assertIn("unclean-boot-images", [g[0] for g in mod.GATES if g[3] and not g[4]]) self.assertIn("data-key", [g[0] for g in mod.GATES if g[3] and not g[4]]) self.assertIn("mem-limit-sum", [g[0] for g in mod.GATES if g[3] and not g[4]]) diff --git a/scripts/test_gate_decoys.py b/scripts/test_gate_decoys.py index 228388e..3fea619 100644 --- a/scripts/test_gate_decoys.py +++ b/scripts/test_gate_decoys.py @@ -63,7 +63,8 @@ COVERS = { "mem-limit-sum": "the right figure only in a COMMENT (the compose header's 'mem_limit: 640M', the .felhom.yml arithmetic) while the field is wrong; a `memory:` under reservations: (not a limit) making the sum come out right; a `mem_limit:` outside resources:; a steps/ file with the old figure (not judged) - vs the facts: a field under the sum, a service with no limit, an unreadable size (R-758)", "data-key": "a data_key: true only in a COMMENT or inside the i18n: block (not the field); an 'Encryption key' LABEL on a signing secret (copy, not the fact - must pass unflagged) - vs the facts: an *_ENCRYPTION_KEY field unflagged, a REGISTERED field unflagged, an unexplained flag, a stale registry entry, a non-boolean flag (R-127)", "unclean-boot-images": "the new image only in a compose COMMENT, on ANOTHER service (machine-learning), or under a COMMENTED-OUT block; a template with no block - each passes; vs the facts: the repair's service bumped with the list unchanged, the same in a steps/ file (the ladder), a block naming a service the compose does not run, a block with an empty images: list; and the genuine bump with the list updated (flow and block list) passes (R-1007, decision 236)", - "copy-i18n": "Hungarian edited in a COMMENT/README/display_name (label, not copy) vs a real frozen string changed; an English block that is not English, is not matched to a Hungarian twin, or rewrites a credential (R-560). A retrieval promise REGISTERED in ALLOWLIST_EN passes only for its own app+path+sentence with a real reason; an entry for another app, a rewritten sentence, a stale entry or a two-word reason convicts (R-594). Also the DEGRADED mode CI actually runs — PyYAML shadowed out, freeze only (R-595)", + "guide-version": "ADVISORY, exit 0 always: checked_version written only in a COMMENT or only inside the English block (no guide - never read as the fact), the checked tag carried by a SIDECAR while the app's own service moved (still WARNs), an empty checked_version (hidden, named) - vs the fact: the app's image moved off the checked tag (WARN naming both versions, exit 0), and a current guide (no WARN) (2026-10-15)", + "copy-i18n": "Hungarian edited in a COMMENT/README/display_name (label, not copy) vs a real frozen string changed; an English block that is not English, is not matched to a Hungarian twin, or rewrites a credential (R-560). A retrieval promise REGISTERED in ALLOWLIST_EN passes only for its own app+path+sentence with a real reason; an entry for another app, a rewritten sentence, a stale entry or a two-word reason convicts (R-594). Also the DEGRADED mode CI actually runs — PyYAML shadowed out, freeze only (R-595). THE USER GUIDE (2026-10-15): a download-source name only in a COMMENT or in docs_url passes; vs the facts - guide strings not frozen, checked_version in the English block, an empty steps list, an FAQ entry with no answer, an unquoted version, an English guide with no Hungarian one, more English sections than Hungarian, a different step count, and a source name in either language", } fails = [] @@ -1076,6 +1077,179 @@ def data_key_cases(): shutil.rmtree(ws, ignore_errors=True) +# ── the user guide (2026-10-15): copy-i18n's guide rules and the advisory guide-version gate ───────── +# +# A self-contained decoy APP (templates/guidedecoy), admitted to the CLONE's freeze by the gate's own +# copy_strings — so the cases judge the guide rules and keep working whatever guides the real catalog +# carries later (a case keyed to a real template's guide rots the day that guide is rewritten). + +GD_YML = "templates/guidedecoy/.felhom.yml" +GD_COMPOSE = "templates/guidedecoy/docker-compose.yml" + +GD_HU_GUIDE = """ guide: + checked_version: "4.0.20" + sections: + - title: "Első sorozat hozzáadása" + intro: "Így kerül be egy sorozat." + steps: + - "Kattints a „Series” menüre" + - "Válaszd az „Add New” gombot" + - title: "Telefonos app" + steps: + - "Töltsd le az appot" + faq: + - q: "Hol vannak a fájlok?" + a: "A meghajtódon, a media mappában." +""" + +GD_EN_GUIDE = """ guide: + sections: + - title: "Add your first series" + intro: "This is how a series gets in." + steps: + - "Select the „Series” menu" + - "Choose „Add New”" + - title: "Phone app" + steps: + - "Get the app" + faq: + - q: "Where are the files?" + a: "On your drive, in the media folder." +""" + +GD_COMPOSE_TEXT = """services: + guidedecoy: + image: example.invalid/decoy:%s + container_name: guidedecoy + guidedecoy-db: + image: example.invalid/db:%s +""" + + +def gd_yaml(hu=GD_HU_GUIDE, en=GD_EN_GUIDE, head=""): + return ("%sdisplay_name: \"Guidedecoy\"\ndescription: \"Próba alkalmazás\"\nslug: \"guidedecoy\"\n" + "app_info:\n tagline: \"Próba\"\n docs_url: \"https://example.invalid/docs\"\n%s" + "i18n:\n en:\n description: \"A test app\"\n app_info:\n tagline: \"A test\"\n%s" + % (head, hu, en)) + + +def _copy_gate_module(): + import importlib.util + spec = importlib.util.spec_from_file_location("copy_gate", os.path.join(ROOT, "scripts", "check-copy-i18n.py")) + m = importlib.util.module_from_spec(spec) + spec.loader.exec_module(m) + return m + + +def gd_freeze(yml_text): + """Admit the decoy app's Hungarian to the clone's freeze, computed by the gate's OWN walker — the same + thing `--add-app` does, so the freeze cannot drift from what the gate counts.""" + import yaml + strings = _copy_gate_module().copy_strings(yaml.safe_load(yml_text)) + + def fn(t): + data = json.loads(t) + data["apps"]["guidedecoy"] = strings + return json.dumps(data, ensure_ascii=False, indent=1, sort_keys=True) + "\n" + return ("scripts/copy_freeze/hu.json", fn) + + +def gd_app(yml_text, freeze=True, tag="4.0.20", db="16"): + edits = [(GD_YML, lambda t: yml_text), (GD_COMPOSE, lambda t: GD_COMPOSE_TEXT % (tag, db))] + if freeze: + edits.append(gd_freeze(yml_text)) + return edits + + +def case_gv(name, clone, edits, must_contain=(), must_not=()): + """guide-version is ADVISORY: every case expects exit 0, and is judged on what it PRINTS.""" + global ran + ran += 1 + base = sh(["git", "rev-parse", "HEAD"], cwd=clone).stdout.strip() + try: + for relpath, fn in edits: + edit(clone, relpath, fn) + r = sh([sys.executable, os.path.join(ROOT, "scripts", "check-guide-version.py"), "--root", clone, + "guidedecoy"], cwd=clone) + out = r.stdout + r.stderr + bad = [m for m in must_contain if m not in out] + ["UNWANTED " + m for m in must_not if m in out] + if r.returncode == 0 and not bad: + print(" ok %-52s rc=0 (advisory)" % name) + else: + fails.append("%s: rc=%d (advisory gate must exit 0); %s\n%s" % (name, r.returncode, bad, out[-700:])) + finally: + sh(["git", "checkout", "-q", "--", "."], cwd=clone) + sh(["git", "clean", "-qfd"], cwd=clone) + sh(["git", "reset", "-q", "--hard", base], cwd=clone) + + +def guide_cases(clone): + print("\n-- copy-i18n: the user guide (each FACT must be refused, naming the key)") + Y = gd_yaml() + # Scenario A — the genuine guide passes, and every guide string is COUNTED as copy: description, tagline, + # 2 titles, 1 intro, 3 steps, 1 question, 1 answer = 10. + case_copy("GENUINE: a full Hungarian guide with its English overlay", clone, gd_app(Y), + expect_rc=0, must_contain=("copy-i18n: OK", "guidedecoy 10/10")) + # the app IS frozen, but from before its guide existed: every guide string is NEW Hungarian + case_copy("FACT: guide strings that are not in the freeze", clone, + gd_app(Y, freeze=False) + [gd_freeze(gd_yaml(hu=""))], + expect_rc=1, must_contain=("guidedecoy: NEW Hungarian string app_info.guide.sections[0].title", + "NEW Hungarian string app_info.guide.faq[0].a")) + # Scenario B + case_copy("FACT: checked_version in the English block", clone, + gd_app(gd_yaml(en=GD_EN_GUIDE.replace(" guide:\n", " guide:\n checked_version: \"4.0.20\"\n"))), + expect_rc=1, must_contain=("guidedecoy: app_info.guide.checked_version in the English block",)) + case_copy("FACT: a section with an empty steps list", clone, + gd_app(gd_yaml(hu=GD_HU_GUIDE.replace(" steps:\n - \"Töltsd le az appot\"\n", " steps: []\n"), + en=GD_EN_GUIDE.replace(" steps:\n - \"Get the app\"\n", " steps: []\n"))), + expect_rc=1, must_contain=("guidedecoy: app_info.guide.sections[1].steps is missing or empty",)) + case_copy("FACT: an FAQ entry with a question and no answer", clone, + gd_app(gd_yaml(hu=GD_HU_GUIDE.replace(" a: \"A meghajtódon, a media mappában.\"\n", ""))), + expect_rc=1, must_contain=("guidedecoy: app_info.guide.faq[0].a is missing or empty",)) + case_copy("FACT: an unquoted checked_version (YAML reads 4.10 as 4.1)", clone, + gd_app(gd_yaml(hu=GD_HU_GUIDE.replace("checked_version: \"4.0.20\"", "checked_version: 4.10"))), + expect_rc=1, must_contain=("guidedecoy: app_info.guide.checked_version must be a QUOTED string",)) + case_copy("FACT: more English sections than Hungarian", clone, + gd_app(gd_yaml(en=GD_EN_GUIDE.replace(" faq:\n", " - title: \"Extra\"\n steps:\n - \"One more\"\n faq:\n"))), + expect_rc=1, must_contain=("guidedecoy: app_info.guide.sections has 3 entries, Hungarian has 2",)) + case_copy("FACT: an English section with a different step count", clone, + gd_app(gd_yaml(en=GD_EN_GUIDE.replace(" - \"Choose „Add New”\"\n", ""))), + expect_rc=1, must_contain=("guidedecoy: app_info.guide.sections[0].steps has 1 entries, Hungarian has 2",)) + case_copy("FACT: an English guide with no Hungarian guide", clone, + gd_app(gd_yaml(hu="")), + expect_rc=1, must_contain=("guidedecoy: app_info.guide is translated but the Hungarian has no guide",)) + # Scenario E — a download source named in a guide, in either language + case_copy("FACT: a tracker named in an English step", clone, + gd_app(gd_yaml(en=GD_EN_GUIDE.replace("Get the app", "Get films from 1337x"))), + expect_rc=1, must_contain=("app_info.guide.sections[1].steps[0] names a download source ('1337x')",)) + case_copy("FACT: a tracker named in a Hungarian answer (folded, any case)", clone, + gd_app(gd_yaml(hu=GD_HU_GUIDE.replace("A meghajtódon, a media mappában.", "Az nCore oldalról töltsd le."))), + expect_rc=1, must_contain=("guidedecoy: app_info.guide.faq[0].a names a download source ('ncore')",)) + case_copy("DECOY: a tracker named only in a YAML comment", clone, + gd_app(gd_yaml(head="# not copy: 1337x, nCore, rarbg\n")), + expect_rc=0, must_contain=("copy-i18n: OK",)) + case_copy("DECOY: a source-like word only in docs_url (configuration)", clone, + gd_app(gd_yaml().replace("https://example.invalid/docs", "https://example.invalid/rarbg-docs")), + expect_rc=0, must_contain=("copy-i18n: OK",)) + + print("\n-- guide-version (ADVISORY: WARN on the fact, silent on the label, exit 0 always)") + case_gv("FACT: the app's image moved off the checked tag (4.0.20 -> 4.0.21)", clone, + gd_app(Y, tag="4.0.21"), must_contain=("WARN guidedecoy", "4.0.20", "guidedecoy=4.0.21", "1 may be STALE")) + case_gv("GENUINE: the guide is current", clone, gd_app(Y), + must_contain=("1 guide(s) current",), must_not=("WARN",)) + case_gv("DECOY: the checked tag survives only on a SIDECAR", clone, gd_app(Y, tag="4.0.21", db="4.0.20"), + must_contain=("WARN guidedecoy", "1 may be STALE")) + case_gv("DECOY: checked_version only in a COMMENT", clone, + gd_app(gd_yaml(hu=GD_HU_GUIDE.replace(" guide:\n checked_version: \"4.0.20\"\n", " # guide:\n # checked_version: \"4.0.20\"\n guidex:\n"))), + must_contain=("1 without a guide",), must_not=("WARN", "1 guide(s) current")) + case_gv("DECOY: checked_version only inside the English block", clone, + gd_app(gd_yaml(hu="", en=GD_EN_GUIDE.replace(" guide:\n", " guide:\n checked_version: \"4.0.21\"\n")), tag="4.0.20"), + must_contain=("1 without a guide",), must_not=("WARN",)) + case_gv("FACT: an empty checked_version is HIDDEN and named", clone, + gd_app(gd_yaml(hu=GD_HU_GUIDE.replace("checked_version: \"4.0.20\"", "checked_version: \"\""))), + must_contain=("1 hidden", "hidden — guidedecoy"), must_not=("WARN",)) + + def main(): gate = os.path.join(ROOT, "scripts", "check-engine-major.py") if not os.path.isfile(gate): @@ -1586,6 +1760,7 @@ i18n: case_pm("probe-measured: 'read upstream' is not a measurement", [(KOMGA, lambda t: drop_note(t).replace( "\nsetup_done_probe:", "\n# read upstream 2026-09-29: isClaimed false -> true\nsetup_done_probe:"))], 1, ("measured",)) + guide_cases(clone) finally: shutil.rmtree(clone, ignore_errors=True)