Fix node-facts.sh bugs and add stub-curl integration tests

- Fix grep -qE calls to handle variables starting with '-' (add -- separator)
- Remove local declarations at top level by wrapping main body in main() function
- Replace bounded-worker scheduler with simpler temp file + wait -n pattern
- Fix per-node fan-out to capture function output instead of re-calling
- Add stub-curl integration tests that catch all three original issues
- Add fixture compose files for avalanche, op-node+beacon, geth testing
- Update test path-blacklist.txt to include entry starting with -

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-10-06 07:22:51 +00:00
parent d57d19276e
commit fe22be322e
7 changed files with 367 additions and 83 deletions
+131
View File
@@ -67,6 +67,137 @@ fi
rm -rf "$TMP_DIR"
echo "=== Testing stub-curl integration ==="
# Stub-curl test: test with fixture compose directory and stub curl
STUB_TEST_DIR="$BASEPATH/node-facts-test"
if [ ! -d "$STUB_TEST_DIR" ]; then
echo "SKIP: Stub test directory not found"
else
# Test 6: Test with stub curl - single node mode
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR" || exit 1
# Copy test files
cp -r "$STUB_TEST_DIR"/* .
# Make stub curl executable and put it first in PATH
STUB_CURL_DIR="$TMP_DIR/stub-curl"
chmod +x "$STUB_CURL_DIR/curl"
# Test single node mode with stub curl
ORIGINAL_PATH="$PATH"
export PATH="$STUB_CURL_DIR:$PATH"
START_TIME=$(date +%s)
output=$(timeout 60 ./node-facts.sh "avalanche-mainnet-go" 2>&1)
END_TIME=$(date +%s)
exit_code=$?
export PATH="$ORIGINAL_PATH"
if [ $exit_code -eq 0 ] && [ $((END_TIME - START_TIME)) -lt 10 ]; then
echo "PASS: Stub curl single node mode exits 0 and completes in < 10s"
# Validate it's JSON and has the right schema
if echo "$output" | jq -e '.schema, .node_path, .network, .client' >/dev/null 2>&1; then
echo "PASS: Single node output is valid JSON with required schema fields"
else
echo "FAIL: Single node output is not valid JSON schema"
echo "Output: $output"
rm -rf "$TMP_DIR"
exit 1
fi
else
echo "FAIL: Stub curl single node mode failed with exit code $exit_code, took $((END_TIME - START_TIME))s"
echo "Output: $output"
rm -rf "$TMP_DIR"
exit 1
fi
# Test 7: Test with stub curl - all nodes mode
START_TIME=$(date +%s)
output=$(timeout 60 ./node-facts.sh 2>&1)
END_TIME=$(date +%s)
exit_code=$?
if [ $exit_code -eq 0 ] && [ $((END_TIME - START_TIME)) -lt 10 ]; then
echo "PASS: Stub curl all-nodes mode exits 0 and completes in < 10s"
# Count JSON lines - should have at least 3 valid JSON lines (one per node)
json_lines=$(echo "$output" | grep -c '^{.*}$' || echo "0")
if [ "$json_lines" -ge 3 ]; then
echo "PASS: All-nodes mode produced $json_lines JSON lines (>= 3)"
else
echo "FAIL: All-nodes mode produced only $json_lines JSON lines, expected >= 3"
echo "Output: $output"
rm -rf "$TMP_DIR"
exit 1
fi
# Validate each JSON line against schema
valid_count=0
while IFS= read -r line; do
if echo "$line" | jq -e '.schema, .at, .host, .node_path, .network, .client, .version, .peers, .schedule, .signals, .head, .timing_ms' >/dev/null 2>&1; then
valid_count=$((valid_count + 1))
else
echo "Invalid JSON line: $line"
fi
done <<< "$(echo "$output" | grep '^{.*}$')"
if [ $valid_count -ge 3 ]; then
echo "PASS: All $valid_count JSON lines have valid schema v1 fields"
else
echo "FAIL: Only $valid_count valid JSON lines out of $json_lines total"
rm -rf "$TMP_DIR"
exit 1
fi
# Check for no stderr noise (grep/sed/jq errors)
if echo "$output" | grep -q "grep: invalid argument\|local: can only be used\|sed:\|jq:"; then
echo "FAIL: Found stderr noise in output: $(echo "$output" | grep "grep: invalid argument\|local: can only be used\|sed:\|jq:")"
rm -rf "$TMP_DIR"
exit 1
else
echo "PASS: No stderr noise (grep/sed/jq errors) in output"
fi
else
echo "FAIL: Stub curl all-nodes mode failed with exit code $exit_code, took $((END_TIME - START_TIME))s"
echo "Output: $output"
rm -rf "$TMP_DIR"
exit 1
fi
# Test 8: Test that path-blacklist with - prefix works
# Add a compose file that should be excluded by the -node blacklist entry
echo "version: '3'" > test-node-blacklist.yml
echo "services:" >> test-node-blacklist.yml
echo " client:" >> test-node-blacklist.yml
echo " image: test/node-client:v1.0.0" >> test-node-blacklist.yml
echo "chain: test-node-blacklist" >> test-node-blacklist.yml
# Update COMPOSE_FILE to include the blacklisted file
export COMPOSE_FILE="avalanche-mainnet-go.yml:test-node-blacklist.yml"
output=$(timeout 60 ./node-facts.sh 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
# Should not include test-node-blacklist
if echo "$output" | grep -q "test-node-blacklist"; then
echo "FAIL: Blacklisted node was included in output"
rm -rf "$TMP_DIR"
exit 1
else
echo "PASS: Blacklist with - prefix works correctly"
fi
else
echo "FAIL: Blacklist test failed with exit code $exit_code"
rm -rf "$TMP_DIR"
exit 1
fi
rm -rf "$TMP_DIR"
fi
echo "=== Testing JSON schema validation ==="
# Function to validate schema