feat(terra): pass-broker prompts say who asked

Prompts and the journal now show "darman via Claude Code" (a `claude`
ancestor) or the terminal holding the tty, plus the caller's command with
store/profile paths cut to program names, and the process chain. It is
a hint, not identity: anything running as darman can fake it.

A client that has already hung up now always loses the race against the
prompt lock and Telegram polling, so it can no longer get a prompt, and
gone clients get no reply (no more EPIPE noise). The ghost-request test
freezes the broker to reproduce the queued-while-restarting case exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 02:12:04 +02:00
co-authored by Claude Opus 5.5
parent 3dccafe2b8
commit 8c0c2822c6
3 changed files with 128 additions and 38 deletions
+16 -1
View File
@@ -110,6 +110,11 @@ let
# ghost: send a request and hang up before the broker reads it, like a
# client killed while queued. silent: a socket that never answers, like a
# crash-looping broker behind its socket unit.
# Stand-in for Claude Code, whose process name is `claude`.
fakeClaude = pkgs.writeShellScriptBin "claude" ''
pass-broker get --item auto-item --reason "from claude"
'';
sockProbe = pkgs.writers.writePython3Bin "sock-probe" { flakeIgnore = [ "E501" ]; } ''
import json
import socket
@@ -136,7 +141,7 @@ pkgs.testers.runNixOSTest {
users.users.darman.isNormalUser = true;
users.users.eve.isNormalUser = true;
environment.systemPackages = [ pkgs.curl pkgs.jq tryGet sockProbe ];
environment.systemPackages = [ pkgs.curl pkgs.jq tryGet sockProbe fakeClaude ];
systemd.tmpfiles.rules = [ "d /tmp/r 1777 root root -" ];
environment.etc = {
@@ -201,6 +206,8 @@ pkgs.testers.runNixOSTest {
start("a", "darman@jupiter")
msg = wait_messages(1)
assert "darman@jupiter" in msg["text"] and "vm test" in msg["text"], msg
assert "\nBy: darman via " in msg["text"], msg
assert "\nCommand: bash try-get a darman@jupiter\n" in msg["text"], msg
assert msg["chat_id"] == 4242, msg
press(button(msg, 0), sender=999)
machine.sleep(2)
@@ -275,7 +282,11 @@ pkgs.testers.runNixOSTest {
with subtest("a request whose client already hung up is dropped without a prompt"):
before = views()
# Frozen broker = the crash-loop case: the request waits in the socket
# while its client exits, and only then gets read.
machine.succeed("systemctl kill --signal=SIGSTOP pass-broker.service")
machine.succeed("sock-probe ghost")
machine.succeed("systemctl kill --signal=SIGCONT pass-broker.service")
journal_has("dropped HomeLab/root@jupiter: requester went away")
machine.sleep(2)
assert len(tg()["messages"]) == 6
@@ -290,6 +301,10 @@ pkgs.testers.runNixOSTest {
)
assert "no answer within 30s" in err, err
with subtest("a request from under Claude Code is labelled as such"):
assert machine.succeed("su darman -c claude").strip() == "autopw"
journal_has('reason="from claude" by darman via Claude Code [bash claude]')
with subtest("other users are refused, and darman cannot read the session"):
err = machine.fail("su eve -c 'pass-broker get --item auto-item --reason x' 2>&1")
assert "uid not allowed" in err, err