Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bin/fm-worker-authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import sys


ROOT = Path(__file__).resolve().parent.parent


AUTHORITY_SCHEMA = "fm.worker-authority/v1"
RELEASE_SCHEMA = "fm.worker-release/v2"
REQUIRED_HEADINGS = (
Expand Down Expand Up @@ -75,7 +78,7 @@ def endpoint_evidence(home, task, values):
backend = values.get("backend", ["tmux"])[0]
target = exactly(values, "window")
expected = "fm-{}".format(task)
helper = home / "bin" / "fm-backend.sh"
helper = ROOT / "bin" / "fm-backend.sh"
script = '. "$1"; fm_backend_target_state "$2" "$3" "$4" "${5:-}"'
result = subprocess.run(
["bash", "-c", script, "_", str(helper), backend, target, expected,
Expand Down Expand Up @@ -145,7 +148,7 @@ def account_evidence(values, task, home):
account_task = values.get("account_task", [task])[0]
if account_task != task:
raise AuthorityError("account authority task identity differs")
helper = home / "bin" / "fm-account-directory.sh"
helper = ROOT / "bin" / "fm-account-directory.sh"
if not helper.is_file():
raise AuthorityError("ordinary account authority helper is unavailable")
vendor = "claude" if "claude" in Path(account_home).parts else "codex" if "codex" in Path(account_home).parts else ""
Expand All @@ -165,7 +168,7 @@ def account_evidence(values, task, home):
'cd "$account" && pwd -P'
)
result = subprocess.run(
["bash", "-c", script, "_", str(home / "bin" / "fm-account-directory.sh"), vendor, account_home],
["bash", "-c", script, "_", str(ROOT / "bin" / "fm-account-directory.sh"), vendor, account_home],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env={**os.environ, "FM_HOME": str(home), "FM_ROOT": str(home)},
)
Expand Down
32 changes: 31 additions & 1 deletion tests/fm-worker-lifecycle.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1845,21 +1845,50 @@ PY
pass "landing authority refreshes and prunes origin before proving reachability"
}

endpoint_authority_checkout_helper() {
local tmp
fm_test_tmproot_into tmp fm-worker-endpoint-authority
# A production FM_HOME is a data home with no bin/. The backend helper must
# resolve from the checkout that ships this tool; resolving it under the
# home made every receipt die at rc 127 before any endpoint was probed.
mkdir -p "$tmp/home/state" "$tmp/shim"
cat > "$tmp/shim/tmux" <<'SH'
#!/bin/sh
echo "no server running on /tmp/fm-endpoint-authority-test" >&2
exit 1
SH
chmod +x "$tmp/shim/tmux"
PATH="$tmp/shim:$PATH" python3 - "$AUTHORITY" "$tmp/home" <<'PY' || fail "endpoint authority did not resolve its helper from the checkout"
import importlib.util
import sys
from pathlib import Path
spec = importlib.util.spec_from_file_location("worker_authority", sys.argv[1])
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
home = Path(sys.argv[2])
assert not (home / "bin").exists()
evidence = module.endpoint_evidence(home, "task-x", {"backend": ["tmux"], "window": ["fmtest:1"]})
assert b"absent" in evidence
PY
pass "endpoint authority sources the checkout backend helper against a binless home"
}

account_authority_real_helper() {
local tmp
fm_test_tmproot_into tmp fm-worker-account-authority
mkdir -p "$tmp/accounts/claude/3"
ln -s "$tmp/accounts/claude/3" "$tmp/accounts/claude/link"
FM_ACCOUNT_DIRECTORY_TEST_LAB=firstmate-account-directory-test-lab-v1 \
FM_ACCOUNT_DIRECTORY_ROOT="$tmp/accounts" \
python3 - "$AUTHORITY" "$ROOT" "$tmp/accounts/claude/3" "$tmp/accounts/claude/link" <<'PY' || fail "account authority against the real helper failed"
python3 - "$AUTHORITY" "$tmp" "$tmp/accounts/claude/3" "$tmp/accounts/claude/link" <<'PY' || fail "account authority against the real helper failed"
import importlib.util
import sys
from pathlib import Path
spec = importlib.util.spec_from_file_location("worker_authority", sys.argv[1])
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
home = Path(sys.argv[2])
assert not (home / "bin").exists()
values = {"account_home": [sys.argv[3]], "account_task": ["task-x"]}
evidence = module.account_evidence(values, "task-x", home)
assert b"ordinary-account-owner" in evidence
Expand Down Expand Up @@ -2226,6 +2255,7 @@ end_to_end_lifecycle
shared_specialized_cli
shared_shape_cli
landing_authority_refresh
endpoint_authority_checkout_helper
account_authority_real_helper
restart_idempotency
partial_apply_never_persists
Expand Down
Loading