imbajin commented on code in PR #3161:
URL: https://github.com/apache/hugegraph/pull/3161#discussion_r3840559504


##########
hugegraph-server/hugegraph-dist/src/assembly/travis/test-check-jacoco-report.sh:
##########
@@ -0,0 +1,438 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -uo pipefail
+
+SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+REPO_ROOT=$(cd "${SCRIPT_DIR}/../../../../.." && pwd)
+VALIDATOR="${SCRIPT_DIR}/check-jacoco-report.sh"
+TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/jacoco-report-test.XXXXXX")
+CASE_OUTPUT=""
+CASE_RC=0
+
+trap 'rm -rf "${TMP_DIR}"' EXIT
+
+fail() {
+    echo "FAIL: $1" >&2
+    [[ -z "${CASE_OUTPUT}" ]] || printf '%s\n' "${CASE_OUTPUT}" >&2
+    exit 1
+}
+
+run_case() {
+    CASE_OUTPUT=$("${VALIDATOR}" "$@" 2>&1)
+    CASE_RC=$?
+}
+
+run_report_case() {
+    run_case --require-test-report "${TMP_DIR}/tests.xml" "$@"
+}
+
+run_case_with_timeout() {
+    CASE_OUTPUT=$(timeout 2 "${VALIDATOR}" "$@" 2>&1)

Review Comment:
   ⚠️ Important
   
   Blocking: no. The malformed-argument timeout case invokes GNU-only 
`timeout`, but the workflow does not install a dependency and this script is 
also runnable locally. On stock macOS Bash, `timeout` is absent (only 
`gtimeout` may be available), so the harness exits 127 instead of checking the 
validator's termination. Please use a portable Python subprocess timeout or 
explicitly detect/install `gtimeout`.



##########
hugegraph-server/hugegraph-dist/src/assembly/travis/check-jacoco-report.sh:
##########
@@ -0,0 +1,200 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -uo pipefail
+
+REQUIRED_SESSIONS=()
+REQUIRED_TEST_REPORTS=()
+REQUIRED_COVERED_GROUPS=()
+while (( $# > 0 )); do
+    case "${1}" in
+        --require-session)
+            if (( $# < 2 )) || [[ -z "${2:-}" || "${2}" == --* ]]; then
+                echo "ERROR: --require-session requires a non-empty value" >&2
+                exit 1
+            fi
+            REQUIRED_SESSIONS+=("${2}")
+            shift 2
+            ;;
+        --require-test-report)
+            if (( $# < 2 )) || [[ -z "${2:-}" || "${2}" == --* ]]; then
+                echo "ERROR: --require-test-report requires a non-empty value" 
>&2
+                exit 1
+            fi
+            REQUIRED_TEST_REPORTS+=("${2}")
+            shift 2
+            ;;
+        --require-covered-group)
+            if (( $# < 2 )) || [[ -z "${2:-}" || "${2}" == --* ]]; then
+                echo "ERROR: --require-covered-group requires a non-empty 
value" >&2
+                exit 1
+            fi
+            REQUIRED_COVERED_GROUPS+=("${2}")
+            shift 2
+            ;;
+        --*)
+            echo "ERROR: unknown option: ${1}" >&2
+            exit 1
+            ;;
+        *)
+            break
+            ;;
+    esac
+done
+
+if (( ${#REQUIRED_SESSIONS[@]} == 0 )); then
+    echo "ERROR: at least one --require-session is required" >&2
+    exit 1
+fi
+
+if (( ${#REQUIRED_TEST_REPORTS[@]} == 0 )); then
+    echo "ERROR: at least one --require-test-report is required" >&2
+    exit 1
+fi
+
+REPORT_FILE="${1:-}"
+if (( $# > 0 )); then
+    shift
+fi
+
+if [[ -z "${REPORT_FILE}" || ! -s "${REPORT_FILE}" ]]; then
+    echo "ERROR: JaCoCo report not found or empty: ${REPORT_FILE:-<unset>}" >&2
+    exit 1
+fi
+
+if (( $# == 0 )); then
+    echo "ERROR: at least one expected module is required" >&2
+    exit 1
+fi
+
+validate_test_report() {
+    local test_report="${1}"
+
+    if [[ ! -s "${test_report}" ]]; then
+        echo "ERROR: Surefire report not found or empty: ${test_report}" >&2
+        return 1
+    fi
+
+    local test_count
+    if ! test_count=$(python3 - "${test_report}" <<'PY'
+import sys
+import xml.etree.ElementTree as ET
+
+root = ET.parse(sys.argv[1]).getroot()
+if root.tag.rsplit("}", 1)[-1] != "testsuite" or "tests" not in root.attrib:
+    raise ValueError("not a Surefire testsuite report")
+test_count = int(root.attrib["tests"])

Review Comment:
   ⚠️ Important
   
   Blocking: yes. This only validates that the Surefire `tests` attribute is 
positive; it ignores `skipped`, so a report such as `tests=2 skipped=2` is 
accepted even though the suite executed no tests. Because the 
aggregate/session/module checks can still pass from other reactor output, CI 
may upload coverage for an all-skipped suite. Please require at least one 
non-skipped test (for example `tests - skipped > 0`) and add an all-skipped 
contract case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to