Skip to content

Commit 7144f8c

Browse files
committed
Fixes for actions workflow failures 6
1 parent b50db50 commit 7144f8c

File tree

9 files changed

+271
-94
lines changed

9 files changed

+271
-94
lines changed

scripts/validate-cli-e2e.sh

Lines changed: 189 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -270,35 +270,153 @@ install_all_packs() {
270270
log_success "All packs installed successfully"
271271
}
272272

273-
# Run unit tests using the dedicated script
274-
run_unit_tests_for_languages() {
275-
local languages="$1"
273+
# Run unit tests for a single language
274+
run_unit_tests_for_language() {
275+
local language="$1"
276+
local work_dir="$2"
277+
278+
log_info "Running unit tests for language: $language"
279+
280+
# Get environment info
281+
local os_name=$(uname -s)
282+
if [[ "$os_name" == "Darwin" ]]; then
283+
os_name="macOS"
284+
fi
285+
286+
log_info " → Environment: $os_name"
287+
288+
# Change to the work directory since that's where QLT expects to be run from
289+
local old_pwd=$(pwd)
290+
cd "$work_dir" || return 1
291+
292+
# Create test results directory for the language
293+
local test_results_dir="${work_dir}/${language}/test-results"
294+
mkdir -p "$test_results_dir"
295+
296+
# Execute tests using dotnet run
297+
local test_output
298+
log_info " → Executing unit tests for $language..."
299+
if ! test_output=$(dotnet "$QLT_BINARY" test run execute-unit-tests \
300+
--language "$language" \
301+
--num-threads 2 \
302+
--work-dir "$test_results_dir" \
303+
--runner-os "$os_name" \
304+
--automation-type actions 2>&1); then
305+
log_error "Unit test execution failed for $language"
306+
log_error "Test execution output:"
307+
echo "$test_output"
308+
cd "$old_pwd"
309+
return 1
310+
fi
311+
312+
log_info "Test execution output for $language:"
313+
echo "$test_output"
314+
315+
cd "$old_pwd"
316+
log_success "Unit test execution completed for $language"
317+
return 0
318+
}
319+
320+
# Validate unit test results for a single language
321+
validate_unit_test_results() {
322+
local language="$1"
276323
local work_dir="$2"
277324

278-
log_info "Running unit tests for languages: $languages"
325+
log_info "Validating unit test results for $language..."
279326

280-
# Get the directory where this script is located
281-
local script_dir="$SCRIPT_DIR"
282-
local unit_test_script="$script_dir/run-unit-tests.sh"
327+
local results_dir="${work_dir}/${language}/test-results"
328+
if [[ ! -d "$results_dir" ]]; then
329+
log_error "Test results directory not found: $results_dir"
330+
log_info "This suggests that unit test execution may have failed or no tests were generated"
331+
return 1
332+
fi
283333

284-
if [[ ! -f "$unit_test_script" ]]; then
285-
log_error "Unit test script not found: $unit_test_script"
334+
# Check if there are any test result files
335+
local result_files
336+
result_files=$(find "$results_dir" -name "*.json" -o -name "test_report_*.json" 2>/dev/null | wc -l)
337+
if [[ $result_files -eq 0 ]]; then
338+
log_warning "No test result files found in $results_dir"
339+
log_info "Available files in test results directory:"
340+
ls -la "$results_dir" || log_warning "Cannot list test results directory"
341+
fi
342+
343+
# Change to the work directory since that's where QLT expects to be run from
344+
local old_pwd=$(pwd)
345+
cd "$work_dir" || return 1
346+
347+
# First run validation with pretty-print for detailed output
348+
local validation_output
349+
log_info " → Running test result validation with detailed output..."
350+
if ! validation_output=$(dotnet "$QLT_BINARY" test run validate-unit-tests --pretty-print --results-directory "$results_dir" 2>&1); then
351+
log_error "Test result validation failed for $language"
352+
log_error "Detailed validation output:"
353+
echo "$validation_output"
354+
cd "$old_pwd"
286355
return 1
287356
fi
288357

289-
if [[ ! -x "$unit_test_script" ]]; then
290-
log_error "Unit test script is not executable: $unit_test_script"
358+
log_info "Validation output for $language:"
359+
echo "$validation_output"
360+
361+
# Also run the standard validation (without pretty-print) for exit code
362+
local standard_validation_output
363+
if ! standard_validation_output=$(dotnet "$QLT_BINARY" test run validate-unit-tests --results-directory "$results_dir" 2>&1); then
364+
log_error "Standard validation check failed for $language"
365+
log_error "Standard validation output:"
366+
echo "$standard_validation_output"
367+
cd "$old_pwd"
291368
return 1
292369
fi
293370

294-
# Run the unit tests script
295-
if "$unit_test_script" --test-dir "$work_dir" --languages "$languages"; then
296-
log_success "Unit tests passed : --languages $languages"
297-
return 0
371+
cd "$old_pwd"
372+
log_success "Test result validation passed for $language"
373+
return 0
374+
}
375+
376+
# Check and diagnose test environment for a language
377+
diagnose_test_environment() {
378+
local language="$1"
379+
local work_dir="$2"
380+
381+
log_info "Diagnosing test environment for $language..."
382+
383+
local lang_dir="$work_dir/$language"
384+
local pack_dir="$lang_dir/testpack-$language"
385+
local test_dir="$pack_dir/test"
386+
local results_dir="$lang_dir/test-results"
387+
388+
# Check directory structure
389+
log_info "Directory structure check:"
390+
if [[ -d "$lang_dir" ]]; then
391+
log_success " ✓ Language directory exists: $lang_dir"
298392
else
299-
log_error "Unit tests failed : --languages $languages"
393+
log_error " ✗ Language directory missing: $lang_dir"
300394
return 1
301395
fi
396+
397+
if [[ -d "$pack_dir" ]]; then
398+
log_success " ✓ Pack directory exists: $pack_dir"
399+
else
400+
log_error " ✗ Pack directory missing: $pack_dir"
401+
fi
402+
403+
if [[ -d "$test_dir" ]]; then
404+
log_success " ✓ Test directory exists: $test_dir"
405+
local test_count
406+
test_count=$(find "$test_dir" -name "*.qlref" 2>/dev/null | wc -l)
407+
log_info " → Found $test_count test reference files"
408+
else
409+
log_error " ✗ Test directory missing: $test_dir"
410+
fi
411+
412+
if [[ -d "$results_dir" ]]; then
413+
log_info " → Test results directory exists: $results_dir"
414+
local result_count
415+
result_count=$(find "$results_dir" -name "*.json" 2>/dev/null | wc -l)
416+
log_info " → Found $result_count result files"
417+
else
418+
log_warning " → Test results directory not found: $results_dir"
419+
fi
302420
}
303421

304422
# Validate single language
@@ -444,11 +562,27 @@ validate_language() {
444562
# Run unit tests if enabled
445563
if [[ "$RUN_TESTS" == "true" ]]; then
446564
log_info " → Running unit tests for $language..."
447-
if run_unit_tests_for_languages "$language" "$TEST_DIR"; then
448-
log_success " ✓ Unit tests passed for $language"
449-
else
450-
log_error "Unit tests failed for $language"
565+
566+
# Run unit tests (execution)
567+
local unit_test_failed=false
568+
if ! run_unit_tests_for_language "$language" "$TEST_DIR"; then
569+
log_error "Unit test execution failed for $language"
570+
unit_test_failed=true
571+
fi
572+
573+
# Validate unit test results (even if execution failed, we want to see what we can)
574+
if ! validate_unit_test_results "$language" "$TEST_DIR"; then
575+
log_error "Unit test result validation failed for $language"
576+
unit_test_failed=true
577+
fi
578+
579+
if [[ "$unit_test_failed" == "true" ]]; then
580+
log_error " ✗ Unit tests failed for $language"
581+
# Provide diagnostic information
582+
diagnose_test_environment "$language" "$TEST_DIR"
451583
return 1
584+
else
585+
log_success " ✓ Unit tests passed for $language"
452586
fi
453587
else
454588
log_info " → Skipping unit tests for $language (disabled)"
@@ -464,11 +598,14 @@ main() {
464598
parse_arguments "$@"
465599

466600
log_info "Starting end-to-end CLI validation..."
467-
log_info "Repository: $REPO_ROOT"
468-
log_info "Test directory: $TEST_DIR"
469-
log_info "Languages: ${LANGUAGES[*]}"
470-
log_info "Query kinds: ${QUERY_KINDS[*]}"
471-
log_info "Run tests: $RUN_TESTS"
601+
log_info "=============================================="
602+
log_info "Configuration:"
603+
log_info " Repository: $REPO_ROOT"
604+
log_info " Test directory: $TEST_DIR"
605+
log_info " Languages: ${LANGUAGES[*]}"
606+
log_info " Query kinds: ${QUERY_KINDS[*]}"
607+
log_info " Run tests: $RUN_TESTS"
608+
log_info "=============================================="
472609

473610
# Check if QLT binary exists
474611
if [[ ! -f "$QLT_BINARY" ]]; then
@@ -497,34 +634,55 @@ main() {
497634
local failed=0
498635
local failed_languages=()
499636

500-
# Validate each language
637+
# Validate each language (continue even if some fail)
501638
for language in "${LANGUAGES[@]}"; do
639+
log_info ""
640+
log_info "========================================="
641+
log_info "Processing language: $language"
642+
log_info "========================================="
643+
502644
if validate_language "$language"; then
503645
((passed++))
646+
log_success "✓ Language $language validation PASSED"
504647
else
505648
((failed++))
506649
failed_languages+=("$language")
650+
log_error "✗ Language $language validation FAILED"
651+
log_warning "Continuing with remaining languages..."
507652
fi
508653
done
509654

510655
echo
511-
log_info "=== Validation Summary ==="
512-
log_success "Number of Languages Passed: $passed"
656+
echo
657+
log_info "=============================================="
658+
log_info "=== FINAL VALIDATION SUMMARY ==="
659+
log_info "=============================================="
660+
log_info "Total languages tested: $((passed + failed))"
661+
log_success "Languages passed: $passed"
662+
513663
if [[ $failed -gt 0 ]]; then
514-
log_error "Number of Languages Failed: $failed"
664+
log_error "Languages failed: $failed"
515665
if [[ ${#failed_languages[@]} -gt 0 ]]; then
516666
log_error "Failed languages: ${failed_languages[*]}"
667+
echo
668+
log_info "Troubleshooting information:"
669+
log_info "- Generated files are available in: $TEST_DIR"
670+
log_info "- Check unit test results in: $TEST_DIR/<language>/test-results/"
671+
log_info "- Review query validation output above for compilation errors"
672+
log_info "- For detailed test failures, examine the validation output for each language"
517673
fi
518674
else
519675
log_success "All languages passed validation and unit testing."
520676
fi
521677

678+
echo
522679
if [[ $failed -eq 0 ]]; then
523-
log_success "All validations passed! 🎉"
680+
log_success "🎉 ALL VALIDATIONS PASSED! 🎉"
524681
log_info "Generated files are available in: $TEST_DIR"
525682
exit 0
526683
else
527-
log_error "Some validations failed. 😞"
684+
log_error "😞 SOME VALIDATIONS FAILED"
685+
log_error "Failed: $failed out of $((passed + failed)) languages"
528686
log_info "Generated files are available for troubleshooting in: $TEST_DIR"
529687
exit 1
530688
fi
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
{% if query_kind == "path-problem" %}
2-
{% comment %}Path-problem queries with none() source and sink return no results{% endcomment %}
3-
{% else %}
4-
{% comment %}Problem queries that select all expressions return results for each expression{% endcomment %}
5-
| {{ test_file_prefix }}.cpp:2:5:2:7 | Replace this with your query. |
6-
| {{ test_file_prefix }}.cpp:4:5:4:12 | Replace this with your query. |
7-
| {{ test_file_prefix }}.cpp:4:12:4:13 | Replace this with your query. |
8-
{% endif %}
1+
{%- if query_kind == "path-problem" -%}
2+
edges
3+
nodes
4+
subpaths
5+
#select
6+
{%- else -%}
7+
| {{ test_file_prefix }}.cpp:0:0:0:0 | {{ test_file_prefix }}.cpp | Replace this with your query. |
8+
| file://:0:0:0:0 | | Replace this with your query. |
9+
{%- endif -%}
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
{% if query_kind == "path-problem" %}
2-
{% comment %}Path-problem queries with none() source and sink return no results{% endcomment %}
3-
{% else %}
4-
{% comment %}Problem queries that select all expressions return results for each expression{% endcomment %}
5-
| {{ test_file_prefix }}.cs:7:9:7:11 | Replace this with your query. |
6-
| {{ test_file_prefix }}.cs:9:5:9:16 | Replace this with your query. |
7-
{% endif %}
1+
{%- if query_kind == "path-problem" -%}
2+
edges
3+
nodes
4+
subpaths
5+
#select
6+
{%- else -%}
7+
| {{ test_file_prefix }}.cs:0:0:0:0 | {{ test_file_prefix }}.cs | Replace this with your query. |
8+
| {{ test_file_prefix }}.dll:0:0:0:0 | {{ test_file_prefix }}.dll | Replace this with your query. |
9+
| file:///Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Console.dll:0:0:0:0 | /Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Console.dll | Replace this with your query. |
10+
| file:///Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Core.dll:0:0:0:0 | /Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Core.dll | Replace this with your query. |
11+
| file:///Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Private.CoreLib.dll:0:0:0:0 | /Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Private.CoreLib.dll | Replace this with your query. |
12+
| file:///Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Runtime.dll:0:0:0:0 | /Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.Runtime.dll | Replace this with your query. |
13+
| file:///Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.dll:0:0:0:0 | /Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/System.dll | Replace this with your query. |
14+
| file:///Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/mscorlib.dll:0:0:0:0 | /Users/data-douser/.qlt/packages/d5b581ceb3581aa73dec1e8b043e68bf/codeql/csharp/tools/osx64/mscorlib.dll | Replace this with your query. |
15+
| file://:0:0:0:0 | | Replace this with your query. |
16+
{%- endif -%}

src/CodeQLToolkit.Features/Templates/Query/csharp/new-query.liquid

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
import {{ql_language_import}}
1212

13-
from Expr e
14-
select e, "Replace this with your query."
13+
from File f
14+
select f, "Replace this with your query."
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{% if query_kind == "path-problem" %}
2-
{% comment %}Path-problem queries with none() source and sink return no results{% endcomment %}
3-
{% else %}
4-
{% comment %}Problem queries that select all expressions return results for each expression{% endcomment %}
5-
| {{ test_file_prefix }}.go:4:5:4:17 | Replace this with your query. |
6-
| {{ test_file_prefix }}.go:4:10:4:17 | Replace this with your query. |
7-
{% endif %}
1+
{%- if query_kind == "path-problem" -%}
2+
edges
3+
nodes
4+
subpaths
5+
#select
6+
{%- else -%}
7+
{%- endif -%}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{% if query_kind == "path-problem" %}
2-
{% comment %}Path-problem queries with none() source and sink return no results{% endcomment %}
3-
{% else %}
4-
{% comment %}Problem queries that select all expressions return results for each expression{% endcomment %}
5-
| {{ test_file_prefix }}.java:4:9:4:11 | Replace this with your query. |
6-
| {{ test_file_prefix }}.java:6:5:6:16 | Replace this with your query. |
7-
{% endif %}
1+
{%- if query_kind == "path-problem" -%}
2+
edges
3+
nodes
4+
subpaths
5+
#select
6+
{%- else -%}
7+
{%- endif -%}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{% if query_kind == "path-problem" %}
2-
{% comment %}Path-problem queries with none() source and sink return no results{% endcomment %}
3-
{% else %}
4-
{% comment %}Problem queries that select all expressions return results for each expression{% endcomment %}
5-
| {{ test_file_prefix }}.js:2:5:2:12 | Replace this with your query. |
6-
| {{ test_file_prefix }}.js:6:5:6:17 | Replace this with your query. |
7-
| {{ test_file_prefix }}.js:6:10:6:17 | Replace this with your query. |
8-
{% endif %}
1+
{%- if query_kind == "path-problem" -%}
2+
WARNING: module 'PathGraph' has been deprecated and may be removed in future (TestQueryKindPathProblem.ql:12,8-27)
3+
nodes
4+
edges
5+
#select
6+
{%- else -%}
7+
| {{ test_file_prefix }}.js:0:0:0:0 | {{ test_file_prefix }}.js | Replace this with your query. |
8+
{%- endif -%}

0 commit comments

Comments
 (0)