94f44931dd
gates / gates (push) Successful in 45s
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
87 lines
3.5 KiB
Python
87 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""test_shared_scripts.py — the felhom.eu sibling is found from a worktree too (R-1114).
|
|
|
|
Builds a throwaway workspace in a temp dir — a `git/` with a main clone and a felhom.eu sibling, and a
|
|
worktree of the main clone under `wt/` — so nothing here reads the real repos. Git only; no docker.
|
|
|
|
Red-proof (run 2026-10-17): with step 2 (the main clone) removed from shared_scripts_dir, W1 fails
|
|
("worktree resolved to …/wt/felhom.eu/scripts").
|
|
|
|
Run from `controller/`: python3 scripts/test_shared_scripts.py
|
|
Exit 0 all pass · 1 a case failed.
|
|
"""
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, HERE)
|
|
import shared_scripts # noqa: E402
|
|
|
|
fails = []
|
|
|
|
|
|
def git(cwd, *args):
|
|
subprocess.run(["git", "-C", cwd] + list(args), check=True, capture_output=True,
|
|
env=dict(os.environ, GIT_AUTHOR_NAME="t", GIT_AUTHOR_EMAIL="t@t", GIT_COMMITTER_NAME="t",
|
|
GIT_COMMITTER_EMAIL="t@t"))
|
|
|
|
|
|
def check(name, got, want):
|
|
if os.path.realpath(got) == os.path.realpath(want):
|
|
print(" ok %s" % name)
|
|
else:
|
|
fails.append("%s: resolved to %s, want %s" % (name, got, want))
|
|
|
|
|
|
def main():
|
|
tmp = tempfile.mkdtemp(prefix="r1114-")
|
|
old_env = os.environ.pop("FELHOM_SHARED_SCRIPTS", None)
|
|
try:
|
|
ws = os.path.join(tmp, "git")
|
|
main_clone = os.path.join(ws, "felhom-controller")
|
|
sibling = os.path.join(ws, "felhom.eu", "scripts")
|
|
os.makedirs(main_clone)
|
|
os.makedirs(sibling)
|
|
git(main_clone, "init", "-q")
|
|
git(main_clone, "commit", "-q", "--allow-empty", "-m", "base")
|
|
wt = os.path.join(tmp, "wt", "b3")
|
|
os.makedirs(os.path.dirname(wt))
|
|
git(main_clone, "worktree", "add", "-q", "--detach", wt)
|
|
|
|
check("N1 the normal clone finds ../felhom.eu", shared_scripts.shared_scripts_dir(main_clone), sibling)
|
|
check("W1 a worktree outside git/ finds the MAIN clone's sibling",
|
|
shared_scripts.shared_scripts_dir(wt), sibling)
|
|
check("W2 a worktree's workspace is the MAIN clone's parent (FELHOM_WORKSPACE for reuse-refs)",
|
|
shared_scripts.workspace_dir(wt), ws)
|
|
check("N2 the normal clone's workspace is its parent", shared_scripts.workspace_dir(main_clone), ws)
|
|
# A fixture directory INSIDE a repo is not that repo's top level: it must not borrow the real sibling.
|
|
fixture = os.path.join(main_clone, "testdata", "fake-repo")
|
|
os.makedirs(fixture)
|
|
check("F1 a fixture dir inside a repo keeps its own ../felhom.eu",
|
|
shared_scripts.shared_scripts_dir(fixture), os.path.join(main_clone, "testdata", "felhom.eu", "scripts"))
|
|
check("G1 no git at all keeps ../felhom.eu", shared_scripts.shared_scripts_dir(os.path.join(tmp, "plain")),
|
|
os.path.join(tmp, "felhom.eu", "scripts"))
|
|
os.environ["FELHOM_SHARED_SCRIPTS"] = os.path.join(tmp, "override")
|
|
check("E1 FELHOM_SHARED_SCRIPTS wins", shared_scripts.shared_scripts_dir(wt), os.path.join(tmp, "override"))
|
|
finally:
|
|
os.environ.pop("FELHOM_SHARED_SCRIPTS", None)
|
|
if old_env is not None:
|
|
os.environ["FELHOM_SHARED_SCRIPTS"] = old_env
|
|
shutil.rmtree(tmp, ignore_errors=True)
|
|
|
|
if fails:
|
|
print("\nFAIL:")
|
|
for f in fails:
|
|
print(" - " + f)
|
|
return 1
|
|
print("shared-scripts resolver OK")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|