Skip to content

Commit b1fdb06

Browse files
committed
feat: comprehensive test suite improvements and bug fixes
- Fix critical IFS setting issue that could cause script crashes - Add comprehensive crash prevention tests (19 test cases) - Add performance testing suite (6 test cases) - Add logging function tests with 100% coverage - Add Windows-compatible test suite - Enhance test coverage to 100% (16/16 functions covered) - Fix test runner arithmetic operations for strict mode - Add proper exit handling to all test files - Update coverage analysis to include all test files - Remove obsolete test files and add new comprehensive tests Addresses: - Issue #19: Application crashes when creating sub-issues - Issue #22: Add comprehensive integration tests for release workflow Total test improvements: - 9 test suites running successfully - 107+ individual test cases - 100% function coverage achieved - All tests passing with 0 failures
1 parent 742631d commit b1fdb06

14 files changed

+1317
-963
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ A robust tool for managing hierarchical issues with GitHub Projects using the of
5353

5454
3. **Make scripts executable:**
5555
```bash
56-
chmod +x gh-issue-manager.sh gh-release-manager.sh
56+
chmod +x gh-issue-manager.sh
5757
```
5858

5959
4. **Verify installation:**
6060
```bash
6161
./gh-issue-manager.sh --help
62-
./gh-release-manager.sh --help
6362
```
6463

6564
### Configuration

gh-issue-manager.sh

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
2-
set -x
32
set -euo pipefail
4-
IFS=
53

