Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ EXPOSE 9000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD test -f /data/distributed.db || exit 1
CMD test -e /data/distributed.db || exit 1

# Default entrypoint
ENTRYPOINT ["validator-node"]
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:
command: ["validator-node", "--data-dir", "/data", "--listen-addr", "/ip4/0.0.0.0/tcp/9000"]

healthcheck:
test: ["CMD-SHELL", "test -f /data/distributed.db || exit 1"]
test: ["CMD-SHELL", "test -e /data/distributed.db || exit 1"]
interval: 30s
timeout: 10s
retries: 3
Expand Down
232 changes: 232 additions & 0 deletions scripts/test-comprehensive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
#!/bin/bash
# =============================================================================
# Platform Comprehensive Test Suite
# =============================================================================
# Runs all tests including unit tests, integration tests, Docker tests,
# and multi-validator P2P network tests.
#
# Usage:
# ./scripts/test-comprehensive.sh
#
# Requirements:
# - Docker daemon running
# - Rust toolchain installed
# - Network access for Bittensor integration tests
# =============================================================================

set -e

Comment on lines +17 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check if the file exists and examine its structure
git ls-files | grep -E "scripts/test-comprehensive\.sh"

Repository: PlatformNetwork/platform-v2

Length of output: 100


🏁 Script executed:

# Read the file to verify the lines mentioned
wc -l scripts/test-comprehensive.sh

Repository: PlatformNetwork/platform-v2

Length of output: 104


🏁 Script executed:

# Read the relevant sections of the file
cat -n scripts/test-comprehensive.sh | sed -n '1,30p'

Repository: PlatformNetwork/platform-v2

Length of output: 1038


🏁 Script executed:

# Check the pipeline sections at the mentioned lines
cat -n scripts/test-comprehensive.sh | sed -n '85,95p'

Repository: PlatformNetwork/platform-v2

Length of output: 592


🏁 Script executed:

# Check around line 109
cat -n scripts/test-comprehensive.sh | sed -n '105,115p'

Repository: PlatformNetwork/platform-v2

Length of output: 597


🏁 Script executed:

# Check around line 184
cat -n scripts/test-comprehensive.sh | sed -n '180,190p'

Repository: PlatformNetwork/platform-v2

Length of output: 580


🏁 Script executed:

# Search for pipefail in the file
grep -n "pipefail" scripts/test-comprehensive.sh || echo "No pipefail found"

Repository: PlatformNetwork/platform-v2

Length of output: 88


Enable pipefail to prevent masked test failures in piped commands.

The pipelines at lines 88, 109, and 184 use cargo test ... | tee ... in if conditions without set -o pipefail. This causes test failures to be masked since the exit code comes from tee (which succeeds) rather than cargo test, allowing failed tests to incorrectly pass the conditional checks.

🔧 Proposed fix
 set -e
+set -o pipefail

Add set -o pipefail after line 17 to properly propagate exit codes through pipelines.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set -e
set -e
set -o pipefail
🤖 Prompt for AI Agents
In `@scripts/test-comprehensive.sh` around lines 17 - 18, The script currently
uses "set -e" but misses "set -o pipefail", so failures in piped commands like
the "cargo test ... | tee ..." pipelines (used around the cargo test checks) can
be masked by tee's success; add "set -o pipefail" immediately after the existing
"set -e" in scripts/test-comprehensive.sh so that pipeline failures (e.g., in
the cargo test | tee pipelines) correctly propagate non-zero exit codes to the
script's conditionals and cause test failures to be detected.

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Test result counters
PASSED=0
FAILED=0
SKIPPED=0

# Log functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}

log_success() {
echo -e "${GREEN}[PASS]${NC} $1"
((PASSED++))
}

log_failure() {
echo -e "${RED}[FAIL]${NC} $1"
((FAILED++))
}

log_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}

log_skip() {
echo -e "${YELLOW}[SKIP]${NC} $1"
((SKIPPED++))
}

# Header
echo "============================================================================="
echo " Platform Comprehensive Test Suite"
echo "============================================================================="
echo ""
date
echo ""

# =============================================================================
# Phase 1: Build
# =============================================================================
echo ""
echo "============================================================================="
echo "Phase 1: Build (cargo build --release)"
echo "============================================================================="

log_info "Building workspace..."
if cargo build --release 2>&1; then
log_success "Build completed successfully"
else
log_failure "Build failed"
exit 1
fi

# =============================================================================
# Phase 2: Unit Tests
# =============================================================================
echo ""
echo "============================================================================="
echo "Phase 2: Unit Tests (cargo test --workspace)"
echo "============================================================================="

log_info "Running unit tests..."
if cargo test --workspace --release 2>&1 | tee /tmp/unit_tests.log; then
UNIT_RESULTS=$(grep -E "^test result:" /tmp/unit_tests.log | tail -1)
log_success "Unit tests completed: $UNIT_RESULTS"
else
log_failure "Unit tests failed"
fi

# =============================================================================
# Phase 3: Docker Integration Tests
# =============================================================================
echo ""
echo "============================================================================="
echo "Phase 3: Docker Integration Tests"
echo "============================================================================="

# Check Docker availability
if docker info > /dev/null 2>&1; then
log_info "Docker daemon available"

