Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
fix renewal busy-loop and e2e watch test
Antonio Ojea0befa5dd237d
diff --git a/cmd/sam-node/node.go b/cmd/sam-node/node.goindex 7b642e09..561313ae 100644--- a/cmd/sam-node/node.go+++ b/cmd/sam-node/node.go@@ -507,6 +507,9 @@ func (n *SamNode) StartRenewalLoop(ctx context.Context, issuerURL, clientID, clirenewAfter = duration - RenewalBuffer} else if duration > 0 {renewAfter = duration / 2+ if renewAfter < 2*time.Second {+ renewAfter = 2 * time.Second+ }} else {renewAfter = 1 * time.Second}diff --git a/tests/e2e/watch.bats b/tests/e2e/watch.batsindex b979db20..af11106a 100644--- a/tests/e2e/watch.bats+++ b/tests/e2e/watch.bats@@ -2,6 +2,7 @@setup() {export SAM_NODE_BINARY="${SAM_NODE_BINARY:-./bin/sam-node}"+ export SAM_HUB_BINARY="${SAM_HUB_BINARY:-./bin/sam-hub}"if [[ ! -x "$SAM_NODE_BINARY" ]]; thenskip "sam-node binary not found at $SAM_NODE_BINARY"fi@@ -9,13 +10,8 @@ setup() {export TEST_TMPDIRTEST_TMPDIR="$(mktemp -d)"export HOME="$TEST_TMPDIR/home"-export SAM_DATA_DIR="$TEST_TMPDIR/data"- DB_PATH="$SAM_DATA_DIR/agent.db"mkdir -p "$SAM_DATA_DIR"-- # Generate mock DB- go run tests/e2e/gen_db.go "$DB_PATH"}teardown() {@@ -23,10 +19,45 @@ teardown() {rm -rf "$TEST_TMPDIR"}-@test "sam-node run with stored identity reaches online state" {+@test "sam-node run with stored identity fails if hub is unreachable" {+ DB_PATH="$SAM_DATA_DIR/agent.db"+ go run tests/e2e/gen_db.go "$DB_PATH"++ log_file="$TEST_TMPDIR/run.log"+ run "$SAM_NODE_BINARY" run --listen /ip4/127.0.0.1/udp/0/quic-v1 --listen /ip4/127.0.0.1/tcp/0 --api-token "dummy-token" --bind-addr "127.0.0.1:0" >"$log_file" 2>&1++ if [[ "$status" -eq 0 ]]; then+ echo "Test failed: Node was expected to exit with non-zero status"+ cat "$log_file"+ return 1+ fi++ if ! grep -q "failed to authenticate with any hub: all connection attempts failed" "$log_file"; then+ echo "Test failed: Node did not log the expected error message"+ cat "$log_file"+ return 1+ fi+}++@test "sam-node run with stored identity reaches online state when hub is reachable" {+ if [[ ! -x "$SAM_HUB_BINARY" ]]; then+ skip "sam-hub binary not found at $SAM_HUB_BINARY"+ fi++ hub_log="$TEST_TMPDIR/hub.log"+ "$SAM_HUB_BINARY" start >"$hub_log" 2>&1 &+ hub_pid=$!++ # Wait for hub to start+ sleep 2++ # Join node to the hub to get a valid stored identity+ join_log="$TEST_TMPDIR/join.log"+ "$SAM_NODE_BINARY" join "http://127.0.0.1:9090" >"$join_log" 2>&1+log_file="$TEST_TMPDIR/run.log""$SAM_NODE_BINARY" run --listen /ip4/127.0.0.1/udp/0/quic-v1 --listen /ip4/127.0.0.1/tcp/0 --api-token "dummy-token" --bind-addr "127.0.0.1:0" >"$log_file" 2>&1 &- pid=$!+ node_pid=$!online=""for _ in {1..40}; do@@ -37,8 +68,10 @@ teardown() {sleep 0.1done- kill "$pid" >/dev/null 2>&1 || true- wait "$pid" >/dev/null 2>&1 || true+ kill "$node_pid" >/dev/null 2>&1 || true+ wait "$node_pid" >/dev/null 2>&1 || true+ kill "$hub_pid" >/dev/null 2>&1 || true+ wait "$hub_pid" >/dev/null 2>&1 || trueif [[ "$online" != "yes" ]]; thenecho "Test failed. Node logs:"@@ -47,5 +80,3 @@ teardown() {[[ "$online" == "yes" ]]}--