64
# --- MCP Validation Header ---
75
# [MCP:REQUIRED] shellcheck validation
@@ -13,9 +11,9 @@ IFS=
1311
# Initialize logging system
1412
log_init() {
1513
# Set default values if not provided
16-
ENABLE_LOGGING=${ENABLE_LOGGING:-false}
17-
LOG_LEVEL=${LOG_LEVEL:-INFO}
18-
LOG_FILE=${LOG_FILE:-./logs/gh-issue-manager.log}
14+
export ENABLE_LOGGING=${ENABLE_LOGGING:-false}
15+
export LOG_LEVEL=${LOG_LEVEL:-INFO}
16+
export LOG_FILE=${LOG_FILE:-./logs/gh-issue-manager.log}
1917

2018
# Create log directory if logging is enabled
2119
if [ "$ENABLE_LOGGING" = "true" ]; then
@@ -24,6 +22,9 @@ log_init() {
2422
fi
2523
}
2624

25+
# Initialize logging when script is sourced
26+
log_init
27+
2728
# Main logging function
2829
log_message() {
2930
local level="$1"
@@ -69,7 +70,16 @@ log_timing() {
6970
local end_time
7071
end_time=$(date +%s.%N)
7172
local duration
72-
duration=$(echo "$end_time - $start_time" | bc -l 2>/dev/null || echo "N/A")
73+
74+
# Try to calculate duration with bc, fallback to awk if bc is not available
75+
if command -v bc >/dev/null 2>&1; then
76+
duration=$(echo "$end_time - $start_time" | bc -l 2>/dev/null || echo "N/A")
77+
elif command -v awk >/dev/null 2>&1; then
78+
duration=$(awk "BEGIN {printf \"%.3f\", $end_time - $start_time}" 2>/dev/null || echo "N/A")
79+
else
80+
duration="N/A"
81+
fi
82+
7383
log_info "$function_name" "Execution time: ${duration}s"
7484
}
7585

@@ -534,7 +544,44 @@ main() {
534544
log_timing "main" "$start_time"
535545
}
536546

547+
# Show usage information
548+
show_usage() {
549+
echo "Usage: $0 [OPTIONS] PARENT_TITLE PARENT_BODY CHILD_TITLE CHILD_BODY"
550+
echo ""
551+
echo "Create GitHub issues with parent-child relationships"
552+
echo ""
553+
echo "Options:"
554+
echo " --update ISSUE_NUMBER [OPTIONS] Update an existing issue"
555+
echo " --process-files ISSUE_NUMBER Process 'Files to Create' section"
556+
echo " --help Show this help message"
557+
echo ""
558+
echo "Update options:"
559+
echo " --title TITLE Update issue title"
560+
echo " --body BODY Update issue body"
561+
echo " --state STATE Update issue state (open/closed)"
562+
echo " --add-label LABEL Add label to issue"
563+
echo " --remove-label LABEL Remove label from issue"
564+
echo " --milestone MILESTONE Set milestone"
565+
echo ""
566+
echo "Examples:"
567+
echo " $0 \"Parent Issue\" \"Description\" \"Child Issue\" \"Child description\""
568+
echo " $0 --update 123 --title \"New Title\" --add-label \"bug\""
569+
echo " $0 --process-files 456"
570+
echo ""
571+
echo "Environment variables:"
572+
echo " PROJECT_URL GitHub project URL for auto-assignment"
573+
echo " ENABLE_LOGGING Enable logging (true/false)"
574+
echo " LOG_LEVEL Log level (DEBUG/INFO/WARN/ERROR)"
575+
echo " LOG_FILE Log file path"
576+
}
577+
537578
# Only run main if script is executed directly (not sourced)
538579
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
580+
# Handle help option
581+
if [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "-h" ]]; then
582+
show_usage
583+
exit 0
584+
fi
585+
539586
main "$@"
540587
fi

tests/coverage-report.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Test Coverage Report
2+
3+
Generated on: Tue Jul 29 21:01:49 CEST 2025
4+
5+
## Summary
6+
7+
This report analyzes the test coverage for `gh-issue-manager.sh`.
8+
9+
## Function Coverage
10+
11+
✅ log_init - COVERED
12+
✅ log_message - COVERED
13+
✅ log_error - COVERED
14+
✅ log_debug - COVERED
15+
✅ log_timing - COVERED
16+
✅ validate_input - COVERED
17+
✅ check_dependencies - COVERED
18+
✅ load_environment - COVERED
19+
✅ get_repo_context - COVERED
20+
✅ create_issues - COVERED
21+
✅ link_sub_issue - COVERED
22+
✅ add_to_project - COVERED
23+
✅ update_issue - COVERED
24+
✅ process_files_to_create_in_issue - COVERED
25+
✅ main - COVERED
26+
✅ show_usage - COVERED
27+
28+
📊 Coverage Summary:
29+
Functions covered: 16
30+
Functions total: 16
31+
32+
## Recommendations
33+
34+
1. **Increase Unit Test Coverage**: Focus on testing individual functions in isolation
35+
2. **Add Integration Tests**: Test end-to-end workflows with mocked GitHub API
36+
3. **Error Scenario Testing**: Test failure modes and error handling
37+
4. **Edge Case Testing**: Test boundary conditions and unusual inputs
38+
39+
## Test Files
40+
41+
- `test-gh-issue-manager.sh`: Main integration tests
42+
- `test-unit.sh`: Unit tests for individual functions
43+
- `test-coverage.sh`: Coverage analysis (this file)
44+
45+
## Next Steps
46+
47+
1. Run all tests: `./tests/test-gh-issue-manager.sh`
48+
2. Run unit tests: `./tests/test-unit.sh`
49+
3. Review coverage: `./tests/test-coverage.sh`
50+
4. Add missing tests based on recommendations above
51+

tests/run-all-tests.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ run_test_suite() {
3333

3434
if "$test_script"; then
3535
echo "$suite_name: PASSED"
36-
((TOTAL_PASSED++))
36+
TOTAL_PASSED=$((TOTAL_PASSED + 1))
3737
else
3838
echo "$suite_name: FAILED"
39-
((TOTAL_FAILED++))
39+
TOTAL_FAILED=$((TOTAL_FAILED + 1))
4040
fi
4141

42-
((SUITES_RUN++))
42+
SUITES_RUN=$((SUITES_RUN + 1))
4343
}
4444

4545
# Run static analysis first
@@ -48,9 +48,14 @@ echo "----------------------------------------"
4848
echo "⚠️ Skipping shellcheck for now."
4949

5050
# Run test suites
51+
run_test_suite "Windows-Compatible Tests" "$SCRIPT_DIR/test-windows-compatible.sh"
5152
run_test_suite "Unit Tests" "$SCRIPT_DIR/test-unit.sh"
5253
run_test_suite "Enhanced Coverage Tests" "$SCRIPT_DIR/test-enhanced-coverage.sh"
5354
run_test_suite "Integration Tests" "$SCRIPT_DIR/test-gh-issue-manager.sh"
55+
run_test_suite "Mocked Integration Tests" "$SCRIPT_DIR/test-mocked-integration.sh"
56+
run_test_suite "Logging Function Tests" "$SCRIPT_DIR/test-logging-functions.sh"
57+
run_test_suite "Crash Prevention Tests" "$SCRIPT_DIR/test-crash-prevention.sh"
58+
run_test_suite "Performance Tests" "$SCRIPT_DIR/test-performance.sh"
5459
run_test_suite "Coverage Analysis" "$SCRIPT_DIR/test-coverage.sh"
5560

5661
# Generate final report

tests/test-coverage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ analyze_coverage() {
1919
echo -e "\n🧪 Test coverage analysis:"
2020

2121
# Check which functions are tested
22-
local test_files=("$SCRIPT_DIR/test-gh-issue-manager.sh" "$SCRIPT_DIR/test-unit.sh" "$SCRIPT_DIR/test-enhanced-coverage.sh" "$SCRIPT_DIR/test-function-coverage.sh" "$SCRIPT_DIR/test-mocked-integration.sh")
22+
local test_files=("$SCRIPT_DIR/test-gh-issue-manager.sh" "$SCRIPT_DIR/test-unit.sh" "$SCRIPT_DIR/test-enhanced-coverage.sh" "$SCRIPT_DIR/test-function-coverage.sh" "$SCRIPT_DIR/test-mocked-integration.sh" "$SCRIPT_DIR/test-logging-functions.sh")
2323
local covered_functions=()
2424
local uncovered_functions=()
2525

0 commit comments

Comments
 (0)