Skip to content

Commit 16c99c6

Browse files
whoabuddyclaude
andauthored
fix(tests): add network flag and per-network log dirs to cron script (#29)
Support --network=testnet|mainnet CLI argument for running tests against different environments. Organize log output into per-network subdirectories. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 460079d commit 16c99c6

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

scripts/run-tests-cron.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
# Cron script to run full test suite - only logs failures
3-
# Usage: ./scripts/run-tests-cron.sh
4-
# Cron: 0 * * * * /home/whoabuddy/dev/aibtcdev/x402-api/scripts/run-tests-cron.sh
3+
# Usage: ./scripts/run-tests-cron.sh [--network=testnet|mainnet]
4+
# Cron: 0 4,12,20 * * * /path/to/run-tests-cron.sh
5+
# 0 10 * * * /path/to/run-tests-cron.sh --network=mainnet
56

67
# Set up PATH for cron environment (bun, node, npm, etc.)
78
NODE_VERSIONS_DIR="$HOME/.nvm/versions/node"
@@ -37,16 +38,28 @@ if [ -f .dev.vars ]; then
3738
set +a
3839
fi
3940

40-
# Configuration - override these in .env if needed
41-
# X402_NETWORK defaults to testnet for safety
41+
# Parse command-line arguments (override .env values)
42+
CLI_NETWORK=""
43+
for arg in "$@"; do
44+
case "$arg" in
45+
--network=*) CLI_NETWORK="${arg#*=}" ;;
46+
esac
47+
done
48+
49+
# Network priority: CLI arg > .env > default (testnet)
50+
if [ -n "$CLI_NETWORK" ]; then
51+
export X402_NETWORK="$CLI_NETWORK"
52+
else
53+
export X402_NETWORK="${X402_NETWORK:-testnet}"
54+
fi
55+
4256
# URL is derived from network automatically:
4357
# testnet → https://x402.aibtc.dev (staging)
4458
# mainnet → https://x402.aibtc.com (production)
4559
# Override with X402_WORKER_URL if needed (e.g., for localhost testing)
46-
export X402_NETWORK="${X402_NETWORK:-testnet}"
4760

48-
# Log directory
49-
LOG_DIR="logs/test-runs"
61+
# Log directory (separate subdirs per network)
62+
LOG_DIR="logs/test-runs/${X402_NETWORK}"
5063
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
5164
LOG_FILE="${LOG_DIR}/test-${TIMESTAMP}.log"
5265

0 commit comments

Comments
 (0)