From 137ae09a7047edba183f78968f98bf1408e49d62 Mon Sep 17 00:00:00 2001 From: Joseph2910 <184524642+Joseph2910@users.noreply.github.com> Date: Wed, 29 Oct 2025 16:15:54 +0000 Subject: [PATCH] fix: Solve reliability issues --- .../Set-up/scripts/get_local_settings.sh | 2 +- .../app/api/GetValidationExceptions/route.ts | 2 +- .../src/Web/app/api/UpdateException/route.ts | 4 ++-- .../api/UpdateExceptionServiceNowId/route.ts | 2 +- .../src/Web/app/exceptions/[filter]/page.tsx | 2 +- .../src/Web/app/exceptions/page.tsx | 2 +- .../src/Web/app/lib/pagination.ts | 4 ++-- .../CohortManager/src/Web/app/lib/utils.ts | 4 ++-- scripts/azure/GetImageTagsByManifest.sh | 14 +++++++------- scripts/deployment/get-docker-names.sh | 4 ++-- scripts/docker/dgoss.sh | 6 +++--- scripts/docker/docker.lib.sh | 18 +++++++++--------- scripts/docker/tests/docker.test.sh | 2 +- scripts/githooks/check-markdown-format.sh | 2 +- scripts/githooks/scan-secrets.sh | 2 +- scripts/podman/amd64-build-from-compose.sh | 6 +++--- scripts/reports/create-sbom-report.sh | 4 ++-- scripts/reports/sonar-analysis.sh | 6 +++--- scripts/shellscript-linter.sh | 2 +- tests/playwright-tests/scripts/health-check.js | 8 ++++---- 20 files changed, 48 insertions(+), 48 deletions(-) diff --git a/application/CohortManager/Set-up/scripts/get_local_settings.sh b/application/CohortManager/Set-up/scripts/get_local_settings.sh index 586488c3b9..9cdff47bb8 100755 --- a/application/CohortManager/Set-up/scripts/get_local_settings.sh +++ b/application/CohortManager/Set-up/scripts/get_local_settings.sh @@ -35,7 +35,7 @@ process_files() { # Read the content of the found local.settings.json file and echo it into the target file cat "$file" >> $OUTPUT_SCRIPT # Check if this is the last file and add EOF accordingly - if [ $index -lt $file_count ]; then + if [[ $index -lt $file_count ]]; then echo -e "\nEOF" >> $OUTPUT_SCRIPT fi done diff --git a/application/CohortManager/src/Web/app/api/GetValidationExceptions/route.ts b/application/CohortManager/src/Web/app/api/GetValidationExceptions/route.ts index 2d0a1867ab..50bbd58737 100644 --- a/application/CohortManager/src/Web/app/api/GetValidationExceptions/route.ts +++ b/application/CohortManager/src/Web/app/api/GetValidationExceptions/route.ts @@ -146,7 +146,7 @@ export async function GET(request: Request) { const isReport = searchParams.get("isReport"); const exceptionCategory = searchParams.get("exceptionCategory"); const reportDate = searchParams.get("reportDate"); - const page = Math.max(1, parseInt(searchParams.get("page") || "1", 10)); + const page = Math.max(1, Number.parseInt(searchParams.get("page") || "1", 10)); // Handle single exception requests - get fresh data from store if (exceptionId !== null) { diff --git a/application/CohortManager/src/Web/app/api/UpdateException/route.ts b/application/CohortManager/src/Web/app/api/UpdateException/route.ts index de54882220..18cc545b59 100644 --- a/application/CohortManager/src/Web/app/api/UpdateException/route.ts +++ b/application/CohortManager/src/Web/app/api/UpdateException/route.ts @@ -48,8 +48,8 @@ export async function PUT(request: NextRequest) { ); } - const exceptionId = parseInt(updateRequest.ExceptionId, 10); - if (isNaN(exceptionId) || exceptionId === 0) { + const exceptionId = Number.parseInt(updateRequest.ExceptionId, 10); + if (Number.isNaN(exceptionId) || exceptionId === 0) { console.warn("Invalid ExceptionId provided:", updateRequest.ExceptionId); return NextResponse.json( { error: "Invalid ExceptionId provided" }, diff --git a/application/CohortManager/src/Web/app/api/UpdateExceptionServiceNowId/route.ts b/application/CohortManager/src/Web/app/api/UpdateExceptionServiceNowId/route.ts index f4f422800f..96323d94db 100644 --- a/application/CohortManager/src/Web/app/api/UpdateExceptionServiceNowId/route.ts +++ b/application/CohortManager/src/Web/app/api/UpdateExceptionServiceNowId/route.ts @@ -51,7 +51,7 @@ export async function PUT(request: NextRequest) { const exceptionId = typeof rawExceptionId === "number" ? rawExceptionId - : parseInt(rawExceptionId, 10); + : Number.parseInt(rawExceptionId, 10); if (!Number.isFinite(exceptionId) || exceptionId <= 0) { console.warn("Invalid ExceptionId provided:", rawExceptionId); return NextResponse.json( diff --git a/application/CohortManager/src/Web/app/exceptions/[filter]/page.tsx b/application/CohortManager/src/Web/app/exceptions/[filter]/page.tsx index 6c5eef5b8e..5f3466367f 100644 --- a/application/CohortManager/src/Web/app/exceptions/[filter]/page.tsx +++ b/application/CohortManager/src/Web/app/exceptions/[filter]/page.tsx @@ -42,7 +42,7 @@ export default async function Page({ const sortBy = resolvedSearchParams.sortBy === "0" ? 0 : 1; const currentPage = Math.max( 1, - parseInt(resolvedSearchParams.page || "1", 10) + Number.parseInt(resolvedSearchParams.page || "1", 10) ); const sortOptions = [ diff --git a/application/CohortManager/src/Web/app/exceptions/page.tsx b/application/CohortManager/src/Web/app/exceptions/page.tsx index 45c9d433db..38e0ece1a1 100644 --- a/application/CohortManager/src/Web/app/exceptions/page.tsx +++ b/application/CohortManager/src/Web/app/exceptions/page.tsx @@ -52,7 +52,7 @@ export default async function Page({ const sortBy = resolvedSearchParams.sortBy === "0" ? 0 : 1; const currentPage = Math.max( 1, - parseInt(resolvedSearchParams.page || "1", 10) + Number.parseInt(resolvedSearchParams.page || "1", 10) ); const sortOptions = [ diff --git a/application/CohortManager/src/Web/app/lib/pagination.ts b/application/CohortManager/src/Web/app/lib/pagination.ts index d922d6c4d3..5ada5d2837 100644 --- a/application/CohortManager/src/Web/app/lib/pagination.ts +++ b/application/CohortManager/src/Web/app/lib/pagination.ts @@ -116,12 +116,12 @@ export function extractPageFromUrl(url: string): number { try { const parsed = new URL(url); const value = parsed.searchParams.get(PAGE_PARAM); - const page = value ? parseInt(value, 10) : 1; + const page = value ? Number.parseInt(value, 10) : 1; return Number.isNaN(page) ? 1 : Math.max(1, page); } catch { const pageRegex = new RegExp(`[?&]${PAGE_PARAM}=(\\d+)`); const match = pageRegex.exec(url); - const page = match ? parseInt(match[1], 10) : 1; + const page = match ? Number.parseInt(match[1], 10) : 1; return Number.isNaN(page) ? 1 : Math.max(1, page); } } diff --git a/application/CohortManager/src/Web/app/lib/utils.ts b/application/CohortManager/src/Web/app/lib/utils.ts index 6bd144eb6b..0f8a248bd8 100644 --- a/application/CohortManager/src/Web/app/lib/utils.ts +++ b/application/CohortManager/src/Web/app/lib/utils.ts @@ -18,7 +18,7 @@ export const formatCompactDate = (dateString: string): string => { if (!dateString) return ""; const date = new Date(dateString); - if (isNaN(date.getTime())) return ""; + if (Number.isNaN(date.getTime())) return ""; const day = String(date.getDate()).padStart(2, "0"); const month = String(date.getMonth() + 1).padStart(2, "0"); @@ -37,7 +37,7 @@ export function getCurrentDate(): string { export function formatGenderValue(gender?: number | string | null): string { if (gender === null || gender === undefined || gender === "") return ""; - const genderNum = typeof gender === "string" ? parseInt(gender, 10) : gender; + const genderNum = typeof gender === "string" ? Number.parseInt(gender, 10) : gender; if (genderNum === 1) return "Male"; if (genderNum === 2) return "Female"; if (genderNum === 9) return "Unspecified"; diff --git a/scripts/azure/GetImageTagsByManifest.sh b/scripts/azure/GetImageTagsByManifest.sh index cfd63cb395..9ebf78aae9 100644 --- a/scripts/azure/GetImageTagsByManifest.sh +++ b/scripts/azure/GetImageTagsByManifest.sh @@ -55,28 +55,28 @@ while [[ "$#" -gt 0 ]]; do shift done -if [ -z "${containerRegistry}" ]; then +if [[ -z "${containerRegistry}" ]]; then echo "Please provide a container registry argument" exit 1 fi # stop processing if no image name is provided -if [ -z "${functionAppName}" ]; then +if [[ -z "${functionAppName}" ]]; then echo "Please provide an image name as an argument" exit 1 fi -if [ -z "${subscriptionId}" ]; then +if [[ -z "${subscriptionId}" ]]; then echo "Please provide a Subscription ID argument" exit 1 fi -if [ -z "${resourceGroup}" ]; then +if [[ -z "${resourceGroup}" ]]; then echo "Please provide a resource group argument" exit 1 fi -if [ verbose == true ]; then +if [[ verbose == true ]]; then echo "function app name: $functionAppName" echo "subscription Id: $subscriptionId" echo "resourceGroup: $resourceGroup" @@ -88,13 +88,13 @@ fi digest=$(az acr repository show --name $containerRegistry --image $functionAppName:$tag --query 'digest' --output tsv 2> /dev/null) # stop processing if the image does not exist -if [ -z "$digest" ]; then +if [[ -z "$digest" ]]; then echo "Image $image not found in $containerRegistry" exit 1 fi # echo the digest -if [ verbose == true ]; then +if [[ verbose == true ]]; then echo $digest fi diff --git a/scripts/deployment/get-docker-names.sh b/scripts/deployment/get-docker-names.sh index 41aac351dc..6bac3acffb 100644 --- a/scripts/deployment/get-docker-names.sh +++ b/scripts/deployment/get-docker-names.sh @@ -54,7 +54,7 @@ IFS=$', \n' echo "Adding Docker compose file includes..." files_to_process=(${COMPOSE_FILES_CSV}) -while [ ${#files_to_process[@]} -gt 0 ]; do +while [[ ${#files_to_process[@]} -gt 0 ]]; do compose_file="${files_to_process[0]}" files_to_process=("${files_to_process[@]:1}") # Remove the first file from the list includes=($(yq -r '.include[]' "${compose_file}")) @@ -121,7 +121,7 @@ for compose_file in ${COMPOSE_FILES_CSV}; do echo done -if [ ${#non_matched_changes[@]} -ne 0 ]; then +if [[ ${#non_matched_changes[@]} -ne 0 ]]; then # Remove duplicates (non-matched items across several compose files) mapfile -t unique_changes < <(printf "%s\n" "${non_matched_changes[@]}" | sort -u) diff --git a/scripts/docker/dgoss.sh b/scripts/docker/dgoss.sh index e573a48ba6..3db6d745ad 100644 --- a/scripts/docker/dgoss.sh +++ b/scripts/docker/dgoss.sh @@ -24,7 +24,7 @@ error() { cleanup() { set +e { kill "$log_pid" && wait "$log_pid"; } 2> /dev/null - if [ -n "$CONTAINER_LOG_OUTPUT" ]; then + if [[ -n "$CONTAINER_LOG_OUTPUT" ]]; then cp "$tmp_dir/docker_output.log" "$CONTAINER_LOG_OUTPUT" fi rm -rf "$tmp_dir" @@ -47,7 +47,7 @@ run(){ case "$GOSS_FILES_STRATEGY" in mount) info "Starting $CONTAINER_RUNTIME container" - if [ "$CONTAINER_RUNTIME" == "podman" -a $# == 2 ]; then + if [[ "$CONTAINER_RUNTIME" == "podman" -a $# == 2 ]]; then id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}" sleep infinity) else id=$($CONTAINER_RUNTIME run -d -v "$tmp_dir:/goss:z" "${@:2}") @@ -113,7 +113,7 @@ case "$1" in fi [[ $GOSS_SLEEP ]] && { info "Sleeping for $GOSS_SLEEP"; sleep "$GOSS_SLEEP"; } info "Container health" - if [ "true" != "$($CONTAINER_RUNTIME inspect -f '{{.State.Running}}' "$id")" ]; then + if [[ "true" != "$($CONTAINER_RUNTIME inspect -f '{{.State.Running}}' "$id")" ]]; then $CONTAINER_RUNTIME logs "$id" >&2 error "the container failed to start" fi diff --git a/scripts/docker/docker.lib.sh b/scripts/docker/docker.lib.sh index 187871050b..6028d30789 100644 --- a/scripts/docker/docker.lib.sh +++ b/scripts/docker/docker.lib.sh @@ -127,7 +127,7 @@ function version-create-effective-file() { local version_file="$dir/VERSION" local build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')} - if [ -f "$version_file" ]; then + if [[ -f "$version_file" ]]; then # shellcheck disable=SC2002 cat "$version_file" | \ sed "s/\(\${yyyy}\|\$yyyy\)/$(date --date="${build_datetime}" -u +"%Y")/g" | \ @@ -167,9 +167,9 @@ function docker-get-image-version-and-pull() { # match it by name and version regex, if given. local versions_file="${TOOL_VERSIONS:=$(git rev-parse --show-toplevel)/.tool-versions}" local version="latest" - if [ -f "$versions_file" ]; then + if [[ -f "$versions_file" ]]; then line=$(grep "docker/${name} " "$versions_file" | sed "s/^#\s*//; s/\s*#.*$//" | grep "${match_version:-".*"}") - [ -n "$line" ] && version=$(echo "$line" | awk '{print $2}') + [[ -n "$line" ]] && version=$(echo "$line" | awk '{print $2}') fi # Split the image version into two, tag name and digest sha256. @@ -178,7 +178,7 @@ function docker-get-image-version-and-pull() { # Check if the image exists locally already if ! docker images | awk '{ print $1 ":" $2 }' | grep -q "^${name}:${tag}$"; then - if [ "$digest" != "latest" ]; then + if [[ "$digest" != "latest" ]]; then # Pull image by the digest sha256 and tag it docker pull \ --platform linux/amd64 \ @@ -222,11 +222,11 @@ function _replace-image-latest-by-specific-version() { local dockerfile="${dir}/Dockerfile.effective" local build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')} - if [ -f "$versions_file" ]; then + if [[ -f "$versions_file" ]]; then # First, list the entries specific for Docker to take precedence, then the rest but exclude comments content=$(grep " docker/" "$versions_file"; grep -v " docker/" "$versions_file" ||: | grep -v "^#") echo "$content" | while IFS= read -r line; do - [ -z "$line" ] && continue + [[ -z "$line" ]] && continue line=$(echo "$line" | sed "s/^#\s*//; s/\s*#.*$//" | sed "s;docker/;;") name=$(echo "$line" | awk '{print $1}') version=$(echo "$line" | awk '{print $2}') @@ -234,7 +234,7 @@ function _replace-image-latest-by-specific-version() { done fi - if [ -f "$dockerfile" ]; then + if [[ -f "$dockerfile" ]]; then # shellcheck disable=SC2002 cat "$dockerfile" | \ sed "s/\(\${yyyy}\|\$yyyy\)/$(date --date="${build_datetime}" -u +"%Y")/g" | \ @@ -292,9 +292,9 @@ function _get-git-branch-name() { local branch_name=$(git rev-parse --abbrev-ref HEAD) - if [ -n "${GITHUB_HEAD_REF:-}" ]; then + if [[ -n "${GITHUB_HEAD_REF:-}" ]]; then branch_name=$GITHUB_HEAD_REF - elif [ -n "${GITHUB_REF:-}" ]; then + elif [[ -n "${GITHUB_REF:-}" ]]; then # shellcheck disable=SC2001 branch_name=$(echo "$GITHUB_REF" | sed "s#refs/heads/##") fi diff --git a/scripts/docker/tests/docker.test.sh b/scripts/docker/tests/docker.test.sh index 8f487b8f9a..27adb9b98a 100755 --- a/scripts/docker/tests/docker.test.sh +++ b/scripts/docker/tests/docker.test.sh @@ -44,7 +44,7 @@ function main() { done echo "Total: ${#tests[@]}, Passed: $(( ${#tests[@]} - status )), Failed: $status" test-docker-suite-teardown - [ $status -gt 0 ] && return 1 || return 0 + [[ $status -gt 0 ]] && return 1 || return 0 } # ============================================================================== diff --git a/scripts/githooks/check-markdown-format.sh b/scripts/githooks/check-markdown-format.sh index 698df4a57e..faca1c9032 100755 --- a/scripts/githooks/check-markdown-format.sh +++ b/scripts/githooks/check-markdown-format.sh @@ -51,7 +51,7 @@ function main() { ;; esac - if [ -n "$files" ]; then + if [[ -n "$files" ]]; then if command -v markdownlint > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then files="$files" run-markdownlint-natively else diff --git a/scripts/githooks/scan-secrets.sh b/scripts/githooks/scan-secrets.sh index 5482c8b194..825368db56 100755 --- a/scripts/githooks/scan-secrets.sh +++ b/scripts/githooks/scan-secrets.sh @@ -62,7 +62,7 @@ function get-cmd-to-run() { ;; esac # Include base line file if it exists - if [ -f "$dir/scripts/config/.gitleaks-baseline.json" ]; then + if [[ -f "$dir/scripts/config/.gitleaks-baseline.json" ]]; then cmd="$cmd --baseline-path $dir/scripts/config/.gitleaks-baseline.json" fi # Include the config file diff --git a/scripts/podman/amd64-build-from-compose.sh b/scripts/podman/amd64-build-from-compose.sh index d1e39a1a4e..a1e69b43f9 100755 --- a/scripts/podman/amd64-build-from-compose.sh +++ b/scripts/podman/amd64-build-from-compose.sh @@ -14,7 +14,7 @@ check_tools() { return 0 fi - if [ ${#missing_tools[@]} -ne 0 ]; then + if [[ ${#missing_tools[@]} -ne 0 ]]; then echo "Error: Missing required tools: ${missing_tools[*]}" >&2 echo "Please install the missing tools and try again." >&2 exit 1 @@ -70,7 +70,7 @@ parse_services() { } # Validate arguments -if [ $# -eq 0 ]; then +if [[ $# -eq 0 ]]; then echo "Usage: $0 [compose-file2] ..." >&2 exit 1 fi @@ -122,7 +122,7 @@ for compose_file in "$@"; do done # Check if the while loop failed (due to pipe) - if [ ${PIPESTATUS[1]} -ne 0 ]; then + if [[ ${PIPESTATUS[1]} -ne 0 ]]; then echo "Error: Build failed for $compose_file" >&2 exit 1 fi diff --git a/scripts/reports/create-sbom-report.sh b/scripts/reports/create-sbom-report.sh index c03239d051..d4650c08a7 100755 --- a/scripts/reports/create-sbom-report.sh +++ b/scripts/reports/create-sbom-report.sh @@ -48,7 +48,7 @@ function create-report() { function run-syft-natively() { -if [ -z "$CHECK_DOCKER_IMAGE" ]; then +if [[ -z "$CHECK_DOCKER_IMAGE" ]]; then syft scan docker:$CHECK_DOCKER_IMAGE \ --config "$PWD/scripts/config/syft.yaml" \ --output spdx-json="$PWD/$SBOM_REPOSITORY_REPORT.tmp.json" @@ -68,7 +68,7 @@ function run-syft-in-docker() { # shellcheck disable=SC2155 local image=$(name=ghcr.io/anchore/syft docker-get-image-version-and-pull) - if [ -z "$CHECK_DOCKER_IMAGE" ]; then + if [[ -z "$CHECK_DOCKER_IMAGE" ]]; then docker run --rm --platform linux/amd64 \ --volume "$PWD":/workdir \ --volume /var/run/docker.sock:/var/run/docker.sock \ diff --git a/scripts/reports/sonar-analysis.sh b/scripts/reports/sonar-analysis.sh index 06c45365f9..a1621255d0 100644 --- a/scripts/reports/sonar-analysis.sh +++ b/scripts/reports/sonar-analysis.sh @@ -90,7 +90,7 @@ dotnet test "${UNIT_TEST_DIR}/ConsolidatedTests.csproj" \ # Run frontend tests to generate lcov coverage echo "Running frontend tests to generate coverage" -if [ -d "application/CohortManager/src/Web" ]; then +if [[ -d "application/CohortManager/src/Web" ]]; then ( cd application/CohortManager/src/Web || exit 1 # Configure npm to better handle transient 429s and avoid extra work @@ -103,13 +103,13 @@ if [ -d "application/CohortManager/src/Web" ]; then export npm_config_prefer_offline=true # Retry npm ci with simple backoff to survive registry rate limits n=0 - until [ "$n" -ge 3 ] + until [[ "$n" -ge 3 ]] do npm ci && break n=$((n+1)) sleep $((n*15)) done - if [ "$n" -ge 3 ]; then + if [[ "$n" -ge 3 ]]; then echo "npm ci failed after retries" >&2 exit 1 fi diff --git a/scripts/shellscript-linter.sh b/scripts/shellscript-linter.sh index 8b3fe09c05..072b430ec5 100755 --- a/scripts/shellscript-linter.sh +++ b/scripts/shellscript-linter.sh @@ -21,7 +21,7 @@ function main() { cd "$(git rev-parse --show-toplevel)" - [ -z "${file:-}" ] && echo "WARNING: 'file' variable not set, defaulting to itself" + [[ -z "${file:-}" ]] && echo "WARNING: 'file' variable not set, defaulting to itself" local file=${file:-scripts/shellscript-linter.sh} if command -v shellcheck > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then file="$file" run-shellcheck-natively diff --git a/tests/playwright-tests/scripts/health-check.js b/tests/playwright-tests/scripts/health-check.js index c1e68d991f..7fd13f780c 100644 --- a/tests/playwright-tests/scripts/health-check.js +++ b/tests/playwright-tests/scripts/health-check.js @@ -15,16 +15,16 @@ function parseArgs() { if (skipNext) { skipNext = false; continue; } const a = args[i]; if (a === '--max-attempts' && args[i + 1]) { - const parsed = parseInt(args[i + 1], 10); - if (isNaN(parsed) || parsed < 1) { + const parsed = Number.parseInt(args[i + 1], 10); + if (Number.isNaN(parsed) || parsed < 1) { console.error('Error: --max-attempts must be a positive number'); process.exit(1); } maxAttempts = parsed; skipNext = true; } else if (a === '--interval' && args[i + 1]) { - const parsed = parseInt(args[i + 1], 10); - if (isNaN(parsed) || parsed < 100) { + const parsed = Number.parseInt(args[i + 1], 10); + if (Number.isNaN(parsed) || parsed < 100) { console.error('Error: --interval must be at least 100ms'); process.exit(1); }