A snapshot: read at commit 707a04c7ce8 on 2026-10-18T00:06:01Z by majordomus 0.29.0. Nothing on this page is read again. See it live
test/cases/106_context_peers.sh
An object of kind test
What it is
- URI
majordomus://test/test/cases/106_context_peers.sh- Kind
test- Identity
test/cases/106_context_peers.sh- Path
test/cases/106_context_peers.sh- Provenance
- declared
- Media type
text/plain- As a capability
- test.test/cases/106_context_peers.sh
Front matter
{}Content
# majordomus-covers: context
# The peers section of `context`: the other workers attached to this repository's shared
# server, and specifically the ones whose claims meet this task's scope.
#
# Co-operation between concurrent workers failed by being voluntary — a session announced,
# reconnected under a new identity and was invisible to eight others for three hours; two
# sessions built the same subsystem because neither read the board. So the board arrives in
# the one command every worker is already told to run. What this case holds is that it
# arrives, that it names the collision rather than merely the peers, and above all that it
# is never load-bearing: no lease, no server, a server that does not answer, an executable
# that is not built, or a board that says nothing must all leave `context` exactly as it
# was.
#
# Where the server is now comes from `serve status`, the executable's one typed reading of
# the lease (ADR 0035, project.the-lease-is-read-once); the lease this case plants is read
# by that reader rather than by the shell. Everything asserted below is asserted about the
# same contract as before the move, which is the point of leaving the assertions alone.
. "$ROOT/test/lib.sh"
command -v jq >/dev/null 2>&1 || skip "jq absent"
command -v curl >/dev/null 2>&1 || skip "curl absent"
command -v python3 >/dev/null 2>&1 || skip "python3 absent"
"$MJ" init >/dev/null; "$MJ" update >/dev/null
mkdir -p lib site && echo a > lib/a && echo s > site/s && git add . && git commit -qm base
"$MJ" start "the ordering rule" --scope lib --profile implementation >/dev/null
# --- with no shared server, context is what it always was
expect_exit 0 "$MJ" context
expect_no_grep '^## PEERS'
order=$(printf '%s\n' "$LAST_OUT" | grep -E '^## ' | tr '\n' ' ')
case "$order" in "## GIT ## TASK"*) ;; *) echo " a repository with one worker grew a section about it: $order"; exit 1 ;; esac
# --- an executable that is not built is the same answer, and it is proved above: the
# section is asked for from `serve status` and there is nothing to ask, so `context` is
# exactly what it was. That half of the contract is what a tree without a build can hold;
# the board itself needs the reader, so the rest is a skip rather than a failure.
BIN="${MAJORDOMUS_BIN:-$ROOT/apps/majordomus-cli/target/debug/majordomus}"
[ -x "$BIN" ] || skip "no built executable to read the lease with; the never-load-bearing half is proved above"
# --- a board with one peer whose claim is inside this task's scope
board="$T/board.json"
cat > "$board" <<'JSON'
{"count":2,"peers":[
{"id":"p1","client":{"name":"codex","version":"1"},"transport":"http","connected_at":"2026-09-09T18:00:00Z","last_seen_seconds_ago":4,"attached":true,
"announcement":{"intent":"the evidence subsystem. Second sentence is not shown.","scope":["lib/evidence.sh","docs/EVIDENCE.md"],"at":"2026-09-09T18:00:00Z"}},
{"id":"p2","client":{"name":"gemini-cli","version":"1"},"transport":"http","connected_at":"2026-09-09T17:00:00Z","last_seen_seconds_ago":900,"attached":false,
"announcement":{"intent":"the installer","scope":["site"],"at":"2026-09-09T17:00:00Z"}}
]}
JSON
srv="$T/serve.py"
cat > "$srv" <<'PY'
import http.server, socketserver, sys, threading
body = open(sys.argv[2], 'rb').read()
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path != "/api/v1/peers":
self.send_response(404); self.end_headers(); return
self.send_response(200); self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body))); self.end_headers(); self.wfile.write(body)
def log_message(self, *a): pass
with socketserver.TCPServer(("127.0.0.1", 0), H) as s:
print(s.server_address[1], flush=True)
open(sys.argv[1], "w").write(str(s.server_address[1]))
s.serve_forever()
PY
python3 "$srv" "$T/port" "$board" > "$T/port.out" 2>"$T/serve.err" &
stub=$!
trap 'kill "$stub" 2>/dev/null || true' EXIT
i=0; until [ -s "$T/port" ] || [ "$i" -ge 100 ]; do i=$((i+1)); sleep 0.05; done
[ -s "$T/port" ] || { echo " the stub board never bound a port"; cat "$T/serve.err"; exit 1; }
port="$(cat "$T/port")"
mkdir -p .ai/local/state/mcp
printf '{"schema":"majordomus-mcp-lease/v1","url":"http://127.0.0.1:%s"}\n' "$port" > .ai/local/state/mcp/server.json
expect_exit 0 "$MJ" context
expect_grep '^## PEERS'
# the peer is named with what it said, and only the first sentence of it
expect_grep 'p1 here'
expect_grep 'the evidence subsystem$'
expect_no_grep 'Second sentence is not shown'
expect_grep 'claims lib/evidence.sh docs/EVIDENCE.md'
# a peer that has gone is still on the board, and said so
expect_grep 'p2 gone'
# and the collision is named as a collision, both sides of it
expect_grep '^OVERLAP'
expect_grep 'p1 claims lib/evidence.sh, inside your lib'
# what does not meet the scope is not reported as if it did
expect_no_grep 'p2 claims site'
# the section sits between git and the task: a worker on your paths outranks your own records
order=$(printf '%s\n' "$LAST_OUT" | grep -E '^## ' | tr '\n' ' ')
case "$order" in "## GIT ## PEERS ## TASK"*) ;; *) echo " peers is not between git and task: $order"; exit 1 ;; esac
# --- a peer that said nothing, listed last: the section still prints and context still
# exits 0. Under `set -e` the bare `[ -n "$pscope" ] &&` on the last row of the listing
# was the loop's exit status, and every board whose newest peer had not announced ended
# `context` with nothing on either stream and exit 1 (2026-09-10, the primary checkout).
cat > "$board" <<'JSON'
{"count":2,"peers":[
{"id":"p1","client":{"name":"codex","version":"1"},"transport":"http","connected_at":"2026-09-09T18:00:00Z","last_seen_seconds_ago":4,"attached":true,
"announcement":{"intent":"the evidence subsystem","scope":["lib/evidence.sh"],"at":"2026-09-09T18:00:00Z"}},
{"id":"p3","client":{"name":"claude-code","version":"1"},"transport":"http","connected_at":"2026-09-09T19:00:00Z","last_seen_seconds_ago":2,"attached":true}
]}
JSON
kill "$stub" 2>/dev/null || true; wait "$stub" 2>/dev/null || true
python3 "$srv" "$T/port3" "$board" > /dev/null 2>&1 &
stub=$!
i=0; until [ -s "$T/port3" ] || [ "$i" -ge 100 ]; do i=$((i+1)); sleep 0.05; done
printf '{"schema":"majordomus-mcp-lease/v1","url":"http://127.0.0.1:%s"}\n' "$(cat "$T/port3")" > .ai/local/state/mcp/server.json
expect_exit 0 "$MJ" context
expect_grep '^## PEERS'
expect_grep 'p3 here'
expect_grep '(said nothing)'
expect_grep '^## TASK'
# --- a server bound to every interface is asked on loopback. A machine that names
# 0.0.0.0 in MAJORDOMUS_HTTP_HOST, so that a second machine can reach its server, publishes
# the unspecified address in its lease; before this was held, the guard below refused it as
# "not loopback" and the board vanished from `context` on exactly the machines that had the
# most peers to collide with. The stub listens on 127.0.0.1 alone, so the section appearing
# is also the proof that the request went to loopback and nowhere else.
printf '{"schema":"majordomus-mcp-lease/v1","url":"http://0.0.0.0:%s"}\n' "$(cat "$T/port3")" > .ai/local/state/mcp/server.json
expect_exit 0 "$MJ" context
expect_grep '^## PEERS'
expect_grep 'p3 here'
# --- and any other address is still refused: the one request this tool makes does not
# leave the machine, whatever a lease says. The board is up and would answer; it is the
# address that is not asked. 192.0.2.0/24 is reserved for documentation and routes nowhere.
printf '{"schema":"majordomus-mcp-lease/v1","url":"http://192.0.2.1:%s"}\n' "$(cat "$T/port3")" > .ai/local/state/mcp/server.json
expect_exit 0 "$MJ" context
expect_no_grep '^## PEERS'
printf '{"schema":"majordomus-mcp-lease/v1","url":"http://0.0.0.0.example.org:%s"}\n' "$(cat "$T/port3")" > .ai/local/state/mcp/server.json
expect_exit 0 "$MJ" context
expect_no_grep '^## PEERS'
# --- a board nobody is on says nothing at all
printf '{"count":0,"peers":[]}\n' > "$board"
kill "$stub" 2>/dev/null || true; wait "$stub" 2>/dev/null || true
python3 "$srv" "$T/port2" "$board" > /dev/null 2>&1 &
stub=$!
i=0; until [ -s "$T/port2" ] || [ "$i" -ge 100 ]; do i=$((i+1)); sleep 0.05; done
printf '{"schema":"majordomus-mcp-lease/v1","url":"http://127.0.0.1:%s"}\n' "$(cat "$T/port2")" > .ai/local/state/mcp/server.json
expect_exit 0 "$MJ" context
expect_no_grep '^## PEERS'
# --- a lease pointing at nothing is not an error: the hint is never load-bearing
kill "$stub" 2>/dev/null || true; wait "$stub" 2>/dev/null || true
expect_exit 0 "$MJ" context
expect_no_grep '^## PEERS'
expect_grep '^## GIT'
expect_grep '^## TASK'
# --- a malformed lease is the same: nothing, and no complaint
printf 'not json at all\n' > .ai/local/state/mcp/server.json
expect_exit 0 "$MJ" context
expect_no_grep '^## PEERS'
echo " the board reaches the worker who never asked for it, and never at the cost of context"