Files
felhom-controller/controller/scripts/shared_scripts.py
T
admin 94f44931dd
gates / gates (push) Successful in 45s
v0.325.0: share + escrow limiters reserve first; family sessions as fingerprints; samba renames apply; path guard widened; gates in a worktree
R-1111 reserveAttempt is the one limiter body (share password, escrow re-auth, dashboard sign-in). R-1112
family.json holds fingerprints; old files are converted at load. R-1113 the household's pass reuses its
family session. R-1109 the samba compose carries the smb.conf hash. R-1110 TestNoBareDrivePathToPathHelpers.
R-1114 shared_scripts.py resolves the felhom.eu sibling from a worktree. Each red-proved.

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-10-17 09:36:34 +02:00

65 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""shared_scripts.py — where the felhom.eu sibling clone's scripts/ directory is (R-1114).
Four of this repo's gates use a script that lives ONCE in felhom.eu/scripts/ and is never copied
(reuse_refs_check, instructions_gate, observations_gate; customer_copy_vocab for the retrieval-promise
gate; golden_currency_gate for the golden notice). They used to look only at `<repo>/../felhom.eu`. In a
git worktree outside `git/` (e.g. /mnt/5_hdd/felhom.eu/wt/<name>) that directory does not exist, the
gates reported MISSING and the runner failed — measured 2026-10-16 night by two helper sessions.
The order, one place for all of them:
1. FELHOM_SHARED_SCRIPTS, when set (the decoy suite points it at a fixture; nothing else should).
2. The MAIN clone's sibling: `git worktree list --porcelain` names the main working tree first. Used only
when repo_root IS a git top level, so a fixture directory inside the real repo never resolves to the
real felhom.eu.
3. `<repo_root>/../felhom.eu/scripts` — the normal clone and CI (which clones felhom.eu beside the repo).
An absent directory is returned as-is: each caller already reports a missing shared script as a
failure or INCONCLUSIVE, never a pass. Pinned by test_shared_scripts.py.
"""
import os
import subprocess
def _git(repo_root, *args):
try:
p = subprocess.run(["git", "-C", repo_root] + list(args), capture_output=True, text=True, timeout=20)
except (OSError, subprocess.SubprocessError):
return None
return p.stdout if p.returncode == 0 else None
def main_clone(repo_root):
"""The main working tree of the git repository repo_root is the top level of, or None."""
top = _git(repo_root, "rev-parse", "--show-toplevel")
if top is None or os.path.realpath(top.strip()) != os.path.realpath(repo_root):
return None
out = _git(repo_root, "worktree", "list", "--porcelain")
if not out:
return None
for line in out.splitlines():
if line.startswith("worktree "):
return line[len("worktree "):].strip()
return None
def shared_scripts_dir(repo_root):
"""felhom.eu/scripts for this repo root: env override, else the main clone's sibling, else ../felhom.eu."""
env = os.environ.get("FELHOM_SHARED_SCRIPTS")
if env:
return env
main = main_clone(repo_root)
if main:
cand = os.path.join(os.path.dirname(main), "felhom.eu", "scripts")
if os.path.isdir(cand):
return cand
return os.path.join(os.path.dirname(os.path.abspath(repo_root)), "felhom.eu", "scripts")
def workspace_dir(repo_root):
"""The directory the sibling repos live in: the main clone's parent (for a worktree outside git/), else
repo_root's parent. The runner hands it to the shared gates as FELHOM_WORKSPACE."""
main = main_clone(repo_root)
if main and os.path.isdir(os.path.join(os.path.dirname(main), "felhom.eu")):
return os.path.dirname(main)
return os.path.dirname(os.path.abspath(repo_root))