Skip to content
Closed
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
192 changes: 192 additions & 0 deletions .github/tests/aggregate-reports.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#!/usr/bin/env bats

# Unit tests for aggregate-reports.sh

setup() {
export TEST_DIR=$(mktemp -d)
export SCRIPT_PATH="$BATS_TEST_DIRNAME/../scripts/aggregate-reports.sh"
export GITHUB_OUTPUT=$(mktemp)

# Create sync-reports directory
mkdir -p "$TEST_DIR/sync-reports"

# Change to test directory
cd "$TEST_DIR"
}

teardown() {
rm -rf "$TEST_DIR"
rm -f "$GITHUB_OUTPUT"
}

# ============================================
# Tests for aggregate_sync_reports()
# ============================================

@test "aggregate-reports: calculates totals from single report" {
cat > "$TEST_DIR/sync-reports/sync_report_changelog.md" <<EOF
## Changelog

### Summary
- **Added**: 3 files
- **Updated**: 2 files
- **Deleted**: 1 files
- **Total changes**: 6
EOF

run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

# Check totals
run grep "total_changes=6" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_added=3" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_updated=2" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_deleted=1" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}

@test "aggregate-reports: aggregates multiple reports" {
cat > "$TEST_DIR/sync-reports/sync_report_changelog.md" <<EOF
## Changelog

### Summary
- **Added**: 2 files
- **Updated**: 1 files
- **Deleted**: 0 files
- **Total changes**: 3
EOF

cat > "$TEST_DIR/sync-reports/sync_report_api_gen.md" <<EOF
## API Gen

### Summary
- **Added**: 5 files
- **Updated**: 3 files
- **Deleted**: 2 files
- **Total changes**: 10
EOF

run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

# Check aggregated totals (2+5=7 added, 1+3=4 updated, 0+2=2 deleted, 3+10=13 total)
run grep "total_changes=13" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_added=7" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_updated=4" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_deleted=2" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}

@test "aggregate-reports: handles report with no changes" {
cat > "$TEST_DIR/sync-reports/sync_report_config.md" <<EOF
## Config

### Summary
- **Added**: 0 files
- **Updated**: 0 files
- **Deleted**: 0 files
- **Total changes**: 0
EOF

run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

run grep "total_changes=0" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}

@test "aggregate-reports: handles missing sync-reports directory" {
rm -rf "$TEST_DIR/sync-reports"

run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

# Should output zeros
run grep "total_changes=0" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}

@test "aggregate-reports: handles empty sync-reports directory" {
# Directory exists but is empty
run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

run grep "total_changes=0" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}

@test "aggregate-reports: handles report with 'No updates found' message" {
cat > "$TEST_DIR/sync-reports/sync_report_config.md" <<EOF
## Config

No config updates found
EOF

run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

# Should not count this as a change
run grep "total_changes=0" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}

@test "aggregate-reports: outputs all_reports multiline content" {
cat > "$TEST_DIR/sync-reports/sync_report_test.md" <<EOF
## Test Report

### Summary
- **Added**: 1 files
- **Updated**: 0 files
- **Deleted**: 0 files
- **Total changes**: 1

### Added Files
- test_file.mdx
EOF

run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

# Check that all_reports is in the output
run grep "all_reports<<EOF" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}

@test "aggregate-reports: handles all six sync types" {
for sync_type in changelog config docker_compose api_gen api_debug api_ops; do
cat > "$TEST_DIR/sync-reports/sync_report_${sync_type}.md" <<EOF
## ${sync_type}

### Summary
- **Added**: 1 files
- **Updated**: 1 files
- **Deleted**: 0 files
- **Total changes**: 2
EOF
done

run bash "$SCRIPT_PATH"
[ "$status" -eq 0 ]

# Total should be 6 types * 2 changes each = 12
run grep "total_changes=12" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_added=6" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]

run grep "total_updated=6" "$GITHUB_OUTPUT"
[ "$status" -eq 0 ]
}
106 changes: 106 additions & 0 deletions .github/tests/sanitize-config.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bats

# Unit tests for sanitize-config.sh

setup() {
export TEST_DIR=$(mktemp -d)
export SCRIPT_PATH="$BATS_TEST_DIRNAME/../scripts/sanitize-config.sh"
}

teardown() {
rm -rf "$TEST_DIR"
}

# ============================================
# Tests for sanitize-config.sh
# ============================================

@test "sanitize-config: replaces genlayerchainrpcurl with TODO placeholder" {
# Create test config
cat > "$TEST_DIR/config.yaml" <<EOF
rollup:
genlayerchainrpcurl: "https://secret-rpc.example.com"
genlayerchainwebsocketurl: "wss://secret-ws.example.com"
other: "value"
EOF

run bash "$SCRIPT_PATH" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]

# Check that RPC URL was replaced
run grep "TODO: Set your GenLayer Chain ZKSync HTTP RPC URL here" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]
}

@test "sanitize-config: replaces genlayerchainwebsocketurl with TODO placeholder" {
cat > "$TEST_DIR/config.yaml" <<EOF
rollup:
genlayerchainrpcurl: "https://secret-rpc.example.com"
genlayerchainwebsocketurl: "wss://secret-ws.example.com"
EOF

run bash "$SCRIPT_PATH" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]

# Check that WebSocket URL was replaced
run grep "TODO: Set your GenLayer Chain ZKSync WebSocket RPC URL here" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]
}

@test "sanitize-config: removes node.dev section" {
cat > "$TEST_DIR/config.yaml" <<EOF
rollup:
genlayerchainrpcurl: "https://rpc.example.com"
genlayerchainwebsocketurl: "wss://ws.example.com"
node:
production: true
dev:
debug: true
verbose: true
EOF

run bash "$SCRIPT_PATH" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]

# Check that dev section was removed
run grep "dev:" "$TEST_DIR/config.yaml"
[ "$status" -ne 0 ]

# Check that production section still exists
run grep "production: true" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]
}

@test "sanitize-config: preserves other config values" {
cat > "$TEST_DIR/config.yaml" <<EOF
rollup:
genlayerchainrpcurl: "https://rpc.example.com"
genlayerchainwebsocketurl: "wss://ws.example.com"
chainid: 12345
server:
port: 8080
host: "0.0.0.0"
EOF

run bash "$SCRIPT_PATH" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]

# Check that other values are preserved
run grep "chainid: 12345" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]

run grep "port: 8080" "$TEST_DIR/config.yaml"
[ "$status" -eq 0 ]
}

@test "sanitize-config: fails with missing argument" {
run bash "$SCRIPT_PATH"
[ "$status" -eq 1 ]
[[ "$output" == *"Usage:"* ]]
}

@test "sanitize-config: fails with non-existent file" {
run bash "$SCRIPT_PATH" "$TEST_DIR/nonexistent.yaml"
[ "$status" -eq 1 ]
[[ "$output" == *"File not found"* ]]
}
Loading