# Secure Container Runtime tests
log_info "Running secure-container-runtime Docker tests..."
if cargo test -p secure-container-runtime --release -- --ignored 2>&1 | tee /tmp/docker_tests.log; then
log_success "Secure container runtime Docker tests passed"
else
log_failure "Secure container runtime Docker tests failed"
fi

# Challenge Orchestrator Docker tests
log_info "Running challenge-orchestrator Docker tests..."
if cargo test -p challenge-orchestrator --release -- --ignored 2>&1; then
log_success "Challenge orchestrator Docker tests passed"
else
log_failure "Challenge orchestrator Docker tests failed"
fi
else
log_skip "Docker not available, skipping Docker tests"
fi

# =============================================================================
# Phase 4: Bittensor Integration Tests
# =============================================================================
echo ""
echo "============================================================================="
echo "Phase 4: Bittensor Integration Tests"
echo "============================================================================="

log_info "Running Bittensor integration tests (requires network)..."
if timeout 120 cargo test -p platform-bittensor --release -- --ignored 2>&1; then
log_success "Bittensor integration tests passed"
else
log_warning "Bittensor integration tests failed or timed out (may require network)"
fi

# =============================================================================
# Phase 5: Security Policy Tests
# =============================================================================
echo ""
echo "============================================================================="
echo "Phase 5: Security Policy Tests"
echo "============================================================================="

log_info "Verifying security policies..."

# Test that Docker socket mounting is blocked
log_info "Testing Docker socket mount blocking..."
if cargo test -p secure-container-runtime test_default_policy_blocks_docker_socket --release 2>&1; then
log_success "Docker socket mount blocking verified"
else
log_failure "Docker socket mount blocking test failed"
fi

# Test image whitelist
log_info "Testing image whitelist enforcement..."
if cargo test -p secure-container-runtime test_strict_policy_blocks_non_whitelisted_images --release 2>&1; then
log_success "Image whitelist enforcement verified"
else
log_failure "Image whitelist enforcement test failed"
fi

# Test resource limits
log_info "Testing resource limit enforcement..."
if cargo test -p secure-container-runtime test_policy_enforces_resource_limits --release 2>&1; then
log_success "Resource limit enforcement verified"
else
log_failure "Resource limit enforcement test failed"
fi

# =============================================================================
# Phase 6: P2P Consensus Tests
# =============================================================================
echo ""
echo "============================================================================="
echo "Phase 6: P2P Consensus Tests"
echo "============================================================================="

log_info "Running P2P consensus unit tests..."
if cargo test -p platform-p2p-consensus --release 2>&1 | tee /tmp/p2p_tests.log; then
P2P_RESULTS=$(grep -E "^test result:" /tmp/p2p_tests.log | tail -1)
log_success "P2P consensus tests: $P2P_RESULTS"
else
log_failure "P2P consensus tests failed"
fi

# =============================================================================
# Phase 7: Storage Tests
# =============================================================================
echo ""
echo "============================================================================="
echo "Phase 7: Storage Tests"
echo "============================================================================="

log_info "Running storage tests..."
if cargo test -p platform-storage --release 2>&1; then
log_success "Storage tests passed"
else
log_failure "Storage tests failed"
fi

log_info "Running distributed storage tests..."
if cargo test -p platform-distributed-storage --release 2>&1; then
log_success "Distributed storage tests passed"
else
log_failure "Distributed storage tests failed"
fi

# =============================================================================
# Summary
# =============================================================================
echo ""
echo "============================================================================="
echo " Test Summary"
echo "============================================================================="
echo ""
echo -e " ${GREEN}Passed:${NC} $PASSED"
echo -e " ${RED}Failed:${NC} $FAILED"
echo -e " ${YELLOW}Skipped:${NC} $SKIPPED"
echo ""

if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}All tests passed!${NC}"
exit 0
else
echo -e "${RED}Some tests failed. Please review the output above.${NC}"
exit 1
fi
63 changes: 63 additions & 0 deletions tests/docker/Dockerfile.test-validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# =============================================================================
# Platform Test Validator Docker Image
# =============================================================================
# Lightweight build for testing multi-validator P2P network
# Uses pre-built binary from cargo build --release
# =============================================================================

FROM rust:1.92-bookworm AS builder

# Install dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
protobuf-compiler \
cmake \
clang \
libclang-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy workspace files
COPY Cargo.toml Cargo.lock ./
COPY crates ./crates
COPY bins ./bins
COPY tests ./tests

# Build release binary
RUN cargo build --release --bin validator-node

# Runtime stage
FROM debian:bookworm-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
curl \
&& rm -rf /var/lib/apt/lists/*

# Copy binary from builder
COPY --from=builder /app/target/release/validator-node /usr/local/bin/validator-node

# Create data directory
RUN mkdir -p /data && chmod 755 /data

# Environment defaults
ENV RUST_LOG=info,validator_node=debug,platform_p2p_consensus=info
ENV DATA_DIR=/data
ENV NETUID=100

# Expose P2P port
EXPOSE 9000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD test -e /data/distributed.db || exit 1

# Entry point script to handle arguments
COPY tests/docker/entrypoint-test.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
Loading