-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTEST-audit_inception_commit.sh
More file actions
executable file
·730 lines (633 loc) · 25.1 KB
/
TEST-audit_inception_commit.sh
File metadata and controls
executable file
·730 lines (633 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
#!/usr/bin/env zsh
########################################################################
## Script: TEST-audit_inception_commit.sh
## Version: 0.1.05 (2025-03-04)
## Origin: https://github.com/OpenIntegrityProject/core/blob/main/src/tests/TEST-audit_inception_commit.sh
## Description: Tests the audit_inception_commit-POC.sh script for compliance with
## Open Integrity requirements and verifies all CLI options.
## Includes GitHub integration tests when GitHub CLI is available and
## authenticated.
## License: BSD-2-Clause-Patent (https://spdx.org/licenses/BSD-2-Clause-Patent.html)
## Copyright: (c) 2025 Blockchain Commons LLC (https://www.BlockchainCommons.com)
## Attribution: Christopher Allen <[email protected]>
## Usage: TEST-audit_inception_commit.sh [-v|--verbose]
## Examples: TEST-audit_inception_commit.sh
## TEST-audit_inception_commit.sh --verbose
## Change Log:
## 0.1.05 (2025-03-04) - Updated exit code expectations to match new
## behavior in audit_inception_commit-POC.sh v0.1.05:
## * Changed expected exit code from 1 to 0 for successful tests
## * Updated test patterns to match new output format
## * Added proper identification of phase classification in output checking
########################################################################
# Reset the shell environment to a known state
emulate -LR zsh
# Safe shell scripting options
setopt errexit nounset pipefail localoptions warncreateglobal
# Script constants
typeset -r Script_Name=$(basename "$0")
typeset -r Script_Version="0.1.05"
typeset -r Script_Dir=$(dirname "$0:A")
typeset -r Repo_Root=$(realpath "${Script_Dir}/..")
# Define TRUE/FALSE constants
typeset -r TRUE=1
typeset -r FALSE=0
# Script-scoped variables
typeset -r Target_Script="${Repo_Root}/audit_inception_commit-POC.sh"
typeset -r Sandbox_Dir="${Repo_Root}/../sandbox"
typeset Valid_Repo="${Sandbox_Dir}/valid_repo"
typeset Invalid_Repo="${Sandbox_Dir}/invalid_repo"
typeset -r Snippet_Path="${Repo_Root}/create_inception_commit.sh"
typeset -i Verbose_Mode=$FALSE
# GitHub-related variables
typeset -i GitHub_CLI_Available=$FALSE
typeset -i GitHub_Authenticated=$FALSE
typeset GitHub_User=""
typeset -r GitHub_Temp_Repo_Name="oi-temp-test-repo-$(date +%s)"
typeset GitHub_Repo_Path=""
typeset -i github_cleanup_needed=$FALSE
# Script-scoped exit status codes
typeset -r Exit_Status_Success=0
typeset -r Exit_Status_General=1
typeset -r Exit_Status_Usage=2
typeset -r Exit_Status_Test_Failure=3
typeset -r Exit_Status_IO=3
typeset -r Exit_Status_Git_Failure=5
# Tracking variables
typeset -i Tests_Total=0
typeset -i Tests_Passed=0
typeset -i Tests_Failed=0
typeset -A test_results
#----------------------------------------------------------------------#
# Function: show_Usage
#----------------------------------------------------------------------#
# Description:
# Displays usage information for the script
# Parameters:
# None
# Returns:
# Exits with Exit_Status_Usage
#----------------------------------------------------------------------#
show_Usage() {
print "$Script_Name v$Script_Version - Test audit_inception_commit-POC.sh script"
print ""
print "Usage: $Script_Name [-v|--verbose]"
print ""
print "Options:"
print " -v, --verbose Enable verbose output"
print " -h, --help Show this help message"
print ""
print "Examples:"
print " $Script_Name Run tests with standard output"
print " $Script_Name -v Run tests with verbose output"
exit $Exit_Status_Usage
}
#----------------------------------------------------------------------#
# Function: z_Setup_Test_Environment
#----------------------------------------------------------------------#
# Description:
# Creates test repositories for the audit tests
# Parameters:
# None
# Returns:
# Exit_Status_Success on success
# Exit_Status_General on failure
#----------------------------------------------------------------------#
z_Setup_Test_Environment() {
print "Setting up test environment..."
# Check if create_inception_commit.sh exists
if [[ ! -f "$Snippet_Path" ]]; then
print "❌ FAILED: Snippet script not found at: $Snippet_Path"
return $Exit_Status_General
fi
# Make sure snippet script is executable
chmod +x "$Snippet_Path"
# Create valid repo with proper inception commit
print "Creating valid test repository..."
if ! "$Snippet_Path" -r "$Valid_Repo" > /dev/null 2>&1; then
print "❌ FAILED: Could not create valid test repository"
print "Command: $Snippet_Path -r $Valid_Repo"
return $Exit_Status_General
fi
# Create a directory (not a repository) for invalid tests
mkdir -p "$Invalid_Repo"
# Check GitHub CLI availability
z_Check_GitHub_CLI
print "Test environment setup completed"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: z_Cleanup_Test_Directories
#----------------------------------------------------------------------#
# Description:
# Removes test directories to ensure a clean test environment
# Parameters:
# None
# Returns:
# Exit_Status_Success on success
#----------------------------------------------------------------------#
z_Cleanup_Test_Directories() {
print "Cleaning up test directories..."
# Create parent directories if they don't exist
if [[ ! -d "$(dirname "$Sandbox_Dir")" ]]; then
mkdir -p "$(dirname "$Sandbox_Dir")"
fi
# Try to remove the directories directly first
rm -rf "$Sandbox_Dir" 2>/dev/null || {
# If removal fails, try resetting permissions using Zsh glob qualifiers
# (/DN) for directories, recursively, don't sort
# (.DN) for regular files, recursively, don't sort
chmod 755 "$Sandbox_Dir"/**/*(/DN) 2>/dev/null || true
chmod 644 "$Sandbox_Dir"/**/*(.DN) 2>/dev/null || true
rm -rf "$Sandbox_Dir" 2>/dev/null || true
}
# Ensure test directories don't exist before creating them
if [[ -d "$Sandbox_Dir" ]]; then
print "Warning: Unable to fully remove existing test directory: $Sandbox_Dir"
print "Using new unique directory instead."
Sandbox_Dir="${Sandbox_Dir}-$(date +%s)"
fi
# Create fresh sandbox directory
mkdir -p "$Sandbox_Dir" || {
print "Error: Failed to create test base directory: $Sandbox_Dir"
return $Exit_Status_General
}
# Update dependent paths
Valid_Repo="${Sandbox_Dir}/valid_repo"
Invalid_Repo="${Sandbox_Dir}/invalid_repo"
print "Test directories prepared at $Sandbox_Dir"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: z_Check_GitHub_CLI
#----------------------------------------------------------------------#
# Description:
# Checks if GitHub CLI is available and authenticated
# Parameters:
# None
# Returns:
# Sets GitHub_CLI_Available and GitHub_Authenticated flags
# Sets GitHub_User if authenticated
#----------------------------------------------------------------------#
z_Check_GitHub_CLI() {
print "Checking GitHub CLI availability..."
# Check if GitHub CLI is installed
if command -v gh >/dev/null 2>&1; then
GitHub_CLI_Available=$TRUE
print "GitHub CLI found"
# Check if authenticated
if gh auth status >/dev/null 2>&1; then
GitHub_Authenticated=$TRUE
# Get username for repository creation - more robust pattern matching
GitHub_User=$(gh api user 2>/dev/null | grep -o '"login":[[:space:]]*"[^"]*"' | sed 's/.*"login":[[:space:]]*"\([^"]*\)".*/\1/')
print "GitHub CLI is authenticated as $GitHub_User"
else
print "GitHub CLI is available but not authenticated"
print "To run GitHub integration tests, run: gh auth login"
fi
else
print "GitHub CLI not found - GitHub integration tests will be skipped"
print "To install GitHub CLI, see: https://cli.github.com/"
fi
}
#----------------------------------------------------------------------#
# Function: z_Run_Test
#----------------------------------------------------------------------#
# Description:
# Runs a single test and reports results with more detailed tracking
# Parameters:
# $1 - Test name
# $2 - Command to run
# $3 - Expected exit code
# $4 - Pattern to search for in output (optional)
# Returns:
# Exit_Status_Success if test passes
# Exit_Status_Test_Failure if test fails
#----------------------------------------------------------------------#
z_Run_Test() {
typeset TestName="$1"
typeset Command="$2"
typeset ExpectedExit="$3"
typeset ExpectedPattern="${4:-}"
(( Tests_Total++ ))
print "TEST: $TestName"
# Run the command and capture output
typeset Output
typeset ActualExit
if (( Verbose_Mode )); then
print "COMMAND: $Command"
# Run command and capture both output and exit code
Output=$(eval "$Command" 2>&1)
ActualExit=$?
print "$Output"
print "EXIT CODE: $ActualExit (Expected: $ExpectedExit)"
else
Output=$(eval "$Command" 2>&1)
ActualExit=$?
fi
# Check exit code
if (( ActualExit != ExpectedExit )); then
print "❌ FAILED: Expected exit code $ExpectedExit, got $ActualExit"
if (( !Verbose_Mode )); then
print "OUTPUT: $Output"
fi
(( Tests_Failed++ ))
test_results["$TestName"]="FAIL (exit code mismatch: expected $ExpectedExit, got $ActualExit)"
return $Exit_Status_Test_Failure
fi
# Check output pattern if provided
if [[ -n "$ExpectedPattern" ]]; then
if ! echo "$Output" | grep -q "$ExpectedPattern"; then
print "❌ FAILED: Output doesn't match pattern '$ExpectedPattern'"
if (( !Verbose_Mode )); then
print "OUTPUT: $Output"
fi
(( Tests_Failed++ ))
test_results["$TestName"]="FAIL (output mismatch: pattern '$ExpectedPattern' not found)"
return $Exit_Status_Test_Failure
fi
fi
print "✅ PASSED"
(( Tests_Passed++ ))
test_results["$TestName"]="PASS"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: z_Print_Summary
#----------------------------------------------------------------------#
# Description:
# Prints a summary of test results with enhanced formatting
# Parameters:
# None
# Returns:
# Exit_Status_Success always
#----------------------------------------------------------------------#
z_Print_Summary() {
print "\n===== TEST SUMMARY ====="
print "Total tests: $Tests_Total"
print "Passed: $Tests_Passed"
print "Failed: $Tests_Failed"
if (( Tests_Failed == 0 )); then
print "\n🎉 ALL TESTS PASSED! 🎉"
else
print "\n❌ SOME TESTS FAILED!"
typeset test_name
for test_name in ${(k)test_results}; do
if [[ ${test_results[$test_name]} != "PASS" ]]; then
print " - \"$test_name\": ${test_results[$test_name]}"
fi
done
fi
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: test_Help_And_Basic_Functionality
#----------------------------------------------------------------------#
# Description:
# Tests help display and basic functionality
# Parameters:
# None
# Returns:
# Exit_Status_Success if all tests pass
#----------------------------------------------------------------------#
test_Help_And_Basic_Functionality() {
print "\n===== Testing help and basic functionality ====="
z_Run_Test "Help display (short)" \
"\"$Target_Script\" -h" \
0 \
"USAGE:"
z_Run_Test "Help display (long)" \
"\"$Target_Script\" --help" \
0 \
"USAGE:"
# Expect exit code 0 for successful repository audit (even with GitHub integration warnings)
# The new architectural approach separates local validation (phases 1-3) from remote validation (phases 4-5)
z_Run_Test "Basic repository audit" \
"\"$Target_Script\" -C \"$Valid_Repo\"" \
0 \
"in compliance with Open Integrity specification"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: test_CLI_Options
#----------------------------------------------------------------------#
# Description:
# Tests various CLI options
# Parameters:
# None
# Returns:
# Exit_Status_Success if all tests pass
#----------------------------------------------------------------------#
test_CLI_Options() {
print "\n===== Testing CLI options ====="
# Expect exit code 0 for successful tests
z_Run_Test "Verbose mode" \
"\"$Target_Script\" --verbose -C \"$Valid_Repo\"" \
0 \
"Trust Assessment Summary:"
z_Run_Test "Debug mode" \
"\"$Target_Script\" --debug -C \"$Valid_Repo\"" \
0 \
"Framework argument processing:"
z_Run_Test "Quiet mode" \
"\"$Target_Script\" --quiet -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
z_Run_Test "No color option" \
"\"$Target_Script\" --no-color -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
z_Run_Test "Force color option" \
"\"$Target_Script\" --color -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
z_Run_Test "No prompt option" \
"\"$Target_Script\" --no-prompt -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
z_Run_Test "Interactive option" \
"echo N | \"$Target_Script\" --interactive -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
z_Run_Test "Combined options (verbose + debug)" \
"\"$Target_Script\" --verbose --debug -C \"$Valid_Repo\"" \
0 \
"Exit code from execute_Audit_Phases: 0"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: test_Error_Cases
#----------------------------------------------------------------------#
# Description:
# Tests error handling
# Parameters:
# None
# Returns:
# Exit_Status_Success if all tests pass
#----------------------------------------------------------------------#
test_Error_Cases() {
print "\n===== Testing error cases ====="
# Based on the output, the invalid option returns 0 with help text
z_Run_Test "Invalid option" \
"\"$Target_Script\" --invalid-option 2>&1" \
0 \
"Unknown option"
# Based on the output, invalid directory returns 1
z_Run_Test "Invalid directory" \
"\"$Target_Script\" -C /path/does/not/exist 2>&1" \
1 \
"Invalid directory"
# Update: non-repository directory now returns 0 (change in v0.1.05)
z_Run_Test "Non-repository directory" \
"\"$Target_Script\" -C \"$Invalid_Repo\" 2>&1" \
0 \
"Repository Structure:"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: test_Identity_Verification
#----------------------------------------------------------------------#
# Description:
# Tests the identity verification specifically
# Parameters:
# None
# Returns:
# Exit_Status_Success if all tests pass
#----------------------------------------------------------------------#
test_Identity_Verification() {
print "\n===== Testing identity verification ====="
# Identity verification should now return exit code 0 for successful verification
z_Run_Test "Identity verification" \
"\"$Target_Script\" --verbose -C \"$Valid_Repo\"" \
0 \
"Identity Check: Committer matches key fingerprint"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: test_Environment_Variables
#----------------------------------------------------------------------#
# Description:
# Tests script behavior with different environment variables
# Parameters:
# None
# Returns:
# Exit_Status_Success if all tests pass
#----------------------------------------------------------------------#
test_Environment_Variables() {
print "\n===== Testing environment variables ====="
# Environment variables tests should also return exit code 0 for successful verification
z_Run_Test "NO_COLOR environment variable" \
"NO_COLOR=1 \"$Target_Script\" -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
z_Run_Test "FORCE_COLOR environment variable" \
"FORCE_COLOR=1 \"$Target_Script\" -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
z_Run_Test "CI environment variable" \
"CI=1 \"$Target_Script\" -C \"$Valid_Repo\"" \
0 \
"Audit Complete:"
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: test_GitHub_Integration
#----------------------------------------------------------------------#
# Description:
# Tests GitHub integration features (only runs if GitHub CLI is
# available and authenticated)
# Parameters:
# None
# Returns:
# Exit_Status_Success if all tests pass
# Exit_Status_General if GitHub setup fails
#----------------------------------------------------------------------#
test_GitHub_Integration() {
# Skip if GitHub CLI is not available or not authenticated
if (( GitHub_CLI_Available == FALSE || GitHub_Authenticated == FALSE )); then
print "\n===== Skipping GitHub integration tests ====="
print "GitHub CLI not available or not authenticated."
if (( GitHub_CLI_Available == TRUE )); then
print "To run GitHub integration tests, authenticate with: gh auth login"
else
print "To run GitHub integration tests, install GitHub CLI: https://cli.github.com/"
fi
return $Exit_Status_Success
fi
print "\n===== Testing GitHub integration ====="
# Set up cleanup variable
github_cleanup_needed=$FALSE
GitHub_Repo_Path="${Sandbox_Dir}/${GitHub_Temp_Repo_Name}"
# Ensure we have a valid GitHub username
if [[ -z "$GitHub_User" ]]; then
print "❌ FAILED: Could not determine GitHub username"
return $Exit_Status_General
fi
# Create a local repository with an inception commit first
print "Creating local repository with inception commit at: $GitHub_Repo_Path"
if ! "$Snippet_Path" -r "$GitHub_Repo_Path" > /dev/null 2>&1; then
print "❌ FAILED: Could not create local repository with inception commit"
return $Exit_Status_General
fi
# Set up trap for cleanup - only needs to clean local directory at this point
trap 'if ((github_cleanup_needed)); then
print "Cleaning up GitHub resources due to interrupt/error..."
rm -rf "$GitHub_Repo_Path" 2>/dev/null
gh repo delete "$GitHub_User/$GitHub_Temp_Repo_Name" --yes > /dev/null 2>&1
fi' EXIT INT TERM
# Create GitHub repository from the local repo
print "Creating GitHub repository from local repository: $GitHub_Temp_Repo_Name"
# Change to the repo directory
cd "$GitHub_Repo_Path"
# Create GitHub repository with the proper source flag
if ! gh repo create "$GitHub_Temp_Repo_Name" --private --source=. --push > /dev/null 2>&1; then
print "❌ FAILED: Could not create GitHub repository from local repository"
cd - > /dev/null
rm -rf "$GitHub_Repo_Path"
return $Exit_Status_General
fi
# Return to original directory
cd - > /dev/null
# Mark that we need cleanup for both local and remote
github_cleanup_needed=$TRUE
# Now run tests on this GitHub-connected repository
# NOTE (2025-03-04): The audit script now returns exit code 0 for both local and GitHub repositories
# when all local verification phases pass (phases 1-3), even if remote phases (4-5) have warnings.
# This implements the architectural decision to separate local verification from remote verification.
z_Run_Test "Full GitHub integration" \
"\"$Target_Script\" -C \"$GitHub_Repo_Path\"" \
0 \
"in compliance with Open Integrity specification"
z_Run_Test "GitHub standards compliance check" \
"echo 'Y' | \"$Target_Script\" --interactive -C \"$GitHub_Repo_Path\"" \
0 \
"Community Standards:"
z_Run_Test "GitHub integration with verbose mode" \
"\"$Target_Script\" --verbose -C \"$GitHub_Repo_Path\"" \
0 \
"Trust Assessment Summary:"
# Clean up the GitHub repository
print "Cleaning up GitHub repository"
rm -rf "$GitHub_Repo_Path"
if ! gh repo delete "$GitHub_User/$GitHub_Temp_Repo_Name" --yes > /dev/null 2>&1; then
print "⚠️ Warning: Failed to delete temporary GitHub repository. Please delete manually:"
print "gh repo delete $GitHub_User/$GitHub_Temp_Repo_Name --yes"
fi
# Mark cleanup as completed
github_cleanup_needed=$FALSE
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: parse_Parameters
#----------------------------------------------------------------------#
# Description:
# Processes command line parameters
# Parameters:
# $@ - Command line arguments
# Returns:
# Exit_Status_Success if parameters are valid
# Calls show_Usage() for invalid parameters
#----------------------------------------------------------------------#
parse_Parameters() {
print "Parsing command line parameters..."
while (( $# > 0 )); do
case "$1" in
-v|--verbose)
Verbose_Mode=$TRUE
print "Verbose mode enabled"
shift
;;
-h|--help)
show_Usage
;;
-*)
print -u2 "Error: Unknown option: $1"
show_Usage
;;
*)
print -u2 "Error: Unexpected argument: $1"
show_Usage
;;
esac
done
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: core_Logic
#----------------------------------------------------------------------#
# Description:
# Orchestrates the main script workflow
# Parameters:
# None
# Returns:
# Exit_Status_Success on success
# Exit_Status_Test_Failure if any tests fail
#----------------------------------------------------------------------#
core_Logic() {
print "Starting tests for audit_inception_commit-POC.sh"
print "Target script: $Target_Script"
# Check that target script exists
if [[ ! -f "$Target_Script" ]]; then
print "ERROR: Target script not found at: $Target_Script"
return $Exit_Status_General
fi
# Check that target script is executable
if [[ ! -x "$Target_Script" ]]; then
print "Making target script executable"
chmod +x "$Target_Script"
fi
# Clean up and set up test directories
z_Cleanup_Test_Directories || return $?
z_Setup_Test_Environment || return $?
# Run all test suites
test_Help_And_Basic_Functionality
test_CLI_Options
test_Error_Cases
test_Identity_Verification
test_Environment_Variables
test_GitHub_Integration
# Print summary
z_Print_Summary
# Return based on test results
if (( Tests_Failed > 0 )); then
return $Exit_Status_Test_Failure
fi
return $Exit_Status_Success
}
#----------------------------------------------------------------------#
# Function: main
#----------------------------------------------------------------------#
# Description:
# Main entry point for the script
# Parameters:
# $@ - Command line arguments
# Returns:
# Exit_Status_Success on success
# Various error codes on failure
#----------------------------------------------------------------------#
main() {
print "=== TEST-audit_inception_commit.sh v$Script_Version ==="
# Parse command line parameters
parse_Parameters "$@" || exit $?
# Execute core logic
core_Logic || {
typeset exit_code=$?
if (( exit_code == Exit_Status_Test_Failure )); then
print "Some tests failed, but test execution completed."
exit $exit_code
else
print "Fatal error during test execution: $exit_code"
exit $exit_code
fi
}
print "All tests completed successfully."
return $Exit_Status_Success
}
# Execute main() only if this script is being run directly (not sourced).
# Zsh-specific syntax: ${(%):-%N} expands to the script name when run directly,
# but to the function name when sourced. This is different from Bash's
# equivalent test: [[ "${BASH_SOURCE[0]}" == "${0}" ]]
if [[ "${(%):-%N}" == "$0" ]]; then
main "$@"
exit $? # Explicitly propagate the exit status from main
fi