Skip to content

Commit 56ecdb1

Browse files
authored
Merge pull request #1432 from o1-labs/docs/graphql-endpoint-troubleshooting
CI: fix test-docs-infrastructure
2 parents feb3947 + 774c0c3 commit 56ecdb1

36 files changed

+819
-532
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#!/bin/bash
2+
3+
# Test Documentation Scripts - GraphQL API (Local Runner)
4+
# This script contains the same logic as .github/workflows/test-docs-graphql-api.yaml
5+
#
6+
# Usage:
7+
# ./test-graphql-api-local.sh
8+
#
9+
# Or run individual steps:
10+
# ./.github/scripts/test-script-query-consistency.sh
11+
# ./.github/scripts/test-graphql-command-scripts.sh
12+
#
13+
# This script runs all GraphQL API tests locally without GitHub Actions
14+
15+
set -e
16+
17+
echo "Testing GraphQL API Scripts Locally"
18+
echo "===================================="
19+
20+
# Check if jq is installed
21+
if ! command -v jq &> /dev/null; then
22+
echo "❌ jq is required but not installed."
23+
echo "Install it with:"
24+
echo " - Ubuntu/Debian: sudo apt-get install jq"
25+
echo " - macOS: brew install jq"
26+
exit 1
27+
fi
28+
29+
echo "✅ jq is installed: $(jq --version)"
30+
echo ""
31+
32+
# Test 1: Script and query file consistency
33+
echo "🔍 Testing consistency between bash scripts and GraphQL query files..."
34+
35+
script_dir="website/docs/developers/scripts/graphql-api/queries/curl"
36+
query_dir="website/docs/developers/scripts/graphql-api/queries/query"
37+
38+
inconsistent=0
39+
40+
# Check that each script that references a query file has a corresponding .graphql file
41+
for script_file in "$script_dir"/*.sh; do
42+
if [ ! -f "$script_file" ]; then
43+
continue
44+
fi
45+
46+
script_name=$(basename "$script_file" .sh)
47+
48+
# Look for query file references in the script
49+
if grep -q "query/" "$script_file"; then
50+
expected_query_file="$query_dir/$script_name.graphql"
51+
52+
if [ -f "$expected_query_file" ]; then
53+
echo "$script_name has corresponding query file"
54+
else
55+
echo "$script_name missing query file: $expected_query_file"
56+
inconsistent=$((inconsistent + 1))
57+
fi
58+
fi
59+
done
60+
61+
# Check that each query file has a corresponding script
62+
for query_file in "$query_dir"/*.graphql; do
63+
if [ ! -f "$query_file" ]; then
64+
continue
65+
fi
66+
67+
query_name=$(basename "$query_file" .graphql)
68+
expected_script_file="$script_dir/$query_name.sh"
69+
70+
if [ -f "$expected_script_file" ]; then
71+
echo "$query_name has corresponding script file"
72+
else
73+
echo "$query_name query file has no corresponding script: $expected_script_file"
74+
inconsistent=$((inconsistent + 1))
75+
fi
76+
done
77+
78+
if [ $inconsistent -gt 0 ]; then
79+
echo "$inconsistent script/query file inconsistencies found"
80+
exit 1
81+
else
82+
echo "All scripts and query files are consistent"
83+
fi
84+
85+
echo ""
86+
87+
# Test 2: GraphQL command scripts
88+
echo "🔍 Testing GraphQL API command scripts..."
89+
90+
# Dynamically discover all bash scripts in the queries/curl directory (only test queries, not mutations)
91+
script_dir="website/docs/developers/scripts/graphql-api/queries/curl"
92+
93+
if [ ! -d "$script_dir" ]; then
94+
echo "❌ Script directory not found: $script_dir"
95+
exit 1
96+
fi
97+
98+
# Get all .sh files in the curl directory
99+
script_files=$(ls "$script_dir"/*.sh 2>/dev/null)
100+
101+
if [ -z "$script_files" ]; then
102+
echo "❌ No bash scripts found in $script_dir"
103+
exit 1
104+
fi
105+
106+
failed=0
107+
108+
for script_file in $script_files; do
109+
if [ ! -f "$script_file" ]; then
110+
echo "❌ Script file not found: $script_file"
111+
failed=$((failed + 1))
112+
continue
113+
fi
114+
115+
echo "Testing script: $script_file"
116+
117+
# Execute the script and capture output
118+
if output=$(bash "$script_file" 2>&1); then
119+
echo "✅ Script executed successfully with output $output"
120+
121+
# Try to parse output as JSON using jq
122+
if json_response=$(echo "$output" | jq . 2>/dev/null); then
123+
# Valid JSON response - check for GraphQL errors
124+
if echo "$json_response" | jq -e '.errors' > /dev/null 2>&1; then
125+
echo "❌ Script returned GraphQL errors:"
126+
echo "$json_response" | jq '.errors'
127+
failed=$((failed + 1))
128+
elif echo "$json_response" | jq -e '.data' > /dev/null 2>&1; then
129+
echo "✅ Script response contains valid data: $(echo "$json_response" | head -c 100)..."
130+
else
131+
echo "⚠️ Unexpected JSON response format: $(echo "$json_response" | head -c 100)..."
132+
fi
133+
else
134+
echo "❌ Script did not return valid JSON"
135+
failed=$((failed + 1))
136+
fi
137+
else
138+
echo "❌ Script execution failed: $script_file"
139+
failed=$((failed + 1))
140+
fi
141+
142+
echo "---"
143+
done
144+
145+
if [ $failed -gt 0 ]; then
146+
echo "$failed GraphQL script tests failed"
147+
echo "Some GraphQL API scripts may need updates."
148+
exit 1
149+
else
150+
echo "All GraphQL API command scripts are working"
151+
fi
152+
153+
echo ""
154+
echo "All tests passed successfully!"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
# Test GraphQL command scripts
4+
# This corresponds to the second step in test-docs-graphql-api.yaml
5+
#
6+
# Usage:
7+
# ./test-graphql-command-scripts.sh
8+
#
9+
# This script tests GraphQL API command scripts by executing them and validating responses
10+
11+
set -e
12+
13+
# Check if jq is installed
14+
if ! command -v jq &> /dev/null; then
15+
echo "jq is required but not installed."
16+
echo "Install it with:"
17+
echo " - Ubuntu/Debian: sudo apt-get install jq"
18+
echo " - macOS: brew install jq"
19+
exit 1
20+
fi
21+
22+
echo "🔍 Testing GraphQL API command scripts..."
23+
24+
# Dynamically discover all bash scripts in the queries/curl directory (only test queries, not mutations)
25+
script_dir="website/docs/developers/scripts/graphql-api/queries/curl"
26+
27+
if [ ! -d "$script_dir" ]; then
28+
echo "❌ Script directory not found: $script_dir"
29+
exit 1
30+
fi
31+
32+
# Get all .sh files in the curl directory
33+
script_files=$(ls "$script_dir"/*.sh 2>/dev/null)
34+
35+
if [ -z "$script_files" ]; then
36+
echo "❌ No bash scripts found in $script_dir"
37+
exit 1
38+
fi
39+
40+
failed=0
41+
42+
for script_file in $script_files; do
43+
if [ ! -f "$script_file" ]; then
44+
echo "❌ Script file not found: $script_file"
45+
failed=$((failed + 1))
46+
continue
47+
fi
48+
49+
echo "Testing script: $script_file"
50+
51+
# Execute the script and capture output
52+
if output=$(bash "$script_file" 2>&1); then
53+
echo "✅ Script executed successfully"
54+
55+
# Try to parse output as JSON using jq
56+
if echo "$output" | jq . > /dev/null 2>&1; then
57+
# Valid JSON response - check for GraphQL errors
58+
if echo "$output" | jq -e '.errors' > /dev/null 2>&1; then
59+
echo "❌ Script returned GraphQL errors:"
60+
echo "$output" | jq '.errors'
61+
failed=$((failed + 1))
62+
elif echo "$output" | jq -e '.data' > /dev/null 2>&1; then
63+
echo "✅ Script response contains valid data: $(echo "$output" | head -c 100)..."
64+
else
65+
echo "⚠️ Unexpected JSON response format: $(echo "$output" | head -c 100)..."
66+
fi
67+
else
68+
echo "❌ Script did not return valid JSON: $(echo "$output" | head -c 100)..."
69+
failed=$((failed + 1))
70+
fi
71+
else
72+
echo "❌ Script execution failed: $script_file"
73+
failed=$((failed + 1))
74+
fi
75+
76+
echo "---"
77+
done
78+
79+
if [ $failed -gt 0 ]; then
80+
echo "💥 $failed GraphQL script tests failed"
81+
echo "Some GraphQL API scripts may need updates."
82+
exit 1
83+
else
84+
echo "🎉 All GraphQL API command scripts are working"
85+
fi
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
# Test infrastructure command scripts
4+
# This corresponds to the sixth step in test-docs-infrastructure.yaml
5+
#
6+
# Usage:
7+
# ./test-infrastructure-scripts.sh
8+
#
9+
# This script tests infrastructure command scripts against live endpoints
10+
11+
echo "🔍 Testing infrastructure command scripts..."
12+
13+
# Dynamically discover all bash scripts in the infrastructure directory
14+
script_dir="website/docs/developers/scripts/infrastructure"
15+
16+
if [ ! -d "$script_dir" ]; then
17+
echo "❌ Script directory not found: $script_dir"
18+
exit 1
19+
fi
20+
21+
# Get all .sh files in the infrastructure directory
22+
script_files=$(ls "$script_dir"/*.sh 2>/dev/null)
23+
24+
if [ -z "$script_files" ]; then
25+
echo "❌ No bash scripts found in $script_dir"
26+
exit 1
27+
fi
28+
29+
failed=0
30+
31+
# Use first plain node for testing infrastructure scripts
32+
plain_nodes_file="website/docs/developers/scripts/infrastructure/plain-nodes.txt"
33+
test_endpoint=""
34+
if [ -f "$plain_nodes_file" ]; then
35+
first_node=$(head -n 1 "$plain_nodes_file")
36+
test_endpoint="${first_node}graphql"
37+
else
38+
exit 1
39+
fi
40+
41+
for script_file in $script_files; do
42+
if [ ! -f "$script_file" ]; then
43+
echo "❌ Script file not found: $script_file"
44+
failed=$((failed + 1))
45+
continue
46+
fi
47+
48+
echo "Testing script: $script_file with the endpoint $test_endpoint"
49+
50+
# Execute the script with test endpoint and capture output
51+
if output=$(bash "$script_file" "$test_endpoint" 2>&1); then
52+
echo "✅ Script executed successfully"
53+
54+
# Try to parse output as JSON using jq
55+
if json_response=$(echo "$output" | jq . 2>/dev/null); then
56+
# Valid JSON response - check for GraphQL errors
57+
if echo "$json_response" | jq -e '.errors' > /dev/null 2>&1; then
58+
echo "❌ Script returned GraphQL errors:"
59+
echo "$json_response" | jq '.errors'
60+
failed=$((failed + 1))
61+
elif echo "$json_response" | jq -e '.data' > /dev/null 2>&1; then
62+
echo "✅ Script response contains valid data: $(echo "$json_response" | head -c 100)..."
63+
else
64+
echo "⚠️ Unexpected JSON response format: $(echo "$json_response" | head -c 100)..."
65+
fi
66+
else
67+
echo "❌ Script did not return valid JSON"
68+
failed=$((failed + 1))
69+
fi
70+
else
71+
echo "❌ Script execution failed: $script_file"
72+
failed=$((failed + 1))
73+
fi
74+
75+
echo "---"
76+
done
77+
78+
if [ $failed -gt 0 ]; then
79+
echo "💥 $failed infrastructure script tests failed"
80+
echo "Some infrastructure scripts may need updates."
81+
exit 1
82+
else
83+
echo "🎉 All infrastructure command scripts are working"
84+
fi
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# Test plain node API capabilities
4+
# This corresponds to the fifth step in test-docs-infrastructure.yaml
5+
#
6+
# Usage:
7+
# ./test-plain-node-capabilities.sh
8+
#
9+
# This script tests API capabilities of o1Labs plain nodes
10+
11+
echo "🔍 Testing plain node API capabilities..."
12+
13+
# Read plain nodes from file
14+
plain_nodes_file="website/docs/developers/scripts/infrastructure/plain-nodes.txt"
15+
plain_nodes=$(cat "$plain_nodes_file")
16+
17+
# Test with first available node
18+
for node_url in $plain_nodes; do
19+
graphql_url="${node_url}graphql"
20+
21+
echo "Testing API capabilities on: $graphql_url"
22+
23+
# Test network ID query using website script
24+
network_success=false
25+
if network_response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/network-id.sh "$graphql_url" 2>&1); then
26+
if echo "$network_response" | jq -e '.data.networkID' > /dev/null 2>&1; then
27+
network_id=$(echo "$network_response" | jq -r '.data.networkID')
28+
echo "✅ Network ID query successful: $network_id"
29+
network_success=true
30+
else
31+
echo "⚠️ Network ID query failed or unexpected response"
32+
fi
33+
else
34+
echo "⚠️ Network ID query script failed"
35+
fi
36+
37+
# Test best chain query using website script
38+
chain_success=false
39+
if chain_response=$(bash website/docs/developers/scripts/graphql-api/queries/curl/best-chain.sh "$graphql_url" 2>&1); then
40+
if echo "$chain_response" | jq -e '.data.bestChain[0].stateHash' > /dev/null 2>&1; then
41+
state_hash=$(echo "$chain_response" | jq -r '.data.bestChain[0].stateHash')
42+
echo "✅ Best chain query successful: ${state_hash:0:16}..."
43+
chain_success=true
44+
else
45+
echo "⚠️ Best chain query failed or unexpected response"
46+
fi
47+
else
48+
echo "⚠️ Best chain query script failed"
49+
fi
50+
51+
# We only need to test one working node
52+
if [ "$network_success" = true ] && [ "$chain_success" = true ]; then
53+
echo "🎉 Plain node API capabilities verified"
54+
break
55+
fi
56+
done

0 commit comments

Comments
 (0)