-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathe2e.sh
More file actions
executable file
·4941 lines (4452 loc) · 199 KB
/
Copy pathe2e.sh
File metadata and controls
executable file
·4941 lines (4452 loc) · 199 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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# End-to-end testing script for GitHub Agentic Workflows
# This script triggers all test workflows and validates their outcomes
#
# Usage: ./e2e.sh [OPTIONS]
#
# This script will:
# 1. Check prerequisites (gh CLI, authentication, gh-aw binary)
# 2. Enable workflows before testing them
# 3. Trigger workflows using "gh aw run"
# 4. Wait for completion and validate outcomes
# 5. Disable workflows after testing
# 6. Generate comprehensive test report
# 7. Optionally clean up test resources
#
# Test Types:
# - workflow_dispatch: Direct trigger tests (create issues, PRs, code scanning alerts, etc.)
# - issue-triggered: Tests triggered by creating issues with specific titles
# - command-triggered: Tests triggered by posting commands in issue comments
# - PR-triggered: Tests triggered by creating pull requests
#
# Options:
# --dry-run Show what would be tested without running
# --use-samples Use declared samples for more deterministic testing
# --verbose, -v Stream build/compile/version diagnostics to stdout
# --help, -h Show help message
#
# Examples:
# ./e2e.sh # Run all tests
# ./e2e.sh --dry-run # See what would be tested
#
# Prerequisites:
# - GitHub CLI (gh) installed and authenticated
# - gh-aw binary built (run 'make build')
# - Proper repository permissions for creating issues/PRs
# - Internet access for GitHub API calls
set -uo pipefail # Removed -e to allow test failures without stopping the script
# Error Handling Strategy:
# - Individual test failures are tracked but don't stop the overall test suite
# - Polling timeouts are handled gracefully and recorded as test failures
# - Critical prerequisite failures (like missing gh CLI) still exit immediately
# - Cleanup operations continue even if some steps fail
# Colors and emojis for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Test results tracking
declare -a PASSED_TESTS=()
declare -a FAILED_TESTS=()
declare -a SKIPPED_TESTS=()
declare -A TEST_RUN_URLS=() # maps test name -> actions run URL (when available)
declare -A FINAL_RUN_URLS=() # populated in parent during batch result reading
RUN_PASSES_FILE="${E2E_RUN_PASSES_FILE:-passes.txt}"
RUN_FAILURES_FILE="${E2E_RUN_FAILURES_FILE:-}"
# Parallel execution settings
BATCH_SIZE=25
NO_PARALLEL=false
# Lock file for synchronized result tracking across parallel processes
RESULTS_LOCK="/tmp/e2e-results-$$.lock"
# File listing workflows that failed to compile (set in check_prerequisites).
# Subprocesses read this to skip dispatch and immediately record FAIL.
COMPILE_FAILED_FILE=""
# Global tracking of workflows that need to be disabled
# This is used by the trap handler to ensure cleanup on early exit
declare -a GLOBAL_WORKFLOWS_TO_DISABLE=()
GLOBAL_WORKFLOWS_LOCK="/tmp/e2e-workflows-$$.lock"
# Workflows that must NEVER be disabled by the runner. These are the CI/infra
# workflows (the nightly E2E matrix in particular) that need to stay enabled so
# their `schedule:` triggers keep firing. `disable_all_workflows_before_testing`
# disables every active workflow before a run, so without this allow-list it
# would turn off the very workflow that invokes it in CI, killing nightly runs.
# Names must match the `name:` field of the workflow as reported by
# `gh workflow list`.
declare -a NEVER_DISABLE_WORKFLOWS=(
"e2e"
"Suggest New E2E Tests"
)
# Returns 0 (true) if the given workflow name is on the never-disable list.
is_protected_workflow() {
local name="$1"
local protected
for protected in "${NEVER_DISABLE_WORKFLOWS[@]}"; do
[[ "$name" == "$protected" ]] && return 0
done
return 1
}
# Record a test pass: update arrays, write the current-run result, and remove from fails.txt
record_test_pass() {
local test_name="$1"
PASSED_TESTS+=("$test_name")
# Write the current-run result with run ID (same format as fails.txt)
local _url="${TEST_RUN_URLS[$test_name]:-}"
local _run_id=""
if [[ -n "$_url" ]]; then
_run_id="${_url##*/}"
fi
if [[ -n "$_run_id" ]]; then
echo "$test_name $_run_id" >> "$RUN_PASSES_FILE"
else
echo "$test_name" >> "$RUN_PASSES_FILE"
fi
# Remove the test from fails.txt if present
if [[ -f "fails.txt" ]]; then
local _tmp
_tmp=$(grep -v "^${test_name} \|^${test_name}$" "fails.txt" 2>/dev/null || true)
if [[ -n "$_tmp" ]]; then
echo "$_tmp" > "fails.txt"
else
rm -f "fails.txt"
fi
fi
}
# Record a test failure: update arrays and add/append to fails.txt
record_test_fail() {
local test_name="$1"
FAILED_TESTS+=("$test_name")
# Look up the run ID
local _url="${TEST_RUN_URLS[$test_name]:-}"
local _run_id=""
if [[ -n "$_url" ]]; then
_run_id="${_url##*/}"
fi
if [[ -z "$_run_id" ]]; then
local _wf="${test_name}.lock.yml"
_run_id=$(gh run list \
--repo "$REPO_OWNER/$REPO_NAME" \
--workflow="$_wf" \
--limit=20 \
--json databaseId,conclusion \
--jq '[.[] | select(.conclusion != "skipped")][0].databaseId' 2>/dev/null || echo "")
fi
if [[ -n "$RUN_FAILURES_FILE" ]] && ! grep -q "^${test_name}\( \|$\)" "$RUN_FAILURES_FILE" 2>/dev/null; then
if [[ -n "$_run_id" ]]; then
echo "$test_name $_run_id" >> "$RUN_FAILURES_FILE"
else
echo "$test_name" >> "$RUN_FAILURES_FILE"
fi
fi
# Update fails.txt: append run ID to existing line or add new entry
if [[ -f "fails.txt" ]] && grep -q "^${test_name} \|^${test_name}$" "fails.txt" 2>/dev/null; then
if [[ -n "$_run_id" ]]; then
local _existing_line
_existing_line=$(grep "^${test_name} \|^${test_name}$" "fails.txt")
if [[ "$_existing_line" != *"$_run_id"* ]]; then
sed -i "s|^${test_name}\( .*\)\?$|${test_name}\1 ${_run_id}|" "fails.txt"
fi
fi
else
if [[ -n "$_run_id" ]]; then
echo "$test_name $_run_id" >> "fails.txt"
else
echo "$test_name" >> "fails.txt"
fi
fi
}
# Helper function to safely execute commands that might fail
# Usage: safe_run "operation description" command arg1 arg2...
safe_run() {
local description="$1"
shift
if "$@"; then
return 0
else
local exit_code=$?
warning "Failed to $description (exit code: $exit_code)"
return $exit_code
fi
}
# Configuration
REPO_OWNER="githubnext"
REPO_NAME="gh-aw-test"
TIMEOUT_MINUTES=10
# In CI, poll 10x less frequently (50s vs 5s) to conserve GitHub API rate limits.
# The human isn't watching for fast feedback, so the extra latency is fine.
POLL_INTERVAL=5
# Outcome poll: how often wait_for_* functions recheck the GitHub API for expected output.
# Kept faster than POLL_INTERVAL because each check is cheap, but still CI-aware.
OUTCOME_POLL_INTERVAL=5
# Throttle before launching a new batch if GitHub REST API remaining calls drops below this.
RATE_LIMIT_THRESHOLD=400
if [[ "${CI:-false}" == "true" ]]; then
POLL_INTERVAL=50
OUTCOME_POLL_INTERVAL=20
fi
LOG_FILE="e2e-test-$(date +%Y%m%d-%H%M%S).log"
TEMP_USER_PAT_SET=false
USE_SAMPLES=false
# --verbose: when true, build/compile/version diagnostics that normally go only
# to $LOG_FILE are ALSO streamed to stdout. Useful in CI where $LOG_FILE is not
# surfaced and a failing `make build` / capability probe is otherwise opaque.
VERBOSE=false
# Shared results file for parallel execution
RESULTS_FILE="/tmp/e2e-results-$$.txt"
# --gh-aw-ref: when non-empty, the script resets a parallel ../gh-aw checkout to
# this ref, builds it, and uses the resulting binary for compile+enable+disable+run.
# Compiled workflows will then reference github/gh-aw/actions/setup@<GH_AW_REF>
# instead of the published github/gh-aw-actions/setup@<version>.
GH_AW_REF=""
GH_AW_SRC_DIR="../gh-aw"
GH_AW_BIN="gh aw"
GH_AW_RESOLVED_SHA="" # short commit SHA of the gh-aw binary actually used
GH_AW_VERSION_STR="" # output of gh-aw --version for the binary actually used
# --branch / $E2E_BRANCH: when non-empty, e2e.sh pushes the recompiled
# workflows to this branch (force-push) instead of committing to main, and
# dispatches every test workflow with `--ref <branch>` so the run executes the
# branch's version. This isolates concurrent/serial matrix entries from each
# other (and from main) — each (gh-aw ref × samples) combination gets its own
# stable branch that is reused and force-updated on every run. When empty, the
# legacy behaviour (push to main, dispatch from the default branch) is used.
E2E_BRANCH="${E2E_BRANCH:-}"
# DISPATCH_REF is derived from E2E_BRANCH and passed to `gh aw run --ref` /
# `gh workflow run --ref`. Empty means "use the repository default branch".
DISPATCH_REF=""
# CI mode: when the standard `$CI` environment variable is set to `true`
# (which GitHub Actions and most other CI providers do automatically), e2e.sh
# does NOT mutate repository secrets. Default to false if unset.
CI="${CI:-false}"
# Utility functions
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') $*" | tee -a "$LOG_FILE"
}
info() {
echo -e "${BLUE}ℹ️ $*${NC}" | tee -a "$LOG_FILE"
}
success() {
echo -e "${GREEN}✅ $*${NC}" | tee -a "$LOG_FILE"
}
warning() {
echo -e "${YELLOW}⚠️ $*${NC}" | tee -a "$LOG_FILE"
}
error() {
echo -e "${RED}❌ $*${NC}" | tee -a "$LOG_FILE"
}
progress() {
echo -e "${PURPLE}🔨 $*${NC}" | tee -a "$LOG_FILE"
}
# Run a command, always appending its combined output to $LOG_FILE. When
# VERBOSE is true the output is ALSO streamed to stdout (via the terminal),
# which is important in CI where $LOG_FILE is not otherwise surfaced. Returns
# the command's exit status.
run_logged() {
if [[ "$VERBOSE" == true ]]; then
# tee keeps the log file in sync while echoing to the console.
"$@" 2>&1 | tee -a "$LOG_FILE"
return "${PIPESTATUS[0]}"
else
"$@" &>> "$LOG_FILE"
fi
}
# Secret management functions
set_temp_user_pat() {
info "Setting TEMP_USER_PAT secret for cross-repo testing..."
# Get the current user's PAT
local user_pat=$(gh auth token 2>/dev/null)
if [[ -z "$user_pat" ]]; then
error "Failed to get GitHub auth token. Run 'gh auth login'"
return 1
fi
# Set the secret in the repository (gh secret set is idempotent - overwrites if already present)
local secret_err
local max_attempts=3
local attempt=1
while [[ $attempt -le $max_attempts ]]; do
secret_err=$(echo "$user_pat" | gh secret set TEMP_USER_PAT --repo "$REPO_OWNER/$REPO_NAME" 2>&1)
local rc=$?
echo "$secret_err" >> "$LOG_FILE"
if [[ $rc -eq 0 ]]; then
TEMP_USER_PAT_SET=true
success "TEMP_USER_PAT secret set successfully"
return 0
fi
if [[ $attempt -lt $max_attempts ]]; then
warning "Failed to set TEMP_USER_PAT secret (attempt $attempt/$max_attempts): $secret_err"
sleep 5
fi
attempt=$((attempt + 1))
done
error "Failed to set TEMP_USER_PAT secret after $max_attempts attempts: $secret_err"
return 1
}
delete_temp_user_pat() {
if [[ "$TEMP_USER_PAT_SET" == true ]]; then
info "Cleaning up TEMP_USER_PAT secret..."
if gh secret delete TEMP_USER_PAT --repo "$REPO_OWNER/$REPO_NAME" &>> "$LOG_FILE"; then
TEMP_USER_PAT_SET=false
success "TEMP_USER_PAT secret deleted successfully"
return 0
else
warning "Failed to delete TEMP_USER_PAT secret (it may not exist)"
return 1
fi
fi
}
cleanup_on_exit() {
# Prevent double execution
if [[ "${CLEANUP_DONE:-false}" == "true" ]]; then
return 0
fi
CLEANUP_DONE=true
echo
info "Performing cleanup..."
# Load workflows from temp file (for parallel processes)
if [[ -f "/tmp/e2e-workflows-list-$$.txt" ]]; then
while IFS= read -r wf; do
[[ -n "$wf" ]] && GLOBAL_WORKFLOWS_TO_DISABLE+=("$wf")
done < "/tmp/e2e-workflows-list-$$.txt"
fi
# Disable any workflows that were enabled during testing
if [[ ${#GLOBAL_WORKFLOWS_TO_DISABLE[@]} -gt 0 ]]; then
# Remove duplicates
local -A seen
local unique_workflows=()
for workflow in "${GLOBAL_WORKFLOWS_TO_DISABLE[@]}"; do
if [[ -z "${seen[$workflow]:-}" ]]; then
seen[$workflow]=1
unique_workflows+=("$workflow")
fi
done
info "Disabling ${#unique_workflows[@]} workflow(s) in parallel that were enabled during testing..."
for workflow in "${unique_workflows[@]}"; do
# Never disable protected CI/infra workflows (e.g. the nightly E2E
# matrix) even if they somehow ended up on the disable queue.
if is_protected_workflow "$workflow"; then
info " 🔒 Keeping '$workflow' enabled (protected workflow)"
continue
fi
(disable_workflow "$workflow" 2>/dev/null || warning "Failed to disable workflow '$workflow', continuing...") &
done
wait
fi
delete_temp_user_pat
# Clean up lock files
rm -f "$RESULTS_LOCK" "$GLOBAL_WORKFLOWS_LOCK" "$RESULTS_FILE" "/tmp/e2e-workflows-list-$$.txt" ${COMPILE_FAILED_FILE:+"$COMPILE_FAILED_FILE"} 2>/dev/null || true
}
# Test pattern matching functions
matches_pattern() {
local test_name="$1"
local pattern="$2"
# Convert glob pattern to regex
local regex_pattern=$(echo "$pattern" | sed 's/\*/[^[:space:]]*/g')
if [[ "$test_name" =~ ^${regex_pattern}$ ]]; then
return 0
else
return 1
fi
}
# Get target repo from workflow name (defaults to current repo)
get_target_repo() {
local workflow_name="$1"
if [[ "$workflow_name" == *"siderepo"* ]]; then
echo "githubnext/gh-aw-side-repo"
else
echo ""
fi
}
# Extract AI type from workflow name
extract_ai_type() {
local workflow_name="$1"
# Check for nosandbox variants first (more specific)
if [[ "$workflow_name" == *"claude-nosandbox"* ]]; then
echo "claude-nosandbox"
elif [[ "$workflow_name" == *"codex-nosandbox"* ]]; then
echo "codex-nosandbox"
elif [[ "$workflow_name" == *"copilot-nosandbox"* ]]; then
echo "copilot-nosandbox"
# Then check for regular variants
elif [[ "$workflow_name" == *"claude"* ]]; then
echo "claude"
elif [[ "$workflow_name" == *"codex"* ]]; then
echo "codex"
elif [[ "$workflow_name" == *"copilot"* ]]; then
echo "copilot"
else
echo ""
fi
}
# Get display name for AI type
get_ai_display_name() {
local ai_type="$1"
case "$ai_type" in
claude-nosandbox)
echo "Claude (No Sandbox)"
;;
codex-nosandbox)
echo "Codex (No Sandbox)"
;;
copilot-nosandbox)
echo "Copilot (No Sandbox)"
;;
claude)
echo "Claude"
;;
codex)
echo "Codex"
;;
copilot)
echo "Copilot"
;;
*)
echo "${ai_type^}"
;;
esac
}
# Get expected labels for AI type
# Nosandbox variants use separate labels: base-type, nosandbox, automation
# Regular variants use: base-type, automation
get_expected_labels() {
local ai_type="$1"
case "$ai_type" in
claude-nosandbox)
echo "claude,nosandbox,automation"
;;
codex-nosandbox)
echo "codex,nosandbox,automation"
;;
copilot-nosandbox)
echo "copilot,nosandbox,automation"
;;
*)
echo "${ai_type},automation"
;;
esac
}
# Get title prefix for validation based on workflow name and type
# PR tests use different prefixes to avoid conflicts in parallel execution
get_title_prefix() {
local workflow_name="$1"
local ai_type="$2"
# Determine the appropriate suffix based on workflow type
if [[ "$workflow_name" == *"create-two-pull-requests"* ]]; then
echo "[${ai_type}-test-two-prs] "
elif [[ "$workflow_name" == *"subdir-create-pull-request"* ]]; then
echo "[${ai_type}-test-subdir-pr] "
elif [[ "$workflow_name" == *"sparse-create-pull-request"* ]]; then
echo "[${ai_type}-test-sparse-pr] "
elif [[ "$workflow_name" == *"create-pull-request"* ]]; then
echo "[${ai_type}-test-single-pr] "
elif [[ "$workflow_name" == *"gh-steps"* ]]; then
echo "[${ai_type}-test-gh-steps] "
else
# Default for non-PR tests (issues, discussions, etc.)
echo "[${ai_type}-test] "
fi
}
should_run_test() {
local test_name="$1"
local patterns=("${@:2}")
# If no patterns specified, run all tests
if [[ ${#patterns[@]} -eq 0 ]]; then
return 0
fi
# Check if test matches any pattern
for pattern in "${patterns[@]}"; do
if matches_pattern "$test_name" "$pattern"; then
return 0
fi
done
return 1
}
get_all_tests() {
# Workflow dispatch tests
echo "test-claude-create-issue"
echo "test-codex-create-issue"
echo "test-copilot-create-issue"
echo "test-claude-create-discussion"
echo "test-codex-create-discussion"
echo "test-copilot-create-discussion"
echo "test-claude-create-pull-request"
echo "test-codex-create-pull-request"
echo "test-copilot-create-pull-request"
echo "test-claude-create-two-pull-requests"
echo "test-codex-create-two-pull-requests"
echo "test-copilot-create-two-pull-requests"
echo "test-claude-create-code-scanning-alert"
echo "test-codex-create-repository-code-scanning-alert"
echo "test-copilot-create-repository-code-scanning-alert"
echo "test-copilot-create-check-run"
echo "test-claude-mcp"
echo "test-codex-mcp"
echo "test-copilot-mcp"
echo "test-copilot-mcp-code-quality"
echo "test-copilot-skills-frontmatter"
echo "test-claude-custom-safe-outputs"
echo "test-codex-custom-safe-outputs"
echo "test-copilot-custom-safe-outputs"
echo "test-copilot-gh-steps"
echo "test-copilot-restore-memory-custom-job"
# Issue-triggered tests
echo "test-claude-add-comment"
echo "test-claude-add-labels"
echo "test-claude-add-discussion-comment"
echo "test-codex-add-comment"
echo "test-codex-add-labels"
echo "test-codex-add-discussion-comment"
echo "test-copilot-add-comment"
echo "test-copilot-add-labels"
echo "test-copilot-add-discussion-comment"
echo "test-claude-update-issue"
echo "test-codex-update-issue"
echo "test-copilot-update-issue"
echo "test-copilot-close-issue"
echo "test-copilot-remove-labels"
echo "test-copilot-replace-label"
echo "test-copilot-close-discussion"
echo "test-copilot-update-discussion"
echo "test-copilot-assign-to-user"
echo "test-copilot-unassign-from-user"
echo "test-copilot-assign-milestone"
echo "test-copilot-assign-to-agent"
echo "test-copilot-link-sub-issue"
echo "test-copilot-hide-comment"
# PR-triggered tests
echo "test-claude-update-pull-request"
echo "test-codex-update-pull-request"
echo "test-copilot-update-pull-request"
echo "test-copilot-close-pull-request"
echo "test-copilot-add-reviewer"
echo "test-copilot-mark-pull-request-as-ready-for-review"
# Command-triggered tests
echo "test-claude-command"
echo "test-codex-command"
echo "test-copilot-command"
echo "test-claude-push-to-pull-request-branch"
echo "test-codex-push-to-pull-request-branch"
echo "test-copilot-push-to-pull-request-branch-using-slash-command"
echo "test-copilot-push-to-pull-request-branch-using-dispatch"
echo "test-claude-create-pull-request-review-comment"
echo "test-codex-create-pull-request-review-comment"
echo "test-copilot-create-pull-request-review-comment"
echo "test-copilot-reply-to-pull-request-review-comment"
echo "test-copilot-resolve-pull-request-review-thread"
echo "test-copilot-submit-pull-request-review"
echo "test-copilot-set-issue-type"
echo "test-copilot-set-issue-field"
echo "test-copilot-set-issue-field-builtin-rejection"
echo "test-copilot-issue-intents"
# Workflow_dispatch tests with inputs (dispatch-workflow needs a sentinel)
echo "test-copilot-submit-pull-request-review-locked"
echo "test-copilot-dismiss-pull-request-review"
echo "test-copilot-dispatch-workflow"
echo "test-copilot-call-workflow"
echo "test-copilot-inline-sub-agents"
echo "test-copilot-network-isolation"
echo "test-copilot-noop"
echo "test-copilot-report-incomplete"
echo "test-copilot-missing-data"
echo "test-copilot-missing-tool"
echo "test-copilot-update-release"
echo "test-copilot-upload-asset"
echo "test-copilot-upload-code-coverage"
# Nosandbox tests - limited set for claude/codex, full matrix for copilot
echo "test-copilot-nosandbox-create-issue"
echo "test-copilot-nosandbox-create-discussion"
echo "test-copilot-nosandbox-create-pull-request"
echo "test-copilot-nosandbox-create-two-pull-requests"
echo "test-copilot-nosandbox-create-repository-code-scanning-alert"
echo "test-copilot-nosandbox-mcp"
echo "test-copilot-nosandbox-custom-safe-outputs"
echo "test-copilot-nosandbox-add-comment"
echo "test-copilot-nosandbox-add-labels"
echo "test-copilot-nosandbox-add-discussion-comment"
echo "test-copilot-nosandbox-update-issue"
echo "test-copilot-nosandbox-command"
echo "test-copilot-nosandbox-push-to-pull-request-branch"
echo "test-copilot-nosandbox-create-pull-request-review-comment"
# Siderepo tests - cross-repo private repository tests
echo "test-copilot-siderepo-create-issue"
echo "test-copilot-siderepo-create-discussion"
echo "test-copilot-siderepo-create-pull-request"
echo "test-copilot-siderepo-sparse-create-pull-request"
echo "test-copilot-siderepo-subdir-create-pull-request"
echo "test-copilot-siderepo-create-two-pull-requests"
# echo "test-copilot-siderepo-create-repository-code-scanning-alert" # Disabled: doesn't support target-repo
echo "test-copilot-siderepo-mcp"
# echo "test-copilot-siderepo-custom-safe-outputs" # Disabled: doesn't support target-repo
echo "test-copilot-siderepo-add-comment"
echo "test-copilot-siderepo-add-labels"
echo "test-copilot-siderepo-add-discussion-comment"
echo "test-copilot-siderepo-update-issue"
echo "test-copilot-siderepo-link-sub-issue"
echo "test-copilot-siderepo-push-to-pull-request-branch-using-dispatch"
echo "test-copilot-siderepo-sparse-push-to-pull-request-branch-using-dispatch"
echo "test-copilot-siderepo-create-pull-request-review-comment"
}
filter_tests() {
local patterns=("$@")
local all_tests
all_tests=($(get_all_tests))
local filtered_tests=()
for test in "${all_tests[@]}"; do
if should_run_test "$test" "${patterns[@]}"; then
filtered_tests+=("$test")
fi
done
# Only print if there are filtered tests
if [[ ${#filtered_tests[@]} -gt 0 ]]; then
printf '%s\n' "${filtered_tests[@]}"
fi
}
# Reset a parallel gh-aw checkout to $GH_AW_REF, build it, and set GH_AW_BIN.
# Used when the user passes --gh-aw-ref <ref> to test compiled workflows against
# a specific gh-aw branch, tag, or SHA. The compiled lock.yml files will then
# pin github/gh-aw/actions/setup@<ref> at runtime instead of the published
# github/gh-aw-actions/setup@<version>.
setup_local_gh_aw_binary() {
info "Setting up local gh-aw build for ref '$GH_AW_REF'..."
if [[ ! -d "$GH_AW_SRC_DIR/.git" ]]; then
error "--gh-aw-ref requires a parallel gh-aw checkout at $GH_AW_SRC_DIR (not found)"
exit 1
fi
progress "Fetching latest refs from origin in $GH_AW_SRC_DIR..."
# --force + --prune-tags tolerates moved/deleted upstream tags
if ! run_logged git -C "$GH_AW_SRC_DIR" fetch origin --prune --prune-tags --tags --force; then
error "Failed to fetch from origin in $GH_AW_SRC_DIR"
exit 1
fi
progress "Resetting $GH_AW_SRC_DIR to '$GH_AW_REF'..."
# Try branch (origin/<ref>) first, then fall back to tag/SHA.
if git -C "$GH_AW_SRC_DIR" rev-parse --verify "origin/$GH_AW_REF" &>/dev/null; then
if ! run_logged git -C "$GH_AW_SRC_DIR" checkout -B "$GH_AW_REF" "origin/$GH_AW_REF"; then
error "Failed to checkout branch '$GH_AW_REF' in $GH_AW_SRC_DIR"
exit 1
fi
else
if ! run_logged git -C "$GH_AW_SRC_DIR" checkout --detach "$GH_AW_REF"; then
error "Failed to checkout ref '$GH_AW_REF' in $GH_AW_SRC_DIR (not a branch, tag, or SHA)"
exit 1
fi
fi
# Record the resolved commit so a stale/empty build is easy to diagnose.
local resolved_sha
resolved_sha=$(git -C "$GH_AW_SRC_DIR" rev-parse --short HEAD 2>/dev/null || echo "unknown")
info " $GH_AW_SRC_DIR is at commit $resolved_sha"
progress "Building gh-aw binary at $GH_AW_SRC_DIR (make build)..."
if ! ( cd "$GH_AW_SRC_DIR" && run_logged make build ); then
error "Failed to build gh-aw binary in $GH_AW_SRC_DIR. Check $LOG_FILE for details"
exit 1
fi
local bin_path="$GH_AW_SRC_DIR/gh-aw"
if [[ ! -x "$bin_path" ]]; then
error "Built binary not found at $bin_path"
exit 1
fi
GH_AW_BIN="$bin_path"
GH_AW_RESOLVED_SHA="$resolved_sha"
# Capture version output (incl. stderr) for diagnostics. An empty version
# usually means the build silently produced a binary without ldflags/version
# info or that an old binary is being reused.
local built_version
built_version=$($GH_AW_BIN --version 2>&1 || echo "unknown")
GH_AW_VERSION_STR="$built_version"
echo "gh-aw --version output: ${built_version:-<empty>}" >> "$LOG_FILE"
success "Built gh-aw binary: $bin_path (commit $resolved_sha, version: ${built_version:-<empty>})"
# Verify the binary supports --gh-aw-ref. Capture the help output so a
# failure here can be diagnosed (e.g. ref older than the flag, or the wrong
# binary was built/picked up).
local compile_help
compile_help=$($GH_AW_BIN compile --help 2>&1)
echo "--- '$GH_AW_BIN compile --help' output ---" >> "$LOG_FILE"
echo "$compile_help" >> "$LOG_FILE"
if [[ "$VERBOSE" == true ]]; then
echo "$compile_help"
fi
if ! grep -q -- "--gh-aw-ref" <<< "$compile_help"; then
error "The built gh-aw binary does not support --gh-aw-ref. The ref '$GH_AW_REF' (commit $resolved_sha) is likely older than the flag's introduction, or the wrong binary was built (version: ${built_version:-<empty>})."
error "Re-run with --verbose to see the full build and 'compile --help' output."
exit 1
fi
}
check_prerequisites() {
info "Checking prerequisites..."
# Check gh CLI is installed and authenticated
if ! command -v gh &> /dev/null; then
error "GitHub CLI (gh) is not installed"
exit 1
fi
# Check authentication
if ! gh auth status &> /dev/null; then
error "GitHub CLI is not authenticated. Run 'gh auth login'"
exit 1
fi
# Either install/upgrade the released gh-aw extension OR build the requested
# ref from a parallel ../gh-aw checkout.
if [[ -n "$GH_AW_REF" ]]; then
setup_local_gh_aw_binary
else
info "Checking gh-aw extension..."
if gh extension list | grep -q "github/gh-aw"; then
if [[ "${CI:-}" == "true" ]]; then
# In CI the job step already installed the correct pinned version;
# do NOT upgrade, or we would override the pinned version with latest.
info "Running in CI mode; using pre-installed gh-aw extension (skipping upgrade)"
else
info "gh-aw extension already installed, upgrading to latest version..."
if gh extension upgrade github/gh-aw &>> "$LOG_FILE"; then
success "gh-aw extension upgraded successfully"
else
warning "Failed to upgrade gh-aw extension, continuing with existing version"
fi
fi
else
info "Installing gh-aw extension..."
if gh extension install github/gh-aw &>> "$LOG_FILE"; then
success "gh-aw extension installed successfully"
else
error "Failed to install gh-aw extension. Check $LOG_FILE for details"
exit 1
fi
fi
fi
# Verify the chosen gh-aw binary is available
if ! $GH_AW_BIN --version &>> "$LOG_FILE"; then
error "gh-aw binary ($GH_AW_BIN) is not available"
exit 1
fi
# Check we're in the right repo
local current_repo=$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null || echo "")
if [[ "$current_repo" != "$REPO_OWNER/$REPO_NAME" ]]; then
error "Not in the correct repository. Expected $REPO_OWNER/$REPO_NAME, got $current_repo"
exit 1
fi
# For the main-branch push path: sync to the latest origin/main BEFORE
# compiling. Lock files are auto-generated; the only conflict-free way to
# push a new compilation is to start from whatever is already on main, run
# compile, and push the result as a clean fast-forward. This avoids the
# need for any rebase/merge of generated files.
# (E2E_BRANCH uses force-push, so no pre-sync is needed for that path.)
if [[ -z "$E2E_BRANCH" ]]; then
git fetch origin main &>> "$LOG_FILE"
git reset --hard origin/main &>> "$LOG_FILE"
fi
# Compile workflows. When --gh-aw-ref is set, pass it through so compiled
# workflows reference github/gh-aw/actions/setup@<ref> at runtime.
local compile_cmd=($GH_AW_BIN compile)
if [[ -n "$GH_AW_REF" ]]; then
compile_cmd+=(--gh-aw-ref "$GH_AW_REF")
fi
if [[ "$USE_SAMPLES" == true ]]; then
compile_cmd+=(--use-samples)
fi
compile_cmd+=(--json)
info "Running: ${compile_cmd[*]}"
local _compile_out
_compile_out=$(mktemp)
"${compile_cmd[@]}" 2>&1 | tee -a "$LOG_FILE" > "$_compile_out"
local _compile_rc=${PIPESTATUS[0]}
if [[ $_compile_rc -ne 0 ]]; then
local _failed_wfs
_failed_wfs=$(python3 -c "
import sys, json, re, os
data = open(sys.argv[1]).read()
m = re.search(r'\\[\\s*\\{.*\\}\\s*\\]', data, re.DOTALL)
if not m: sys.exit(0)
for item in json.loads(m.group(0)):
if not item.get('valid', True):
wf = os.path.basename(item.get('workflow', '')).replace('.md', '')
if wf: print(wf)
" "$_compile_out" 2>/dev/null || true)
rm -f "$_compile_out"
if [[ -n "$_failed_wfs" ]]; then
COMPILE_FAILED_FILE="/tmp/e2e-compile-failed-$$.txt"
printf '%s\n' "$_failed_wfs" > "$COMPILE_FAILED_FILE"
warning "Some workflows failed to compile; those tests will be marked failed:"
while IFS= read -r _wf; do
warning " ✗ compile failed: $_wf"
done <<< "$_failed_wfs"
else
error "'${compile_cmd[*]}' failed. Check $LOG_FILE for details"
exit 1
fi
else
rm -f "$_compile_out"
fi
# Always recompile suggest-new-e2e-tests.md without samples
if ! $GH_AW_BIN compile suggest-new-e2e-tests.md --json &>> "$LOG_FILE"; then
error "Failed to compile suggest-new-e2e-tests.md. Check $LOG_FILE for details"
exit 1
fi
# If there are any updates from the compile, commit them and push them so the
# workflows are up to date for testing.
#
# Two destinations:
# * E2E_BRANCH set -> create/reset a dedicated branch from the current
# HEAD, commit any changes, and force-push the branch. Test workflows are
# later dispatched with `--ref $E2E_BRANCH`, so this never touches main
# and parallel/serial matrix entries can't clobber each other.
# * E2E_BRANCH empty -> legacy behaviour: commit and push to main.
# NOTE: when running against --gh-aw-ref the lock.yml diff is expected; we still
# push so the test runs see the ref-specific workflows.
local commit_msg="chore: update compiled workflows via e2e.sh"
if [[ -n "$GH_AW_REF" ]]; then
commit_msg="chore: e2e.sh recompile against gh-aw ref ${GH_AW_REF}"
fi
if [[ -n "$E2E_BRANCH" ]]; then
DISPATCH_REF="$E2E_BRANCH"
info "Using dedicated test branch '$E2E_BRANCH' (workflows dispatched with --ref '$E2E_BRANCH')"
# Move onto the dedicated branch, carrying any compile changes in the
# working tree with us.
if ! git checkout -B "$E2E_BRANCH" &>> "$LOG_FILE"; then
error "Failed to create/reset local branch '$E2E_BRANCH'. Check $LOG_FILE for details"
exit 1
fi
local git_status
git_status=$(git status --porcelain)
if [[ -n "$git_status" ]]; then
git add . &>> "$LOG_FILE"
git commit -m "$commit_msg" &>> "$LOG_FILE"
else
info "No changes detected after compile; force-pushing branch to keep it in sync"
fi
# Always force-push so the remote branch exactly matches the compiled
# state (the branch is ephemeral/reused and safe to overwrite).
if git push --force origin "$E2E_BRANCH" &>> "$LOG_FILE"; then
success "Pushed compiled workflows to branch '$E2E_BRANCH'"
else
error "Failed to push to branch '$E2E_BRANCH'. Check $LOG_FILE for details"
exit 1
fi
else
local git_status
git_status=$(git status --porcelain)
if [[ -n "$git_status" ]]; then
info "Detected changes after compile; committing and pushing to main branch"
git add . &>> "$LOG_FILE"
git commit -m "$commit_msg" &>> "$LOG_FILE"
if git push origin main &>> "$LOG_FILE"; then
success "Changes pushed to main branch"
else
error "Failed to push changes to main branch. Check $LOG_FILE for details"
exit 1
fi
else
info "No changes detected after compile"
fi
fi
# PAT handling.
#
# Two modes (selected automatically via the standard `$CI` env var):
# * Local mode (CI unset or != "true"): the script uses its own
# `gh auth token` to set the repository's TEMP_USER_PAT secret so
# dispatched workflows can do cross-repo operations. We also delete
# the secret on exit.
# * CI mode (CI=true): the script MUST NOT mutate repo secrets (parallel
# matrix runs would clobber each other and we don't want CI write-scope
# tokens leaking through `gh secret set`). Instead, the PAT is supplied
# as the GH_AW_TEST_PAT environment variable, sourced from the actions
# secret of the same name. The repo's TEMP_USER_PAT secret is expected
# to be pre-configured (typically to the same value).
if [[ "$CI" == true ]]; then
if [[ -z "${GH_AW_TEST_PAT:-}" ]]; then
error "CI mode (CI=true) requires the GH_AW_TEST_PAT environment variable to be set (sourced from the actions secret of the same name). e2e.sh will not set repo secrets in this mode."
exit 1
fi
info "CI mode: skipping TEMP_USER_PAT secret management; using pre-configured repo secret + GH_AW_TEST_PAT env"
else
# Set TEMP_USER_PAT secret for cross-repo testing
if ! set_temp_user_pat; then
error "Failed to set TEMP_USER_PAT secret. Cross-repo tests will fail."
exit 1
fi
fi
success "Prerequisites check passed"
}
disable_all_workflows_before_testing() {
info "Disabling all workflows that aren't already disabled..."
# Get list of all workflows with their state
# Format: workflow_id state
progress "Running: gh workflow list --all --json name,state"
local workflows_output
workflows_output=$(gh workflow list --all --json name,state --jq '.[] | "\(.name)\t\(.state)"' 2>/dev/null)
if [[ -z "$workflows_output" ]]; then
warning "No workflows found or failed to list workflows"
return 0
fi
local -a to_disable=()
local already_disabled_count=0
while IFS=$'\t' read -r workflow_name workflow_state; do
# Never disable protected CI/infra workflows (e.g. the nightly E2E
# matrix), otherwise the scheduled run that invokes us in CI would be
# turned off and nightly testing would stop.
if is_protected_workflow "$workflow_name"; then
info " 🔒 Keeping '$workflow_name' enabled (protected workflow)"
continue
fi
# Skip if already disabled
if [[ "$workflow_state" == "disabled_manually" ]] || [[ "$workflow_state" == "disabled_inactivity" ]]; then
info " ⏭️ Skipping '$workflow_name' (already $workflow_state)"
already_disabled_count=$((already_disabled_count + 1))
continue
fi
to_disable+=("$workflow_name")
done <<< "$workflows_output"
local disabled_count=0
if [[ ${#to_disable[@]} -gt 0 ]]; then
local parallelism=$BATCH_SIZE
[[ $parallelism -lt 1 ]] && parallelism=1
info "Disabling ${#to_disable[@]} workflow(s) in parallel (up to $parallelism at a time)..."
local results_file
results_file=$(mktemp)
local running=0
for workflow_name in "${to_disable[@]}"; do
(
if gh workflow disable "$workflow_name" &>> "$LOG_FILE"; then